Makefile.osx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. CC?=gcc
  2. AS=$(CC) -c
  3. # set CFLAGS depending on SIMD
  4. CFLAGS?=-g
  5. CFLAGS+=-Wall -Wextra -Wno-unused-parameter
  6. ifeq ($(SIMD), ssse3)
  7. CFLAGS+=-mssse3 -mno-avx2
  8. else ifeq ($(SIMD), avx2)
  9. CFLAGS+=-mssse3 -mavx2
  10. else ifneq ($(SIMD), none)
  11. SIMD=auto
  12. CFLAGS+=-DNTRU_DETECT_SIMD
  13. else
  14. CFLAGS+=-mno-ssse3 -mno-avx2
  15. endif
  16. # use -march=native if SIMD=auto
  17. BENCH_ARCH_OPTION=
  18. ifeq ($(SIMD), auto)
  19. BENCH_ARCH_OPTION=-march=native
  20. endif
  21. OPTFLAGS=-O2
  22. bench: OPTFLAGS=-O3 $(BENCH_ARCH_OPTION)
  23. CFLAGS+=$(OPTFLAGS)
  24. SRCDIR=src
  25. TESTDIR=tests
  26. 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
  27. ifneq ($(SIMD), none)
  28. LIB_OBJS+=sha1-mb-x86_64.o sha256-mb-x86_64.o hash_simd.o poly_ssse3.o
  29. ifneq ($(SIMD), ssse3)
  30. LIB_OBJS+=poly_avx2.o
  31. endif
  32. endif
  33. 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
  34. VERSION=0.5
  35. INST_PFX=/usr
  36. INST_LIBDIR=$(INST_PFX)/lib
  37. INST_INCLUDE=$(INST_PFX)/include/libntru
  38. INST_DOCDIR=$(INST_PFX)/share/doc/libntru
  39. INST_HEADERS=ntru.h types.h key.h encparams.h hash.h rand.h err.h
  40. PERL=/usr/bin/perl
  41. PERLASM_SCHEME=macosx
  42. LIB_OBJS_PATHS=$(patsubst %,$(SRCDIR)/%,$(LIB_OBJS))
  43. TEST_OBJS_PATHS=$(patsubst %,$(TESTDIR)/%,$(TEST_OBJS))
  44. DIST_NAME=libntru-$(VERSION)
  45. MAKEFILENAME=$(lastword $(MAKEFILE_LIST))
  46. .PHONY: all lib install uninstall dist test clean distclean
  47. all: lib
  48. lib: $(LIB_OBJS_PATHS)
  49. $(CC) $(CFLAGS) $(CPPFLAGS) -dynamiclib -o libntru.dylib $(LIB_OBJS_PATHS) $(LDFLAGS) $(LIBS)
  50. install: lib
  51. test -d "$(DESTDIR)$(INST_PFX)" || mkdir -p "$(DESTDIR)$(INST_PFX)"
  52. test -d "$(DESTDIR)$(INST_LIBDIR)" || mkdir "$(DESTDIR)$(INST_LIBDIR)"
  53. test -d "$(DESTDIR)$(INST_INCLUDE)" || mkdir -p "$(DESTDIR)$(INST_INCLUDE)"
  54. test -d "$(DESTDIR)$(INST_DOCDIR)" || mkdir -p "$(DESTDIR)$(INST_DOCDIR)"
  55. install -m 0755 libntru.so "$(DESTDIR)$(INST_LIBDIR)/libntru.so"
  56. install -m 0644 README.md "$(DESTDIR)$(INST_DOCDIR)/README.md"
  57. for header in $(INST_HEADERS) ; do \
  58. install -m 0644 "$(SRCDIR)/$$header" "$(DESTDIR)$(INST_INCLUDE)/" ; \
  59. done
  60. uninstall:
  61. rm -f "$(DESTDIR)$(INST_LIBDIR)/libntru.so"
  62. rm -f "$(DESTDIR)$(INST_DOCDIR)/README.md"
  63. rmdir "$(DESTDIR)$(INST_DOCDIR)/"
  64. for header in $(INST_HEADERS) ; do \
  65. rm "$(DESTDIR)$(INST_INCLUDE)/$$header" ; \
  66. done
  67. rmdir "$(DESTDIR)$(INST_INCLUDE)/"
  68. dist:
  69. rm -rf $(DIST_NAME)
  70. mkdir $(DIST_NAME)
  71. mkdir $(DIST_NAME)/$(SRCDIR)
  72. mkdir $(DIST_NAME)/$(TESTDIR)
  73. cp Makefile Makefile.win Makefile.osx README.md LICENSE PATENTS $(DIST_NAME)
  74. cp $(SRCDIR)/*.c $(DIST_NAME)/$(SRCDIR)
  75. cp $(SRCDIR)/*.h $(DIST_NAME)/$(SRCDIR)
  76. cp $(TESTDIR)/*.c $(DIST_NAME)/$(TESTDIR)
  77. cp $(TESTDIR)/*.h $(DIST_NAME)/$(TESTDIR)
  78. tar cf $(DIST_NAME).tar.xz $(DIST_NAME) --lzma
  79. rm -rf $(DIST_NAME)
  80. test:
  81. $(MAKE) -f $(MAKEFILENAME) testnoham
  82. @echo
  83. @echo Testing patent-reduced build
  84. DYLD_LIBRARY_PATH=. ./testnoham
  85. $(MAKE) -f $(MAKEFILENAME) testham
  86. @echo
  87. @echo Testing full build
  88. DYLD_LIBRARY_PATH=. ./testham
  89. testham: clean lib $(TEST_OBJS_PATHS)
  90. @echo CFLAGS=$(CFLAGS)
  91. $(CC) $(CFLAGS) -o testham $(TEST_OBJS_PATHS) -L. -lntru -lm
  92. testnoham: CFLAGS += -DNTRU_AVOID_HAMMING_WT_PATENT
  93. testnoham: clean lib $(TEST_OBJS_PATHS)
  94. @echo CFLAGS=$(CFLAGS)
  95. $(CC) $(CFLAGS) -o testnoham $(TEST_OBJS_PATHS) -L. -lntru -lm
  96. bench: lib
  97. $(CC) $(CFLAGS) $(CPPFLAGS) -o bench $(SRCDIR)/bench.c $(LDFLAGS) -L. -lntru
  98. hybrid: lib
  99. $(CC) $(CFLAGS) $(CPPFLAGS) -o hybrid $(SRCDIR)/hybrid.c $(LDFLAGS) -L. -lntru -lsodium
  100. $(SRCDIR)/%.o: $(SRCDIR)/%.c
  101. $(CC) $(CFLAGS) $(CPPFLAGS) -c -fPIC $< -o $@
  102. $(SRCDIR)/poly_ssse3.o: $(SRCDIR)/poly_ssse3.c
  103. $(CC) $(CFLAGS) $(CPPFLAGS) -mssse3 -c -fPIC $(SRCDIR)/poly_ssse3.c -o $(SRCDIR)/poly_ssse3.o
  104. $(SRCDIR)/poly_avx2.o: $(SRCDIR)/poly_avx2.c
  105. $(CC) $(CFLAGS) $(CPPFLAGS) -mavx2 -c -fPIC $(SRCDIR)/poly_avx2.c -o $(SRCDIR)/poly_avx2.o
  106. $(SRCDIR)/hash_simd.o: $(SRCDIR)/hash_simd.c
  107. $(CC) $(CFLAGS) $(CPPFLAGS) -mssse3 -c -fPIC $(SRCDIR)/hash_simd.c -o $(SRCDIR)/hash_simd.o
  108. $(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) > $@
  109. $(SRCDIR)/sha1-mb-x86_64.o: $(SRCDIR)/sha1-mb-x86_64.s
  110. $(AS) $(SRCDIR)/sha1-mb-x86_64.s -o $@
  111. $(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) > $@
  112. $(SRCDIR)/sha256-mb-x86_64.o: $(SRCDIR)/sha256-mb-x86_64.s
  113. $(AS) $(SRCDIR)/sha256-mb-x86_64.s -o $@
  114. tests/%.o: tests/%.c
  115. $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -I$(SRCDIR) -c $< -o $@
  116. clean:
  117. @# also clean files generated on other OSes
  118. rm -f $(SRCDIR)/*.o $(SRCDIR)/*.s $(TESTDIR)/*.o libntru.so libntru.a libntru.dylib libntru.dll testham testnoham testham.exe testnoham.exe bench bench.exe hybrid hybrid.exe
  119. distclean: clean
  120. rm -rf $(DIST_NAME)
  121. rm -f $(DIST_NAME).tar.xz $(DIST_NAME).zip