-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile.custom
241 lines (187 loc) · 7.49 KB
/
Makefile.custom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Copyright (c) 2014-2017 Cryptography Research, Inc.
# Copyright (c) 2018 the libgoldilocks contributors.
# Released under the MIT License. See LICENSE.txt for license information.
UNAME := $(shell uname)
ARCH := $(shell uname -m)
ARCH_DEF := arch_32
ifeq ($(ARCH),ia64|mips64|mips64eb|mipseb64|mips64el|mipsel64|mips64*|powerpc64*|sparc64|x86_64*|amd64*)
ARCH_DEF = arch_x86_64
endif
ifeq ($(ARCH),arch64|aarch64|powerpc*)
ARCH_DEF = arch_ref64
endif
ifeq ($(ARCH),arm64)
ARCH_DEF = arch_neon
endif
ifeq ($(ARCH),arm32|armv*)
ARCH_DEF = arch_neon
endif
$(info ARCH_DEF is $(ARCH_DEF))
$(info ARCH is $(ARCH))
# Subdirectories for objects etc.
# Many of them are mapped to build/obj right now, but could be split later.
# The non-build/obj directories are the public interface.
BUILD_OBJ = build/obj
BUILD_C = src/GEN
BUILD_PY = build/obj
BUILD_LIB = build/lib
BUILD_INC = src/public_include
BUILD_BIN = build/bin
BUILD_IBIN = build/obj/bin
DOXYGEN ?= doxygen
LD = $(CC)
LDXX = $(CXX)
ASM ?= $(CC)
PYTHON ?= python
WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
-Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)
INCFLAGS = -Isrc -Isrc/include -I$(BUILD_INC) -Isrc/include/$(ARCH_DEF) -Isrc/$(ARCH_DEF)
PUB_INCFLAGS = -I$(BUILD_INC)
LANGFLAGS = -std=c99 -fno-strict-aliasing
LANGXXFLAGS = -fno-strict-aliasing
GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC
OFLAGS ?= -Os
MACOSX_VERSION_MIN ?= 10.9
ifeq ($(UNAME),Darwin)
GENFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN)
endif
ARCHFLAGS ?= -march=native
ifeq ($(CC),clang)
WARNFLAGS_C += -Wgcc-compat
endif
ifeq ($(CXX),clang++)
WARNFLAGS_CXX = -Wgcc-compat
endif
ARCHFLAGS += $(XARCHFLAGS)
CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(WARNFLAGS_C) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
PUB_CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(WARNFLAGS_C) $(PUB_INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
CXXFLAGS = $(LANGXXFLAGS) $(WARNFLAGS) $(WARNFLAGS_CXX) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCXXFLAGS)
LDFLAGS = $(XLDFLAGS)
ASFLAGS = $(ARCHFLAGS) $(XASFLAGS)
SAGE ?= sage
SAGES= $(shell ls test/*.sage)
BUILDPYS= $(SAGES:test/%.sage=$(BUILD_PY)/%.py)
.PHONY: clean all test test_ct bench todo doc lib bat sage sagetest gen_code
.PRECIOUS: $(BUILD_C)/%.c $(BUILD_IBIN)/%
HEADERS= Makefile.custom $(shell find src test -name "*.h") $(BUILD_OBJ)/timestamp
GENCOMPONENTS = $(BUILD_OBJ)/f_impl.o $(BUILD_OBJ)/f_arithmetic.o $(BUILD_OBJ)/f_generic.o
LIBCOMPONENTS = $(BUILD_OBJ)/utils.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/spongerng.o $(GENCOMPONENTS) $(BUILD_OBJ)/goldilocks.o $(BUILD_OBJ)/elligator.o $(BUILD_OBJ)/scalar.o $(BUILD_OBJ)/eddsa.o $(BUILD_OBJ)/goldilocks_tables.o
BENCHCOMPONENTS = $(BUILD_OBJ)/bench.o $(BUILD_OBJ)/shake.o
all: lib $(BUILD_IBIN)/test $(BUILD_IBIN)/bench $(BUILD_BIN)/shakesum
scan: clean
scan-build --use-analyzer=`which clang` \
-enable-checker deadcode -enable-checker llvm \
-enable-checker osx -enable-checker security -enable-checker unix \
make all
# Internal test programs, which are not part of the final build/bin directory.
$(BUILD_IBIN)/test: $(BUILD_OBJ)/test_goldilocks.o lib
ifeq ($(UNAME),Darwin)
$(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -lgoldilocks
else
$(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -lgoldilocks
endif
$(BUILD_IBIN)/bench: $(BUILD_OBJ)/bench_goldilocks.o lib
ifeq ($(UNAME),Darwin)
$(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -lgoldilocks
else
$(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -lgoldilocks
endif
# Create all the build subdirectories
$(BUILD_OBJ)/timestamp:
mkdir -p $(BUILD_OBJ) $(BUILD_C) $(BUILD_PY) \
$(BUILD_LIB) $(BUILD_INC) $(BUILD_BIN) $(BUILD_IBIN) $(BUILD_H) $(BUILD_INC)/goldilocks \
$(PER_OBJ_DIRS) $(BUILD_C)/goldilocks
touch $@
GEN_CODE = $(BUILD_C)/goldilocks_tables.c
$(BUILD_IBIN)/goldilocks_gen_tables: $(BUILD_OBJ)/goldilocks_gen_tables.o \
$(BUILD_OBJ)/goldilocks.o $(BUILD_OBJ)/scalar.o $(BUILD_OBJ)/utils.o \
$(GENCOMPONENTS)
$(LD) $(LDFLAGS) -o $@ $^
$(BUILD_C)/goldilocks_tables.c: $(BUILD_IBIN)/goldilocks_gen_tables
./$< > $@ || (rm $@; exit 1)
$(BUILD_OBJ)/%.o: $(BUILD_C)/%.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $< \
-I build/obj/ -I src/ -I src/$(ARCH_DEF) -I src/include/$(ARCH_DEF)
$(BUILD_OBJ)/goldilocks_gen_tables.o: src/goldilocks_gen_tables.c $(HEADERS)
$(CC) $(CFLAGS) \
-I build/obj/ -I src -I src/$(ARCH_DEF) -I src/include/$(ARCH_DEF) \
-c -o $@ $<
# The shakesum utility is in the public bin directory.
$(BUILD_BIN)/shakesum: $(BUILD_OBJ)/shakesum.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/utils.o
$(LD) $(LDFLAGS) -o $@ $^
# The main goldilocks library, and its symlinks.
lib: $(BUILD_LIB)/libgoldilocks.so
$(BUILD_LIB)/libgoldilocks.so: $(BUILD_LIB)/libgoldilocks.so.1
ln -sf `basename $^` $@
$(BUILD_LIB)/libgoldilocks.so.1: $(LIBCOMPONENTS)
rm -f $@
ifeq ($(UNAME),Darwin)
libtool -macosx_version_min $(MACOSX_VERSION_MIN) -dynamic -dead_strip -lc -x -o $@ \
$(LIBCOMPONENTS)
else ifeq ($(UNAME),SunOS)
$(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -o $@ $(LIBCOMPONENTS)
strip --discard-all $@
else
$(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -Wl,--gc-sections -o $@ $(LIBCOMPONENTS)
strip --discard-all $@
endif
# $(BUILD_OBJ)/%.o: src/%.c $(HEADERS)
# $(CC) $(CFLAGS) -I src/$(ARCH_DEF) -I src/include/$(ARCH_DEF) \
# -c -o $@ $<
$(BUILD_OBJ)/%.o: src/$(ARCH_DEF)/%.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_OBJ)/%.o: src/%.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_OBJ)/%.o: test/%.c $(HEADERS)
$(CC) $(PUB_CFLAGS) -c -o $@ $<
$(BUILD_OBJ)/%.o: test/%.cxx $(HEADERS)
$(CXX) $(CXXFLAGS) -c -o $@ $<
# The sage test scripts
sage: $(BUILDPYS)
sagetest: sage lib
$(SAGE) $(BUILD_PY)/test_goldilocks.sage
$(BUILDPYS): $(SAGES) $(BUILD_OBJ)/timestamp
cp -f $(SAGES) $(BUILD_PY)/
$(SAGE) --preparse $(SAGES:test/%.sage=$(BUILD_PY)/%.sage)
# some sage versions compile to .sage.py
for f in $(SAGES:test/%.sage=$(BUILD_PY)/%); do \
if [ -e $$f.sage.py ]; then \
mv $$f.sage.py $$f.py; \
fi; \
done
# The documentation files
$(BUILD_DOC)/timestamp:
mkdir -p `dirname $@`
touch $@
#
doc: Doxyfile $(BUILD_OBJ)/timestamp
$(DOXYGEN) > /dev/null
gen_code: $(GEN_CODE)
# Finds todo items in .h and .c files
TODO_TYPES ?= HACK TODO @todo FIXME BUG XXX PERF FUTURE REMOVE MAGIC UNIFY
TODO_LOCATIONS ?= src/*.c src/include src/p* test Makefile.custom Doxyfile
todo::
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep --color=auto -w \
`echo $(TODO_TYPES) | tr ' ' '|'`
@echo '============================='
@(for i in $(TODO_TYPES); do \
(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep -w $$i > /dev/null || continue; \
/bin/echo -n $$i' ' | head -c 10; \
(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep -w $$i| wc -l; \
done)
@echo '============================='
@echo -n 'Total '
@(find $(TODO_LOCATIONS) -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx' -or -name '*.py') | xargs egrep -w \
`echo $(TODO_TYPES) | tr ' ' '|'` | wc -l
bench: $(BUILD_IBIN)/bench
./$<
test: $(BUILD_IBIN)/test
./$<
mem-check: $(BUILD_IBIN)/test
valgrind --track-origins=yes --error-exitcode=2 --leak-check=full ./$<
microbench: $(BUILD_IBIN)/bench
./$< --micro
clean:
rm -fr build
clean_generated: clean
rm -fr $(BUILD_C)/*