#############################
# SUNOS Makefile for FUDGIT
#############################
#
# macro definitions

# SPARC 2 have an alignment difference between double and int.
# This memory alignment difference 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 slightly slower.
# Therefore, do not use DALIGN if not a SPARC 2.
# The diagnostic is a bus error on a command like "let x=2"
ALIGN  = -DDALIGN

# The following is overriden if DL is NO in the Master Makefile
DLLIB = -Ldld/ -ldl -ldld
DLAR = dld/libdld.a dld/libdl.a

# Comment out -lmalloc  if not there
LDFLAGS = -lm -Lreadline/ -lreadline -ltermcap $(DLLIB) # -lmalloc 

# Final compiling flags
FCFLAGS =  $(OPT)

# The following for SUN4
# Define -DNOWAITPID if you only have wait3().
CFLAGS = $(OPT) -DNOTRUNC -DDL_$(DL)

# READLINE CFLAGS for SUN
READLINE = OTH_CFLAGS="$(VI_MODE)" # nothing required

# DLD CFLAGS for SUN
DLDFLAGS = CFLAGS="-I."

# DL CFLAGS for SUN
DLFLAGS = CFLAGS="-I.."

# You should not need to edit anything below that line except
# for removing alloca.o from the object list if your compiler supports
# it. (e.g. sparc or if you use gcc to compile)

# Comment out alloca.o from the object list if you compiler supports it.
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 strstr.o if.o strings.o extramath.o \
	 # alloca.o

# Guess
SHELL = /bin/sh
# Default compiler
CC = gcc
#CC = cc
YFLAGS = -d
DATE = `cat ../Date`
VERSION = `cat ../Version`

all:
	-if [ "$(DL)" = "YES" ] ; \
	then (cd dld; $(MAKE) CC="$(CC)" $(DLDFLAGS)) ;fi
	-if [ "$(DL)" = "YES" ] ; \
	then (cd dld/dl; $(MAKE) CC="$(CC)" $(DLFLAGS)) ;fi
	(cd readline; $(MAKE) CC="$(CC)" $(READLINE))
	$(MAKE) -f Makefile.sun4 DLLIB="$(DLLIB)" DLAR="$(DLAR)" \
	CC="$(CC)" ../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
	$(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

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

minit.o: macro.h setshow.h

medfit.o: dalloca.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: symbol.h code.h fudgit.h math.tab.h dalloca.h command.h

svdfit.o: dalloca.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) $(READLINE) )
