VERSION := 0.1.5
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 NEWS LICENSE README 159.txt 201.txt
  
libsrcs := curve.c fp.c fieldquadratic.o poly.c darray.c mnt.c mpc.c \
           pairing.c parse.c get_time.c solinas.o
srcs := $(libsrcs) testfi.c testbbs.c sig.c testbls.c testbb.c testsig.c \
        testibe.c testpairing.c testmnt.c testpoly.c poly.c darray.c fp.c \
        benchmark.c bmsolinas.c
libobjs := $(libsrcs:.c=.o)
objs := $(srcs:.c=.o)
binaries := testfi testbbs testbb testbls testibe testsig testmnt benchmark
  
.PHONY: target dist clean
  
target: $(binaries)
  
bmsolinas: bmsolinas.o $(libobjs)
benchmark: benchmark.o $(libobjs)
testfi: testfi.o $(libobjs)
testbbs: testbbs.o $(libobjs)
testbls: testbls.o $(libobjs) sig.o
testbb: testbb.o $(libobjs) sig.o
testsig: testsig.o $(libobjs)
testibe: testibe.o $(libobjs)
testpairing: testpairing.o $(libobjs)
testmnt: testmnt.o $(libobjs)
testpoly: testpoly.o poly.o darray.o fp.o
	$(CC) -o $@ $(CFLAGS) $^ -lgmp

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

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

clean:
	-rm -f $(binaries) $(objs) Makefile.bak

# 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 darray.h parse.h
fp.o: field.h
poly.o: poly.h field.h darray.h
darray.o: noleak.h darray.h
mnt.o: mpc.h pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
mnt.o: fieldquadratic.h mnt.h
mpc.o: darray.h mpc.h
pairing.o: pairing.h curve.h poly.h field.h darray.h solinas.h
pairing.o: fieldquadratic.h pbc.h mnt.h
parse.o: parse.h
get_time.o: get_time.h
testfi.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testfi.o: fieldquadratic.h mnt.h
testbbs.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testbbs.o: fieldquadratic.h mnt.h get_time.h
sig.o: sig.h pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
sig.o: fieldquadratic.h mnt.h
testbls.o: sig.h pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testbls.o: fieldquadratic.h mnt.h
testbb.o: sig.h pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testbb.o: fieldquadratic.h mnt.h
testsig.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testsig.o: fieldquadratic.h mnt.h
testibe.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testibe.o: fieldquadratic.h mnt.h
testpairing.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testpairing.o: fieldquadratic.h mnt.h
testmnt.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testmnt.o: fieldquadratic.h mnt.h
testpoly.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
testpoly.o: fieldquadratic.h mnt.h
poly.o: poly.h field.h darray.h
darray.o: noleak.h darray.h
fp.o: field.h
benchmark.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
benchmark.o: fieldquadratic.h mnt.h get_time.h
bmsolinas.o: pbc.h pairing.h curve.h poly.h field.h darray.h solinas.h
bmsolinas.o: fieldquadratic.h mnt.h get_time.h
