########################################
# This is the Master Makefile for FUDGIT
########################################
#
# macro definitions
# Change the following according to your needs
# Where to put the program onced compiled.
BINDIR=$(HOME)/usr/local/bin
# Where to put the help file.
LIBDIR=$(HOME)/usr/local/lib
# LIBDIR=/ds13/c/users/lacasse/lib
# Do you trust your optimizer?
# OPT = -g # -DYYDEBUG
OPT = -O 
# OPT = -O -fomit-frame-pointer
# 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 not leave space between YES and #.
# Do you want VI mode to be compiled?
VI_MODE = # This is off
# VI_MODE = -DVI_MODE  # This is on
# Your favorite compiler-compiler (yacc, bison, etc...)
# YACC = bison -y
YACC = yacc
# 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
# Select the compiler required
# CC = cc  # IRIX, SUN4, OSF, LINUX, DATAGEN, NeXT, ULTRIX
CC = c89  # Required for AIX, HPUX
# CC = gcc # SUNOS3 or 4, SYSV Release4

# You should not need to edit below this point 
# Just type 'make target' and then 'make install'
# 'target' is one of :
#     aix, datagen, hpux, linux, irix4, next, osf, sun3, sun4, svr4, ultrix
# 

# Some shortcuts for me
DATE = `cat Date`
SRC = src
SHELL = /bin/sh
VERSION = 2.34

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

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

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

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

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

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

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

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

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

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

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

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

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

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 $(LIBDIR)/fudgit.help

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

doc:
	(cd docs; $(MAKE) CC="$(CC)" 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 .

