############################
# IRIX Makefile for FUDGIT
############################
#
# The following definitions are overwritten frm DL=NO in the Master Makefile
DLLIB = -Ldl/ -ldl -lmld 
DLAR = dl/libdl.a

# -lmalloc is better than regular
LDFLAGS = -lm -Lreadline/ -lreadline -ltermcap $(DLLIB) -lmalloc

# nlist(3) returns the type value + 1 if found on earlier operating
# systems. On IRIX 4.0.5, it returns the same value if found, zero
# otherwise. Defining SAME_STPROC takes care of that.
# If your operating system is below 4.0.5 do not define the following:
#PROC = -DSAME_STPROC

# Flags for the intrisic IRIX compiler
SPECIALCFLAGS = -xansi -prototypes -D__STDC__\
	 -fullwarn -woff 202,269,270,302,303

# If you want to use gcc
# SPECIALCFLAGS = -Wall

# YOU SHOULD NOT NEED TO EDIT BELOW THIS POINT
# shell definition
SHELL = /bin/sh
# compiling flags for SGI machines IRIX 3.5 to 4.0
CFLAGS = $(OPT) -D_BSD_COMPAT -D_BSD_SIGNALS $(SPECIALCFLAGS) -DDL_$(DL)
# Final compiling flags
FCFLAGS =  -D_BSD_COMPAT -D_BSD_SIGNALS $(OPT) $(SPECIALCFLAGS)
# READLINE CFLAGS for IRIX
READLINE = OTH_CFLAGS="-D_BSD_SIGNALS -D_BSD_COMPAT \
	$(SPECIALCFLAGS) $(VI_MODE)" USG="-DUSG"
# 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

DLFLAGS = CFLAGS="$(SPECIALCFLAGS)" # CFLAGS="$(SPECIALCFLAGS) -DDEBUG -O"

all:
	-if [ "$(DL)" = "YES" ] ; then (cd dl; $(MAKE) CC="$(CC)" $(DLFLAGS)) ;fi
	(cd readline; $(MAKE) CC="$(CC)" $(READLINE))
	$(MAKE) -f Makefile.irix4 CC="$(CC)" \
	DLLIB="$(DLLIB)" DLAR="$(DLAR)" ../fudgit

../fudgit: $(OBJECTS) fudgit.h setshow.h readline/libreadline.a $(DLAR)
	$(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 install.dummy.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 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

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) )

dl/libdl.a:
	-if [ "$(DL)" = "YES" ] ; then (cd dl; $(MAKE) $(DLFLAGS) ); fi
