include $(CONFIG) ifeq ($(shell uname),Linux) BUILD_FOR ?= linux else BUILD_FOR ?= win endif # Select compiler (g++ for linux, mingw-w64 for windows) ifeq ($(BUILD_FOR),linux) CXX=x86_64-linux-gnu-g++ else ifeq ($(BUILD_FOR),win) CXX=x86_64-w64-mingw32-g++ else $(error Invalid target "$(BUILD_FOR) (valid choices: linux win)") endif endif # Output directory, based on target OS, unless defined manually OUTDIR ?= $(OUTDIRBASE)/$(BUILD_FOR) # CPPUnit CPPUNIT = $(OUTDIR)/cppunit CPPUNIT_SOURCE = $(OUTDIRBASE)/cppunit CPPUNIT_BUILD = $(OUTDIR)/cppunit-build ifeq ($(BUILD_FOR),linux) CPPUNIT_HOST=x86_64-linux-gnu endif ifeq ($(BUILD_FOR),win) CPPUNIT_HOST=x86_64-w64-mingw32 endif CPPFLAGS += -I$(CPPUNIT)/include LDFLAGS += -L$(CPPUNIT)/lib # Compiler and linker flags CPPFLAGS += -Iinclude -I$(OUTDIR) -I$(OUTDIR)/data -DEBCL_BUILD -D_USE_MATH_DEFINES 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 # Libs for either Linux or Windows ifeq ($(BUILD_FOR),linux) LIBS_LIB = -ldl -latomic endif ifeq ($(BUILD_FOR),win) LIBS_LIB = -latomic endif # Library and progam suffixes ifeq ($(BUILD_FOR),linux) SUFFIX_LIB=.so SUFFIX_EXE= endif ifeq ($(BUILD_FOR),win) SUFFIX_LIB=.dll SUFFIX_EXE=.exe endif # Library include src/files.mk LIB_OBJS = $(addprefix $(OUTDIR)/,$(addsuffix .o, $(subst src/,, $(basename $(LIB_SOURCES))))) CXXFLAGS_LIB = $(CXXFLAGS) LIB_DYNAMIC = $(OUTDIR)/libebcorelib$(SUFFIX_LIB) 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 # Tests include tests/list.mk TEST_SUITES := $(addsuffix $(SUFFIX_EXE), $(addprefix $(OUTDIR)/test-,$(TESTS))) TEST_ALL := $(OUTDIR)/run-all-tests$(SUFFIX_EXE) TEST_MAIN := $(OUTDIR)/tests/run-test.o TEST_OBJS := $(addsuffix .o,$(addprefix $(OUTDIR)/tests/,$(TESTS))) $(TEST_MAIN) # Required libraries 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 # Linker flags TEST_LDFLAGS = ifeq ($(BUILD_FOR),win) TEST_LDFLAGS += -mconsole endif # Objects and dependencies ALL_OBJS = $(LIB_OBJS) ifeq ($(BUILD_TESTS),y) ALL_OBJS += $(TEST_OBJS) endif DEPS := $(addsuffix .d,$(ALL_OBJS)) # Default targets 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):$(CPPUNIT)/lib $(OUTDIR)/$(E); \ fi run-tests: tests LD_LIBRARY_PATH=$(OUTDIR):$(CPPUNIT)/lib ./$(TEST_ALL) clean: rm -f $(TEST_SUITES) $(TEST_ALL) $(TEST_OBJS) \ $(LIB_OBJS) $(LIB_TARGETS) fullclean: rm --preserve-root -rf $(OUTDIR) tests: copy-libraries $(TEST_OBJS) $(TEST_SUITES) $(TEST_ALL) .PHONY: all run debug run-tests clean fullclean tests # ---------------------------------------------------------------------------- # # - LIBRARY AND TESTS - # # ---------------------------------------------------------------------------- # -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-%$(SUFFIX_EXE): $(OUTDIR)/tests/%.o $(TEST_MAIN) $(TEST_NEEDS) $(CXX) $(LDFLAGS) $(TEST_LDFLAGS) -o $@ $< $(TEST_MAIN) $(LIBS_TESTS) $(TEST_ALL): $(TEST_OBJS) $(CXX) $(LDFLAGS) $(TEST_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 | cppunit @if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< $(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MF $@.d -MT $@ $< # ---------------------------------------------------------------------------- # # - CPPUNIT - # # ---------------------------------------------------------------------------- # cppunit: | $(CPPUNIT_SOURCE)/configure +if [ ! -d "$(CPPUNIT)" ]; then \ if [ ! -d "$(CPPUNIT_BUILD)" ]; then \ mkdir -p "$(CPPUNIT_BUILD)"; \ fi; \ cd "$(CPPUNIT_BUILD)" && \ "$(abspath $(CPPUNIT_SOURCE))"/configure \ --host=$(CPPUNIT_HOST) \ --prefix="$(abspath $(CPPUNIT))" \ --disable-doxygen \ --enable-silent-rules && \ make && \ make install; \ fi -rm -rf "$(CPPUNIT_BUILD)" $(CPPUNIT_SOURCE)/configure: | cppunit-dl cd "$(CPPUNIT_SOURCE)"; ./autogen.sh cppunit-dl: if [ ! -d "$(CPPUNIT_SOURCE)" ]; then \ git clone git://anongit.freedesktop.org/git/libreoffice/cppunit/ "$(CPPUNIT_SOURCE)"; \ fi .PHONY: cppunit cppunit-linux cppunit-windows cppunit-dl # ---------------------------------------------------------------------------- # # - DLL COPYING - # # ---------------------------------------------------------------------------- # # On Windows, we need all the external DLLs to be copied to the output directory ifeq ($(BUILD_FOR),win) MINGW_DIR ?= /usr/x86_64-w64-mingw32/sys-root/mingw/bin copy-libraries: | cppunit cp $(CPPUNIT)/bin/*dll $(OUTDIR) cp $(MINGW_DIR)/libgcc_s_seh-1.dll $(OUTDIR) cp $(MINGW_DIR)/libatomic-1.dll $(OUTDIR) cp $(MINGW_DIR)/libstdc++-6.dll $(OUTDIR) cp $(MINGW_DIR)/libwinpthread-1.dll $(OUTDIR) else copy-libraries: endif .PHONY: copy-libraries