############################
# NeXT Makefile for FUDGIT
############################
#
# -lmalloc is better than regular
LDFLAGS = -lm -Lreadline/ -lreadline -ltermcap # -lmalloc

# NeXT has gcc
SPECIALCFLAGS = -W -bsd -DNOUNISTD_H -DNOSTDLIB_H -DNOMALLOC_H

# YOU SHOULD NOT NEED TO EDIT BELOW THIS POINT
# shell definition
SHELL = /bin/sh
# compiling flags for NeXT
CFLAGS = $(OPT) $(SPECIALCFLAGS) -DNOMALLINFO -DNOWAITPID -DWAIT4 \
	-DNOTRUNC -DNORAND48
# Final compiling flags
FCFLAGS =  $(OPT) $(SPECIALCFLAGS)
# READLINE CFLAGS for NeXT
READLINE = OTH_CFLAGS="$(SPECIALCFLAGS) $(VI_MODE)" RANLIB=/bin/ranlib
# Default compiler
CC = cc
YFLAGS = -d # -v
DATE = `cat ../Date`
VERSION = `cat ../Version`
COMP = -c

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 if.o strings.o putenv.o extramath.o

all:
	(cd readline; $(MAKE) CC="$(CC)" $(READLINE))
	$(MAKE) -f Makefile.next ../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 code.c
	$(CC) $(COMP) $(CFLAGS) $(POP) code.c

command.o: symbol.h code.h macro.h fudgit.h math.tab.h \
	setshow.h help.h install.c
	$(CC) $(COMP) $(CFLAGS) $(PROC) 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) $(COMP) $(CFLAGS) -DDATE="\"$(DATE)\"" \
	-DVERSION="\"$(VERSION)\"" fudgit.c

help.o: help.h fudgit.h help.c
	$(CC) $(COMP) $(CFLAGS) -DHELPFILE="\"$(LIBDIR)/fudgit.help\"" 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
		$(CC) $(COMP) -W -ansi -DNeXT math.c

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) $(COMP) $(CFLAGS) mathparse.c

medfit.o: dalloca.h

minit.o: macro.h setshow.h

mrqmin.o: dalloca.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

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

svdfit.o: dalloca.h

vgetarg.o: fudgit.h macro.h symbol.h code.h math.tab.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:
	(cd readline; $(MAKE) $(READLINE) )


