# Makefile for all of CONGEN.
# This makefile will recompile CONGEN and rerun all of the test cases.
# Before this procedure is executed, the procedure, cgdefs, in the root
# directory must be executed.
# 

CC = cc
SHELL = /bin/sh
FTPDIR = $(CGROOT)/ftpdir
CGTAPE = /dev/mt/tps0d7nrns

# The following list of directories must be in the correct order for
# the installation procedure to succeed.

PROG_DIRS = $(CGPS)/mkproto $(CGPS)/myacc $(CGPS)/fcpp $(CGPS)/flecs \
            $(CGPS)/wrapgen $(CGS) $(CGPS)
# DOC_DIR = $(CGD)
DOC_DIR = 
DATA_DIRS = $(CGDATA) $(CGTD)
TEST_DIRS = $(CGT) 

DIRS = $(PROG_DIRS) $(DOC_DIR) $(DATA_DIRS) $(TEST_DIRS)

SOURCES = cgdefs.com convex.make descrip.mms fixmake.c makefile \
          rs6000.make sgim1i4.make sgi_r4k_i5.3_c5.3_m2_a32.make sparc.make unicos.make

install all: 	setup
	(cd $(CGPS); \
	 $(MAKE) fsplit; \
	 $(CGBIN)/install -c -m 555 fsplit $(CGBIN))
	for d in $(DIRS) ; do \
	    (cd $$d; echo '---->' $(MAKE) $@ in $$d; $(MAKE) $@ ;) \
	done 

setup:	fixmake
	(cd $(CGPS) ; ./install.sh -m 555 -c install.sh $(CGBIN)/install)
	(cd $(CG); \
	 for f in $(CGPS)/*/makefile.gen $(CGS)/makefile.gen \
                  $(CGPS)/makefile.gen $(CGS)/usermake.gen \
		  $(CGP)/emap/makefile.gen $(CGD)/makefile.gen ; do\
	     echo $$f ; \
	     ./fixmake $(CGPLATFORM) \
                       $$f \
                       `echo $$f | awk '{print substr($$0,1,length($$0)-4)}'` ; \
         done )

fixmake: fixmake.c
	case "$(CGPLATFORM)" in \
	  sparc ) gcc -o fixmake fixmake.c ;; \
	  hpux ) cc -Aa -o fixmake fixmake.c ;; \
	  linux ) cc -o fixmake -static fixmake.c ;; \
	  * )    $(CC) -o fixmake fixmake.c ;; \
	esac
	$(CGBIN)/install -m 555 -c fixmake $(CGBIN)

clean:	
	for d in $(DIRS); do \
	    echo '---->' $$d: $(MAKE) clean ; \
	    (cd $$d; $(MAKE) clean) done

prepare: 
	touch fixmake.c
	$(MAKE) fixmake
	$(MAKE) setup
	for d in $(PROG_DIRS) $(TEST_DIRS) $(DATA_DIRS) ; do \
	    echo '---->' $$d: ; \
	    (cd $$d; $(MAKE) prepare) \
	done

check:	
	more $(CGT)/*.dif

tovax:  tovax.time
	for d in $(DIRS); do \
	    echo '---->' $$d: $(MAKE) tovax ; \
	    (cd $$d; $(MAKE) tovax) done

tovax.time: $(SOURCES)
	cp $? dino
	touch tovax.time

# tomendel:
# 	-rcsall co -q RCS/\*
# 	-find /u/mendel/usr/congen/ -exec chmod u+w \{\} \;
# 	-echo $(CGROOT)/../../ -\> mendel \\n \
# 	      install /usr/congen/\; \\n \
# 	      except RCS\; \\n \
# 	      except convex\; \\n \
# 	      except vms\; \\n \
# 	      except unicos\; \\n \
# 	      except rs6000\; \\n \
# 	      except hpux\; \\n \
# 	      except foo\*\; \\n \
# 	| rdist -R -f -
# 	-rdist -c -R $(CGT)/RCS mendel:/usr/congen/v2/test/RCS
# 	-find /u/mendel/usr/congen/v2 -exec chmod ugo-w \{\} \;
# 
# tosherlock:
# 	-rcsall co -q RCS/\*
# 	-find /u/sherlock/usr2/congen/v2 -exec chmod u+w \{\} \;
# 	-echo $(CG) -\> sherlock \\n \
# 	      install /usr2/congen/v2\; \\n \
# 	      except RCS\; \\n \
# 	      except convex\; \\n \
# 	      except vms\; \\n \
# 	      except unicos\; \\n \
# 	      except rs6000\; \\n \
# 	      except hpux\; \\n \
# 	      except foo\*\; \\n \
# 	| rdist -R -f -
# 	-rdist -c -R $(CGT)/RCS sherlock:/usr2/congen/v2/test/RCS
# 	-find /u/sherlock/usr2/congen/v2 -exec chmod ugo-w \{\} \;
# 
# tocrick:
# 	-rcsall co -q RCS/\*
# 	-rsh crick find /usr/local/congen -exec chmod u+w \{\} \;
# 	-echo $(CG) -\> crick \\n \
# 	      install /usr/local/congen/v2\; \\n \
# 	      except RCS\; \\n \
# 	      except convex\; \\n \
# 	      except vms\; \\n \
# 	      except unicos\; \\n \
# 	      except rs6000\; \\n \
# 	      except hpux\; \\n \
# 	      except foo\*\; \\n \
# 	| rdist -R -f -
# 	-rdist -c -R $(CGT)/RCS crick:/usr/local/congen/v2/test/RCS
# 	-rsh crick find /usr/local/congen/v2 -exec chmod ugo-w \{\} \;

tar.Z:	$(FTPDIR)/congen-2.2.tar.Z $(FTPDIR)/local-2.1.tar.Z

LOCALFILES = src/rcs src/makeinfo src/texindex gnuemacs bruc.emacs \
	     src/gnudiff src/gnumake src/gnugrep \
	     lib/alloca.h lib/getopt.h lib/gnu.a lib/gnusrc 

$(FTPDIR)/congen-2.2.tar.Z:
	if [ -r $(TMPDIR)/congen ] ; then \
	    rm -rf $(TMPDIR)/congen ; \
	fi
	-rcsall co -q RCS/\*
	-$(MAKE) prepare
	-$(MAKE) install
	-$(MAKE) clean
	mkdir -p $(TMPDIR)/congen/v2
	(cd $(TMPDIR)/congen/v2; tar cf - -C $(CGROOT) . | tar xf - )
	-find $(TMPDIR)/congen/ \( -name "*~*" -o -name "#*" \) -exec rm -f \{\} \;
	-find $(TMPDIR)/congen/ -name "*~*" -exec rm -f \{\} \;
	-find $(TMPDIR)/congen/ -name "foo*" -exec rm -f \{\} \;
	-(cd $(TMPDIR)/congen/; rcsall rcspurge -f RCS/\* )
	-(cd $(TMPDIR)/congen; chmod u+w cgdefs )
	-(cd $(TMPDIR); \
	  tar cf - congen | compress >$(FTPDIR)/congen-2.2.tar.Z;)
	-chmod 444 $(FTPDIR)/congen-2.2.tar.Z

$(FTPDIR)/local-2.1.tar.Z:
	if [ -r $(TMPDIR)/local ] ; then \
	    rm -rf $(TMPDIR)/local ; \
	fi
	mkdir $(TMPDIR)/local
	(cd $(TMPDIR)/local; tar cf - -C /usr/local $(LOCALFILES) | tar xfo - )
	-find $(TMPDIR)/local/ \( -name "*~*" -o -name "#*" \) -exec rm -f \{\} \;
	-find $(TMPDIR)/local/ -name "*~*" -exec rm -f \{\} \;
	-find $(TMPDIR)/local/ -name "foo*" -exec rm -f \{\} \;
	-(cd $(TMPDIR); \
	  tar cf - local | compress >$(FTPDIR)/local-2.1.tar.Z)
	-chmod 444 $(FTPDIR)/local-2.1.tar.Z

tape:
	echo "Using $(CGTAPE)"
	mt -t $(CGTAPE) status
	(cd $(FTPDIR); \
	 mt -t $(CGTAPE) retension ; \
	 tar cvf $(CGTAPE) congen.tar.Z local.tar.Z ; \
	 mt -t $(CGTAPE) rewind ; \
	 tar Cvf $(CGTAPE) ; \
	 mt -t $(CGTAPE) rewind ; \
	 echo Completed at `date` \\007)

.DEFAULT:
	co $<


