From b3a7a6b36c695abc5515e806464b497997f59115 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 13 May 2016 11:36:41 +0100 Subject: 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++. --- Makefile | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Makefile (limited to 'Makefile') 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) -- cgit v1.2.3