########################################
# This is the Master Makefile for FUDGIT
########################################
#
# macro definitions
# Change the following according to your needs
# Where to put the program onced compiled.
BINDIR=/usr/local/bin
# Where to put the help file.
# LIBDIR=/usr/local/lib
LIBDIR=/ds13/c/users/lacasse/lib
# Do you trust your optimizer?
# OPT = -g # -DYYDEBUG
OPT = -O
# Do you need safe or fast code? A bit safer not to use MACROPOP.
POP = -DMACROPOP # This is on
# POP = # This is off
# Define the following "YES" or "NO DLLIB= DLAR=" if you want (or not) 
# to compile the dynamic loading feature
# (available on IRIX, ULTRIX, SUNOS only, ignored on others)
DL = NO DLLIB= DLAR= # This is off
# DL = YES # This is on
# Do you want VI mode to be compiled?
VI_MODE = # This is off
# VI_MODE = -DVI_MODE  # This is on
# Undefine -ll here if your OS does not need it for its standard lexer
# This is the case for linux
# IRIX and ULTRIX needs it. 
# If you need it and it is undefined, ld(1) will complain about not
# being able to find yywrap() or yysomething().
# If you don't need it and it is defined, ld(1) will complain about not
# being able to find the 'l' library ('l' stands for 'lex').
LLFLAGS =  -ll # This is on
# LLFLAGS = # This is off
# Some shortcuts for me
DATE = `cat Date`
SRC = src
SHELL = /bin/sh
VERSION = 2.33

# You should not need to edit below this point except for 
# choosing your favorite compiler. 
# As it stands: you must use gcc on sun3 and the standard on others.

default:
	@echo Use to make one of the following:
	@echo
	@echo " aix, datagen, hpux, linux, irix4, next, osf, sun3, sun4, ultrix"
	@echo 
	@echo And then type
	@echo
	@echo "	make install"
	@echo
	@echo Please read the \"Installation\" file first\!
	@echo

aix:
	(cd src; $(MAKE) CC="c89" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" VI_MODE="$(VI_MODE)" -f Makefile.aix)

datagen:
	(cd src; $(MAKE) CC="cc" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" VI_MODE="$(VI_MODE)" -f Makefile.datagen)

hpux:
	(cd src; $(MAKE) CC="c89" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" VI_MODE="$(VI_MODE)" -f Makefile.hpux)

irix4:
	(cd src; $(MAKE) CC="cc" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" DL=$(DL) VI_MODE="$(VI_MODE)" -f Makefile.irix4)

next:
	(cd src; $(MAKE) CC="cc" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" VI_MODE="$(VI_MODE)" -f Makefile.next)

osf:
	(cd src; $(MAKE) CC="cc" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" VI_MODE="$(VI_MODE)" -f Makefile.osf)

sun3:
	(cd src; $(MAKE) CC=gcc LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" DL=$(DL) VI_MODE="$(VI_MODE)" -f Makefile.sun3)

sun4:
	(cd src; $(MAKE) CC="gcc -W" LIBDIR="$(LIBDIR)" OPT="$(OPT)" \
	POP="$(POP)" DL=$(DL) VI_MODE="$(VI_MODE)" -f Makefile.sun4)

ultrix:
	(cd src; $(MAKE) CC="cc" LIBDIR="$(LIBDIR)" OPT="$(OPT)"\
	POP="$(POP)" DL=$(DL) VI_MODE="$(VI_MODE)" -f Makefile.ultrix)

linux:
	(cd src; $(MAKE) CC="cc" LIBDIR="$(LIBDIR)" OPT="$(OPT)"\
	POP="$(POP)" VI_MODE="$(VI_MODE)" -f Makefile.linux)

install: help fudgit
	cp fudgit $(BINDIR)    # Do not strip the executable if DL = YES
	-if [ "$(DL)" = "YES" ] ;  then strip $(BINDIR)/fudgit ; fi
	chmod 755 $(BINDIR)/fudgit
	cp docs/fudgit.help $(LIBDIR)
	chmod 644 docs/fudgit.help

help:
	(cd docs; $(MAKE) LLFLAGS="$(LLFLAGS)" help)

doc:
	(cd docs; $(MAKE) doc)

dist:
	-rm -f fudgit_$(VERSION).tar.Z fudgit_$(VERSION).tar
	#(cd docs; $(MAKE) fudgit.ps.Z; $(MAKE) ../Credits )
	(cd docs; $(MAKE) LLFLAGS="$(LLFLAGS)" ../Credits )
	($(MAKE) cleanall)
	(cd ..; tar cf fudgit_$(VERSION).tar \
	Fudgit_$(VERSION)/[A-Z]* \
	Fudgit_$(VERSION)/docs \
	Fudgit_$(VERSION)/src \
	Fudgit_$(VERSION)/tools \
	Fudgit_$(VERSION)/examples ; \
	compress -f fudgit_$(VERSION).tar; \
	mv fudgit_$(VERSION).tar.Z Fudgit_$(VERSION))

NewVersion: Makefile cleanall
	echo "Misc files:" > Contents
	wc [A-Z]* docs/reference.tmpl \
	docs/fudgit.tex docs/*.l docs/*.c tools/* >> Contents 
	echo "Code: " >> Contents
	wc src/Makefile* src/readline/Makefile* src/dl/Makefile* \
	src/dld/Makefile* src/dld/dl/Makefile* \
	src/*.[hcy] src/readline/*.[hc] src/dl/*.[hc] \
	src/dld/*.[hc] src/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
	-(cd docs; $(MAKE) cleanall)
	-(cd src/readline; $(MAKE) clean)
	-(cd src/dl; $(MAKE) clean)
	-(cd src/dld; $(MAKE) clean)
	-(cd src/dld/dl; $(MAKE) clean)
	-(cd tools; $(MAKE) clean)

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

bundle: cleanall
	-compressdir .
	-uncompress Makefile

unbundleall: 
	-uncompressdir .

