# Makefile for C9X complex variables library
# Edit endian-ness and computer type properly in mconf.h before compiling.

#CC = gcc
CC=/b/gnu/linux/gcc/xgcc -B/b/gnu/linux/gcc/ -I/b/gnu/linux/include
# For 128-bit wide long double
#PRECFLAGS = -DLD128BITS
PRECFLAGS = 
CFLAGS = $(PRECFLAGS) -g -O2 -Wall
# This should be enough to run at least the double precision functions
#LIBS = stubs.o -lm
# These are intended to get the cephes libraries
LIBS = -lml -lmd -lmf
#LIBS = ../libml.a ../libmd.a ../libmf.a
# float precision
SFILES = cmplxf.o clogf.o cgammaf.o
# double precision
DFILES = cmplx.o clog.o cgamma.o
# long double precision
#LFILES = 
LFILES = cmplxl.o clogl.o cgammal.o
LIBMCFILES = $(SFILES) $(DFILES) $(LFILES)

# mtstf and mtstl test the float and long double functions.
all: libmc.a mtst cvect dccalc mtstf mtstl

mtst: mtst.o $(DFILES) stubs.o
	$(CC) -v -o mtst mtst.o $(DFILES) $(LIBS)

mtstf: mtstf.o $(SFILES) stubs.o
	$(CC) -o mtstf mtstf.o $(SFILES) $(LIBS)

mtstl: mtstl.o $(LFILES) stubs.o
	$(CC) -o mtstl mtstl.o $(LFILES) $(LIBS)

cvect: cvect.o clog.o cmplx.o stubs.o
	$(CC) -o cvect cvect.o clog.o cmplx.o $(LIBS)

cvect-nans: cvect-nans.o clog-nans.o cmplx-nans.o
	$(CC) -o cvect-nans cvect-nans.o clog-nans.o cmplx-nans.o $(LIBS)

libmc.a: $(LIBMCFILES)
	rm -f libmc.a
	ar rv libmc.a $(LIBMCFILES)
	ranlib libmc.a

# Complex variable calculator program.
# If you don't have the readline library, leave out the references to it
# (and curses) or get the library from ftp.gnu.org.
# If compiling on a 16-bit computer, you may need to set LARGEMEM 0
# in dccalc.h.
dccalc: dccalc.o
#	$(CC) -o dccalc dccalc.o libmc.a -lreadline -lncurses $(LIBS)
	$(CC) -o dccalc dccalc.o libmc.a $(LIBS)

dccalc.o: dccalc.c dccalc.h
#	$(CC) $(CFLAGS) -DUSE_READLINE=1 -c dccalc.c
	$(CC) $(CFLAGS) -c dccalc.c

clog.o: clog.c complex.h protos.h
cmplx.o: cmplx.c complex.h protos.h
clogf.o: clogf.c complex.h protos.h
cmplxf.o: cmplxf.c complex.h protos.h
clogl.o: clogl.c complex.h protos.h
cmplxl.o: cmplxl.c complex.h protos.h
#clog-nans.o: clog-nans.c complex.h protos.h
#cmplx-nans.o: cmplx-nans.c complex.h protos.h

check: mtst cvect mtstf
	-mtstf
	-cvect
	-mtst
	-mtstl

clean:
	rm -f *.o
	rm -f mtst
	rm -f cvect
	rm -f mtstf
	rm -f mtstl
	rm -f cvect-nans
	rm -f dccalc
	rm -f libmc.a
	rm -f tcabs
	rm -f tcabsf
	rm -f tcexp
	rm -f tcexpf
	rm -f tclog
	rm -f tclogf
	rm -f tcpow
	rm -f tcpowf
	rm -f tcsin
	rm -f tcsinf
	rm -f tcsqrt
	rm -f tcsqrtf

zip:
	rm -f c9x-complex.zip
	rm -f c9x-complex.shar
	rm -f c9x-complex.shar.gz
	zip c9x-complex.zip *.c *.h *.pat *.doc *.mak makefile read.me
	shar *.c *.h *.pat *.doc *.mak makefile read.me > c9x-complex.shar
	gzip c9x-complex.shar
