#Makefile for G0NDIST directory

all: libs progs
libs: libprocs.a libcurves.a libg0n.a
progs: curves_progs g0n_progs

CC = gcc #              Name of C++ compiler
CFLAGS = -c -O2 #          Optimisation flag
CXFLAGS = -DUSE_XSPLIT -DMETHOD=$(METHOD)
RANLIB = ranlib #       name of ranlib program (echo if none)
IOLIB = -lstdc++ #      Comment out if not needed for your system

BINDIR = .# 		place for binaries (usually . is OK):

LFLAGS = -lg0n -lcurves -lprocs  -lg++  $(IOLIB) -lm -L.

#template for compiling *.cc -> *.o :

%.o:   %.cc
	$(CC) $(CFLAGS) $(CXFLAGS) $<

##########################
#                        #
#  libprocs.a            #
#                        #
##########################

PROCS_H = interface.h arith.h marith.h compproc.h vec.h vector.h mat.h matrix.h sub.h subspace.h rat.h kbessel.h mvector.h mmatrix.h msubspace.h method.h splitbase.h xsplit.h conic.h

PROCS_CC = arith.cc marith.cc compproc.cc vec.cc vector.cc mat.cc matrix.cc sub.cc subspace.cc kbessel.cc mvector.cc mmatrix.cc msubspace.cc vectest.cc mvectest.cc mattest.cc mmattest.cc space.cc mspace.cc comptest.cc rattest.cc ptest.cc mptest.cc tbessel.cc xsplit.cc conic.cc tconic.cc

PROCS_OBJS = arith.o marith.o conic.o compproc.o kbessel.o xsplit0.o xsplit1.o xsplit2.o xsplit3.o xsplit4.o xsplit5.o xsplit6.o vector.o matrix.o subspace.o mvector.o mmatrix.o msubspace.o

PROCS_TESTS = vectest mattest space comptest rattest ptest mptest tbessel mvectest mmattest mspace  modtest tconic

libprocs.a: $(PROCS_OBJS)
	ar r libprocs.a $(PROCS_OBJS)
	$(RANLIB) libprocs.a

tconic.o: tconic.cc conic.h marith.h arith.h interface.h
conic.o: conic.cc conic.h marith.h arith.h interface.h
tbessel.o: tbessel.cc kbessel.h
kbessel.o: kbessel.h kbessel.cc
arith.o: arith.cc arith.h
marith.o: interface.h marith.cc marith.h arith.h compproc.h
ptest.o: arith.h ptest.cc 
tsqrt.o: tsqrt.cc marith.h
space.o: space.cc subspace.h matrix.h vector.h arith.h
comptest.o: interface.h comptest.cc compproc.h marith.h
compproc.o: interface.h compproc.cc compproc.h
linear.o: linear.cc linear.h
linsyst.o: linsyst.cc linsyst.h linear.h
lintest.o: lintest.cc linsyst.h linear.h
mptest.o: interface.h marith.h mptest.cc arith.h compproc.h
mvectest.o: interface.h mvectest.cc mvector.h marith.h arith.h compproc.h
mvector.o: interface.h mvector.h mvector.cc marith.h arith.h compproc.h
mmatrix.o: interface.h mmatrix.cc mmatrix.h mvector.h marith.h vector.h compproc.h 
mmattest.o: interface.h mmattest.cc mmatrix.h mvector.h vector.h marith.h compproc.h
msubspace.o: interface.h msubspace.cc msubspace.h mmatrix.h mvector.h vector.h marith.h compproc.h
mspace.o: interface.h mspace.cc msubspace.h mmatrix.h mvector.h marith.h compproc.h
smat.o: smat.cc smat.h vector.h vector.cc arith.h
smat_elim.o: smat_elim.cc smat_elim.h smat.cc smat.h vector.cc vector.h arith.h matrix.h

compproc.h: interface.h

xsplit0.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h
	$(CC) $(CFLAGS) -DMETHOD=0 xsplit.cc -o xsplit0.o

xsplit1.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h
	$(CC) $(CFLAGS) -DMETHOD=1 xsplit.cc -o xsplit1.o

xsplit2.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h
	$(CC) $(CFLAGS) -DMETHOD=2 xsplit.cc -o xsplit2.o

xsplit3.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h \
           marith.h mvector.h mmatrix.h msubspace.h
	$(CC) $(CFLAGS) -DMETHOD=3 xsplit.cc -o xsplit3.o

xsplit4.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h \
           marith.h mvector.h mmatrix.h msubspace.h
	$(CC) $(CFLAGS) -DMETHOD=4 xsplit.cc -o xsplit4.o

xsplit5.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h
	$(CC) $(CFLAGS) -DMETHOD=5 xsplit.cc -o xsplit5.o

xsplit6.o: method.h splitbase.h xsplit.h xsplit.cc arith.h vector.h matrix.h subspace.h
	$(CC) $(CFLAGS) -DMETHOD=6 xsplit.cc -o xsplit6.o

vector.o: vector.cc vector.h vec.cc vec.h arith.h
matrix.o: matrix.cc matrix.h mat.cc mat.h arith.h
subspace.o: subspace.cc subspace.h sub.cc sub.h arith.h

##########################
#                        #
#  libcurves.a           #
#                        #
##########################

CURVE_OBJS = curve.o curvedata.o curvered.o points.o heights.o cperiods.o isogs.o mwprocs.o

CURVE_HEADERS = curve.h points.h cperiods.h isogs.h reader.h mwprocs.h lambda.h

CURVE_CCS = curve.cc curvedata.cc curvered.cc points.cc cperiods.cc isogs.cc heights.cc mwprocs.cc lambda.cc tcurve.cc tpoints.cc theight.cc tate.cc torsion.cc conductor.cc twist.cc allisog.cc findinf.cc 

CURVE_PROGS = tate torsion conductor twist allisog findinf
curve_progs: $(CURVE_PROGS)

tate: tate.o  libcurves.a libprocs.a
	$(CC)  -o $(BINDIR)/tate tate.o $(LFLAGS)
torsion: torsion.o libcurves.a libprocs.a
	$(CC)  -o $(BINDIR)/torsion torsion.o $(LFLAGS)
conductor: conductor.o  libcurves.a libprocs.a
	$(CC)  -o $(BINDIR)/conductor conductor.o $(LFLAGS)
twist: twist.o libcurves.a libprocs.a
	$(CC)  -o $(BINDIR)/twist twist.o $(LFLAGS)
allisog: allisog.o libcurves.a libprocs.a
	$(CC)  -o $(BINDIR)/allisog allisog.o $(LFLAGS)
findinf: findinf.o   libcurves.a libprocs.a
	$(CC)  -o $(BINDIR)/findinf findinf.o $(LFLAGS)

libcurves.a: $(CURVE_OBJS)
	rm -f libcurves.a
	ar r libcurves.a $(CURVE_OBJS)
	$(RANLIB) libcurves.a

##########################
#                        #
#  libg0n.a etc          #
#                        #
##########################

G0N_H = bsdprocs.h heegnerp.h msplitter.h periods.h cusp.h homspace.h newforms.h sign.h getai.h manin.h nflist.h splitter.h h1newforms.h moddata.h oldforms.h symb.h   

G0N_CC = bsdprocs.cc h1bsd.cc heegnerp.cc newforms.cc symb.cc checkap.cc h1bsdc.cc homspace.cc nfcount.cc checkdegphi.cc h1clist.cc homtest.cc nflist.cc th1nf.cc cnf.cc h1curisog.cc hpcurve.cc nftest.cc tmanin.cc curvesort.cc h1curve.cc hpmcurve.cc oftest.cc tmaninx.cc cusp.cc h1degphi.cc lf1per.cc oldforms.cc tmaninxauto.cc fixc6.cc h1degphitex.cc manin.cc pcurve.cc tnf2.cc fixforms.cc h1first.cc periods.cc vlift.cc g2.cc h1newforms.cc mhcount.cc pertest.cc getai.cc h1test.cc moddata.cc getoldeigs.cc hecketest.cc modtest.cc putoldeigs.cc h1.cc heegner.cc msplitter.cc splitter.cc   

METHOD = 2

G0N_OBJS = cusp.o homspace.o symb.o moddata.o oldforms.o newforms.o h1newforms.o periods.o manin.o

libg0n.a: $(G0N_OBJS)
	ar r libg0n.a $(G0N_OBJS)
	$(RANLIB) libg0n.a

G0N_PROGS = tmanin h1first h1bsd h1curve hpcurve h1degphi h1clist h1bsdc
g0n_progs: $(G0N_PROGS)

tmanin: tmanin.o libprocs.a libcurves.a libg0n.a
	$(CC) -o tmanin tmanin.o $(LFLAGS)
h1first: h1first.o libprocs.a libcurves.a libg0n.a
	$(CC) -o h1first h1first.o $(LFLAGS)
h1clist: h1clist.o libprocs.a libcurves.a libg0n.a
	$(CC) -o h1clist h1clist.o $(LFLAGS)
h1bsdc: h1bsdc.o libprocs.a libcurves.a libg0n.a
	$(CC) -o h1bsdc h1bsdc.o $(LFLAGS)
h1bsd: h1bsd.o libprocs.a libcurves.a libg0n.a
	$(CC) -o h1bsd h1bsd.o $(LFLAGS)
h1curve: h1curve.o libprocs.a libcurves.a libg0n.a
	$(CC) -o h1curve h1curve.o $(LFLAGS)
hpcurve: hpcurve.o libprocs.a libcurves.a libg0n.a
	$(CC) -o hpcurve hpcurve.o $(LFLAGS)
h1degphi: h1degphi.o libprocs.a libcurves.a libg0n.a
	$(CC) -o h1degphi h1degphi.o $(LFLAGS)


tar:
	tar -cf g0n.tar -T files

clean:
	/bin/rm -f *.a *.o $(CURVE_PROGS) $(G0N_PROGS) eigs/* intdata/* newforms/*

