Makefile 14.7 KB
Newer Older
Richard van der Hoff's avatar
Richard van der Hoff committed
1
2
#!/usr/bin/make -f

3
include common.mk
4
VERSION := $(MAJOR).$(MINOR).$(PATCH)
5
PREFIX ?= /usr/local
6
BUILD_DIR := build
7
RELEASE_OPTIMIZE_FLAGS ?= -O3
8
DEBUG_OPTIMIZE_FLAGS ?= -g -O0
9
JS_OPTIMIZE_FLAGS ?= -O3
10
FUZZER_OPTIMIZE_FLAGS ?= -O3
Richard van der Hoff's avatar
Richard van der Hoff committed
11
CC = gcc
12
EMCC = emcc
stoically's avatar
stoically committed
13
EMAR = emar
14
AR = ar
15

David Baker's avatar
David Baker committed
16
17
18
19
20
21
22
23
24
25
26
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
	SO := dylib
	OLM_LDFLAGS :=
else
	SO := so
	OLM_LDFLAGS := -Wl,-soname,libolm.so.$(MAJOR) \
                       -Wl,--version-script,version_script.ver
endif

RELEASE_TARGET := $(BUILD_DIR)/libolm.$(SO).$(VERSION)
27
STATIC_RELEASE_TARGET := $(BUILD_DIR)/libolm.a
David Baker's avatar
David Baker committed
28
DEBUG_TARGET := $(BUILD_DIR)/libolm_debug.$(SO).$(VERSION)
David Baker's avatar
David Baker committed
29
30
JS_WASM_TARGET := javascript/olm.js
JS_ASMJS_TARGET := javascript/olm_legacy.js
stoically's avatar
stoically committed
31
WASM_TARGET := $(BUILD_DIR)/wasm/libolm.a
32
33

JS_EXPORTED_FUNCTIONS := javascript/exported_functions.json
34
JS_EXPORTED_RUNTIME_METHODS := [ALLOC_STACK]
David Baker's avatar
David Baker committed
35
JS_EXTERNS := javascript/externs.js
36

37
PUBLIC_HEADERS := include/olm/olm.h include/olm/outbound_group_session.h include/olm/inbound_group_session.h include/olm/pk.h include/olm/sas.h include/olm/error.h
Richard van der Hoff's avatar
Richard van der Hoff committed
38

39
40
41
42
43
SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c) \
    lib/crypto-algorithms/sha256.c \
    lib/crypto-algorithms/aes.c \
    lib/curve25519-donna/curve25519-donna.c

Denis Kasak's avatar
Denis Kasak committed
44
FUZZER_SOURCES := $(wildcard fuzzing/fuzzers/fuzz_*.cpp) $(wildcard fuzzing/fuzzers/fuzz_*.c)
Richard van der Hoff's avatar
Richard van der Hoff committed
45
TEST_SOURCES := $(wildcard tests/test_*.cpp) $(wildcard tests/test_*.c)
46
47
48
49
50

OBJECTS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
RELEASE_OBJECTS := $(addprefix $(BUILD_DIR)/release/,$(OBJECTS))
DEBUG_OBJECTS := $(addprefix $(BUILD_DIR)/debug/,$(OBJECTS))
FUZZER_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(OBJECTS))
51
52
FUZZER_ASAN_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(addprefix asan_,$(OBJECTS)))
FUZZER_MSAN_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(addprefix msan_,$(OBJECTS)))
Denis Kasak's avatar
Denis Kasak committed
53
54
FUZZER_DEBUG_OBJECTS := $(addprefix $(BUILD_DIR)/fuzzers/objects/,$(addprefix debug_,$(OBJECTS)))
FUZZER_BINARIES := $(addprefix $(BUILD_DIR)/fuzzers/,$(basename $(notdir $(FUZZER_SOURCES))))
55
56
FUZZER_ASAN_BINARIES := $(addsuffix _asan,$(FUZZER_BINARIES))
FUZZER_MSAN_BINARIES := $(addsuffix _msan,$(FUZZER_BINARIES))
57
58
59
FUZZER_DEBUG_BINARIES := $(patsubst $(BUILD_DIR)/fuzzers/fuzz_%,$(BUILD_DIR)/fuzzers/debug_%,$(FUZZER_BINARIES))
TEST_BINARIES := $(patsubst tests/%,$(BUILD_DIR)/tests/%,$(basename $(TEST_SOURCES)))
JS_OBJECTS := $(addprefix $(BUILD_DIR)/javascript/,$(OBJECTS))
stoically's avatar
stoically committed
60
WASM_OBJECTS := $(addprefix $(BUILD_DIR)/wasm/,$(OBJECTS))
David Baker's avatar
David Baker committed
61
62
63
64

# pre & post are the js-pre/js-post options to emcc.
# They are injected inside the modularised code and
# processed by the optimiser.
65
JS_PRE := $(wildcard javascript/*pre.js)
66
67
JS_POST := javascript/olm_outbound_group_session.js \
    javascript/olm_inbound_group_session.js \
68
    javascript/olm_pk.js \
69
    javascript/olm_sas.js \
70
    javascript/olm_post.js
David Baker's avatar
David Baker committed
71
72
73
74
75
76
77

# The prefix & suffix are just added onto the start & end
# of what comes out emcc, so are outside of the modularised
# code and not seen by the opimiser.
JS_PREFIX := javascript/olm_prefix.js
JS_SUFFIX := javascript/olm_suffix.js

78
DOCS := tracing/README.html \
79
    docs/megolm.html \
80
    docs/olm.html \
81
    docs/signing.html \
82
83
    README.html \
    CHANGELOG.html
Richard van der Hoff's avatar
Richard van der Hoff committed
84

85
86
87
88
CPPFLAGS += -Iinclude -Ilib \
    -DOLMLIB_VERSION_MAJOR=$(MAJOR) -DOLMLIB_VERSION_MINOR=$(MINOR) \
    -DOLMLIB_VERSION_PATCH=$(PATCH)

89
# we rely on <stdint.h>, which was introduced in C99
David Baker's avatar
David Baker committed
90
91
CFLAGS += -Wall -Werror -std=c99
CXXFLAGS += -Wall -Werror -std=c++11
92
LDFLAGS += -Wall -Werror
Richard van der Hoff's avatar
Richard van der Hoff committed
93

David Baker's avatar
David Baker committed
94
95
96
CFLAGS_NATIVE = -fPIC
CXXFLAGS_NATIVE = -fPIC

David Baker's avatar
David Baker committed
97
EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1
98

David Baker's avatar
David Baker committed
99
100
101
102
103
104
# Olm generally doesn't need a lot of memory to encrypt / decrypt its usual
# payloads (ie. Matrix messages), but we do need about 128K of heap to encrypt
# a 64K event (enough to store the ciphertext and the plaintext, bearing in
# mind that the plaintext can only be 48K because base64). We also have about
# 36K of statics. So let's have 256K of memory.
# (This can't be changed by the app with wasm since it's baked into the wasm).
David Baker's avatar
David Baker committed
105
106
107
# (emscripten also mandates at least 16MB of memory for asm.js now, so
# we don't use this for the legacy build.)
EMCCFLAGS_WASM += -s TOTAL_STACK=65536 -s TOTAL_MEMORY=262144
David Baker's avatar
David Baker committed
108

David Baker's avatar
David Baker committed
109
EMCCFLAGS_ASMJS += -s WASM=0
David Baker's avatar
David Baker committed
110

111
112
113
114
EMCC.c = $(EMCC) $(CFLAGS) $(CPPFLAGS) -c
EMCC.cc = $(EMCC) $(CXXFLAGS) $(CPPFLAGS) -c
EMCC_LINK = $(EMCC) $(LDFLAGS) $(EMCCFLAGS)

115
116
117
AFL_CC = afl-clang-fast
AFL_CXX = afl-clang-fast++

118
119
120
121
AFL.c = $(AFL_CC) $(CFLAGS) $(CPPFLAGS) -c
AFL.cc = $(AFL_CXX) $(CXXFLAGS) $(CPPFLAGS) -c
AFL_LINK.c = $(AFL_CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS)
AFL_LINK.cc = $(AFL_CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS)
122
123
124
125
126
127
128
129
AFL_ASAN.c = AFL_USE_ASAN=1 $(AFL_CC) -m32 $(CFLAGS) $(CPPFLAGS) -c
AFL_ASAN.cc = AFL_USE_ASAN=1 $(AFL_CXX) -m32 $(CXXFLAGS) $(CPPFLAGS) -c
AFL_LINK_ASAN.c = AFL_USE_ASAN=1 $(AFL_CC) -m32 $(LDFLAGS) $(CFLAGS) $(CPPFLAGS)
AFL_LINK_ASAN.cc = AFL_USE_ASAN=1 $(AFL_CXX) -m32 $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS)
AFL_MSAN.c = AFL_USE_MSAN=1 $(AFL_CC) $(CFLAGS) $(CPPFLAGS) -c
AFL_MSAN.cc = AFL_USE_MSAN=1 $(AFL_CXX) $(CXXFLAGS) $(CPPFLAGS) -c
AFL_LINK_MSAN.c = AFL_USE_MSAN=1 $(AFL_CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS)
AFL_LINK_MSAN.cc = AFL_USE_MSAN=1 $(AFL_CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS)
130

Richard van der Hoff's avatar
Richard van der Hoff committed
131
132
133
134
135
# generate .d files when compiling
CPPFLAGS += -MMD

### per-target variables

David Baker's avatar
David Baker committed
136
137
$(RELEASE_OBJECTS): CFLAGS += $(RELEASE_OPTIMIZE_FLAGS) $(CFLAGS_NATIVE)
$(RELEASE_OBJECTS): CXXFLAGS += $(RELEASE_OPTIMIZE_FLAGS) $(CXXFLAGS_NATIVE)
138
139
$(RELEASE_TARGET): LDFLAGS += $(RELEASE_OPTIMIZE_FLAGS)

David Baker's avatar
David Baker committed
140
141
$(DEBUG_OBJECTS): CFLAGS += $(DEBUG_OPTIMIZE_FLAGS) $(CFLAGS_NATIVE)
$(DEBUG_OBJECTS): CXXFLAGS += $(DEBUG_OPTIMIZE_FLAGS) $(CXXFLAGS_NATIVE)
142
$(DEBUG_TARGET): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
Richard van der Hoff's avatar
Richard van der Hoff committed
143
144

$(TEST_BINARIES): CPPFLAGS += -Itests/include
Richard van der Hoff's avatar
Richard van der Hoff committed
145
$(TEST_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS) -L$(BUILD_DIR)
Richard van der Hoff's avatar
Richard van der Hoff committed
146

Denis Kasak's avatar
Denis Kasak committed
147
148
149
150
151
152
153
154
155
156
$(FUZZER_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_DEBUG_OBJECTS): CFLAGS += $(DEBUG_OPTIMIZE_FLAGS) $(CFLAGS_NATIVE) -D OLM_FUZZING=1
$(FUZZER_DEBUG_OBJECTS): CXXFLAGS += $(DEBUG_OPTIMIZE_FLAGS) $(CXXFLAGS_NATIVE) -D OLM_FUZZING=1
$(FUZZER_ASAN_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_ASAN_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_MSAN_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1
$(FUZZER_MSAN_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -D OLM_FUZZING=1

$(FUZZER_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
157
$(FUZZER_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR) -lstdc++
Denis Kasak's avatar
Denis Kasak committed
158
$(FUZZER_ASAN_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
159
$(FUZZER_ASAN_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR) -lstdc++
Denis Kasak's avatar
Denis Kasak committed
160
$(FUZZER_MSAN_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
161
$(FUZZER_MSAN_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR) -lstdc++
Denis Kasak's avatar
Denis Kasak committed
162
$(FUZZER_DEBUG_BINARIES): CPPFLAGS += -Ifuzzing/fuzzers/include
163
$(FUZZER_DEBUG_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS) -lstdc++
164

165
166
$(JS_OBJECTS): CFLAGS += $(JS_OPTIMIZE_FLAGS)
$(JS_OBJECTS): CXXFLAGS += $(JS_OPTIMIZE_FLAGS)
David Baker's avatar
David Baker committed
167
168
$(JS_WASM_TARGET): LDFLAGS += $(JS_OPTIMIZE_FLAGS)
$(JS_ASMJS_TARGET): LDFLAGS += $(JS_OPTIMIZE_FLAGS)
169

170
171
172
173
174
175
176
177
178
179
180
181
182
### Fix to make mkdir work on windows and linux
ifeq ($(shell echo "check_quotes"),"check_quotes")
   WINDOWS := yes
else
   WINDOWS := no
endif

ifeq ($(WINDOWS),yes)
   mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
else
   mkdir = mkdir -p $(1)
endif

Richard van der Hoff's avatar
Richard van der Hoff committed
183
184
### top-level targets

185
lib: $(RELEASE_TARGET)
186
187
.PHONY: lib

188
189
$(RELEASE_TARGET): $(RELEASE_OBJECTS)
	$(CXX) $(LDFLAGS) --shared -fPIC \
David Baker's avatar
David Baker committed
190
            $(OLM_LDFLAGS) \
191
            $(OUTPUT_OPTION) $(RELEASE_OBJECTS)
David Baker's avatar
David Baker committed
192
	ln -sf libolm.$(SO).$(VERSION) $(BUILD_DIR)/libolm.$(SO).$(MAJOR)
193
	ln -sf libolm.$(SO).$(VERSION) $(BUILD_DIR)/libolm.$(SO)
194

195
debug: $(DEBUG_TARGET)
196
197
198
.PHONY: debug

$(DEBUG_TARGET): $(DEBUG_OBJECTS)
199
	$(CXX) $(LDFLAGS) --shared -fPIC \
David Baker's avatar
David Baker committed
200
            $(OLM_LDFLAGS) \
201
            $(OUTPUT_OPTION) $(DEBUG_OBJECTS)
David Baker's avatar
David Baker committed
202
	ln -sf libolm_debug.$(SO).$(VERSION) $(BUILD_DIR)/libolm_debug.$(SO).$(MAJOR)
203

204
205
206
207
static: $(STATIC_RELEASE_TARGET)
.PHONY: static

$(STATIC_RELEASE_TARGET): $(RELEASE_OBJECTS)
208
	$(AR) rcs $@ $^
209

David Baker's avatar
David Baker committed
210
js: $(JS_WASM_TARGET) $(JS_ASMJS_TARGET)
211
212
.PHONY: js

stoically's avatar
stoically committed
213
214
215
216
217
218
wasm: $(WASM_TARGET)
.PHONY: wasm

$(WASM_TARGET): $(WASM_OBJECTS)
	$(EMAR) rcs $@ $^

219
javascript/olm_prefix.js: javascript/olm_prefix.js.in Makefile common.mk
Hubert Chathi's avatar
Hubert Chathi committed
220
221
	sed s/@VERSION@/$(VERSION)/ javascript/olm_prefix.js.in > $@

David Baker's avatar
David Baker committed
222
223
224
# Note that the output file we give to emcc determines the name of the
# wasm file baked into the js, hence messing around outputting to olm.js
# and then renaming it.
David Baker's avatar
David Baker committed
225
$(JS_WASM_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS) $(JS_PREFIX) $(JS_SUFFIX)
David Baker's avatar
David Baker committed
226
	EMCC_CLOSURE_ARGS="--externs $(JS_EXTERNS)" $(EMCC_LINK) \
David Baker's avatar
David Baker committed
227
228
229
	       $(EMCCFLAGS_WASM) \
               $(foreach f,$(JS_PRE),--pre-js $(f)) \
               $(foreach f,$(JS_POST),--post-js $(f)) \
Lukas Lihotzki's avatar
Lukas Lihotzki committed
230
231
               $(foreach f,$(JS_PREFIX),--extern-pre-js $(f)) \
               $(foreach f,$(JS_SUFFIX),--extern-post-js $(f)) \
David Baker's avatar
David Baker committed
232
               -s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \
233
               -s "EXPORTED_RUNTIME_METHODS=$(JS_EXPORTED_RUNTIME_METHODS)" \
234
               -o $@ $(JS_OBJECTS)
David Baker's avatar
David Baker committed
235
236

$(JS_ASMJS_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS) $(JS_PREFIX) $(JS_SUFFIX)
David Baker's avatar
David Baker committed
237
	EMCC_CLOSURE_ARGS="--externs $(JS_EXTERNS)" $(EMCC_LINK) \
David Baker's avatar
David Baker committed
238
	       $(EMCCFLAGS_ASMJS) \
239
240
               $(foreach f,$(JS_PRE),--pre-js $(f)) \
               $(foreach f,$(JS_POST),--post-js $(f)) \
241
242
               $(foreach f,$(JS_PREFIX),--extern-pre-js $(f)) \
               $(foreach f,$(JS_SUFFIX),--extern-post-js $(f)) \
243
               -s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \
244
               -s "EXPORTED_RUNTIME_METHODS=$(JS_EXPORTED_RUNTIME_METHODS)" \
245
               -o $@ $(JS_OBJECTS)
246

Richard van der Hoff's avatar
Richard van der Hoff committed
247
248
249
250
251
build_tests: $(TEST_BINARIES)

test: build_tests
	for i in $(TEST_BINARIES); do \
	    echo $$i; \
252
	    $$i || exit $$?; \
Richard van der Hoff's avatar
Richard van der Hoff committed
253
254
	done

255
256
257
258
259
260
test_mem: build_tests
	for i in $(TEST_BINARIES); do \
	    echo $$i; \
	    valgrind -q --leak-check=yes --exit-on-first-error=yes --error-exitcode=1 $$i || exit $$?; \
	done

261
fuzzers: $(FUZZER_BINARIES) $(FUZZER_ASAN_BINARIES) $(FUZZER_MSAN_BINARIES) $(FUZZER_DEBUG_BINARIES)
262
263
.PHONY: fuzzers

264
$(JS_EXPORTED_FUNCTIONS): $(PUBLIC_HEADERS)
265
	./exports.py $^ > $@.tmp
266
267
	mv $@.tmp $@

268
all: test js lib debug doc
269
270
.PHONY: all

271
install-headers: $(PUBLIC_HEADERS)
272
	test -d $(DESTDIR)$(PREFIX)/include/olm || $(call mkdir,$(DESTDIR)$(PREFIX)/include/olm)
273
	install $(PUBLIC_HEADERS) $(DESTDIR)$(PREFIX)/include/olm/
274
.PHONY: install-headers
275
276

install-debug: debug install-headers
277
	test -d $(DESTDIR)$(PREFIX)/lib || $(call mkdir,$(DESTDIR)$(PREFIX)/lib)
278
	install $(DEBUG_TARGET) $(DESTDIR)$(PREFIX)/lib/libolm_debug.$(SO).$(VERSION)
279
280
	ln -sf libolm_debug.$(SO).$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm_debug.$(SO).$(MAJOR)
	ln -sf libolm_debug.$(SO).$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm_debug.$(SO)
281
282
.PHONY: install-debug

283
install: lib install-headers
284
	test -d $(DESTDIR)$(PREFIX)/lib || $(call mkdir,$(DESTDIR)$(PREFIX)/lib)
285
	install $(RELEASE_TARGET) $(DESTDIR)$(PREFIX)/lib/libolm.$(SO).$(VERSION)
286
287
	ln -sf libolm.$(SO).$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm.$(SO).$(MAJOR)
	ln -sf libolm.$(SO).$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm.$(SO)
288
289
.PHONY: install

290
clean:;
291
	rm -rf $(BUILD_DIR) $(DOCS)
292
.PHONY: clean
293

294
295
296
doc: $(DOCS)
.PHONY: doc

Richard van der Hoff's avatar
Richard van der Hoff committed
297
### rules for building objects
298
$(BUILD_DIR)/release/%.o: %.c
299
	$(call mkdir,$(dir $@))
300
301
	$(COMPILE.c) $(OUTPUT_OPTION) $<

302
$(BUILD_DIR)/release/%.o: %.cpp
303
	$(call mkdir,$(dir $@))
304
305
	$(COMPILE.cc) $(OUTPUT_OPTION) $<

306
$(BUILD_DIR)/debug/%.o: %.c
307
	$(call mkdir,$(dir $@))
Richard van der Hoff's avatar
Richard van der Hoff committed
308
309
	$(COMPILE.c) $(OUTPUT_OPTION) $<

310
$(BUILD_DIR)/debug/%.o: %.cpp
311
	$(call mkdir,$(dir $@))
Richard van der Hoff's avatar
Richard van der Hoff committed
312
313
	$(COMPILE.cc) $(OUTPUT_OPTION) $<

314
$(BUILD_DIR)/javascript/%.o: %.c
315
	$(call mkdir,$(dir $@))
316
317
	$(EMCC.c) $(OUTPUT_OPTION) $<

318
$(BUILD_DIR)/javascript/%.o: %.cpp
319
	$(call mkdir,$(dir $@))
320
321
	$(EMCC.cc) $(OUTPUT_OPTION) $<

stoically's avatar
stoically committed
322
323
324
325
326
327
328
329
$(BUILD_DIR)/wasm/%.o: %.c
	$(call mkdir,$(dir $@))
	$(EMCC.c) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/wasm/%.o: %.cpp
	$(call mkdir,$(dir $@))
	$(EMCC.cc) $(OUTPUT_OPTION) $<

330
$(BUILD_DIR)/tests/%: tests/%.c $(DEBUG_OBJECTS)
331
	$(call mkdir,$(dir $@))
332
	$(LINK.c) -o $@ $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS)
Richard van der Hoff's avatar
Richard van der Hoff committed
333

334
$(BUILD_DIR)/tests/%: tests/%.cpp $(DEBUG_OBJECTS)
335
	$(call mkdir,$(dir $@))
336
	$(LINK.cc) -o $@ $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS)
Richard van der Hoff's avatar
Richard van der Hoff committed
337

338
$(BUILD_DIR)/fuzzers/objects/%.o: %.c
339
	$(call mkdir,$(dir $@))
340
341
	$(AFL.c) $(OUTPUT_OPTION) $<

342
$(BUILD_DIR)/fuzzers/objects/%.o: %.cpp
343
	$(call mkdir,$(dir $@))
344
345
	$(AFL.cc) $(OUTPUT_OPTION) $<

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
$(BUILD_DIR)/fuzzers/objects/asan_%.o: %.c
	$(call mkdir,$(dir $@))
	$(AFL_ASAN.c) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/fuzzers/objects/asan_%.o: %.cpp
	$(call mkdir,$(dir $@))
	$(AFL_ASAN.cc) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/fuzzers/objects/msan_%.o: %.c
	$(call mkdir,$(dir $@))
	$(AFL_MSAN.c) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/fuzzers/objects/msan_%.o: %.cpp
	$(call mkdir,$(dir $@))
	$(AFL_MSAN.cc) $(OUTPUT_OPTION) $<

Denis Kasak's avatar
Denis Kasak committed
362
363
364
365
366
367
368
369
370
371
$(BUILD_DIR)/fuzzers/objects/debug_%.o: %.c
	$(call mkdir,$(dir $@))
	$(COMPILE.c) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/fuzzers/objects/debug_%.o: %.cpp
	$(call mkdir,$(dir $@))
	$(COMPILE.cc) $(OUTPUT_OPTION) $<


$(BUILD_DIR)/fuzzers/fuzz_%: fuzzing/fuzzers/fuzz_%.c $(FUZZER_OBJECTS)
372
	$(AFL_LINK.c) -o $@ $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS)
373

Denis Kasak's avatar
Denis Kasak committed
374
$(BUILD_DIR)/fuzzers/fuzz_%: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_OBJECTS)
375
	$(AFL_LINK.cc) -o $@ $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS)
376

Denis Kasak's avatar
Denis Kasak committed
377
378
$(BUILD_DIR)/fuzzers/debug_%: fuzzing/fuzzers/fuzz_%.c $(FUZZER_DEBUG_OBJECTS)
	$(LINK.c) -o $@ $< $(FUZZER_DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS)
379

Denis Kasak's avatar
Denis Kasak committed
380
381
$(BUILD_DIR)/fuzzers/debug_%: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_DEBUG_OBJECTS)
	$(LINK.cc) -o $@ $< $(FUZZER_DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS)
Richard van der Hoff's avatar
Richard van der Hoff committed
382

Denis Kasak's avatar
Denis Kasak committed
383
$(BUILD_DIR)/fuzzers/fuzz_%_asan: fuzzing/fuzzers/fuzz_%.c $(FUZZER_ASAN_OBJECTS)
384
385
	$(AFL_LINK_ASAN.c) -o $@ $< $(FUZZER_ASAN_OBJECTS) $(LOADLIBES) $(LDLIBS)

Denis Kasak's avatar
Denis Kasak committed
386
$(BUILD_DIR)/fuzzers/fuzz_%_asan: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_ASAN_OBJECTS)
387
388
	$(AFL_LINK_ASAN.cc) -o $@ $< $(FUZZER_ASAN_OBJECTS) $(LOADLIBES) $(LDLIBS)

Denis Kasak's avatar
Denis Kasak committed
389
$(BUILD_DIR)/fuzzers/fuzz_%_msan: fuzzing/fuzzers/fuzz_%.c $(FUZZER_MSAN_OBJECTS)
390
391
	$(AFL_LINK_MSAN.c) -o $@ $< $(FUZZER_MSAN_OBJECTS) $(LOADLIBES) $(LDLIBS)

Denis Kasak's avatar
Denis Kasak committed
392
$(BUILD_DIR)/fuzzers/fuzz_%_msan: fuzzing/fuzzers/fuzz_%.cpp $(FUZZER_MSAN_OBJECTS)
393
394
	$(AFL_LINK_MSAN.cc) -o $@ $< $(FUZZER_MSAN_OBJECTS) $(LOADLIBES) $(LDLIBS)

395
396
397
%.html: %.rst
	rst2html $< $@

Richard van der Hoff's avatar
Richard van der Hoff committed
398
399
### dependencies

400
401
-include $(RELEASE_OBJECTS:.o=.d)
-include $(DEBUG_OBJECTS:.o=.d)
402
-include $(JS_OBJECTS:.o=.d)
Richard van der Hoff's avatar
Richard van der Hoff committed
403
-include $(TEST_BINARIES:=.d)
404
-include $(FUZZER_OBJECTS:.o=.d)
Denis Kasak's avatar
Denis Kasak committed
405
-include $(FUZZER_DEBUG_OBJECTS:.o=.d)
406
407
-include $(FUZZER_ASAN_OBJECTS:.o=.d)
-include $(FUZZER_MSAN_OBJECTS:.o=.d)
408
-include $(FUZZER_BINARIES:=.d)
409
410
-include $(FUZZER_ASAN_BINARIES:=.d)
-include $(FUZZER_MSAN_BINARIES:=.d)
411
-include $(FUZZER_DEBUG_BINARIES:=.d)