# Please try to understand the installation procedure before you mess
# around with this Makefile. It does pay off!

# With the exception of the top level directory and this directory
# there are always two makefiles.  The first one is called
# "IMakefile" and it is used to build the makefile used in
# making the programs and those makefiles are called "Makefile".

# INSTALLATION_NUMs already used (I recommend that you keep these definitions alone
# and that use any number greater than 5.)
# 1 is for my own machine.
# 2 is for the machine of the Menil Foundation, Houston, TX.
# 3 is for the Statistics Department of Purdue University.
# 4 is for Siemens, QM 24, Munich, West Germany.
# 5 is for myself again to simulate another installation.

INSTALLATION_NUM = 1

# Directories, where "Makefile"s are to be generated from "IMakefile"s.
# These directories are specified relative to the setup directory!
# The documentation directory is handled a little bit differently.
PREPARE_DIRS = \
	../lib\
	../sup ../otherc ../h\
	../dvitps ../dvitps/src ../dvitps/h ../dvitps/psr ../dvitps/capab\
	../pfd2tfm ../pfd2tfm/src ../pfd2tfm/h ../pfd2tfm/evs\
	../printpdr\
	../pfd ../pfd/regular ../pfd/regular-II ../pfd/extra\
	../doc ../doc/SliTeX ../psfig ../psfig/ps-ex ../man

# Directories in which to execute "make all, make print etc.".
DIRS = \
	../lib\
	../sup ../otherc ../h\
	../dvitps\
	../printpdr\
	../pfd2tfm\
	../pfd\
	../man ../doc ../psfig

# Directories in which to execute "make install".
INSTALL_DIRS = $(DIRS)

# Directories in which to execute "make clean".
CLEAN_DIRS =   $(DIRS)

CPP = /lib/cpp

# Make all the "Makefile"s.
prepare:
#	Remove certain files to force recompilation and relinking.
	rm -f   ../otherc/defaults.o ../pfd2tfm/src/pfd2tfm\
		../pfd2tfm/src/printpdr\
		../dvitps/src/special.o ../dvitps/src/dvitps\
		../printpdr/printpdr\
		../man/docman.tex ../man/*.l ../psfig/xwindows.tex
	make prepare-setup
	cd ../pfd/regular; make prepare
	cd ../pfd/regular-II; make prepare

# local-defs.xx contains the stuff extracted from local-defs and furthermore
# some definitions used by the C preprocessor.
local-defs.xx:	setup-ld.awk local-defs makefile
	awk -f  setup-ld.awk 'InstallationNumPattern=[$(INSTALLATION_NUM)]' local-defs > $@

prepare-setup:	local-defs.xx setup-1.awk setup-2.awk makefile
	-for dir in $(PREPARE_DIRS) ; do\
		echo "Prepare Makefile from IMakefile in $$dir";\
		echo "#DO NOT CHANGE THIS MAKEFILE, generated from IMakefile at `date`" > \
			$$dir/Makefile;\
		awk -f setup-1.awk 	local-defs.xx $$dir/IMakefile |\
			$(CPP) -P -C |\
			awk -f setup-2.awk >> $$dir/Makefile;\
		cat closing.defs >> $$dir/Makefile;\
	done

all print depend lint relink:
	echo "Make \"$@\" in `pwd`"
	for dir in $(DIRS); do\
		cd $$dir;\
		echo "Make \"$@\" in `pwd`";\
			make $@;\
		cd ../setup;\
	done;

install:
	echo "Make \"$@\" in `pwd`"
	for dir in $(INSTALL_DIRS); do\
		cd $$dir;\
		echo "Make \"$@\" in `pwd`";\
			make $@;\
		cd ../setup;\
	done;

clean::
	echo "Make \"$@\" in `pwd`"
	for dir in $(CLEAN_DIRS); do\
		cd $$dir;\
		echo "Make \"$@\" in `pwd`";\
			make $@;\
		cd ../setup;\
	done;
clean::
	@echo make clean in `pwd`
	rm -f ,* \#* *.BAK *.bak *.CKP *~ *.o *.tmp ERR* a.out core
	rm -f .emacs_* lint ,* .,* *.dvi *.aux *.log *.toc *.lof *.lot
	rm -f dvitype.out texspell.out .*~ TAGS local-defs.xx
