#   Makefile, Copyright 1999 (c) by G. Fankhauser, L. Ruf & C. Jeker,
#   Swiss Federal Institute of Technology,
#   Computer Engineering and Networks Laboratory.
#
#   TOPSY -- A Teachable Operating System.
#            Implementation of a tiny and simple
#            micro kernel for teaching purposes.
#
#   For further information, please visit http://www.tik.ee.ethz.ch/~topsy
#
#   This software is provided under the terms of the GNU General Public Licence.
#   A full copy of the GNU GPL is provided in the file COPYING found in the 
#   development root of Topsy.
#
#       
#       File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Makefile,v $
#       Author(s):             
#       Affiliation:           ETH Zuerich, TIK
#       Version:               $Revision: 3052 $
#       Creation Date:         
#       Last Date of Change:   $Date: 2007-08-18 09:26:00 +0200 (Sam, 18 Aug 2007) $      by: $Author: sryffel $
###############################################################################
FIND=find
XARGS=xargs
RM=rm
ALLARCH=mips ia32 unix sa1100 ixp2400

info:
	@echo "Topsy pre3.0"
	@echo "These are the possible Platforms:"
	@echo "- make mips: builds Topsy for IDT MIPS (ecoff)."
	@echo "- make solaris/linux: builds a unix application Topsy."
	@echo "- make ia32: builds a ia32/i386 port of Topsy."
	@echo "             use make ia32-disk to copy Topsy on a floppy."
	@echo "             use make ia32-net  to create a network bootable image."
	@echo "             use make ia32-run  to run Topsy in a simulator."
	@echo "- make ixp: builds Topsy for Intel IXP1200."
	@echo "- make ixp2400: build Topsy for Intel IXP2400."
	@echo
	@echo "Perhaps you need to edit the right Makefiles/Platform File."
	@echo "- make clean: cleans the entire tree."

mips:
	@echo "Starting to make IDT MIPS R3000 Topsy,"
	@echo "for more info use \"make info\""
	$(MAKE) -f Makefiles/Makefile.IDT.mips

mips-simos:
	$(MAKE) -f Makefiles/Makefile.SimOS.mips

ia32:
	$(MAKE) -f Makefiles/Makefile.ia32.i386

ia32-disk:
	$(MAKE) -f Makefiles/Makefile.ia32.i386 alldisk

ia32-net:
	$(MAKE) -f Makefiles/Makefile.ia32.i386 netimag NETBOOT=-DNETBOOT

solaris:
	$(MAKE) -f Makefiles/Makefile.unix.solaris

linux:
	$(MAKE) -f Makefiles/Makefile.unix.linux

net:
	$(MAKE) -f Net/Makefile.net

# this is hack version of TopsyIXP, it needs to be fixed with the SegMap.h
ixp:
	@echo "Starting to make Intel IXP1200 Topsy,"
	@echo "for more info use \"make info\""
	$(MAKE) -f Makefiles/Makefile.ixp

ixp2400:
	@echo "Starting to make Intel IXP2400 Topsy,"
	@echo "for more info use \"make info\""
	$(MAKE) -f Makefiles/Makefile.ixp2400

# use this to remove compiled files
objclean: 
	$(RM) -rf $(addsuffix .obj, $(ALLARCH))
	$(RM) -f kernel* \
	   user* topsy* \
	   segmap.bin segmap.srec \
	   kSize uSize segmap Boot/mips/BootLinker 
	$(RM) -f Topsy/Version.c IO/ia32/devlist.h IO/ia32/classlist.h
	(cd Boot/ia32/Tools/CreateNetImg; make clean)
	(cd Boot/ia32/LowCore/CoreLoad; make clean)
	(cd Tools; make clean)
	$(RM) Config/ia32/vmplayer/bootcd/*

# use this to remove temporary files
clean: objclean
	$(FIND) . -name "*~"      -print | $(XARGS) $(RM) -f
	$(FIND) . -name ".*~"     -print | $(XARGS) $(RM) -f
	$(FIND) . -name "*.bak"   -print | $(XARGS) $(RM) -f
	$(FIND) . -name "TAGS"   -print | $(XARGS) $(RM) -f
	$(FIND) . -name "tags"   -print | $(XARGS) $(RM) -f
	$(FIND) . -name "semantic.cache"   -print | $(XARGS) $(RM) -f
	$(FIND) . -name ".*.swp"   -print | $(XARGS) $(RM) -f


# this is a practical command to show some statistics on source and object size
size:
	find . -name "*.[chS]" -print | xargs -x wc -l
	make -f Makefiles/Makefile.IDT.mips size
	make -f Makefiles/Makefile.ia32.i386 size
	make -f Makefiles/Makefile.unix.linux size
	make -f Makefiles/Makefile.sa1100
	make -f Makefiles/Makefile.ixp2400

update:
	svn update

commit:
	svn commit

diff:
	svn diff --diff-cmd /usr/bin/diff -x "-p"

patch: clean
	LC_ALL=C; TZ=UTC0; \
	[ -f ../patch.topsy.`date +%Y%m%d`.diff.gz ] && \
	rm   ../patch.topsy.`date +%Y%m%d`.diff.gz ; \
	cvs -Q -z 9 diff -NR -wbBPc | gzip -9 >../patch.topsy.`date +%Y%m%d`.diff.gz ; \
	@echo cvs -Q -z 9 diff -NR -bBc | gzip -9 >../patch.topsy.`date +%Y%m%d`.diff.gz ; \
	@echo "Applied by cd Topsy && gzip -dc ../patch.*.gz | patch -p0"

ia32-etags:
	etags `find -name "*.[hcsS]" | grep -v mips | grep -v sa1100 | grep -v ixp2400 | grep -v unix`

ia32-ctags:
	ctags `$(FIND) . -name "*.[hc]" | grep -v mips | grep -v sa1100 | grep -v ixp2400 | grep -v unix `

ia32-run: ia32-run-bochs

## Bochs: 
ia32-run-bochs: ia32-disk
#	../bochs-2.3/install/i386/bin/bochs -f ./Config/ia32/bochsrc
	../bochs-2.3/install/pentium/bin/bochs -f ./Config/ia32/bochsrc

## Qemu:
ia32-run-qemu: ia32-disk
	../qemu-0.9.0/install/pentium/bin/qemu  	-snapshot \
			-fda topsyimage \
			-boot a \
			-m 64 \
			-localtime \
			-monitor /dev/tty \
			-S \
			-s

## VMPlayer:
ia32-run-vmplayer: ia32-disk
	cp topsyimage Config/ia32/vmplayer/bootcd/
	mkisofs -J -r -b topsyimage -o topsyimage.iso Config/ia32/vmplayer/bootcd/
	sed -e "s\\ide1:0.fileName.*$\\ide1:0.fileName = \"`pwd`/topsyimage.iso\"\\g" -i Config/ia32/vmplayer/topsy-vmplayer.vmx
	vmplayer Config/ia32/vmplayer/topsy-vmplayer.vmx

