# Main Makefile for Shag/OS


SUBDIRS = fconfig util bin lib sys drv objtest ubin

COMMANDS += setup bootdisk deco

all:
	@if [ ! -f config.var ] ; then \
		echo ""; \
		echo "Don't run 'make' in this directory"; \
		echo " - Create a build directory (ex: mkdir ../build)"; \
		echo " - Switch to that directory (ex: cd ../build)"; \
		echo " - Run 'config' from there  (ex: ../"`basename \`pwd\``"/config)"; \
		echo "Or read the file 'INSTALL' for more details"; \
		echo ""; \
	else \
		echo ""; \
		echo "More specific targets are needed"; \
		echo "Choose one of the following:"; \
		echo "	make setup	: general purpose setup"; \
		echo "	make bootdisk	: create a bootable floppy disk"; \
		echo "  make deco	: create deco utility"; \
		echo "or read the INSTALL document for more information"; \
		echo ""; \
	fi;


setup setup.done:
	@if [ $@ = setup.done ] ; then \
		echo "Setup has not been done first.  'make setup' implied..."; \
	fi; \
	TARG="\
		bin/config bin/all \
		lib/setup \
		util/all"; \
	if [ -d $(SRC)/sys/boot ] ; then \
		TARG="$$TARG sys/boot"; \
	fi; \
	if [ -d $(SRC)/sys/mkern ] ; then \
		TARG="$$TARG sys/mkern"; \
	fi; \
	$(MAKE) $$TARG 2>&1 | tee setup.log; \
	if [ $$? != 0 ] ; then \
		echo "output can be found in 'setup.log'"; \
		exit 1; \
	else \
		echo "setup complete. (output in 'setup.log')"; \
		touch setup.done; \
	fi; \
	if [ ! -f setup.done ] ; then \
		exit 1; \
	fi; \
	echo; \
	echo "The following commands can now be executed:"; \
	echo "    $(MAKE) bootprep        - prepare to build SOLO bootdisks"; \
	echo "    $(MAKE) bootdisk        - create a SOLO bootdisk"; \
	echo "    $(MAKE) deco            - build DECO"; \
	echo "    $(MAKE) mkern           - build ShagOS microkernel"; \


deco: setup.done
	@($(MAKE) lib/cparse/config; $(MAKE) lib/cparse/all; $(MAKE) util/deco/deco); \
	if [ $$? != 0 ]; then \
		echo "output can be found in 'deco.log'"; \
		exit 1; \
	else \
		echo "deco complete. (output in 'deco.log')"; \
	fi 2>&1 | tee deco.log

bootdisk: setup.done
	@$(MAKE) sys/boot/bootdisk; \
	if [ $$? != 0 ]; then \
		echo "output can be found in 'bootdisk.log'"; \
		exit 1; \
	else \
		echo "bootdisk complete. (output in 'bootdisk.log')"; \
	fi 2>&1 | tee bootdisk.log

bootprep: setup.done
	@$(MAKE) sys/boot/bootprep; \
	if [ $$? != 0 ]; then \
		echo "output can be found in 'bootprep.log'"; \
		exit 1; \
	else \
		echo "bootprep complete. (output in 'bootprep.log')"; \
	fi 2>&1 | tee booprep.log

# 'make alllinks' needs to be run after checking the source tree out of CVS
alllinks:
	ln -s Make ./Makefile
	ln -s bin/config ./config
	ln -s doc/install ./INSTALL
	ln -s doc/license1.txt ./COPYING
	ln -s bugs ./doc/BUGS
	ln -s lic_spl2 ./doc/COPYING
	ln -s ../sys/boot/doc ./doc/solo
	ln -s ../sys/mkern/doc ./doc/mkern
	ln -s ../fconfig/doc ./doc/sock
	ln -s ../lib/cparse ./doc/cparse
	ln -s ../util/deco ./doc/deco
	ln -s ../util/shacc ./doc/shacc
	ln -s solo/status ./doc/STATUS.solo
	ln -s solo/readme ./doc/README.solo
	ln -s solo/changes ./doc/CHANGES.solo
	ln -s solo/announce ./doc/ANNOUNCE.solo
	ln -s sock/readme ./doc/README.sock
	ln -s mkern/status ./doc/STATUS.mkern
	ln -s deco/readme ./doc/README.deco
	ln -s deco/status ./doc/STATUS.deco
	ln -s shacc/readme ./doc/README.shacc
	ln -s cparse/readme ./doc/README.cparse
	ln -s ../../../sys/boot/doc/changes ./lib/boot/m-pc/CHANGES
	ln -s ../../../sys/boot/doc/status ./lib/boot/m-pc/STATUS
	ln -s ../doc ./sys/boot/m-pc/doc
	ln -s doc/notes ./sys/boot/m-pc/NOTES
	ln -s doc/status ./sys/boot/m-pc/STATUS
	ln -s doc/changes ./sys/boot/m-pc/CHANGES
	ln -s doc/changes ./fconfig/CHANGES
	ln -s doc/status ./fconfig/STATUS
	ln -s ../doc/deco/deco.1 ./man/deco.1
	ln -s ../doc/shacc/shacc.1 ./man/shacc.1

