aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-05-25 17:08:44 +0100
committerRichard van der Hoff <richard@matrix.org>2016-05-25 17:08:44 +0100
commitee8172d882e853e737ac7e8b00fb760f21e80bfe (patch)
treec718e292d6b43933ee2dbb15f79047d9d36b2730 /Makefile
parent27b57c8d8830ebd37ad304703ccb61390d4b0f36 (diff)
Compile some of the crypto libs directly
sha256.c and aes.c contain conflicting declarations, so we need to compile them as separate units. This requires a bit more Makefile-shuffling; the build directory now includes 'src' or 'lib' as appropriate, and we just mkdir -p before each compilation.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile75
1 files changed, 38 insertions, 37 deletions
diff --git a/Makefile b/Makefile
index fca9576..49bec6a 100644
--- a/Makefile
+++ b/Makefile
@@ -17,16 +17,22 @@ JS_EXPORTED_FUNCTIONS := javascript/exported_functions.json
PUBLIC_HEADERS := include/olm/olm.h
-SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c)
-RELEASE_OBJECTS := $(patsubst src/%,$(BUILD_DIR)/release/%,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES))))
-DEBUG_OBJECTS := $(patsubst src/%,$(BUILD_DIR)/debug/%,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES))))
-FUZZER_OBJECTS := $(patsubst src/%,$(BUILD_DIR)/fuzzers/objects/%,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES))))
+SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c) \
+ lib/crypto-algorithms/sha256.c \
+ lib/crypto-algorithms/aes.c \
+ lib/curve25519-donna/curve25519-donna.c
+
FUZZER_SOURCES := $(wildcard fuzzers/fuzz_*.cpp) $(wildcard fuzzers/fuzz_*.c)
-FUZZER_BINARIES := $(patsubst fuzzers/%,$(BUILD_DIR)/fuzzers/%,$(patsubst %.c,%,$(patsubst %.cpp,%,$(FUZZER_SOURCES))))
-FUZZER_DEBUG_BINARIES := $(patsubst $(BUILD_DIR)/fuzzers/fuzz_%,$(BUILD_DIR)/fuzzers/debug_%,$(FUZZER_BINARIES))
TEST_SOURCES := $(wildcard tests/test_*.cpp) $(wildcard tests/test_*.c)
-TEST_BINARIES := $(patsubst tests/%,$(BUILD_DIR)/tests/%,$(patsubst %.c,%,$(patsubst %.cpp,%,$(TEST_SOURCES))))
-JS_OBJECTS := $(patsubst src/%,$(BUILD_DIR)/javascript/%,$(patsubst %.c,%.js.bc,$(patsubst %.cpp,%.js.bc,$(SOURCES))))
+
+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))
JS_PRE := $(wildcard javascript/*pre.js)
JS_POST := $(wildcard javascript/*post.js)
@@ -82,14 +88,6 @@ $(JS_TARGET): LDFLAGS += $(JS_OPTIMIZE_FLAGS)
lib: $(RELEASE_TARGET)
.PHONY: lib
-# Make sure that the build directory exists.
-# We can't check the build directory into git because it is empty.
-makedirs:
- mkdir -p $(BUILD_DIR)/release $(BUILD_DIR)/debug $(BUILD_DIR)/javascript\
- $(BUILD_DIR)/tests $(BUILD_DIR)/fuzzers/objects
-.PHONY: makedirs
-
-
$(RELEASE_TARGET): $(RELEASE_OBJECTS)
$(CXX) $(LDFLAGS) --shared -fPIC \
-Wl,--version-script,version_script.ver \
@@ -112,17 +110,6 @@ $(JS_TARGET): $(JS_OBJECTS) $(JS_PRE) $(JS_POST) $(JS_EXPORTED_FUNCTIONS)
-s "EXPORTED_FUNCTIONS=@$(JS_EXPORTED_FUNCTIONS)" \
$(JS_OBJECTS) -o $@
-clean:;
- rm -rf $(RELEASE_OBJECTS) $(RELEASE_OBJECTS:.o=.d) \
- $(DEBUG_OBJECTS) $(DEBUG_OBJECTS:.o=.d) \
- $(TEST_BINARIES) $(TEST_BINARIES:=.d) \
- $(JS_OBJECTS) $(JS_OBJECTS:.bc=.d) $(JS_TARGET) \
- $(JS_EXPORTED_FUNCTIONS)\
- $(RELEASE_TARGET) $(DEBUG_TARGET)\
- $(FUZZER_OBJECTS) $(FUZZER_OBJECTS:.o=.d)\
- $(FUZZER_BINARIES) $(FUZZER_BINARIES:=.d)\
- $(FUZZER_DEBUG_BINARIES) $(FUZZER_DEBUG_BINARIES:=.d)\
-
build_tests: $(TEST_BINARIES)
test: build_tests
@@ -139,37 +126,51 @@ $(JS_EXPORTED_FUNCTIONS): $(PUBLIC_HEADERS)
mv $@.tmp $@
all: test js lib debug
-.PHONY: lib
+.PHONY: all
+
+clean:;
+ rm -rf $(BUILD_DIR)
+.PHONY: clean
### rules for building objects
-$(BUILD_DIR)/release/%.o: src/%.c | makedirs
+$(BUILD_DIR)/release/%.o: %.c
+ mkdir -p $(dir $@)
$(COMPILE.c) $(OUTPUT_OPTION) $<
-$(BUILD_DIR)/release/%.o: src/%.cpp | makedirs
+$(BUILD_DIR)/release/%.o: %.cpp
+ mkdir -p $(dir $@)
$(COMPILE.cc) $(OUTPUT_OPTION) $<
-$(BUILD_DIR)/debug/%.o: src/%.c | makedirs
+$(BUILD_DIR)/debug/%.o: %.c
+ mkdir -p $(dir $@)
$(COMPILE.c) $(OUTPUT_OPTION) $<
-$(BUILD_DIR)/debug/%.o: src/%.cpp | makedirs
+$(BUILD_DIR)/debug/%.o: %.cpp
+ mkdir -p $(dir $@)
$(COMPILE.cc) $(OUTPUT_OPTION) $<
-$(BUILD_DIR)/javascript/%.js.bc: src/%.c | makedirs
+$(BUILD_DIR)/javascript/%.o: %.c
+ mkdir -p $(dir $@)
$(EMCC.c) $(OUTPUT_OPTION) $<
-$(BUILD_DIR)/javascript/%.js.bc: src/%.cpp | makedirs
+$(BUILD_DIR)/javascript/%.o: %.cpp
+ mkdir -p $(dir $@)
$(EMCC.cc) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/tests/%: tests/%.c $(DEBUG_OBJECTS)
+ mkdir -p $(dir $@)
$(LINK.c) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
$(BUILD_DIR)/tests/%: tests/%.cpp $(DEBUG_OBJECTS)
+ mkdir -p $(dir $@)
$(LINK.cc) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
-$(BUILD_DIR)/fuzzers/objects/%.o: src/%.c | makedirs
+$(BUILD_DIR)/fuzzers/objects/%.o: %.c
+ mkdir -p $(dir $@)
$(AFL.c) $(OUTPUT_OPTION) $<
-$(BUILD_DIR)/fuzzers/objects/%.o: src/%.cpp | makedirs
+$(BUILD_DIR)/fuzzers/objects/%.o: %.cpp
+ mkdir -p $(dir $@)
$(AFL.cc) $(OUTPUT_OPTION) $<
$(BUILD_DIR)/fuzzers/fuzz_%: fuzzers/fuzz_%.c $(FUZZER_OBJECTS)
@@ -188,7 +189,7 @@ $(BUILD_DIR)/fuzzers/debug_%: fuzzers/fuzz_%.cpp $(DEBUG_OBJECTS)
-include $(RELEASE_OBJECTS:.o=.d)
-include $(DEBUG_OBJECTS:.o=.d)
--include $(JS_OBJECTS:.bc=.d)
+-include $(JS_OBJECTS:.o=.d)
-include $(TEST_BINARIES:=.d)
-include $(FUZZER_OBJECTS:.o=.d)
-include $(FUZZER_BINARIES:=.d)