diff options
author | Richard van der Hoff <richard@matrix.org> | 2016-05-13 11:36:41 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2016-05-20 15:15:40 +0100 |
commit | b3a7a6b36c695abc5515e806464b497997f59115 (patch) | |
tree | 3524479694ca97a52839ebbd56e89ebccca846f9 /Makefile | |
parent | acae4e84386056e80eb4bb633fcdf03375c087ea (diff) |
Add a makefile
Replace the python scripts for building the shared lib and tests with a
Makefile, which makes it easier to handle a mix of C and C++.
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a722b70 --- /dev/null +++ b/Makefile @@ -0,0 +1,69 @@ +#!/usr/bin/make -f + +BUILD_DIR := build +OPTIMIZE_FLAGS ?= -g -O3 +TEST_OPTIMIZE_FLAGS ?= -g -O0 +CC = gcc +TARGET := $(BUILD_DIR)/libolm.so + +SOURCES := $(wildcard src/*.cpp) $(wildcard src/*.c) +OBJECTS := $(patsubst src/%,$(BUILD_DIR)/%,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))) +TEST_SOURCES := $(wildcard tests/test_*.cpp) $(wildcard tests/test_*.c) +TEST_BINARIES := $(patsubst tests/%,$(BUILD_DIR)/%,$(patsubst %.c,%,$(patsubst %.cpp,%,$(TEST_SOURCES)))) + +CPPFLAGS += -Iinclude -Ilib +CFLAGS += -Wall --std=c89 -fPIC +CXXFLAGS += -Wall --std=c++11 -fPIC +LDFLAGS += -Wall + +# generate .d files when compiling +CPPFLAGS += -MMD + +### per-target variables + +$(OBJECTS): CFLAGS += $(OPTIMIZE_FLAGS) +$(OBJECTS): CXXFLAGS += $(OPTIMIZE_FLAGS) +$(TARGET): LDFLAGS += $(OPTIMIZE_FLAGS) + +$(TEST_BINARIES): CPPFLAGS += -Itests/include +$(TEST_BINARIES): LDLIBS += -lolm +$(TEST_BINARIES): LDFLAGS += $(TEST_OPTIMIZE_FLAGS) -L$(BUILD_DIR) + +### top-level targets + +$(TARGET): $(OBJECTS) + $(CXX) $(LDFLAGS) --shared -fPIC $^ $(OUTPUT_OPTION) + +clean:; + rm -rf $(OBJECTS) $(OBJECTS:.o=.d) \ + $(TEST_BINARIES) $(TEST_BINARIES:=.d) \ + $(TARGET) + +build_tests: $(TEST_BINARIES) + +test: build_tests + for i in $(TEST_BINARIES); do \ + echo $$i; \ + LD_LIBRARY_PATH=$(BUILD_DIR) $$i || exit $$?; \ + done + +### rules for building objects +$(BUILD_DIR)/%.o: src/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + +$(BUILD_DIR)/%.o: src/%.cpp + $(COMPILE.cc) $(OUTPUT_OPTION) $< + +$(BUILD_DIR)/%: tests/%.c + $(LINK.c) $< $(LOADLIBES) $(LDLIBS) -o $@ + +$(BUILD_DIR)/%: tests/%.cpp + $(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@ + + +### dependencies + +$(TEST_BINARIES): $(TARGET) + +-include $(OBJECTS:.o=.d) +-include $(TEST_BINARIES:=.d) |