2016-05-13 12:36:41 +02:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
2016-10-25 12:35:20 +02:00
|
|
|
MAJOR := 2
|
2017-01-18 17:01:59 +01:00
|
|
|
MINOR := 2
|
2017-01-18 19:16:02 +01:00
|
|
|
PATCH := 1
|
2016-07-04 23:38:04 +02:00
|
|
|
VERSION := $(MAJOR).$(MINOR).$(PATCH)
|
2016-07-04 23:38:05 +02:00
|
|
|
PREFIX ?= /usr/local
|
2016-05-23 17:21:37 +02:00
|
|
|
BUILD_DIR := build
|
2016-05-23 16:58:18 +02:00
|
|
|
RELEASE_OPTIMIZE_FLAGS ?= -g -O3
|
|
|
|
DEBUG_OPTIMIZE_FLAGS ?= -g -O0
|
2016-05-20 10:36:50 +02:00
|
|
|
JS_OPTIMIZE_FLAGS ?= -O3
|
2016-05-23 18:32:24 +02:00
|
|
|
FUZZING_OPTIMIZE_FLAGS ?= -O3
|
2016-05-13 12:36:41 +02:00
|
|
|
CC = gcc
|
2016-05-20 10:36:50 +02:00
|
|
|
EMCC = emcc
|
2016-05-26 14:25:34 +02:00
|
|
|
AFL_CC = afl-gcc
|
2016-05-23 18:32:24 +02:00
|
|
|
AFL_CXX = afl-g++
|
2016-09-05 12:56:53 +02:00
|
|
|
|
2016-07-04 23:38:04 +02:00
|
|
|
RELEASE_TARGET := $(BUILD_DIR)/libolm.so.$(VERSION)
|
|
|
|
DEBUG_TARGET := $(BUILD_DIR)/libolm_debug.so.$(VERSION)
|
2016-05-20 10:36:50 +02:00
|
|
|
JS_TARGET := javascript/olm.js
|
|
|
|
|
|
|
|
JS_EXPORTED_FUNCTIONS := javascript/exported_functions.json
|
|
|
|
|
2016-05-25 15:42:49 +02:00
|
|
|
PUBLIC_HEADERS := include/olm/olm.h include/olm/outbound_group_session.h include/olm/inbound_group_session.h
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c) \
|
|
|
|
lib/crypto-algorithms/sha256.c \
|
|
|
|
lib/crypto-algorithms/aes.c \
|
|
|
|
lib/curve25519-donna/curve25519-donna.c
|
|
|
|
|
2016-05-23 18:32:24 +02:00
|
|
|
FUZZER_SOURCES := $(wildcard fuzzers/fuzz_*.cpp) $(wildcard fuzzers/fuzz_*.c)
|
2016-05-13 12:36:41 +02:00
|
|
|
TEST_SOURCES := $(wildcard tests/test_*.cpp) $(wildcard tests/test_*.c)
|
2016-05-25 18:08:44 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
FUZZER_BINARIES := $(addprefix $(BUILD_DIR)/,$(basename $(FUZZER_SOURCES)))
|
|
|
|
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))
|
2016-05-20 10:36:50 +02:00
|
|
|
JS_PRE := $(wildcard javascript/*pre.js)
|
2016-05-25 15:42:49 +02:00
|
|
|
JS_POST := javascript/olm_outbound_group_session.js \
|
|
|
|
javascript/olm_inbound_group_session.js \
|
|
|
|
javascript/olm_post.js
|
2016-07-11 15:50:49 +02:00
|
|
|
DOCS := tracing/README.html \
|
2016-09-22 12:04:19 +02:00
|
|
|
docs/megolm.html \
|
2016-07-11 15:50:49 +02:00
|
|
|
docs/olm.html \
|
2016-10-27 12:53:55 +02:00
|
|
|
docs/signing.html \
|
2016-07-11 15:50:49 +02:00
|
|
|
README.html \
|
|
|
|
CHANGELOG.html
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-09-01 14:35:23 +02:00
|
|
|
CPPFLAGS += -Iinclude -Ilib \
|
|
|
|
-DOLMLIB_VERSION_MAJOR=$(MAJOR) -DOLMLIB_VERSION_MINOR=$(MINOR) \
|
|
|
|
-DOLMLIB_VERSION_PATCH=$(PATCH)
|
|
|
|
|
2016-05-24 15:36:07 +02:00
|
|
|
# we rely on <stdint.h>, which was introduced in C99
|
|
|
|
CFLAGS += -Wall -Werror -std=c99 -fPIC
|
2016-05-18 19:03:28 +02:00
|
|
|
CXXFLAGS += -Wall -Werror -std=c++11 -fPIC
|
|
|
|
LDFLAGS += -Wall -Werror
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-05-20 10:36:50 +02:00
|
|
|
EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0
|
|
|
|
# NO_BROWSER is kept for compatibility with emscripten 1.35.24, but is no
|
|
|
|
# longer needed.
|
|
|
|
EMCCFLAGS += -s NO_BROWSER=1
|
|
|
|
|
|
|
|
EMCC.c = $(EMCC) $(CFLAGS) $(CPPFLAGS) -c
|
|
|
|
EMCC.cc = $(EMCC) $(CXXFLAGS) $(CPPFLAGS) -c
|
|
|
|
EMCC_LINK = $(EMCC) $(LDFLAGS) $(EMCCFLAGS)
|
|
|
|
|
2016-05-23 18:32:24 +02:00
|
|
|
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)
|
|
|
|
|
2016-05-13 12:36:41 +02:00
|
|
|
# generate .d files when compiling
|
|
|
|
CPPFLAGS += -MMD
|
|
|
|
|
|
|
|
### per-target variables
|
|
|
|
|
2016-05-23 16:58:18 +02:00
|
|
|
$(RELEASE_OBJECTS): CFLAGS += $(RELEASE_OPTIMIZE_FLAGS)
|
|
|
|
$(RELEASE_OBJECTS): CXXFLAGS += $(RELEASE_OPTIMIZE_FLAGS)
|
|
|
|
$(RELEASE_TARGET): LDFLAGS += $(RELEASE_OPTIMIZE_FLAGS)
|
|
|
|
|
|
|
|
$(DEBUG_OBJECTS): CFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
|
|
|
|
$(DEBUG_OBJECTS): CXXFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
|
|
|
|
$(DEBUG_TARGET): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
|
2016-05-13 12:36:41 +02:00
|
|
|
|
|
|
|
$(TEST_BINARIES): CPPFLAGS += -Itests/include
|
2016-05-24 17:28:14 +02:00
|
|
|
$(TEST_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS) -L$(BUILD_DIR)
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-05-23 18:32:24 +02:00
|
|
|
$(FUZZER_OBJECTS): CFLAGS += $(FUZZER_OPTIMIZE_FLAGS)
|
|
|
|
$(FUZZER_OBJECTS): CXXFLAGS += $(FUZZER_OPTIMIZE_FLAGS)
|
|
|
|
$(FUZZER_BINARIES): CPPFLAGS += -Ifuzzers/include
|
|
|
|
$(FUZZER_BINARIES): LDFLAGS += $(FUZZER_OPTIMIZE_FLAGS) -L$(BUILD_DIR)
|
|
|
|
$(FUZZER_DEBUG_BINARIES): CPPFLAGS += -Ifuzzers/include
|
|
|
|
$(FUZZER_DEBUG_BINARIES): LDFLAGS += $(DEBUG_OPTIMIZE_FLAGS)
|
|
|
|
|
2016-05-20 10:36:50 +02:00
|
|
|
$(JS_OBJECTS): CFLAGS += $(JS_OPTIMIZE_FLAGS)
|
|
|
|
$(JS_OBJECTS): CXXFLAGS += $(JS_OPTIMIZE_FLAGS)
|
|
|
|
$(JS_TARGET): LDFLAGS += $(JS_OPTIMIZE_FLAGS)
|
|
|
|
|
2016-05-13 12:36:41 +02:00
|
|
|
### top-level targets
|
|
|
|
|
2016-09-01 14:35:23 +02:00
|
|
|
lib: $(RELEASE_TARGET)
|
2016-05-20 16:28:54 +02:00
|
|
|
.PHONY: lib
|
|
|
|
|
2016-05-23 16:58:18 +02:00
|
|
|
$(RELEASE_TARGET): $(RELEASE_OBJECTS)
|
|
|
|
$(CXX) $(LDFLAGS) --shared -fPIC \
|
2016-07-04 23:38:04 +02:00
|
|
|
-Wl,-soname,libolm.so.$(MAJOR) \
|
2016-05-23 16:58:18 +02:00
|
|
|
-Wl,--version-script,version_script.ver \
|
|
|
|
$(OUTPUT_OPTION) $(RELEASE_OBJECTS)
|
2016-09-05 12:56:53 +02:00
|
|
|
ln -sf libolm.so.$(VERSION) $(BUILD_DIR)/libolm.so.$(MAJOR)
|
2016-05-23 16:58:18 +02:00
|
|
|
|
2016-09-01 14:35:23 +02:00
|
|
|
debug: $(DEBUG_TARGET)
|
2016-05-23 16:58:18 +02:00
|
|
|
.PHONY: debug
|
|
|
|
|
|
|
|
$(DEBUG_TARGET): $(DEBUG_OBJECTS)
|
2016-05-20 13:01:18 +02:00
|
|
|
$(CXX) $(LDFLAGS) --shared -fPIC \
|
2016-07-04 23:38:04 +02:00
|
|
|
-Wl,-soname,libolm_debug.so.$(MAJOR) \
|
2016-05-23 16:58:18 +02:00
|
|
|
-Wl,--version-script,version_script.ver \
|
|
|
|
$(OUTPUT_OPTION) $(DEBUG_OBJECTS)
|
2016-09-05 12:56:53 +02:00
|
|
|
ln -sf libolm_debug.so.$(VERSION) $(BUILD_DIR)/libolm_debug.so.$(MAJOR)
|
2016-07-04 23:38:04 +02:00
|
|
|
|
2016-05-20 10:36:50 +02:00
|
|
|
js: $(JS_TARGET)
|
|
|
|
.PHONY: js
|
|
|
|
|
|
|
|
$(JS_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS)
|
|
|
|
$(EMCC_LINK) \
|
2016-05-25 15:42:49 +02:00
|
|
|
$(foreach f,$(JS_PRE),--pre-js $(f)) \
|
|
|
|
$(foreach f,$(JS_POST),--post-js $(f)) \
|
2016-05-23 16:58:18 +02:00
|
|
|
-s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \
|
2016-05-20 10:36:50 +02:00
|
|
|
$(JS_OBJECTS) -o $@
|
|
|
|
|
2016-05-13 12:36:41 +02:00
|
|
|
build_tests: $(TEST_BINARIES)
|
|
|
|
|
|
|
|
test: build_tests
|
|
|
|
for i in $(TEST_BINARIES); do \
|
|
|
|
echo $$i; \
|
2016-05-20 13:01:18 +02:00
|
|
|
$$i || exit $$?; \
|
2016-05-13 12:36:41 +02:00
|
|
|
done
|
|
|
|
|
2016-05-23 18:32:24 +02:00
|
|
|
fuzzers: $(FUZZER_BINARIES) $(FUZZER_DEBUG_BINARIES)
|
|
|
|
.PHONY: fuzzers
|
|
|
|
|
2016-05-20 10:36:50 +02:00
|
|
|
$(JS_EXPORTED_FUNCTIONS): $(PUBLIC_HEADERS)
|
2016-05-25 15:42:49 +02:00
|
|
|
perl -MJSON -ne '$$f{"_$$1"}=1 if /(olm_[^( ]*)\(/; END { @f=sort keys %f; print encode_json \@f }' $^ > $@.tmp
|
2016-05-20 10:36:50 +02:00
|
|
|
mv $@.tmp $@
|
|
|
|
|
2016-07-11 15:50:49 +02:00
|
|
|
all: test js lib debug doc
|
2016-05-25 18:08:44 +02:00
|
|
|
.PHONY: all
|
|
|
|
|
2016-09-21 19:08:05 +02:00
|
|
|
install-headers: $(PUBLIC_HEADERS)
|
|
|
|
test -d $(DESTDIR)$(PREFIX)/include/olm || mkdir -p $(DESTDIR)$(PREFIX)/include/olm
|
|
|
|
install -Dm644 $(PUBLIC_HEADERS) $(DESTDIR)$(PREFIX)/include/olm/
|
2016-09-23 13:22:34 +02:00
|
|
|
.PHONY: install-headers
|
2016-09-21 19:08:05 +02:00
|
|
|
|
|
|
|
install-debug: debug install-headers
|
|
|
|
test -d $(DESTDIR)$(PREFIX)/lib || mkdir -p $(DESTDIR)$(PREFIX)/lib
|
2016-07-04 23:38:05 +02:00
|
|
|
install -Dm755 $(DEBUG_TARGET) $(DESTDIR)$(PREFIX)/lib/libolm_debug.so.$(VERSION)
|
|
|
|
ln -s libolm_debug.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm_debug.so.$(MAJOR)
|
|
|
|
ln -s libolm_debug.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm_debug.so
|
|
|
|
.PHONY: install-debug
|
|
|
|
|
2016-09-21 19:08:05 +02:00
|
|
|
install: lib install-headers
|
|
|
|
test -d $(DESTDIR)$(PREFIX)/lib || mkdir -p $(DESTDIR)$(PREFIX)/lib
|
2016-07-04 23:38:05 +02:00
|
|
|
install -Dm755 $(RELEASE_TARGET) $(DESTDIR)$(PREFIX)/lib/libolm.so.$(VERSION)
|
|
|
|
ln -s libolm.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm.so.$(MAJOR)
|
|
|
|
ln -s libolm.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libolm.so
|
|
|
|
.PHONY: install
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
clean:;
|
2016-07-11 15:50:49 +02:00
|
|
|
rm -rf $(BUILD_DIR) $(DOCS)
|
2016-05-25 18:08:44 +02:00
|
|
|
.PHONY: clean
|
2016-05-20 16:28:54 +02:00
|
|
|
|
2016-07-11 15:50:49 +02:00
|
|
|
doc: $(DOCS)
|
|
|
|
.PHONY: doc
|
|
|
|
|
2016-05-13 12:36:41 +02:00
|
|
|
### rules for building objects
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/release/%.o: %.c
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-23 16:58:18 +02:00
|
|
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/release/%.o: %.cpp
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-23 16:58:18 +02:00
|
|
|
$(COMPILE.cc) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/debug/%.o: %.c
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-13 12:36:41 +02:00
|
|
|
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/debug/%.o: %.cpp
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-13 12:36:41 +02:00
|
|
|
$(COMPILE.cc) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/javascript/%.o: %.c
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-20 10:36:50 +02:00
|
|
|
$(EMCC.c) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/javascript/%.o: %.cpp
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-20 10:36:50 +02:00
|
|
|
$(EMCC.cc) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-23 16:58:18 +02:00
|
|
|
$(BUILD_DIR)/tests/%: tests/%.c $(DEBUG_OBJECTS)
|
2016-05-25 18:08:44 +02:00
|
|
|
mkdir -p $(dir $@)
|
2016-05-23 17:23:57 +02:00
|
|
|
$(LINK.c) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-05-23 16:58:18 +02:00
|
|
|
$(BUILD_DIR)/tests/%: tests/%.cpp $(DEBUG_OBJECTS)
|
2016-05-25 18:08:44 +02:00
|
|
|
mkdir -p $(dir $@)
|
2016-05-23 17:23:57 +02:00
|
|
|
$(LINK.cc) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/fuzzers/objects/%.o: %.c
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-23 18:32:24 +02:00
|
|
|
$(AFL.c) $(OUTPUT_OPTION) $<
|
|
|
|
|
2016-05-25 18:08:44 +02:00
|
|
|
$(BUILD_DIR)/fuzzers/objects/%.o: %.cpp
|
|
|
|
mkdir -p $(dir $@)
|
2016-05-23 18:32:24 +02:00
|
|
|
$(AFL.cc) $(OUTPUT_OPTION) $<
|
|
|
|
|
|
|
|
$(BUILD_DIR)/fuzzers/fuzz_%: fuzzers/fuzz_%.c $(FUZZER_OBJECTS)
|
|
|
|
$(AFL_LINK.c) $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/fuzzers/fuzz_%: fuzzers/fuzz_%.cpp $(FUZZER_OBJECTS)
|
|
|
|
$(AFL_LINK.cc) $< $(FUZZER_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/fuzzers/debug_%: fuzzers/fuzz_%.c $(DEBUG_OBJECTS)
|
|
|
|
$(LINK.c) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/fuzzers/debug_%: fuzzers/fuzz_%.cpp $(DEBUG_OBJECTS)
|
|
|
|
$(LINK.cc) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
|
2016-05-13 12:36:41 +02:00
|
|
|
|
2016-07-11 15:50:49 +02:00
|
|
|
%.html: %.rst
|
|
|
|
rst2html $< $@
|
|
|
|
|
2016-05-13 12:36:41 +02:00
|
|
|
### dependencies
|
|
|
|
|
2016-05-23 16:58:18 +02:00
|
|
|
-include $(RELEASE_OBJECTS:.o=.d)
|
|
|
|
-include $(DEBUG_OBJECTS:.o=.d)
|
2016-05-25 18:08:44 +02:00
|
|
|
-include $(JS_OBJECTS:.o=.d)
|
2016-05-13 12:36:41 +02:00
|
|
|
-include $(TEST_BINARIES:=.d)
|
2016-05-23 18:32:24 +02:00
|
|
|
-include $(FUZZER_OBJECTS:.o=.d)
|
|
|
|
-include $(FUZZER_BINARIES:=.d)
|
|
|
|
-include $(FUZZER_DEBUG_BINARIES:=.d)
|