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

ALLFILES := include/*.h \
	arith/*.[ch] ecc/*.[ch] misc/*.[ch] \
	sig/*.[ch] test/*.[ch] bce/*.[ch] \
	Makefile \
	CREDITS NEWS COPYING README INSTALL \
	doc/custom.dsl doc/manual.xml doc/manual.txt doc/html/default.css doc/html/manual.html \
	*.param report_times genallcparams list_hilbert

# source file list.
# add a new .c file to exactly one of these ...
libpbc_srcs := \
	arith/field.c arith/naivefp.c arith/fieldquadratic.c arith/poly.c \
	arith/random.c \
	misc/parse.c misc/darray.c misc/symtab.c misc/get_time.c \
	ecc/mpc.c ecc/mnt.c ecc/hilbert.c \
	ecc/curve.c ecc/pairing.c ecc/param.c \
	ecc/bgn_param.c ecc/a_param.c ecc/c_param.c ecc/e_param.c ecc/f_param.c
libsig_srcs := sig/hash.c sig/sig.c		# eventually also bbs.c ...
test_srcs := test/testbls.c test/testbb.c test/testsig.c test/testbbs.c \
	test/testibs.c \
	bce/testbce.c \
	test/testibe.c \
	test/testhilbert.c test/listmnt.c \
	test/genaparam.c test/gencparam.c test/geneparam.c test/genfparam.c \
	test/genbgn.c \
	test/testpairing.c test/testpoly.c \
	test/benchmark.c \
	test/19.c test/sing.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
test/benchmark: test/benchmark.o libpbc.a
test/testhilbert: test/testhilbert.o libpbc.a
bce/testbce: bce/testbce.o bce/bce.o libpbc.a
test/testbbs: test/testbbs.o libpbc.a
test/testbls: test/testbls.o libsig.a libpbc.a
test/testibs: test/testibs.o libsig.a libpbc.a
test/testbb: test/testbb.o libsig.a libpbc.a
test/testsig: test/testsig.o libpbc.a
test/testibe: test/testibe.o libpbc.a
test/testpairing: test/testpairing.o libpbc.a
test/genaparam: test/genaparam.o libpbc.a
test/gencparam: test/gencparam.o libpbc.a
test/geneparam: test/geneparam.o libpbc.a
test/genfparam: test/genfparam.o libpbc.a
test/genbgn: test/genbgn.o libpbc.a
test/listmnt: test/listmnt.o libpbc.a
test/testpoly: test/testpoly.o libpbc.a
test/19: test/19.o libpbc.a
test/sing: test/sing.o libpbc.a

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

depend:
	makedepend -Iinclude -Y -- $(CFLAGS) -- $(srcs) 2> /dev/null

# DO NOT DELETE

arith/field.o: include/field.h include/random.h
arith/naivefp.o: include/field.h include/random.h
arith/fieldquadratic.o: include/fieldquadratic.h include/field.h
arith/fieldquadratic.o: include/random.h
arith/poly.o: include/poly.h include/field.h include/random.h
arith/poly.o: include/darray.h
arith/random.o: include/random.h
misc/parse.o: include/parse.h
misc/darray.o: include/noleak.h include/darray.h
misc/symtab.o: include/symtab.h include/darray.h
misc/get_time.o: include/get_time.h
ecc/mpc.o: include/darray.h include/mpc.h
ecc/mnt.o: include/mnt.h include/darray.h include/curve.h include/poly.h
ecc/mnt.o: include/field.h include/random.h
ecc/hilbert.o: include/hilbert.h include/poly.h include/field.h
ecc/hilbert.o: include/random.h include/darray.h include/mpc.h
ecc/curve.o: include/curve.h include/poly.h include/field.h include/random.h
ecc/curve.o: include/darray.h include/parse.h
ecc/pairing.o: include/pairing.h include/curve.h include/poly.h
ecc/pairing.o: include/field.h include/random.h include/darray.h
ecc/pairing.o: include/a_param.h include/fieldquadratic.h include/c_param.h
ecc/pairing.o: include/mnt.h include/e_param.h include/f_param.h
ecc/pairing.o: include/bgn_param.h include/parse.h
ecc/param.o: include/param.h include/symtab.h include/darray.h
ecc/param.o: include/parse.h
ecc/bgn_param.o: include/bgn_param.h include/fieldquadratic.h include/field.h
ecc/bgn_param.o: include/random.h include/pairing.h include/curve.h
ecc/bgn_param.o: include/poly.h include/darray.h include/param.h
ecc/bgn_param.o: include/symtab.h
ecc/a_param.o: include/a_param.h include/fieldquadratic.h include/field.h
ecc/a_param.o: include/random.h include/pairing.h include/curve.h
ecc/a_param.o: include/poly.h include/darray.h include/param.h
ecc/a_param.o: include/symtab.h
ecc/c_param.o: include/poly.h include/field.h include/random.h
ecc/c_param.o: include/darray.h include/fieldquadratic.h include/hilbert.h
ecc/c_param.o: include/c_param.h include/pairing.h include/curve.h
ecc/c_param.o: include/mnt.h include/param.h include/symtab.h
ecc/e_param.o: include/e_param.h include/pairing.h include/curve.h
ecc/e_param.o: include/poly.h include/field.h include/random.h
ecc/e_param.o: include/darray.h include/param.h include/symtab.h
ecc/f_param.o: include/pbc.h include/pairing.h include/curve.h include/poly.h
ecc/f_param.o: include/field.h include/random.h include/darray.h
ecc/f_param.o: include/mnt.h include/param.h include/symtab.h
ecc/f_param.o: include/f_param.h include/fieldquadratic.h
sig/hash.o: include/hash.h
sig/sig.o: include/sig.h include/pbc.h include/pairing.h include/curve.h
sig/sig.o: include/poly.h include/field.h include/random.h include/darray.h
sig/sig.o: include/mnt.h include/hash.h
test/testbls.o: include/sig.h include/pbc.h include/pairing.h include/curve.h
test/testbls.o: include/poly.h include/field.h include/random.h
test/testbls.o: include/darray.h include/mnt.h
test/testbb.o: include/sig.h include/pbc.h include/pairing.h include/curve.h
test/testbb.o: include/poly.h include/field.h include/random.h
test/testbb.o: include/darray.h include/mnt.h
test/testsig.o: include/pbc.h include/pairing.h include/curve.h
test/testsig.o: include/poly.h include/field.h include/random.h
test/testsig.o: include/darray.h include/mnt.h
test/testbbs.o: include/pbc.h include/pairing.h include/curve.h
test/testbbs.o: include/poly.h include/field.h include/random.h
test/testbbs.o: include/darray.h include/mnt.h include/get_time.h
test/testibs.o: include/sig.h include/pbc.h include/pairing.h include/curve.h
test/testibs.o: include/poly.h include/field.h include/random.h
test/testibs.o: include/darray.h include/mnt.h
bce/testbce.o: include/pbc.h include/pairing.h include/curve.h include/poly.h
bce/testbce.o: include/field.h include/random.h include/darray.h
bce/testbce.o: include/mnt.h bce/bce.h
test/testibe.o: include/pbc.h include/pairing.h include/curve.h
test/testibe.o: include/poly.h include/field.h include/random.h
test/testibe.o: include/darray.h include/mnt.h
test/testhilbert.o: include/hilbert.h include/poly.h include/field.h
test/testhilbert.o: include/random.h include/darray.h
test/listmnt.o: include/pbc.h include/pairing.h include/curve.h
test/listmnt.o: include/poly.h include/field.h include/random.h
test/listmnt.o: include/darray.h include/mnt.h
test/genaparam.o: include/pbc.h include/pairing.h include/curve.h
test/genaparam.o: include/poly.h include/field.h include/random.h
test/genaparam.o: include/darray.h include/mnt.h include/a_param.h
test/genaparam.o: include/fieldquadratic.h
test/gencparam.o: include/pbc.h include/pairing.h include/curve.h
test/gencparam.o: include/poly.h include/field.h include/random.h
test/gencparam.o: include/darray.h include/mnt.h include/c_param.h
test/geneparam.o: include/pbc.h include/pairing.h include/curve.h
test/geneparam.o: include/poly.h include/field.h include/random.h
test/geneparam.o: include/darray.h include/mnt.h include/e_param.h
test/genfparam.o: include/pbc.h include/pairing.h include/curve.h
test/genfparam.o: include/poly.h include/field.h include/random.h
test/genfparam.o: include/darray.h include/mnt.h include/f_param.h
test/genbgn.o: include/pbc.h include/pairing.h include/curve.h include/poly.h
test/genbgn.o: include/field.h include/random.h include/darray.h
test/genbgn.o: include/mnt.h include/bgn_param.h include/fieldquadratic.h
test/testpairing.o: include/pbc.h include/pairing.h include/curve.h
test/testpairing.o: include/poly.h include/field.h include/random.h
test/testpairing.o: include/darray.h include/mnt.h
test/testpoly.o: include/pbc.h include/pairing.h include/curve.h
test/testpoly.o: include/poly.h include/field.h include/random.h
test/testpoly.o: include/darray.h include/mnt.h
test/benchmark.o: include/pbc.h include/pairing.h include/curve.h
test/benchmark.o: include/poly.h include/field.h include/random.h
test/benchmark.o: include/darray.h include/mnt.h include/get_time.h
test/19.o: include/pbc.h include/pairing.h include/curve.h include/poly.h
test/19.o: include/field.h include/random.h include/darray.h include/mnt.h
test/19.o: include/fieldquadratic.h
test/sing.o: include/pbc.h include/pairing.h include/curve.h include/poly.h
test/sing.o: include/field.h include/random.h include/darray.h include/mnt.h
