Makefile.win 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. CC?=gcc
  2. AS=$(CC) -c
  3. ifeq ($(SIMD), sse)
  4. SIMD=ssse3
  5. endif
  6. # set CFLAGS depending on SIMD
  7. CFLAGS?=-g
  8. CFLAGS+=-Wall -Wextra -Wno-unused-parameter
  9. ifeq ($(SIMD), ssse3)
  10. CFLAGS+=-mssse3
  11. else ifeq ($(SIMD), avx2)
  12. CFLAGS+=-mssse3 -mavx2
  13. else ifneq ($(SIMD), none)
  14. SIMD=auto
  15. CFLAGS+=-DNTRU_DETECT_SIMD
  16. endif
  17. # use -march=native if SIMD=auto
  18. BENCH_ARCH_OPTION=
  19. ifeq ($(SIMD), auto)
  20. BENCH_ARCH_OPTION=-march=native
  21. endif
  22. OPTFLAGS=-O2
  23. bench: OPTFLAGS=-O3 $(BENCH_ARCH_OPTION)
  24. CFLAGS+=$(OPTFLAGS)
  25. SRCDIR=src
  26. TESTDIR=tests
  27. 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
  28. ifneq ($(SIMD), none)
  29. LIB_OBJS+=sha1-mb-x86_64.o sha256-mb-x86_64.o hash_simd.o poly_ssse3.o
  30. ifneq ($(SIMD), ssse3)
  31. LIB_OBJS+=poly_avx2.o
  32. endif
  33. endif
  34. TEST_OBJS=test_bitstring.o test_hash.o test_idxgen.o test_key.o test_ntruprime.o test_ntru.o test.o test_poly.o test_util.o
  35. VERSION=0.5
  36. INST_PFX=%PROGRAMFILES%
  37. INST_LIBDIR=$(INST_PFX)\libntru
  38. INST_INCLUDE=$(INST_PFX)\libntru\include
  39. INST_DOCDIR=$(INST_PFX)\libntru
  40. INST_HEADERS=ntru.h types.h key.h encparams.h hash.h rand.h err.h
  41. PERL=c:\mingw\msys\1.0\bin\perl
  42. PERLASM_SCHEME=coff
  43. LIB_OBJS_PATHS=$(patsubst %,$(SRCDIR)/%,$(LIB_OBJS))
  44. TEST_OBJS_PATHS=$(patsubst %,$(TESTDIR)/%,$(TEST_OBJS))
  45. DIST_NAME=libntru-$(VERSION)
  46. MAKEFILENAME=$(lastword $(MAKEFILE_LIST))
  47. .PHONY: all lib install dist test clean distclean
  48. all: lib
  49. lib: $(LIB_OBJS_PATHS)
  50. $(CC) $(CFLAGS) $(CPPFLAGS) -shared -o libntru.dll $(LIB_OBJS_PATHS) -lws2_32 -ladvapi32
  51. install: lib
  52. if not exist "$(DESTDIR)$(INST_PFX)" mkdir "$(DESTDIR)$(INST_PFX)"
  53. if not exist "$(DESTDIR)$(INST_LIBDIR)" mkdir "$(DESTDIR)$(INST_LIBDIR)"
  54. if not exist "$(DESTDIR)$(INST_INCLUDE)" mkdir "$(DESTDIR)$(INST_INCLUDE)"
  55. if not exist "$(DESTDIR)$(INST_DOCDIR)" mkdir "$(DESTDIR)$(INST_DOCDIR)"
  56. copy libntru.dll "$(DESTDIR)$(INST_LIBDIR)"
  57. copy README.md "$(DESTDIR)$(INST_DOCDIR)"
  58. for %%h in ($(INST_HEADERS)) do \
  59. copy $(SRCDIR)\%%h "$(INST_INCLUDE)"
  60. uninstall:
  61. if exist "$(DESTDIR)$(INST_LIBDIR)\libntru.dll" del "$(DESTDIR)$(INST_LIBDIR)\libntru.dll"
  62. if exist "$(DESTDIR)$(INST_DOCDIR)\README.md" del "$(DESTDIR)$(INST_DOCDIR)\README.md"
  63. for %%h in ($(DESTDIR)$(INST_HEADERS)) do \
  64. if exist "$(DESTDIR)$(INST_INCLUDE)\%%h" del "$(DESTDIR)$(INST_INCLUDE)\%%h"
  65. if exist "$(DESTDIR)$(INST_INCLUDE)" rmdir "$(DESTDIR)$(INST_INCLUDE)"
  66. if exist "$(DESTDIR)$(INST_LIBDIR)" rmdir "$(DESTDIR)$(INST_LIBDIR)"
  67. if exist "$(DESTDIR)$(INST_DOCDIR)" rmdir "$(DESTDIR)$(INST_DOCDIR)"
  68. dist:
  69. @if exist $(DIST_NAME)\$(SRCDIR)\*.c del $(DIST_NAME)\$(SRCDIR)\*.c
  70. @if exist $(DIST_NAME)\$(SRCDIR)\*.h del $(DIST_NAME)\$(SRCDIR)\*.h
  71. @if exist $(DIST_NAME)\$(SRCDIR) rmdir $(DIST_NAME)\$(SRCDIR)
  72. @if exist $(DIST_NAME)\$(TESTDIR)\*.c del $(DIST_NAME)\$(TESTDIR)\*.c
  73. @if exist $(DIST_NAME)\$(TESTDIR)\*.h del $(DIST_NAME)\$(TESTDIR)\*.h
  74. @if exist $(DIST_NAME)\$(TESTDIR) rmdir $(DIST_NAME)\$(TESTDIR)
  75. @if exist $(DIST_NAME)\*.* del /q $(DIST_NAME)\*.*
  76. @if exist $(DIST_NAME) rmdir $(DIST_NAME)
  77. mkdir $(DIST_NAME)
  78. mkdir $(DIST_NAME)\$(SRCDIR)
  79. mkdir $(DIST_NAME)\$(TESTDIR)
  80. copy Makefile $(DIST_NAME)
  81. copy Makefile.win $(DIST_NAME)
  82. copy Makefile.osx $(DIST_NAME)
  83. copy README.md $(DIST_NAME)
  84. copy LICENSE $(DIST_NAME)
  85. copy PATENTS $(DIST_NAME)
  86. copy $(SRCDIR)\*.c $(DIST_NAME)\$(SRCDIR)
  87. copy $(SRCDIR)\*.h $(DIST_NAME)\$(SRCDIR)
  88. copy $(TESTDIR)\*.c $(DIST_NAME)\$(TESTDIR)
  89. copy $(TESTDIR)\*.h $(DIST_NAME)\$(TESTDIR)
  90. @rem zip is provided by MinGW
  91. zip -rm $(DIST_NAME).zip $(DIST_NAME)
  92. test:
  93. $(MAKE) -f $(MAKEFILENAME) testnoham
  94. @echo.
  95. @echo Testing patent-reduced build
  96. testnoham.exe
  97. $(MAKE) -f $(MAKEFILENAME) testham
  98. @echo.
  99. @echo Testing full build
  100. testham.exe
  101. testham: clean lib $(TEST_OBJS_PATHS)
  102. @echo CFLAGS=$(CFLAGS)
  103. $(CC) $(CFLAGS) -o testham.exe $(TEST_OBJS_PATHS) $(LDFLAGS) -L. -llibntru -lm -lws2_32
  104. testnoham: CFLAGS += -DNTRU_AVOID_HAMMING_WT_PATENT
  105. testnoham: clean lib $(TEST_OBJS_PATHS)
  106. @echo CFLAGS=$(CFLAGS)
  107. $(CC) $(CFLAGS) -o testnoham.exe $(TEST_OBJS_PATHS) $(LDFLAGS) -L. -llibntru -lm -lws2_32
  108. bench: lib
  109. $(CC) $(CFLAGS) $(CPPFLAGS) -o bench $(SRCDIR)/bench.c $(LDFLAGS) -L. -llibntru
  110. hybrid: lib
  111. $(CC) $(CFLAGS) $(CPPFLAGS) -o hybrid $(SRCDIR)/hybrid.c $(LDFLAGS) -L. -llibntru -lsodium -lgdi32
  112. $(SRCDIR)/%.o: $(SRCDIR)/%.c
  113. $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
  114. $(SRCDIR)/poly_ssse3.o: $(SRCDIR)/poly_ssse3.c
  115. $(CC) $(CFLAGS) $(CPPFLAGS) -mssse3 -c -fPIC $(SRCDIR)/poly_ssse3.c -o $(SRCDIR)/poly_ssse3.o
  116. $(SRCDIR)/poly_avx2.o: $(SRCDIR)/poly_avx2.c
  117. $(CC) $(CFLAGS) $(CPPFLAGS) -mavx2 -c -fPIC $(SRCDIR)/poly_avx2.c -o $(SRCDIR)/poly_avx2.o
  118. $(SRCDIR)/hash_simd.o: $(SRCDIR)/hash_simd.c
  119. $(CC) $(CFLAGS) $(CPPFLAGS) -mssse3 -c -fPIC $(SRCDIR)/hash_simd.c -o $(SRCDIR)/hash_simd.o
  120. $(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) > $@
  121. $(SRCDIR)/sha1-mb-x86_64.o: $(SRCDIR)/sha1-mb-x86_64.s
  122. $(AS) $(SRCDIR)/sha1-mb-x86_64.s -o $@
  123. $(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) > $@
  124. $(SRCDIR)/sha256-mb-x86_64.o: $(SRCDIR)/sha256-mb-x86_64.s
  125. $(AS) $(SRCDIR)/sha256-mb-x86_64.s -o $@
  126. $(TESTDIR)/%.o: tests/%.c
  127. $(CC) $(CFLAGS) $(CPPFLAGS) -I$(SRCDIR) -c $< -o $@
  128. clean:
  129. @if exist $(SRCDIR)\*.o del $(SRCDIR)\*.o
  130. @if exist $(SRCDIR)\*.s del $(SRCDIR)\*.s
  131. @if exist $(TESTDIR)\*.o del $(TESTDIR)\*.o
  132. @if exist libntru.dll del libntru.dll
  133. @if exist testham.exe del testham.exe
  134. @if exist testnoham.exe del testnoham.exe
  135. @if exist bench.exe del bench.exe
  136. @if exist hybrid.exe del hybrid.exe
  137. @rem ***** clean files generated on other OSes *****
  138. @if exist libntru.so del libntru.so
  139. @if exist libntru.a del libntru.a
  140. @if exist libntru.dylib del libntru.dylib
  141. @if exist testham del testnoham
  142. @if exist testnoham del testnoham
  143. @if exist bench del bench
  144. @if exist hybrid del hybrid
  145. distclean: clean
  146. @if exist $(DIST_NAME)\$(SRCDIR)\*.c del $(DIST_NAME)\$(SRCDIR)\*.c
  147. @if exist $(DIST_NAME)\$(SRCDIR)\*.h del $(DIST_NAME)\$(SRCDIR)\*.h
  148. @if exist $(DIST_NAME)\$(SRCDIR) rmdir $(DIST_NAME)\$(SRCDIR)
  149. @if exist $(DIST_NAME)\$(TESTDIR)\*.c del $(DIST_NAME)\$(TESTDIR)\*.c
  150. @if exist $(DIST_NAME)\$(TESTDIR)\*.h del $(DIST_NAME)\$(TESTDIR)\*.h
  151. @if exist $(DIST_NAME)\$(TESTDIR) rmdir $(DIST_NAME)\$(TESTDIR)
  152. @if exist $(DIST_NAME)\*.* del /q $(DIST_NAME)\*.*
  153. @if exist $(DIST_NAME) rmdir $(DIST_NAME)
  154. @if exist $(DIST_NAME).zip del $(DIST_NAME).zip
  155. @if exist $(DIST_NAME).tar.xz del $(DIST_NAME).tar.xz