blob: a722b70285c756c431f75ae546b82a068765858e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)
|