
# looks like src/err is not needed 
# its already included in src/slatec

CC = cc

F77 = g77

OPT = -O3 -g

PICOPT = -fPIC

AR = ar r

all:
	make clean
	make slatec-static
	make clean
	make slatec-shared


all-check: all check

check:
	cd src/chk; make static

checkobj: 
	cd src/chk; make OCFLAGS="$(OPT)" OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

piccheckobj:
	cd src/chk; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)


allobj:  fishfftobj fnlibobj linobj pchipobj slatecobj machobj \
		checkobj


allpicobj:   picfishfftobj picfnlibobj piclinobj picpchipobj picslatecobj picmachobj \
		piccheckobj


#errobj:
#	cd src/err; make OFFLAGS=$(OPT) CC=$(CC) F77=$(F77)

#picerrobj:
#	cd src/err; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)

machobj:
	cd src/machine; make OCFLAGS="$(OPT)" OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

picmachobj:
	cd src/machine; make OCFLAGS="$(OPT) $(PICOPT)" OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)



fishfftobj:
	cd src/fishfft; make OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

picfishfftobj:
	cd src/fishfft; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)

fnlibobj:
	cd src/fnlib; make OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

picfnlibobj:
	cd src/fnlib; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)

linobj:
	cd src/lin; make OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

piclinobj:
	cd src/lin; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)

pchipobj:
	cd src/pchip; make OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

picpchipobj:
	cd src/pchip; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)

slatecobj:
	cd src/slatec; make OFFLAGS="$(OPT)" CC="$(CC)" F77="$(F77)"

picslatecobj:
	cd src/slatec; make OFFLAGS="$(OPT) $(PICOPT)" CC=$(CC) F77=$(F77)


slatec-static : allobj
	rm -f libslatec.a
#	$(AR) libslatec.a src/err/*.o  do not include this line
#	$(AR) libslatec.a src/fishfft/*.o
#	$(AR) libslatec.a src/fnlib/*.o
#	$(AR) libslatec.a src/machine/*.o
#	$(AR) libslatec.a src/lin/*.o
#	$(AR) libslatec.a src/pchip/*.o
#	$(AR) libslatec.a src/slatec/*.o
	$(AR) libslatec.a src/slatec/*.o src/fishfft/*.o src/fnlib/*.o \
		src/machine/*.o src/lin/*.o src/pchip/*.o src/chk/*.o
	ranlib libslatec.a

slatec-shared : allpicobj
	-rm -r libslatec.so
	ld --shared -o libslatec.so.$(MI_N)  \
	  src/fishfft/*.o src/fnlib/*.o src/lin/*.o  src/machine/*.o \
	  src/pchip/*.o src/slatec/*.o src/chk/*.o -soname libslatec.so.$(MA_N) -lc

clean:
	cd src/chk; make clean
#	cd src/err; make clean
	cd src/machine; make clean
	cd src/fishfft; make clean
	cd src/fnlib; make clean
	cd src/lin; make clean
	cd src/pchip; make clean
	cd src/slatec; make clean

distclean: clean
	rm -rf *.a *.so*
