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.
 
 
 
 
 

159 lines
4.2 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. ifneq (,$(findstring arm,$(MACHINE)))
  25. ifneq (,$(findstring neon,$(ARCH)))
  26. ARCHFLAGS += -mfpu=neon
  27. else
  28. ARCHFLAGS += -mfpu=vfpv3-d16
  29. endif
  30. ARCHFLAGS += -mcpu=cortex-a8 # FIXME
  31. GENFLAGS += -DN_TESTS_BASE=1000 # sooooo sloooooow
  32. else
  33. ARCHFLAGS += -maes -mavx2 -mbmi2 #TODO
  34. endif
  35. ifeq ($(CC),clang)
  36. WARNFLAGS += -Wgcc-compat
  37. endif
  38. ifeq (,$(findstring 64,$(ARCH))$(findstring gcc,$(CC)))
  39. # ARCHFLAGS += -m32
  40. XCFLAGS += -DGOLDI_FORCE_32_BIT=1
  41. endif
  42. CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
  43. LDFLAGS = $(ARCHFLAGS) $(XLDFLAGS)
  44. ASFLAGS = $(ARCHFLAGS)
  45. .PHONY: clean all test bench todo doc lib bat
  46. .PRECIOUS: build/%.s
  47. HEADERS= Makefile $(shell find . -name "*.h") build/timestamp
  48. LIBCOMPONENTS= build/goldilocks.o build/barrett_field.o build/crandom.o \
  49. build/p448.o build/ec_point.o build/scalarmul.o build/sha512.o build/magic.o
  50. TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \
  51. build/test_pointops.o build/test_arithmetic.o build/test_goldilocks.o build/magic.o
  52. BENCHCOMPONENTS=build/bench.o
  53. BATNAME=build/ed448goldilocks
  54. all: lib build/test build/bench
  55. scan: clean
  56. scan-build --use-analyzer=`which clang` \
  57. -enable-checker deadcode -enable-checker llvm \
  58. -enable-checker osx -enable-checker security -enable-checker unix \
  59. make build/bench build/test build/goldilocks.so
  60. build/bench: $(LIBCOMPONENTS) $(BENCHCOMPONENTS)
  61. $(LD) $(LDFLAGS) -o $@ $^
  62. build/test: $(LIBCOMPONENTS) $(TESTCOMPONENTS)
  63. $(LD) $(LDFLAGS) -o $@ $^ -lgmp
  64. lib: build/goldilocks.so
  65. build/goldilocks.so: $(LIBCOMPONENTS)
  66. rm -f $@
  67. ifeq ($(UNAME),Darwin)
  68. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  69. $(LIBCOMPONENTS)
  70. else
  71. $(LD) -shared -Wl,-soname,goldilocks.so.1 -Wl,--gc-sections -o $@ $(LIBCOMPONENTS)
  72. strip --discard-all $@
  73. ln -sf $@ build/goldilocks.so.1
  74. endif
  75. build/timestamp:
  76. mkdir -p build
  77. touch $@
  78. build/%.o: build/%.s
  79. $(ASM) $(ASFLAGS) -c -o $@ $<
  80. build/%.s: src/%.c $(HEADERS)
  81. $(CC) $(CFLAGS) -S -c -o $@ $<
  82. build/%.s: test/%.c $(HEADERS)
  83. $(CC) $(CFLAGS) -S -c -o $@ $<
  84. build/%.s: src/$(ARCH)/%.c $(HEADERS)
  85. $(CC) $(CFLAGS) -S -c -o $@ $<
  86. doc/timestamp:
  87. mkdir -p doc
  88. touch $@
  89. doc: Doxyfile doc/timestamp src/*.c src/include/*.h src/$(ARCH)/*.c src/$(ARCH)/*.h
  90. doxygen
  91. bat: $(BATNAME)
  92. $(BATNAME): include/* src/* src/*/*
  93. rm -fr $@
  94. for arch in src/arch*; do \
  95. mkdir -p $@/`basename $$arch`; \
  96. cp include/* src/*.c src/include/* $$arch/* $@/`basename $$arch`; \
  97. perl -p -i -e 's/.*endif.*GOLDILOCKS_CONFIG_H/#define SUPERCOP_WONT_LET_ME_OPEN_FILES 1\n\n$$&/' $@/`basename $$arch`/config.h; \
  98. perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $@/`basename $$arch`/api.h; \
  99. done
  100. echo 'Mike Hamburg' > $@/designers
  101. echo 'Ed448-Goldilocks sign and dh' > $@/description
  102. todo::
  103. @(find * -name '*.h'; find * -name '*.c') | xargs egrep --color=auto -w \
  104. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC'
  105. @echo '============================='
  106. @(for i in FIXME BUG XXX TODO HACK PERF FUTURE REMOVE MAGIC; do \
  107. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i > /dev/null || continue; \
  108. /bin/echo -n $$i' ' | head -c 10; \
  109. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i| wc -l; \
  110. done)
  111. @echo '============================='
  112. @echo -n 'Total '
  113. @(find * -name '*.h'; find * -name '*.c') | xargs egrep -w \
  114. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC' | wc -l
  115. bench: build/bench
  116. ./$<
  117. test: build/test
  118. ./$<
  119. clean:
  120. rm -fr build doc $(BATNAME)