2014-04-14 20:29:55 +00:00
|
|
|
# compiler, tools
|
|
|
|
CC = gcc
|
|
|
|
PKG_CONFIG ?= pkg-config
|
|
|
|
|
|
|
|
# flags
|
|
|
|
CFLAGS ?= -march=native -O2 -pipe
|
2014-04-20 18:06:49 +00:00
|
|
|
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function
|
2014-04-14 20:29:55 +00:00
|
|
|
ifeq ($(shell $(CC) -v 2>&1 | grep 'gcc version' &>/dev/null && echo 1),1)
|
|
|
|
CFLAGS += -Wno-unused-but-set-variable
|
|
|
|
endif
|
|
|
|
LDFLAGS ?= -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu
|
|
|
|
# ifndef NOSTATIC
|
|
|
|
# LDFLAGS += -static
|
|
|
|
# endif
|
|
|
|
|
|
|
|
ifndef NODEBUG
|
|
|
|
CFLAGS += -O0 -g3
|
|
|
|
endif
|
|
|
|
|
|
|
|
# install variables
|
|
|
|
INSTALL = install
|
|
|
|
INSTALL_BIN = install -m755
|
|
|
|
INSTALL_DIR = install -d
|
|
|
|
PREFIX = /usr/local
|
|
|
|
LIBDIR = lib64
|
|
|
|
INSTALL_BINDIR = $(PREFIX)/bin
|
|
|
|
INSTALL_LIBDIR = $(PREFIX)/$(LIBDIR)
|
|
|
|
|
|
|
|
|
|
|
|
# libs
|
|
|
|
ifdef SHARED_LIB
|
|
|
|
PQC_LIBS = libpqc.so
|
|
|
|
else
|
|
|
|
PQC_LIBS = libpqc.a
|
|
|
|
endif
|
|
|
|
# CUNIT_LIBS = -lcunit
|
2014-05-27 23:09:52 +00:00
|
|
|
LIBS += -L. -lgmp -lmpfr -lm $(shell $(PKG_CONFIG) --libs glib-2.0)
|
2014-04-14 20:29:55 +00:00
|
|
|
|
|
|
|
# objects
|
2014-05-26 19:38:39 +00:00
|
|
|
PQC_OBJS = poly.o mem.o encrypt.o decrypt.o keypair.o ascii_poly.o file.o \
|
|
|
|
ntru_string.o
|
2014-05-26 19:30:42 +00:00
|
|
|
PQC_HEADERS = err.h poly.h context.h encrypt.h decrypt.h keypair.h \
|
|
|
|
ascii_poly.h common.h file.h ntru_string.h
|
2014-04-14 20:29:55 +00:00
|
|
|
# CUNIT_OBJS = cunit.o
|
|
|
|
|
|
|
|
# includes
|
2014-05-27 23:09:52 +00:00
|
|
|
INCS = -I. $(shell $(PKG_CONFIG) --cflags glib-2.0)
|
2014-04-14 20:29:55 +00:00
|
|
|
|
|
|
|
ifndef UNBUNDLE
|
2014-05-18 22:04:00 +00:00
|
|
|
LIBFLINT = ../external/flint-2.4.3/libflint.a
|
2014-05-25 02:40:49 +00:00
|
|
|
INCS += -I../external/flint-2.4.3
|
2014-04-14 20:29:55 +00:00
|
|
|
else
|
2014-05-18 22:04:00 +00:00
|
|
|
LIBFLINT = -lflint
|
2014-05-25 02:40:49 +00:00
|
|
|
INCS += -I/usr/include/flint
|
2014-04-14 20:29:55 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
$(CC) -fPIC $(CFLAGS) $(CPPFLAGS) $(INCS) -c $*.c
|
|
|
|
|
|
|
|
all: libpqc.a libpqc.so
|
|
|
|
|
|
|
|
|
|
|
|
# test: $(CUNIT_OBJS) $(PQC_LIBS)
|
|
|
|
# $(CC) $(CFLAGS) -o $@ $(CUNIT_OBJS) $(LDFLAGS) $(CUNIT_LIBS) $(PQC_LIBS) $(LIBS)
|
|
|
|
|
|
|
|
ifndef UNBUNDLE
|
2014-05-18 22:04:00 +00:00
|
|
|
$(LIBFLINT):
|
|
|
|
cd ../external/flint-2.4.3 && ./configure --prefix=/usr --with-gmp=/usr --with-mpfr=/usr --disable-shared
|
|
|
|
$(MAKE) -C ../external/flint-2.4.3
|
2014-04-14 20:29:55 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
libpqc.a: $(PQC_OBJS) $(PQC_HEADERS)
|
|
|
|
$(AR) cru libpqc.a $(PQC_OBJS)
|
|
|
|
|
2014-05-24 23:36:44 +00:00
|
|
|
libpqc.so: libpqc.a $(PQC_HEADERS) $(LIBFLINT)
|
2014-04-14 20:29:55 +00:00
|
|
|
$(CC) -shared $(CFLAGS) -o $@ $(LDFLAGS) \
|
2014-05-24 23:36:44 +00:00
|
|
|
libpqc.a $(LIBFLINT) $(LIBS)
|
2014-04-14 20:29:55 +00:00
|
|
|
|
2014-05-24 23:36:44 +00:00
|
|
|
main: main.o libpqc.a $(LIBFLINT)
|
2014-04-14 21:51:33 +00:00
|
|
|
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) \
|
2014-05-24 23:36:44 +00:00
|
|
|
main.o libpqc.a $(LIBFLINT) $(LIBS)
|
2014-04-14 21:51:33 +00:00
|
|
|
|
2014-04-14 20:29:55 +00:00
|
|
|
install:
|
|
|
|
$(INSTALL_DIR) "$(DESTDIR)$(INSTALL_BINDIR)"
|
|
|
|
[ -e libpqc.so ] && $(INSTALL_DIR) "$(DESTDIR)$(INSTALL_LIBDIR)"
|
|
|
|
[ -e libpqc.so ] && $(INSTALL_BIN) libpqc.so "$(DESTDIR)$(INSTALL_LIBDIR)"
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
[ -e "$(DESTDIR)$(INSTALL_LIBDIR)/libpqc.so" ] && rm "$(DESTDIR)$(INSTALL_LIBDIR)/libpqc.so"
|
|
|
|
|
|
|
|
# check:
|
|
|
|
# ./test
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f *.o test libpqc.a libpqc.so main
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: clean install
|