########################################
# This is the Master Makefile for FUDGIT
########################################

# Where to put the program onced compiled.
BINDIR=/usr/local/bin

# Where to put the help file.
LIBDIR=/usr/local/lib

# Where to put the man page.
MANDIR=/usr/local/man/man1

# The following options are selected by commenting '#' them in or out.

# Do you want dynamic loading? You must have gcc or be on an SGI.
# DYNLOAD = -Ddynamic-loading

# Do you have a dynamic loadable library of readline (e.g. on linux)?
# If not, leave the following commented out so that readline library
# will be built and statically linked to.
# DLLRL = -Duse-dll-readline

# The default yacc'er
YACC = yacc
# YACC = bison -y

# -=-==-=-=--=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# You should not need to edit below this point
# -=-==-=-=--=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# Just type 'make target' and then 'make install'
# 'target' is one of :
#     3868bsd, aix, datagen, freebsd, hpux, linux, irix4, irix5, next, osf,
#     sun3, sun4, svr4, ultrix, ultrix_vax, (vms)
# -=-==-=-=--=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #

SHELL = /bin/sh
VERSION = 2.42

#########################################################################
default:
	@echo Use to make one of the following:
	@echo
	@echo " 386bsd, aix, datagen, freebsd, hpux, irix4, irix5,"
	@echo " linux, next, osf, sun3, sun4, svr4, "
	@echo " ultrix, ultrix_vax, (vms)"
	@echo
	@echo And then type
	@echo
	@echo "	make install"
	@echo
	@echo Please read the \"INSTALL\" file first\!
	@echo

386bsd: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -D386bsd $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

aix: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Daix $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

datagen: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Ddatagen $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

freebsd: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dfreebsd $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

hpux: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dhpux $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

irix4: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dirix4 $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

irix5: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dirix5 $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

next: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dnext $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

osf: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dosf $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

sun3: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dsun3 $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

sun4: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dsun4 $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

solaris: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dsolaris $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

ultrix: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dultrix $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

ultrix_vax: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dultrix_vax $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

linux: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dlinux $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

svr4: simplecpp
	@echo Building Makefile.active ...
	docs/simplecpp -Dsvr4 $(DYNLOAD) $(DLLRL) Makefile.in Makefile.active
	@echo done.
	$(MAKE) LIBDIR="$(LIBDIR)" YACC="$(YACC)" -f Makefile.active

################################################################################
install: Makefile.active
	$(MAKE) BINDIR="$(BINDIR)" LIBDIR="$(LIBDIR)" MANDIR="$(MANDIR)" \
	YACC="$(YACC)" install -f Makefile.active

help: Makefile.active
	$(MAKE) help -f Makefile.active

doc: Makefile.active
	$(MAKE) doc -f Makefile.active

simplecpp:
	@echo Building included simple preprocessor ...
	(cd docs; $(MAKE) simplecpp)
	@echo done.

dist:
	-rm -f fudgit_$(VERSION).tar.gz fudgit_$(VERSION).tar
	(cd docs; $(MAKE) ../Credits )
	($(MAKE) cleanall)
	(cd ..; tar cf fudgit_$(VERSION).tar \
	Fudgit_$(VERSION)/[A-Z]* \
	Fudgit_$(VERSION)/.[a-z]* \
	Fudgit_$(VERSION)/docs \
	Fudgit_$(VERSION)/src \
	Fudgit_$(VERSION)/libs \
	Fudgit_$(VERSION)/tools \
	Fudgit_$(VERSION)/examples ; \
	gzip -9 -f fudgit_$(VERSION).tar; \
	mv fudgit_$(VERSION).tar.gz Fudgit_$(VERSION))

NewVersion: Makefile cleanall
	echo "Misc files:" > .contents
	wc [A-LN-Z]* docs/reference.tmpl \
	docs/fudgit.tex docs/*.l docs/*.c tools/* >> .contents
	echo "Code: " >> .contents
	wc Makefile* src/Makefile* libs/readline/Makefile* libs/dl/Makefile* \
	libs/dld/Makefile* libs/dld/dl/Makefile* \
	src/*.[hcy] libs/readline/*.[hc] libs/dl/*.[hc] \
	libs/dld/*.[hc] libs/dld/dl/*.[hc] >> .contents
	echo "Examples: " >> .contents
	wc examples/* >> .contents
	date > .date
	echo $(VERSION) > .version

clean:
	-/bin/rm -f core src/*.o src/*.u src/y.tab.h \
	src/math.tab.h src/y.tab.c src/mathparse.c src/y.output src/yacc.*

cleanall:
	-/bin/rm -f src/*.o src/core src/y.tab.h \
	src/math.tab.h src/y.tab.c src/mathparse.c \
	src/y.output src/yacc.*
	-/bin/rm -f fudgit Makefile.active
	-/bin/rm -f libs/lib*.a
	-(cd docs; $(MAKE) cleanall)
	-(cd libs/readline; $(MAKE) clean)
	-(cd libs/dl; $(MAKE) clean)
	-(cd libs/dld; $(MAKE) clean)
	-(cd libs/dld/dl; $(MAKE) clean)
	-(cd tools; $(MAKE) clean)

manual:  Makefile.active
	-(cd docs; $(MAKE) fudgit.ps)

Makefile.active:
	@echo "You must specify a target first (e.g. make linux)."; false
