2017-11-01 21:44:54 +01:00
|
|
|
include $(CONFIG)
|
2018-12-16 11:57:58 +01:00
|
|
|
ifeq ($(shell uname),Linux)
|
2018-06-17 12:39:02 +02:00
|
|
|
BUILD_FOR ?= linux
|
2018-12-16 11:57:58 +01:00
|
|
|
else
|
|
|
|
BUILD_FOR ?= win
|
|
|
|
endif
|
2017-11-01 21:44:54 +01:00
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# Select compiler (g++ for linux, mingw-w64 for windows)
|
2018-06-17 12:39:02 +02:00
|
|
|
ifeq ($(BUILD_FOR),linux)
|
|
|
|
CXX=x86_64-linux-gnu-g++
|
|
|
|
else
|
|
|
|
ifeq ($(BUILD_FOR),win)
|
2018-12-16 11:57:58 +01:00
|
|
|
CXX=x86_64-w64-mingw32-g++
|
2018-06-17 12:39:02 +02:00
|
|
|
else
|
2018-12-16 11:57:58 +01:00
|
|
|
$(error Invalid target "$(BUILD_FOR) (valid choices: linux win)")
|
2018-06-17 12:39:02 +02:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# 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
|
2018-06-17 12:39:02 +02:00
|
|
|
ifeq ($(BUILD_FOR),win)
|
2018-12-16 11:57:58 +01:00
|
|
|
CPPUNIT_HOST=x86_64-w64-mingw32
|
2018-06-17 12:39:02 +02:00
|
|
|
endif
|
2018-12-16 11:57:58 +01:00
|
|
|
CPPFLAGS += -I$(CPPUNIT)/include
|
|
|
|
LDFLAGS += -L$(CPPUNIT)/lib
|
2018-06-17 12:39:02 +02:00
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# Compiler and linker flags
|
2018-06-17 12:39:02 +02:00
|
|
|
CPPFLAGS += -Iinclude -I$(OUTDIR) -I$(OUTDIR)/data -DEBCL_BUILD -D_USE_MATH_DEFINES
|
2017-11-01 21:44:54 +01:00
|
|
|
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
|
|
|
|
|
2018-06-17 12:39:02 +02:00
|
|
|
# Libs for either Linux or Windows
|
|
|
|
ifeq ($(BUILD_FOR),linux)
|
2017-11-01 21:44:54 +01:00
|
|
|
LIBS_LIB = -ldl -latomic
|
2018-12-16 11:57:58 +01:00
|
|
|
endif
|
2018-06-17 12:39:02 +02:00
|
|
|
ifeq ($(BUILD_FOR),win)
|
|
|
|
LIBS_LIB = -latomic
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Library and progam suffixes
|
|
|
|
ifeq ($(BUILD_FOR),linux)
|
|
|
|
SUFFIX_LIB=.so
|
|
|
|
SUFFIX_EXE=
|
2018-12-16 11:57:58 +01:00
|
|
|
endif
|
2018-06-17 12:39:02 +02:00
|
|
|
ifeq ($(BUILD_FOR),win)
|
|
|
|
SUFFIX_LIB=.dll
|
|
|
|
SUFFIX_EXE=.exe
|
|
|
|
endif
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# Library
|
|
|
|
include src/files.mk
|
|
|
|
LIB_OBJS = $(addprefix $(OUTDIR)/,$(addsuffix .o, $(subst src/,, $(basename $(LIB_SOURCES)))))
|
2018-06-17 12:39:02 +02:00
|
|
|
CXXFLAGS_LIB = $(CXXFLAGS)
|
|
|
|
LIB_DYNAMIC = $(OUTDIR)/libebcorelib$(SUFFIX_LIB)
|
2017-11-01 21:44:54 +01:00
|
|
|
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
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# Tests
|
2017-11-01 21:44:54 +01:00
|
|
|
include tests/list.mk
|
2018-06-17 12:39:02 +02:00
|
|
|
TEST_SUITES := $(addsuffix $(SUFFIX_EXE), $(addprefix $(OUTDIR)/test-,$(TESTS)))
|
|
|
|
TEST_ALL := $(OUTDIR)/run-all-tests$(SUFFIX_EXE)
|
2017-11-01 21:44:54 +01:00
|
|
|
TEST_MAIN := $(OUTDIR)/tests/run-test.o
|
|
|
|
TEST_OBJS := $(addsuffix .o,$(addprefix $(OUTDIR)/tests/,$(TESTS))) $(TEST_MAIN)
|
2018-12-16 11:57:58 +01:00
|
|
|
# Required libraries
|
2017-11-01 21:44:54 +01:00
|
|
|
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
|
2018-12-16 11:57:58 +01:00
|
|
|
# Linker flags
|
|
|
|
TEST_LDFLAGS =
|
|
|
|
ifeq ($(BUILD_FOR),win)
|
|
|
|
TEST_LDFLAGS += -mconsole
|
|
|
|
endif
|
2017-11-01 21:44:54 +01:00
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# Objects and dependencies
|
2017-11-01 21:44:54 +01:00
|
|
|
ALL_OBJS = $(LIB_OBJS)
|
|
|
|
ifeq ($(BUILD_TESTS),y)
|
|
|
|
ALL_OBJS += $(TEST_OBJS)
|
|
|
|
endif
|
|
|
|
DEPS := $(addsuffix .d,$(ALL_OBJS))
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# Default targets
|
2017-11-01 21:44:54 +01:00
|
|
|
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 \
|
2018-12-16 11:57:58 +01:00
|
|
|
LD_LIBRARY_PATH=$(OUTDIR):$(CPPUNIT)/lib $(OUTDIR)/$(E); \
|
2017-11-01 21:44:54 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
run-tests: tests
|
2018-12-16 11:57:58 +01:00
|
|
|
LD_LIBRARY_PATH=$(OUTDIR):$(CPPUNIT)/lib ./$(TEST_ALL)
|
2017-11-01 21:44:54 +01:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f $(TEST_SUITES) $(TEST_ALL) $(TEST_OBJS) \
|
|
|
|
$(LIB_OBJS) $(LIB_TARGETS)
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
fullclean:
|
|
|
|
rm --preserve-root -rf $(OUTDIR)
|
2017-11-01 21:44:54 +01:00
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
tests: copy-libraries $(TEST_OBJS) $(TEST_SUITES) $(TEST_ALL)
|
2017-11-01 21:44:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: all run debug run-tests clean fullclean tests
|
|
|
|
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
# ---------------------------------------------------------------------------- #
|
|
|
|
# - LIBRARY AND TESTS - #
|
|
|
|
# ---------------------------------------------------------------------------- #
|
2017-11-01 21:44:54 +01:00
|
|
|
|
|
|
|
-include $(DEPS)
|
|
|
|
|
|
|
|
# Library
|
|
|
|
$(LIB_DYNAMIC): $(LIB_OBJS)
|
|
|
|
$(CXX) $(LDFLAGS) -shared -Wl,-soname,$(notdir $(LIB_DYNAMIC)) \
|
|
|
|
-o $(LIB_DYNAMIC) \
|
|
|
|
$(LIB_OBJS) $(LIBS_LIB)
|
|
|
|
|
2017-11-01 23:32:06 +01:00
|
|
|
$(LIB_STATIC): $(LIB_OBJS)
|
|
|
|
ar crD $(LIB_STATIC) $(LIB_OBJS)
|
|
|
|
|
2017-11-01 21:44:54 +01:00
|
|
|
# Tests
|
2018-06-17 12:39:02 +02:00
|
|
|
$(TEST_SUITES): $(OUTDIR)/test-%$(SUFFIX_EXE): $(OUTDIR)/tests/%.o $(TEST_MAIN) $(TEST_NEEDS)
|
2018-12-16 11:57:58 +01:00
|
|
|
$(CXX) $(LDFLAGS) $(TEST_LDFLAGS) -o $@ $< $(TEST_MAIN) $(LIBS_TESTS)
|
2017-11-01 21:44:54 +01:00
|
|
|
|
2018-06-17 12:39:02 +02:00
|
|
|
$(TEST_ALL): $(TEST_OBJS)
|
2018-12-16 11:57:58 +01:00
|
|
|
$(CXX) $(LDFLAGS) $(TEST_LDFLAGS) -o $@ $(TEST_OBJS) $(LIBS_TESTS)
|
2017-11-01 21:44:54 +01:00
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# .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 $@ $<
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
$(TEST_OBJS): $(OUTDIR)/%.o: %.cc | cppunit
|
2017-11-01 21:44:54 +01:00
|
|
|
@if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi
|
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MF $@.d -MT $@ $<
|
|
|
|
|
2018-12-16 11:57:58 +01:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- #
|
|
|
|
# - 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
|