include $(CONFIG) CPPFLAGS += -Iinclude -I$(OUTDIR) -I$(OUTDIR)/data -DEBCL_BUILD CXXFLAGS += -std=c++14 -Wall -Wextra LDFLAGS += -L$(OUTDIR) -pthread ifeq ($(OPTIMIZE),y) CXXFLAGS += -O2 else CXXFLAGS += -O0 endif ifeq ($(DEBUG),y) CXXFLAGS += -g endif CXXFLAGS_LIB = $(CXXFLAGS) LIBS_LIB = -ldl -latomic LIB_DYNAMIC = $(OUTDIR)/libebcorelib.so LIB_STATIC = $(OUTDIR)/libebcorelib.a LIB_TARGETS = ifeq ($(BUILD_DYNAMIC_LIB),y) CXXFLAGS_LIB += -fPIC LIB_TARGETS += $(LIB_DYNAMIC) endif ifeq ($(BUILD_STATIC_LIB),y) LIB_TARGETS += $(LIB_STATIC) endif include src/files.mk LIB_OBJS = $(addprefix $(OUTDIR)/,$(addsuffix .o, $(subst src/,, $(basename $(LIB_SOURCES))))) include tests/list.mk TEST_SUITES := $(addprefix $(OUTDIR)/test-,$(TESTS)) TEST_ALL := $(OUTDIR)/run-all-tests TEST_MAIN := $(OUTDIR)/tests/run-test.o TEST_OBJS := $(addsuffix .o,$(addprefix $(OUTDIR)/tests/,$(TESTS))) $(TEST_MAIN) LIBS_TESTS = -lcppunit ifeq ($(BUILD_DYNAMIC_LIB),y) LIBS_TESTS += -lebcorelib TEST_NEEDS = $(LIB_DYNAMIC) else LIBS_TESTS += $(OUTDIR)/libebcorelib.a $(LIBS_LIB) TEST_NEEDS = $(LIB_STATIC) endif ALL_OBJS = $(LIB_OBJS) ifeq ($(BUILD_TESTS),y) ALL_OBJS += $(TEST_OBJS) endif DEPS := $(addsuffix .d,$(ALL_OBJS)) TARGETS = $(LIB_TARGETS) ifeq ($(BUILD_TESTS),y) TARGETS += tests endif all: $(TARGETS) run: tests @if [ -z "$(E)" ]; then \ echo "\n\nPlease define E\n\n"; \ exit 1; \ else \ LD_LIBRARY_PATH=$(OUTDIR) $(OUTDIR)/$(E); \ fi debug: tests @if [ -z "$(E)" ]; then \ echo "\n\nPlease define E\n\n"; \ exit 1; \ else \ LD_LIBRARY_PATH=$(OUTDIR) debug $(OUTDIR)/$(E); \ fi run-tests: tests LD_LIBRARY_PATH=$(OUTDIR) ./$(TEST_ALL) clean: rm -f $(TEST_SUITES) $(TEST_ALL) $(TEST_OBJS) \ $(LIB_OBJS) $(LIB_TARGETS) fullclean: clean rm -f $(DEPS) -rmdir $(sort $(dir $(TEST_OBJS)) $(dir $(LIB_OBJS))) -rmdir $(OUTDIR) tests: $(LIB_LWLIB) $(TEST_OBJS) $(TEST_SUITES) $(TEST_ALL) .PHONY: all run debug run-tests clean fullclean tests #------------------------------------------------------------------------------ # Actual building -include $(DEPS) # Library $(LIB_DYNAMIC): $(LIB_OBJS) $(CXX) $(LDFLAGS) -shared -Wl,-soname,$(notdir $(LIB_DYNAMIC)) \ -o $(LIB_DYNAMIC) \ $(LIB_OBJS) $(LIBS_LIB) $(LIB_STATIC): $(LIB_OBJS) ar crD $(LIB_STATIC) $(LIB_OBJS) # Tests $(TEST_SUITES): $(OUTDIR)/test-%: $(OUTDIR)/tests/%.o $(TEST_MAIN) $(TEST_NEEDS) $(CXX) $(LDFLAGS) -o $@ $< $(TEST_MAIN) $(LIBS_TESTS) $(TEST_ALL): $(TEST_OBJS) $(LIB_LWLIB) $(CXX) $(LDFLAGS) -o $@ $(TEST_OBJS) $(LIBS_TESTS) #------------------------------------------------------------------------------ # .cc -> .o $(LIB_OBJS): $(OUTDIR)/%.o: src/%.cc @if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi $(CXX) $(CPPFLAGS) $(CXXFLAGS_LIB) -c -o $@ $< $(CXX) $(CPPFLAGS) $(CXXFLAGS_LIB) -M -MF $@.d -MT $@ $< $(TEST_OBJS): $(OUTDIR)/%.o: %.cc @if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< $(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MF $@.d -MT $@ $<