LOCALROOT = comp/
include make.rules

DIRS = comp make.rules makefile TAG

help: force
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	@echo " "
	@echo "top level compiler makefile knows about:"
	@echo " "
	@echo "  tape          = make a tape archive"
	@echo "  archive       = make an archive locally"
	@echo "  extract       = extract an archive from tape"
	@echo "  floppyarchive = make an archive on floppy disk"
	@echo "  floppyextract = extract an archive from floppy disk"
	@echo "  clean         = prune all executables and objects"
	@echo "  increment     = increment the major version no."
	@echo "  all           = build the compiler (all 3 stages)"
	@echo "                  and build all other subdirectories"
	@echo "  ismene        = build the ismene simulator"
	@echo "  release       = release all executables into the RELEASEROOT"
	@echo "  install       = is exactly the same as release"
	@echo "  regression    = run the regression tests"
	@echo "  binary.release= create a binary release of the compiler"

all: force
	@if [ -d comp ] ; then                                          \
            ( cd comp ; $(MAKE) all )                                 ; \
         fi                                                           ; \
         export PATH=`pwd`/comp/bin3:$(PATH)                          ; \
	 if [ -d comp/autotest ] ; then                                 \
            ( cd comp/autotest ; make all )                           ; \
         fi

ismene: force
	@if [ -d ismene ] ; then                                        \
            ( unset MAKELEVEL ; cd ismene ; make all )                ; \
         fi

everything: force
	@echo "------------------------------------------------------------------------"
	@echo "make $@ (only makes sense when using compiler with other packages)"
	@echo "------------------------------------------------------------------------"
	@( $(MAKE) all )
	@if [ -d os ] ; then                                            \
            ( cd os ; $(MAKE) all )                                   ; \
         fi                                                           ; \
	 if [ -d ismene ] ; then                                        \
            ( cd ismene ; $(MAKE) all )                               ; \
         fi                                                           ; \
	 if [ -d games/MorlocTower ] ; then                             \
            ( cd games/MorlocTower ; make all )                       ; \
         fi                                                           ; \

regression: force
	@if [ ! -x comp/bin3/gm2-i386-gas ] ; then                      \
             echo "$(LOGNAME) you must build the compiler first before testing it" ; \
             ( cd comp ; $(MAKE) all )                                ; \
         fi                                                           ; \
         if [ -x comp/bin3/gm2-i386-gas ] ; then                        \
             echo "--------------------------------------------"      ; \
	     echo "                $@"                                ; \
             echo "--------------------------------------------"      ; \
             export PATH=`pwd`/comp/bin3:$(PATH)                      ; \
	     if [ -d comp/autotest ] ; then                             \
                ( cd comp/autotest ; $(MAKE) all )                    ; \
             fi                                                       ; \
         fi

binary.release: force
	@( cd comp ; $(MAKE) binary.release )

install: force
	@if [ -d comp ] ; then                                          \
            ( cd comp ; $(MAKE) install )                             ; \
         fi

release: force
	@if [ -d comp ] ; then                                          \
            ( cd comp ; $(MAKE) release )                             ; \
         fi

install.everything: force
	@( $(MAKE) install )
	@if [ -d os ] ; then                                            \
            ( cd os ; $(MAKE) install )                               ; \
         fi
	@if [ -d ismene ] ; then                                        \
            ( cd ismene ; $(MAKE) install )                           ; \
         fi

release.everything: force
	@( $(MAKE) release )
	@if [ -d os ] ; then                                            \
            ( cd os ; $(MAKE) release )                               ; \
         fi
	@if [ -d ismene ] ; then                                        \
            ( cd ismene ; $(MAKE) release )                           ; \
         fi

tape: clean archive
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	@if [ "$(ARCH)" = "i386" ] ; then                               \
	    echo "this should be run as root"                         ; \
        fi
	@echo "placing $(DIRS) onto tape"
	@if [ "$(TAPE)" = "" ] ; then                                   \
	     echo "You need to set TAPE in make.rules"                ; \
        else                                                            \
	     if [ "`ls /dev/$(TAPE)`" != "" ] ; then                    \
                 tar cf - m2.tar.gz | $(DD) of=/dev/$(TAPE) bs=16k    ; \
                 $(RM) m2.tar.gz                                      ; \
                 mt -f /dev/$(TAPE) rewind                            ; \
                 echo "Checking to see the archive is intact"         ; \
                 $(DD) if=/dev/$(TAPE) bs=16k | tar xvf -             ; \
                 gzip -t m2.tar.gz                                    ; \
             else                                                       \
                 echo "/dev/$(TAPE) does not exist"                   ; \
                 echo "edit make.rules"                               ; \
	     fi                                                       ; \
        fi

archive: force
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	@if [ -f m2.tar.gz ] ; then                                     \
	    $(RM) m2.tar.gz-                                          ; \
            $(MV) m2.tar.gz m2.tar.gz-                                ; \
        fi                                                            ; \
	tar cf - $(DIRS) | gzip -9 > m2.tar.gz                        ; \
	gzip -t m2.tar.gz                                             ; \
	ls -l m2.tar.gz

floppyarchive: force
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	@ans="n"                                                      ; \
        echo -n "Do you want to make a floppy disk [y/n]? "           ; \
        read ans                                                      ; \
        if [ "$$ans" = "y" ] ; then                                     \
	    cp m2.tar.gz /ls120                                       ; \
            sync                                                      ; \
            echo "floppy disk made"                                   ; \
        else                                                            \
            echo "archive NOT copied to floppy disk"                  ; \
        fi

floppyextract: force
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	@if [ "$(FD)" = "" ] ; then                                     \
	     echo "You need to set FD in make.rules"                  ; \
        else                                                            \
	     if [ "`ls /dev/$(FD)`" != "" ] ; then                      \
                 if [ -f m2.tar.gz ] ; then                             \
                     $(MV) m2.tar.gz m2.tar.gz-                       ; \
                 fi                                                   ; \
                 if [ -f $(ARCHIVEFILE) ] ; then                        \
                     number=`cat $(ARCHIVEFILE)`                      ; \
                 else                                                   \
                     number="0"                                       ; \
                 fi                                                   ; \
                 echo "Harddisk   compiler archive: $$number"         ; \
                 $(RM) -r extract ;  mkdir extract                    ; \
                 cd extract                                           ; \
                 cp /ls120/m2.tar.gz m2.tar.gz                        ; \
                 if gzip -t m2.tar.gz ; then                            \
                     gzip -d -c m2.tar.gz | tar xf - comp/.archive    ; \
                     new=`cat comp/.archive`                          ; \
                     echo "Floppydisk compiler archive: $$new"        ; \
                     if [ $$number -lt $$new ] ; then                   \
                         $(MV) m2.tar.gz ..                           ; \
                         cd ..                                        ; \
                         if [ -d comp- ] ; then                         \
                            $(RM) -rf comp-                           ; \
                         fi                                           ; \
                         if [ -d comp ] ; then                          \
                            $(MV) comp comp-                          ; \
                         fi                                           ; \
                         gzip -d -c m2.tar.gz | tar xf -              ; \
                         $(INCFILE) $(ARCHIVEFILE)                    ; \
                     else                                               \
                         echo "archive on floppy disk is older than the one on your harddisk!" ; \
                         cd ..                                        ; \
                     fi                                               ; \
                 else                                                   \
                     echo "gzip consistancy check FAILED"             ; \
                     cd ..                                            ; \
                 fi                                                   ; \
             else                                                       \
                 echo "/dev/$(FD) does not exist"                     ; \
                 echo "edit make.rules"                               ; \
	     fi                                                       ; \
        fi

tapeextract: force
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	@if [ "$(ARCH)" = "i386" ] ; then                               \
	    echo "this should be run as root"                         ; \
        fi
	@if [ "$(TAPE)" = "" ] ; then                                   \
	     echo "You need to set TAPE in make.rules"                ; \
        else                                                            \
	     if [ "`ls /dev/$(TAPE)`" != "" ] ; then                    \
                 $(RM) m2.tar.gz                                      ; \
                 $(DD) if=/dev/$(TAPE) bs=16k | tar xvf -             ; \
                 gzip -t m2.tar.gz                                    ; \
                 gzip -d -c m2.tar.gz | tar tf -                      ; \
             else                                                       \
                 echo "/dev/$(TAPE) does not exist"                   ; \
                 echo "edit make.rules"                               ; \
	     fi                                                       ; \
        fi

increment: force
	$(INCFILE) $(ARCHIVEFILE)

clean: force
	@echo "---------------------------------------"
	@echo "                $@"
	@echo "---------------------------------------"
	echo "BINDIR = $(BINDIR)"
	@if [ -d comp ] ; then                                          \
            ( cd comp ; $(MAKE) clean )                               ; \
         fi
	@if [ -d os ] ; then                                            \
            ( cd os ; make clean )                                    ; \
         fi
	@if [ -d ismene ] ; then                                           \
            ( cd ismene ; make clean )                                   ; \
         fi
	@if [ -d games/MorlocTower ] ; then                             \
            ( cd games/MorlocTower ; make clean )                     ; \
         fi
	@if [ -d comp/autotest ] ; then                                 \
            ( cd comp/autotest ; make clean )                         ; \
         fi


force:


#
# $Log: makefile,v $
# Revision 1.16  1999/01/05 16:08:48  gaius
# minor changes
#
# Revision 1.15  1999/01/05 11:14:30  gaius
# added ismene target
#
# Revision 1.14  1997/05/27 13:28:33  gaius
# make the file TAG part of an archive
#
# Revision 1.13  1997/05/27 12:57:57  gaius
# fixed install and regression tests for release 3.1
#
# Revision 1.12  1997/05/21 10:43:49  gaius
# fixed bug in makefile target everything
#
# Revision 1.11  1997/05/21 10:18:12  gaius
# fixed to make the release target only release the compiler.
#
# Revision 1.10  1997/05/21 08:17:06  gaius
# fixed install scripts inside makefiles. Removed confusion between
# release and install. Both are now treated the same. Made compiler
# handle -h option correctly.
#
# Revision 1.9  1996/10/14 12:50:09  gaius
# minor modifications
#
# Revision 1.8  1996/09/30 13:52:18  gaius
# changes to reflect simulator name change
#
# Revision 1.7  1996/07/26 11:50:03  gaius
# minor modifications
#
# Revision 1.6  1996/06/12 12:27:53  gaius
# modified to operate with the RELEASEROOT environment variable
#
# Revision 1.5  1996/06/12 09:06:30  gaius
# modified the clean to operate with CVS without causing so many anoying errors
#
# Revision 1.4  1996/06/04 10:51:06  gaius
# Added Log command
#
#
