# this is a general makefile for uClinux tools, etc...
#
# compiled by Craig Comstock <craig_comstock@yahoo.com>
# last updated 3/21/2001
#
# based on instructions by Bernhard Kuhn <kuhn@batian.lpr.e-technik.tu-muenchen.de> 
# http://c3po.kc-inc.net/mail/uclinux/0420.html
# and various bits from the uClinux mailing list archives at
# http://c3po.kc-inc.net/mail/uclinux
#
# Requirements: wget, and standard GCC/PRC tools
# I use tcsh, you may need to alter a few things if you use sh or something else.
#
# How to use:
# 
# make download
# make xcopilot
# make gcc
# make uclinux
# make palm-loader
#
# As far as I know palm-loader works only on Palm V and the Visor. I will be working
# on figuring it out for older palms (pro/IIIs).
# 
# This makefile and future better versions are available at my website
# http://palm-linux.sourceforge.net

BASEDIR = /root
DOWNLOAD_PATH = $(BASEDIR)/arch
#DOWNLOAD_PATH = /wind/Downloads
WGET_OPTIONS = -nc -P $(DOWNLOAD_PATH)

download:
	wget $(WGET_OPTIONS) http://jack.testnetz.detecon.net/software/devel_tools/xcopilot-0.6.6.tar.gz
	wget $(WGET_OPTIONS) http://www.rcs.ei.tum.de/~kuhn/uclinux/xcopilot-0.6.6_display.c_diff
	wget $(WGET_OPTIONS) ftp://ftp.gnu.org/gnu/binutils/binutils-2.9.1.tar.gz
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/utilities/binutils-2.9.1.0.6.pic.diff.gz
	wget $(WGET_OPTIONS) ftp://ftp.gnu.org/gnu/gcc/gcc-2.7.2.3.tar.gz
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/utilities/uClinuxgcc-kit-160899.tar.gz
	wget $(WGET_OPTIONS) http://palm-linux.sourceforge.net/uclinux/uclinuxgcc-kit-160899.Makefile.patched
	wget $(WGET_OPTIONS) http://palm-linux.sourceforge.net/uclinux/genromfs.c.patched
	wget $(WGET_OPTIONS) ftp://ftp.kernel.org/pub/linux/kernel/v2.0/linux-2.0.33.tar.gz
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/uClinux-2.0.x/patch2.0.33-170199.diff.gz
	wget $(WGET_OPTIONS) http://www.rcs.ei.tum.de/~kuhn/uclinux/linux-2.0.33_gcc-2.7.2.3.patch
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/ports/xcopilot/pilot-160899.tar.gz
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/utilities/genromfs-0.3.tar.bz2
	wget $(WGET_OPTIONS) http://www.rcs.ei.tum.de/~kuhn/uclinux/genromfs-0.3.patch
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/utilities/coff2flt-0.3.tar.bz2
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/libraries/uC-libc-160899.tar.gz
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/libraries/uC-libm-060199.tar.bz2
	wget $(WGET_OPTIONS) http://www.uclinux.org/pub/uClinux/ports/xcopilot/palm-loader.0.1.0.tar.gz

xcopilot:
	tar -xzf $(DOWNLOAD_PATH)/xcopilot-0.6.6.tar.gz
	cd xcopilot-0.6.6 ; patch display.c < $(DOWNLOAD_PATH)/xcopilot-0.6.6_display.c_diff
	cd xcopilot-0.6.6 ; ./configure ; make
	cp xcopilot-0.6.6/xcopilot $(BASEDIR)/bin
	rm -rf xcopilot-0.6.6

gcc:
	rm -rf /usr/local/gnu
	install -d /usr/local/gnu
	rm -rf uClinuxgcc-kit-160899
	cp $(DOWNLOAD_PATH)/binutils-2.9.1.tar.gz .
	cp $(DOWNLOAD_PATH)/gcc-2.7.2.3.tar.gz .
	tar -xzf $(DOWNLOAD_PATH)/uClinuxgcc-kit-160899.tar.gz
	gunzip $(DOWNLOAD_PATH)/binutils-2.9.1.0.6.pic.diff.gz
	cp $(DOWNLOAD_PATH)/binutils-2.9.1.0.6.pic.diff uclinuxgcc-kit-160899
	gzip $(DOWNLOAD_PATH)/binutils-2.9.1.0.6.pic.diff
	cp $(DOWNLOAD_PATH)/uclinuxgcc-kit-160899.Makefile.patched uclinuxgcc-kit-160899/Makefile
	cd uclinuxgcc-kit-160899 ; make
	echo "export PATH=/usr/local/gnu/bin:$PATH" > /usr/local/bin/init68k
	chmod a+x /usr/local/bin/init68k
	rm -rf binutils-2.9.1.tar.gz
	rm -rf gcc-2.7.2.3.tar.gz
	rm -rf uclinuxgcc-kit-160899

uclinux:
	/usr/local/bin/init68k
	rm -rf pilot
	rm -rf genromfs-0.3
	rm -rf coff2flt-0.3
	rm -rf uC-libc
	rm -rf uC-libm
	rm -rf linux
	tar -xzf $(DOWNLOAD_PATH)/pilot-160899.tar.gz 
	bzip2 -cd $(DOWNLOAD_PATH)/genromfs-0.3.tar.bz2 | tar -x
	bzip2 -cd $(DOWNLOAD_PATH)/coff2flt-0.3.tar.bz2 | tar -x
	gunzip -cd $(DOWNLOAD_PATH)/uC-libc-160899.tar.gz | tar -x
	bzip2 -cd $(DOWNLOAD_PATH)/uC-libm-060199.tar.bz2 | tar -x
	tar -xzf $(DOWNLOAD_PATH)/linux-2.0.33.tar.gz
	cd linux ; gunzip -cd $(DOWNLOAD_PATH)/patch2.0.33-170199.diff.gz | patch -p1
	cd linux ; patch arch/m68knommu/Makefile < $(DOWNLOAD_PATH)/linux-2.0.33_gcc-2.7.2.3.patch
	make -C linux oldconfig
	make -C uC-libc
	make -C uC-libm
	cp $(DOWNLOAD_PATH)/genromfs.c.patched genromfs-0.3/genromfs.c
	make -C genromfs-0.3
	make -C coff2flt-0.3
	cp pilot/pppd/usr.include.net/if.h uC-libc/include/net
	make -C linux
	make -C pilot
	cp pilot/romdisk/romdisk.img linux/romfs.img
	make -C linux dep ; make -C linux clean
	make -C linux vmlinux
	make -C linux updateromfs
	cp linux/vmlinux.rom ~/.xcopilot/vmlinux.rom
	cp linux/vmlinux.trg ~/.xcopilot/vmlinux.trg

palm-loader:
	tar xfz $(DOWNLOAD_PATH)/palm-loader.0.1.0.tar.gz
	cp $(DOWNLOAD_PATH)palm-loader.Makefile ./
	setenv PATH $(PRC_TOOLS_PATH)/bin:$PATH
	make -C palm-loader.0.1.0