############################
# HPUX  Makefile for FUDGIT
############################
#
# macro definitions
SHELL = /bin/sh
# No -lmalloc on some HPUX 
LDFLAGS = -lm -Lreadline/ -lreadline -ltermcap -lmalloc
CFLAGS = $(OPT) -D_INCLUDE_POSIX_SOURCE -DVOID_SIGHANDLER -DSIGHANDLER_1 \
	-DNOHYP_TRIGO -DNORINT -DNOTRUNC -DNOCBRT -DRESTART_SIGHANDLER -DHPUX
# Some HPUX have an alignment difference between double and int.
# On HP750, a memory alignment problem forces us to
# use bcopy() instead of casts. Defining DALIGN
# generates code using bcopy() for writing and reading double
# into the machine. The resulting code is slghtly slower.
# Therefore, do not use DALIGN if not a HP.
ALIGN  = -DDALIGN
# Final compiling flags
FCFLAGS = $(OPT)
# READLINE CFLAGS for HPUX
READLINE = OTH_CFLAGS="-DHPUX -DRESTART_SIGHANDLER -DSIGHANDLER_1 \
 -DVOID_SIGHANDLER -D_INCLUDE_POSIX_SOURCE $(VI_MODE)"

# Compiler
#CC = gcc -Wall # -traditional
CC = cc89
YFLAGS = -d
DATE = `cat ../Date`
VERSION = `cat ../Version`
OBJECTS = mathparse.o fudgit.o alloc.o setshow.o vgetargp.o plot.o\
	fits.o fit.o svdfit.o medfit.o help.o mrqmin.o \
	command.o code.o math.o lexi.o init.o fft.o macro.o minit.o \
	spline.o readline2.o chd.o alloca.o extramath.o if.o strings.o

#  hpux doesn't have an alloca -- so use our own
#  hpux is also missing some math functions -- add them in extramath.c

all: readline/libreadline.a ../fudgit

../fudgit: $(OBJECTS) fudgit.h setshow.h readline/libreadline.a
	$(CC) $(FCFLAGS) -o ../fudgit $(OBJECTS) $(LDFLAGS)

code.o: code.h math.tab.h symbol.h
	$(CC) $(CFLAGS) $(POP) $(ALIGN) -c code.c

command.o: symbol.h code.h macro.h fudgit.h math.tab.h setshow.h help.h \
	install.dummy.c command.h
	$(CC) $(CFLAGS) -w -c command.c

fft.o: math.tab.h code.h symbol.h fudgit.h setshow.h dalloca.h

fits.o: symbol.h code.h fudgit.h math.tab.h setshow.h

fudgit.o: fudgit.h macro.h ../Date fudgit.c ../Version
	$(CC) $(CFLAGS) -DDATE="\"$(DATE)\"" -DVERSION="\"$(VERSION)\"" -c fudgit.c

help.o: help.h fudgit.h help.c
	$(CC) $(CFLAGS) -DHELPFILE="\"$(LIBDIR)/fudgit.help\"" -c help.c

if.o: fudgit.h

init.o: symbol.h code.h math.tab.h fudgit.h

lexi.o: symbol.h code.h fudgit.h math.tab.h

macro.o: macro.h fudgit.h setshow.h

math.o: fudgit.h 

mathparse.o: symbol.h code.h parse.y
	yacc $(YFLAGS) parse.y
	cat y.tab.c | sed s/yy/Ft_mathyy/g > mathparse.c
	rm y.tab.c
	$(CC) $(CFLAGS) -c mathparse.c

medfit.o: dalloca.h

mrqmin.o: dalloca.h

minit.o: macro.h setshow.h

chd.o: fudgit.h

plot.o: fudgit.h setshow.h macro.h

setshow.o: symbol.h code.h fudgit.h math.tab.h setshow.h macro.h functions.h

svdfit.o: dalloca.h

spline.o: symbol.h code.h command.h dalloca.h math.tab.h fudgit.h

vgetarg.o: fudgit.h macro.h

math.tab.h: y.tab.h
	cat y.tab.h | sed s/yy/Ft_mathyy/g > math.tab.h

y.tab.h: mathparse.o

readline/libreadline.a: readline/readline.c readline/history.c \
	readline/funmap.c readline/keymaps.c
	(cd readline; make CC="$(CC)" $(READLINE) )

