You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

169 lines
4.7 KiB

  1. # Copyright (c) 2014 Cryptography Research, Inc.
  2. # Released under the MIT License. See LICENSE.txt for license information.
  3. UNAME := $(shell uname)
  4. MACHINE := $(shell uname -m)
  5. ifeq ($(UNAME),Darwin)
  6. CC = clang
  7. else
  8. CC = gcc
  9. endif
  10. LD = $(CC)
  11. ASM ?= $(CC)
  12. ifneq (,$(findstring x86_64,$(MACHINE)))
  13. ARCH ?= arch_x86_64
  14. else
  15. # no i386 port yet
  16. ARCH ?= arch_arm_32
  17. endif
  18. WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
  19. -Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)
  20. INCFLAGS = -Isrc/include -Iinclude -Isrc/$(ARCH)
  21. LANGFLAGS = -std=c99 -fno-strict-aliasing
  22. GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC
  23. OFLAGS = -O3
  24. TODAY = $(shell date "+%Y-%m-%d")
  25. ifneq (,$(findstring arm,$(MACHINE)))
  26. ifneq (,$(findstring neon,$(ARCH)))
  27. ARCHFLAGS += -mfpu=neon
  28. else
  29. ARCHFLAGS += -mfpu=vfpv3-d16
  30. endif
  31. ARCHFLAGS += -mcpu=cortex-a8 # FIXME
  32. GENFLAGS += -DN_TESTS_BASE=1000 # sooooo sloooooow
  33. else
  34. ARCHFLAGS += -maes -mavx2 -mbmi2 #TODO
  35. endif
  36. ifeq ($(CC),clang)
  37. WARNFLAGS += -Wgcc-compat
  38. endif
  39. ifeq (,$(findstring 64,$(ARCH))$(findstring gcc,$(CC)))
  40. # ARCHFLAGS += -m32
  41. XCFLAGS += -DGOLDI_FORCE_32_BIT=1
  42. endif
  43. CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
  44. LDFLAGS = $(ARCHFLAGS) $(XLDFLAGS)
  45. ASFLAGS = $(ARCHFLAGS)
  46. .PHONY: clean all test bench todo doc lib bat
  47. .PRECIOUS: build/%.s
  48. HEADERS= Makefile $(shell find . -name "*.h") build/timestamp
  49. LIBCOMPONENTS= build/goldilocks.o build/barrett_field.o build/crandom.o \
  50. build/p448.o build/ec_point.o build/scalarmul.o build/sha512.o build/magic.o build/arithmetic.o
  51. TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \
  52. build/test_pointops.o build/test_arithmetic.o build/test_goldilocks.o build/magic.o
  53. BENCHCOMPONENTS=build/bench.o
  54. BATBASE=ed448goldilocks-bats-$(TODAY)
  55. BATNAME=build/$(BATBASE)
  56. all: lib build/test build/bench
  57. scan: clean
  58. scan-build --use-analyzer=`which clang` \
  59. -enable-checker deadcode -enable-checker llvm \
  60. -enable-checker osx -enable-checker security -enable-checker unix \
  61. make build/bench build/test build/goldilocks.so
  62. build/bench: $(LIBCOMPONENTS) $(BENCHCOMPONENTS)
  63. $(LD) $(LDFLAGS) -o $@ $^
  64. build/test: $(LIBCOMPONENTS) $(TESTCOMPONENTS)
  65. $(LD) $(LDFLAGS) -o $@ $^ -lgmp
  66. lib: build/goldilocks.so
  67. build/goldilocks.so: $(LIBCOMPONENTS)
  68. rm -f $@
  69. ifeq ($(UNAME),Darwin)
  70. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  71. $(LIBCOMPONENTS)
  72. else
  73. $(LD) -shared -Wl,-soname,goldilocks.so.1 -Wl,--gc-sections -o $@ $(LIBCOMPONENTS)
  74. strip --discard-all $@
  75. ln -sf $@ build/goldilocks.so.1
  76. endif
  77. build/timestamp:
  78. mkdir -p build
  79. touch $@
  80. build/%.o: build/%.s
  81. $(ASM) $(ASFLAGS) -c -o $@ $<
  82. build/%.s: src/%.c $(HEADERS)
  83. $(CC) $(CFLAGS) -S -c -o $@ $<
  84. build/%.s: test/%.c $(HEADERS)
  85. $(CC) $(CFLAGS) -S -c -o $@ $<
  86. build/%.s: src/$(ARCH)/%.c $(HEADERS)
  87. $(CC) $(CFLAGS) -S -c -o $@ $<
  88. doc/timestamp:
  89. mkdir -p doc
  90. touch $@
  91. doc: Doxyfile doc/timestamp src/*.c src/include/*.h src/$(ARCH)/*.c src/$(ARCH)/*.h
  92. doxygen
  93. bat: $(BATNAME)
  94. $(BATNAME): include/* src/* src/*/* test/batarch.map
  95. rm -fr $@
  96. for prim in dh sign; do \
  97. targ="$@/crypto_$$prim/ed448goldilocks"; \
  98. (while read arch where; do \
  99. mkdir -p $$targ/`basename $$arch`; \
  100. cp include/*.h src/*.c src/include/*.h src/bat/$$prim.c src/$$where/*.c src/$$where/*.h $$targ/`basename $$arch`; \
  101. cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \
  102. perl -p -i -e 's/.*endif.*GOLDILOCKS_CONFIG_H/#define SUPERCOP_WONT_LET_ME_OPEN_FILES 1\n\n$$&/' $$targ/`basename $$arch`/config.h; \
  103. perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \
  104. perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \
  105. done \
  106. ) < test/batarch.map; \
  107. echo 'Mike Hamburg' > $$targ/designers; \
  108. echo 'Ed448-Goldilocks sign and dh' > $$targ/description; \
  109. done
  110. (cd build && tar czf $(BATBASE).tgz $(BATBASE) )
  111. todo::
  112. @(find * -name '*.h'; find * -name '*.c') | xargs egrep --color=auto -w \
  113. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC'
  114. @echo '============================='
  115. @(for i in FIXME BUG XXX TODO HACK PERF FUTURE REMOVE MAGIC; do \
  116. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i > /dev/null || continue; \
  117. /bin/echo -n $$i' ' | head -c 10; \
  118. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i| wc -l; \
  119. done)
  120. @echo '============================='
  121. @echo -n 'Total '
  122. @(find * -name '*.h'; find * -name '*.c') | xargs egrep -w \
  123. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC' | wc -l
  124. bench: build/bench
  125. ./$<
  126. test: build/test
  127. ./$<
  128. clean:
  129. rm -fr build doc $(BATNAME)