VERSION := 0.2.0
PROJNAME := pbc
# these (uppercase) variables apply to gmake-builtin rules
CC:=gcc
CPPFLAGS := -I/usr/local/include
warnflags := -Wall -W -Wfloat-equal -Wendif-labels -Wshadow \
	     -Wpointer-arith -Wcast-align -Wstrict-prototypes \
             -Wredundant-decls #-std=c99 -pedantic
CFLAGS := -O3 -g $(warnflags) -pipe -ffast-math -fomit-frame-pointer
LDFLAGS := -L/usr/local/lib
LDLIBS := -lgmp -lm

ALLFILES := *.[ch] Makefile AUTHORS NEWS COPYING README INSTALL manual.txt *.param

# source file list.
# add a new .c file to exactly one of these ...
libpbc_srcs := curve.c fp.c fieldquadratic.c poly.c darray.c symtab.c mnt.c \
               mpc.c hilbert.c pairing.c parse.c param.c get_time.c random.c \
	       a_param.c c_param.c e_param.c
libsig_srcs := sig.c		# eventually also bbs.c ...
test_srcs := testbls.c testbb.c testsig.c testbbs.c testibe.c \
             testpairing.c testmnt.c benchmark.c

srcs := $(libpbc_srcs) $(libsig_srcs) $(test_srcs)
libpbc_objs := $(libpbc_srcs:.c=.o)
libsig_objs := $(libsig_srcs:.c=.o)
objs := $(srcs:.c=.o)

libs := libpbc.a libsig.a
binaries := $(test_srcs:.c=)

.PHONY: target dist clean spotless depend

target: $(libs) $(binaries)

# file dependencies for library-making
# see GNU Make manual, sect. 11.2 for explanation
libpbc.a: libpbc.a($(libpbc_objs))
	ranlib $@
libsig.a: libsig.a($(libsig_objs))
	ranlib $@

# the test binaries.  when adding a new test binary, add a line here
# to specify its dependencies
benchmark: benchmark.o libpbc.a
testbbs: testbbs.o libpbc.a
testbls: testbls.o libsig.a libpbc.a
testbb: testbb.o libsig.a libpbc.a
testsig: testsig.o libpbc.a
testibe: testibe.o libpbc.a
testpairing: testpairing.o libpbc.a
testmnt: testmnt.o libpbc.a
testpoly: testpoly.o poly.o darray.o fp.o random.o

DISTNAME := $(PROJNAME)-$(VERSION)

dist: $(ALLFILES) clean depend
	-rm -rf $(DISTNAME)
	mkdir $(DISTNAME)
	cp -rl --parents $(ALLFILES) $(DISTNAME)
	tar chfz $(DISTNAME).tgz $(DISTNAME)
	-rm -rf $(DISTNAME)

clean:
	-rm -f $(binaries) $(libs) $(objs)

spotless: clean
	-rm -f Makefile.bak *~ core

# we do not give any -I info because we want to depend only
# on stuff in the current directory
depend:
	makedepend -Y -- $(CFLAGS) -- $(srcs) 2> /dev/null

# DO NOT DELETE

curve.o: curve.h poly.h field.h random.h darray.h parse.h
fp.o: field.h random.h
fieldquadratic.o: fieldquadratic.h field.h random.h
poly.o: poly.h field.h random.h darray.h
darray.o: noleak.h darray.h
symtab.o: symtab.h darray.h
mnt.o: mnt.h darray.h curve.h poly.h field.h random.h
mpc.o: darray.h mpc.h
hilbert.o: hilbert.h poly.h field.h random.h darray.h mpc.h
pairing.o: pairing.h curve.h poly.h field.h random.h darray.h a_param.h
pairing.o: fieldquadratic.h c_param.h mnt.h e_param.h parse.h
parse.o: parse.h
param.o: param.h symtab.h darray.h parse.h
get_time.o: get_time.h
random.o: random.h
a_param.o: a_param.h fieldquadratic.h field.h random.h pairing.h curve.h
a_param.o: poly.h darray.h param.h symtab.h
c_param.o: poly.h field.h random.h darray.h fieldquadratic.h hilbert.h
c_param.o: c_param.h pairing.h curve.h mnt.h param.h symtab.h
e_param.o: e_param.h pairing.h curve.h poly.h field.h random.h darray.h
e_param.o: param.h symtab.h
sig.o: sig.h pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
testbls.o: sig.h pbc.h pairing.h curve.h poly.h field.h random.h darray.h
testbls.o: mnt.h
testbb.o: sig.h pbc.h pairing.h curve.h poly.h field.h random.h darray.h
testbb.o: mnt.h
testsig.o: pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
testbbs.o: pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
testbbs.o: get_time.h
testibe.o: pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
testpairing.o: pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
testmnt.o: pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
testmnt.o: c_param.h
benchmark.o: pbc.h pairing.h curve.h poly.h field.h random.h darray.h mnt.h
benchmark.o: get_time.h
