#############################
# Amiga 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 on SUN OS 3.5
LDFLAGS = -lm -ltermcap -lnet $(DLLIB) # -lmalloc 

# Special flags to C compiler
# SPECIALCFLAGS =

# Special flags to GNU C compiler
SPECIALCFLAGS = -W -O2

# Final compiling flags
FCFLAGS =  $(OPT)

# The following for SUN3, SUN OS 3.5/ Add -DNOWAITPID if
# you only have wait3()
CFLAGS = $(OPT) $(SPECIALCFLAGS) -DNOTRUNC -DNOMALLOC_H -DNOMALLINFO -DNOSETPGID -DNODRAND48

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

# DLD CFLAGS for SUN
DLDFLAGS = CFLAGS="-I. $(SPECIALCFLAGS)"

# DL CFLAGS for SUN
DLFLAGS = CFLAGS="-I.. $(SPECIALCFLAGS)"

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

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 chd.o if.o strings.o extramath.o lgamma.o\
#	alloca.o readline2.o

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

# Comment out alloca.o from the object list if you compiler supports it.
all:
ifeq "$(DL)" "YES"
	(cd dld; $(MAKE) CC="$(CC)" $(DLDFLAGS))
endif
ifeq "$(DL)" "YES"
	(cd dld/dl; $(MAKE) CC="$(CC)" $(DLFLAGS))
endif
#	(cd readline; $(MAKE) CC="$(CC)" $(READLINE))
	$(MAKE) -f Makefile.amiga 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) -c $(CFLAGS) $(POP) $(ALIGN) 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) -c fudgit.c

help.o: help.h fudgit.h help.c
	$(CC) $(CFLAGS) -DHELPFILE="\"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: mathparse.c symbol.h code.h
	$(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) )
