Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
153 lines (135 sloc) 5.7 KB
CC?=gcc
AS=$(CC) -c
OPTFLAGS=-O2
bench: OPTFLAGS=-O3 -march=native
CFLAGS?=-g $(OPTFLAGS)
CFLAGS+=-Wall -Wextra -Wno-unused-parameter
ifeq ($(AVX2), yes)
CFLAGS+=-mavx2
SSE=yes
endif
ifeq ($(SSE), yes)
CFLAGS+=-mssse3
endif
SRCDIR=src
TESTDIR=tests
LIB_OBJS=bitstring.o encparams.o hash.o idxgen.o key.o mgf.o ntru.o poly.o rand.o arith.o sha1.o sha2.o nist_ctr_drbg.o rijndael.o
ifeq ($(SSE), yes)
LIB_OBJS+=sha1-mb-x86_64.o sha256-mb-x86_64.o
endif
TEST_OBJS=test_bitstring.o test_hash.o test_idxgen.o test_key.o test_ntru.o test.o test_poly.o test_util.o
VERSION=0.5
INST_PFX=%PROGRAMFILES%
INST_LIBDIR=$(INST_PFX)\libntru
INST_INCLUDE=$(INST_PFX)\libntru\include
INST_DOCDIR=$(INST_PFX)\libntru
INST_HEADERS=ntru.h types.h key.h encparams.h hash.h rand.h err.h
PERL=c:\mingw\msys\1.0\bin\perl
PERLASM_SCHEME=coff
LIB_OBJS_PATHS=$(patsubst %,$(SRCDIR)/%,$(LIB_OBJS))
TEST_OBJS_PATHS=$(patsubst %,$(TESTDIR)/%,$(TEST_OBJS))
DIST_NAME=libntru-$(VERSION)
MAKEFILENAME=$(lastword $(MAKEFILE_LIST))
.PHONY: all lib install dist test clean distclean
all: lib
lib: $(LIB_OBJS_PATHS)
$(CC) $(CFLAGS) $(CPPFLAGS) -shared -o libntru.dll $(LIB_OBJS_PATHS) -lws2_32 -ladvapi32
install: lib
if not exist "$(DESTDIR)$(INST_PFX)" mkdir "$(DESTDIR)$(INST_PFX)"
if not exist "$(DESTDIR)$(INST_LIBDIR)" mkdir "$(DESTDIR)$(INST_LIBDIR)"
if not exist "$(DESTDIR)$(INST_INCLUDE)" mkdir "$(DESTDIR)$(INST_INCLUDE)"
if not exist "$(DESTDIR)$(INST_DOCDIR)" mkdir "$(DESTDIR)$(INST_DOCDIR)"
copy libntru.dll "$(DESTDIR)$(INST_LIBDIR)"
copy README.md "$(DESTDIR)$(INST_DOCDIR)"
for %%h in ($(INST_HEADERS)) do \
copy $(SRCDIR)\%%h "$(INST_INCLUDE)"
uninstall:
if exist "$(DESTDIR)$(INST_LIBDIR)\libntru.dll" del "$(DESTDIR)$(INST_LIBDIR)\libntru.dll"
if exist "$(DESTDIR)$(INST_DOCDIR)\README.md" del "$(DESTDIR)$(INST_DOCDIR)\README.md"
for %%h in ($(DESTDIR)$(INST_HEADERS)) do \
if exist "$(DESTDIR)$(INST_INCLUDE)\%%h" del "$(DESTDIR)$(INST_INCLUDE)\%%h"
if exist "$(DESTDIR)$(INST_INCLUDE)" rmdir "$(DESTDIR)$(INST_INCLUDE)"
if exist "$(DESTDIR)$(INST_LIBDIR)" rmdir "$(DESTDIR)$(INST_LIBDIR)"
if exist "$(DESTDIR)$(INST_DOCDIR)" rmdir "$(DESTDIR)$(INST_DOCDIR)"
dist:
@if exist $(DIST_NAME)\$(SRCDIR)\*.c del $(DIST_NAME)\$(SRCDIR)\*.c
@if exist $(DIST_NAME)\$(SRCDIR)\*.h del $(DIST_NAME)\$(SRCDIR)\*.h
@if exist $(DIST_NAME)\$(SRCDIR) rmdir $(DIST_NAME)\$(SRCDIR)
@if exist $(DIST_NAME)\$(TESTDIR)\*.c del $(DIST_NAME)\$(TESTDIR)\*.c
@if exist $(DIST_NAME)\$(TESTDIR)\*.h del $(DIST_NAME)\$(TESTDIR)\*.h
@if exist $(DIST_NAME)\$(TESTDIR) rmdir $(DIST_NAME)\$(TESTDIR)
@if exist $(DIST_NAME)\*.* del /q $(DIST_NAME)\*.*
@if exist $(DIST_NAME) rmdir $(DIST_NAME)
mkdir $(DIST_NAME)
mkdir $(DIST_NAME)\$(SRCDIR)
mkdir $(DIST_NAME)\$(TESTDIR)
copy Makefile $(DIST_NAME)
copy Makefile.win $(DIST_NAME)
copy Makefile.osx $(DIST_NAME)
copy README.md $(DIST_NAME)
copy LICENSE $(DIST_NAME)
copy PATENTS $(DIST_NAME)
copy $(SRCDIR)\*.c $(DIST_NAME)\$(SRCDIR)
copy $(SRCDIR)\*.h $(DIST_NAME)\$(SRCDIR)
copy $(TESTDIR)\*.c $(DIST_NAME)\$(TESTDIR)
copy $(TESTDIR)\*.h $(DIST_NAME)\$(TESTDIR)
@rem zip is provided by MinGW
zip -rm $(DIST_NAME).zip $(DIST_NAME)
test:
$(MAKE) -f $(MAKEFILENAME) testnoham
@echo.
@echo Testing patent-reduced build
testnoham.exe
$(MAKE) -f $(MAKEFILENAME) testham
@echo.
@echo Testing full build
testham.exe
testham: clean lib $(TEST_OBJS_PATHS)
@echo CFLAGS=$(CFLAGS)
$(CC) $(CFLAGS) -o testham.exe $(TEST_OBJS_PATHS) $(LDFLAGS) -L. -llibntru -lm -lws2_32
testnoham: CFLAGS += -DNTRU_AVOID_HAMMING_WT_PATENT
testnoham: clean lib $(TEST_OBJS_PATHS)
@echo CFLAGS=$(CFLAGS)
$(CC) $(CFLAGS) -o testnoham.exe $(TEST_OBJS_PATHS) $(LDFLAGS) -L. -llibntru -lm -lws2_32
bench: lib
$(CC) $(CFLAGS) $(CPPFLAGS) -o bench $(SRCDIR)/bench.c $(LDFLAGS) -L. -llibntru
hybrid: lib
$(CC) $(CFLAGS) $(CPPFLAGS) -o hybrid $(SRCDIR)/hybrid.c $(LDFLAGS) -L. -llibntru -lcrypto -lgdi32
$(SRCDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(SRCDIR)/sha1-mb-x86_64.s: $(SRCDIR)/sha1-mb-x86_64.pl; CC=$(CC) ASM="$(AS)" $(PERL) $(SRCDIR)/sha1-mb-x86_64.pl $(PERLASM_SCHEME) > $@
$(SRCDIR)/sha1-mb-x86_64.o: $(SRCDIR)/sha1-mb-x86_64.s
$(AS) $(SRCDIR)/sha1-mb-x86_64.s -o $@
$(SRCDIR)/sha256-mb-x86_64.s: $(SRCDIR)/sha256-mb-x86_64.pl; CC=$(CC) ASM="$(AS)" $(PERL) $(SRCDIR)/sha256-mb-x86_64.pl $(PERLASM_SCHEME) > $@
$(SRCDIR)/sha256-mb-x86_64.o: $(SRCDIR)/sha256-mb-x86_64.s
$(AS) $(SRCDIR)/sha256-mb-x86_64.s -o $@
$(TESTDIR)/%.o: tests/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -I$(SRCDIR) -c $< -o $@
clean:
@if exist $(SRCDIR)\*.o del $(SRCDIR)\*.o
@if exist $(SRCDIR)\*.s del $(SRCDIR)\*.s
@if exist $(TESTDIR)\*.o del $(TESTDIR)\*.o
@if exist libntru.dll del libntru.dll
@if exist testham.exe del testham.exe
@if exist testnoham.exe del testnoham.exe
@if exist bench.exe del bench.exe
@if exist hybrid.exe del hybrid.exe
@rem ***** clean files generated on other OSes *****
@if exist libntru.so del libntru.so
@if exist libntru.a del libntru.a
@if exist libntru.dylib del libntru.dylib
@if exist testham del testnoham
@if exist testnoham del testnoham
@if exist bench del bench
@if exist hybrid del hybrid
distclean: clean
@if exist $(DIST_NAME)\$(SRCDIR)\*.c del $(DIST_NAME)\$(SRCDIR)\*.c
@if exist $(DIST_NAME)\$(SRCDIR)\*.h del $(DIST_NAME)\$(SRCDIR)\*.h
@if exist $(DIST_NAME)\$(SRCDIR) rmdir $(DIST_NAME)\$(SRCDIR)
@if exist $(DIST_NAME)\$(TESTDIR)\*.c del $(DIST_NAME)\$(TESTDIR)\*.c
@if exist $(DIST_NAME)\$(TESTDIR)\*.h del $(DIST_NAME)\$(TESTDIR)\*.h
@if exist $(DIST_NAME)\$(TESTDIR) rmdir $(DIST_NAME)\$(TESTDIR)
@if exist $(DIST_NAME)\*.* del /q $(DIST_NAME)\*.*
@if exist $(DIST_NAME) rmdir $(DIST_NAME)
@if exist $(DIST_NAME).zip del $(DIST_NAME).zip
@if exist $(DIST_NAME).tar.xz del $(DIST_NAME).tar.xz