Makefile.os2 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. LIBS+=-lrt
  26. SRCDIR=src
  27. TESTDIR=tests
  28. 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
  29. ifneq ($(SIMD), none)
  30. LIB_OBJS+=sha1-mb-x86_64.o sha256-mb-x86_64.o hash_simd.o poly_ssse3.o
  31. ifneq ($(SIMD), ssse3)
  32. LIB_OBJS+=poly_avx2.o
  33. endif
  34. endif
  35. 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
  36. VERSION=0.5
  37. INST_PFX=%PROGRAMFILES%
  38. INST_LIBDIR=$(INST_PFX)\libntru
  39. INST_INCLUDE=$(INST_PFX)\libntru\include
  40. INST_DOCDIR=$(INST_PFX)\libntru
  41. INST_HEADERS=ntru.h types.h key.h encparams.h hash.h rand.h err.h
  42. PERL=c:\mingw\msys\1.0\bin\perl
  43. PERLASM_SCHEME=coff
  44. LIB_OBJS_PATHS=$(patsubst %,$(SRCDIR)/%,$(LIB_OBJS))
  45. TEST_OBJS_PATHS=$(patsubst %,$(TESTDIR)/%,$(TEST_OBJS))
  46. DIST_NAME=libntru-$(VERSION)
  47. MAKEFILENAME=$(lastword $(MAKEFILE_LIST))
  48. .PHONY: all lib install dist test clean distclean
  49. all: lib
  50. lib: $(LIB_OBJS_PATHS)
  51. $(CC) $(CFLAGS) $(CPPFLAGS) -shared -o libntru.dll $(LIB_OBJS_PATHS)
  52. install: lib
  53. mkdir "$(DESTDIR)$(INST_PFX)"
  54. mkdir "$(DESTDIR)$(INST_LIBDIR)"
  55. mkdir "$(DESTDIR)$(INST_INCLUDE)"
  56. mkdir "$(DESTDIR)$(INST_DOCDIR)"
  57. copy libntru.dll "$(DESTDIR)$(INST_LIBDIR)"
  58. copy README.md "$(DESTDIR)$(INST_DOCDIR)"
  59. for %%h in ($(INST_HEADERS)) do \
  60. copy $(SRCDIR)\%%h "$(INST_INCLUDE)"
  61. uninstall:
  62. rm -f "$(DESTDIR)$(INST_LIBDIR)\libntru.dll"
  63. rm -f "$(DESTDIR)$(INST_DOCDIR)\README.md"
  64. for %%h in ($(DESTDIR)$(INST_HEADERS)) do \
  65. rm -f "$(DESTDIR)$(INST_INCLUDE)\%%h"
  66. rmdir "$(DESTDIR)$(INST_INCLUDE)"
  67. rmdir "$(DESTDIR)$(INST_LIBDIR)"
  68. rmdir "$(DESTDIR)$(INST_DOCDIR)"
  69. dist:
  70. rm -f $(DIST_NAME)\$(SRCDIR)\*.c
  71. rm -f $(DIST_NAME)\$(SRCDIR)\*.h
  72. rmdir $(DIST_NAME)\$(SRCDIR)
  73. rm -f $(DIST_NAME)\$(TESTDIR)\*.c
  74. rm -f $(DIST_NAME)\$(TESTDIR)\*.h
  75. rmdir $(DIST_NAME)\$(TESTDIR)
  76. rm -f /q $(DIST_NAME)\*.*
  77. rmdir $(DIST_NAME)
  78. mkdir $(DIST_NAME)
  79. mkdir $(DIST_NAME)\$(SRCDIR)
  80. mkdir $(DIST_NAME)\$(TESTDIR)
  81. copy Makefile $(DIST_NAME)
  82. copy Makefile.win $(DIST_NAME)
  83. copy Makefile.osx $(DIST_NAME)
  84. copy README.md $(DIST_NAME)
  85. copy LICENSE $(DIST_NAME)
  86. copy PATENTS $(DIST_NAME)
  87. copy $(SRCDIR)\*.c $(DIST_NAME)\$(SRCDIR)
  88. copy $(SRCDIR)\*.h $(DIST_NAME)\$(SRCDIR)
  89. copy $(TESTDIR)\*.c $(DIST_NAME)\$(TESTDIR)
  90. copy $(TESTDIR)\*.h $(DIST_NAME)\$(TESTDIR)
  91. test:
  92. $(MAKE) -f $(MAKEFILENAME) testnoham
  93. @echo.
  94. @echo Testing patent-reduced build
  95. testnoham.exe
  96. $(MAKE) -f $(MAKEFILENAME) testham
  97. @echo.
  98. @echo Testing full build
  99. testham.exe
  100. testham: clean lib $(TEST_OBJS_PATHS)
  101. @echo CFLAGS=$(CFLAGS)
  102. $(CC) $(CFLAGS) -o testham.exe $(TEST_OBJS_PATHS) -L. -lntru -lm
  103. testnoham: CFLAGS += -DNTRU_AVOID_HAMMING_WT_PATENT
  104. testnoham: clean lib $(TEST_OBJS_PATHS)
  105. @echo CFLAGS=$(CFLAGS)
  106. $(CC) $(CFLAGS) -o testnoham.exe $(TEST_OBJS_PATHS) -L. -lntru -lm
  107. bench: lib
  108. $(CC) $(CFLAGS) $(CPPFLAGS) -o bench $(SRCDIR)/bench.c -L. -lntru
  109. hybrid: lib
  110. $(CC) $(CFLAGS) $(CPPFLAGS) -o hybrid $(SRCDIR)/hybrid.c $(LDFLAGS) -L. -lntru -lsodium -lgdi32
  111. $(SRCDIR)/%.o: $(SRCDIR)/%.c
  112. $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
  113. $(SRCDIR)/poly_ssse3.o: $(SRCDIR)/poly_ssse3.c
  114. $(CC) $(CFLAGS) $(CPPFLAGS) -mssse3 -c -fPIC $(SRCDIR)/poly_ssse3.c -o $(SRCDIR)/poly_ssse3.o
  115. $(SRCDIR)/poly_avx2.o: $(SRCDIR)/poly_avx2.c
  116. $(CC) $(CFLAGS) $(CPPFLAGS) -mavx2 -c -fPIC $(SRCDIR)/poly_avx2.c -o $(SRCDIR)/poly_avx2.o
  117. $(SRCDIR)/hash_simd.o: $(SRCDIR)/hash_simd.c
  118. $(CC) $(CFLAGS) $(CPPFLAGS) -mssse3 -c -fPIC $(SRCDIR)/hash_simd.c -o $(SRCDIR)/hash_simd.o
  119. $(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) > $@
  120. $(SRCDIR)/sha1-mb-x86_64.o: $(SRCDIR)/sha1-mb-x86_64.s
  121. $(AS) $(SRCDIR)/sha1-mb-x86_64.s -o $@
  122. $(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) > $@
  123. $(SRCDIR)/sha256-mb-x86_64.o: $(SRCDIR)/sha256-mb-x86_64.s
  124. $(AS) $(SRCDIR)/sha256-mb-x86_64.s -o $@
  125. $(TESTDIR)/%.o: tests/%.c
  126. $(CC) $(CFLAGS) $(CPPFLAGS) -I$(SRCDIR) -c $< -o $@
  127. clean:
  128. rm -f $(SRCDIR)\*.o
  129. rm -f $(SRCDIR)\*.s
  130. rm -f $(TESTDIR)\*.o
  131. rm -f libntru.dll
  132. rm -f testham.exe
  133. rm -f testnoham.exe
  134. rm -f bench.exe
  135. rm -f libntru.so
  136. rm -f libntru.dylib
  137. rm -f testham
  138. rm -f testnoham
  139. rm -f bench
  140. rm -f hybrid
  141. rm -f hybrid.exe
  142. distclean: clean
  143. rm -f $(DIST_NAME)\$(SRCDIR)\*.c
  144. rm -f $(DIST_NAME)\$(SRCDIR)\*.h
  145. rmdir $(DIST_NAME)\$(SRCDIR)
  146. rm -f $(DIST_NAME)\$(TESTDIR)\*.c
  147. rm -f $(DIST_NAME)\$(TESTDIR)\*.h
  148. rmdir $(DIST_NAME)\$(TESTDIR)
  149. rm -f $(DIST_NAME)\*.*
  150. rmdir $(DIST_NAME)
  151. rm -f $(DIST_NAME).zip
  152. rm -f $(DIST_NAME).tar.xz