Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download
# Makefile for sjasmplus created by Tygrys' hands.# install/uninstall features added, CFLAGS and LDFLAGS modification by z00m's hands. [05.05.2016]# overall optimization and beautification by mborik's hands. [05.05.2016]# overall rewrite by Ped7g [2019-03-21]# added code coverage targets and variables by Ped7g [2019-07-22]## Some examples of my usage of this Makefile:# make tests - to run the CI test+example script runner# make memcheck TEST=misc DEBUG=1 - to use valgrind on assembling sub-directory "misc" in tests# make PREFIX=~/.local install - to install release version into ~/.local/bin/# make clean && make CC=gcc-8 CXX=g++-8 - to compile binary with gcc-8# make DEBUG=1 LUA_COVERAGE=1 coverage - to produce build/debug/coverage/* files by running the tests# make COVERALLS_SERVICE=1 DEBUG=1 coverage - to produce coverage data and upload them to https://coveralls.io/# make CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CFLAGS='-DNDEBUG -O2 -Wall -static -DUSE_LUA -DMAX_PATH=PATH_MAX -I$(SUBDIR_LUA) -I$(SUBDIR_LUABRIDGE) -I$(SUBDIR_CRC32C)' LDFLAGS='' - to cross compile win exe on my linux box with the linux Makefile# make CFLAGS_EXTRA='-m32' LDFLAGS='-ldl -m32' - to builds 32b linux executable# make KEEP_SYMBOLS=1 CC=clang-12 CXX=clang++-12 CFLAGS_EXTRA='-fsanitize=address' LDFLAGS='-ldl -fsanitize=address' - ASAN build# make KEEP_SYMBOLS=1 CC=clang-12 CXX=clang++-12 CFLAGS_EXTRA='-fsanitize=undefined' LDFLAGS='-ldl -fsanitize=undefined' - UBSAN build# Use LUA (system-wide or bundled, depending on USE_BUNDLED_LUA)USE_LUA?=1# Use bundled LUAUSE_BUNDLED_LUA?=1# Where to stage files when building a packageSTAGEDIR?=# Where to install resulting filesPREFIX?=/usr/local# define DEBUG=1 for debug buildDEBUG?=ifdef DEBUGKEEP_SYMBOLS?=$(DEBUG)endif# set up CC+CXX explicitly, because windows MinGW/MSYS environment don't have it set upCC?=ccCXX?=c++BASH?=/usr/bin/env bashSTRIP?=stripINSTALL?=install -cUNINSTALL?=rm -vfREMOVEDIR?=rm -vdfDOCBOOKGEN?=xsltprocMEMCHECK?=valgrind --leak-check=yes# --leak-check=full --show-leak-kinds=all# all internal file names (sources, module subdirs, build dirs, ...) must be WITHOUT space!# (i.e. every relative path from project-dir must be space-less ...)# the project-dir itself can contain space, or any path leading up to itEXE_BASE_NAME=sjasmplusBUILD_DIR=buildSUBDIR_BASE=sjasmSUBDIR_LUA=lua5.4SUBDIR_LUABRIDGE=LuaBridge/SourceSUBDIR_CRC32C=crc32cSUBDIR_DOCS=docsSUBDIR_COV=coverageifeq ($(USE_BUNDLED_LUA), 1)_LUA_CPPFLAGS=-I$(SUBDIR_LUA)endif# TODO too many lua5.4 warnings: -pedantic removedCPPFLAGS+=-Wall -DMAX_PATH=PATH_MAX -I$(SUBDIR_CRC32C)ifeq ($(USE_LUA), 1)CPPFLAGS+=-DUSE_LUA -DLUA_USE_LINUX $(_LUA_CPPFLAGS) -I$(SUBDIR_LUABRIDGE)endifCFLAGS+=$(CFLAGS_EXTRA)ifeq ($(USE_LUA), 1)LDFLAGS+=-ldlendififdef DEBUGBUILD_DIR:=$(BUILD_DIR)/debugCFLAGS+=-g -O0elseBUILD_DIR:=$(BUILD_DIR)/releaseCFLAGS+=-DNDEBUG -O2endif# C++ flags (the CPPFLAGS are for preprocessor BTW, if you always wonder, like me...)CXXFLAGS?=-std=gnu++14 $(CFLAGS)# full path to executableBUILD_EXE=$(BUILD_DIR)/$(EXE_BASE_NAME)# UnitTest++ related values (slightly modified defaults)# Unit Test exe (checks for "--unittest" and runs unit tests then)EXE_UT_BASE_NAME=sjasm+utBUILD_DIR_UT=$(BUILD_DIR)+utSUBDIR_UT=unittest-cppSUBDIR_TESTS=cpp-src-testsBUILD_EXE_UT=$(BUILD_DIR_UT)/$(EXE_UT_BASE_NAME)EXE_FP="$(abspath $(BUILD_EXE))"EXE_UT_FP="$(abspath $(BUILD_EXE_UT))"# turns list of %.c/%.cpp files into $BUILD_DIR/%.o listdefine object_files$(addprefix $(BUILD_DIR)/, $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(1))))endefdefine object_files_ut$(addprefix $(BUILD_DIR_UT)/, $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(1))))endef# sjasmplus filesSRCS:=$(wildcard $(SUBDIR_BASE)/*.c) $(wildcard $(SUBDIR_BASE)/*.cpp)OBJS:=$(call object_files,$(SRCS))OBJS_UT:=$(call object_files_ut,$(SRCS))ifeq ($(USE_BUNDLED_LUA), 1)# liblua filesLUASRCS:=$(wildcard $(SUBDIR_LUA)/*.c)LUAOBJS:=$(call object_files,$(LUASRCS))LUAOBJS_UT:=$(call object_files_ut,$(LUASRCS))endif# crc32c filesCRC32CSRCS:=$(wildcard $(SUBDIR_CRC32C)/*.cpp)CRC32COBJS:=$(call object_files,$(CRC32CSRCS))CRC32COBJS_UT:=$(call object_files_ut,$(CRC32CSRCS))# UnitTest++ filesUTPPSRCS:=$(wildcard $(SUBDIR_UT)/UnitTest++/*.cpp) $(wildcard $(SUBDIR_UT)/UnitTest++/Posix/*.cpp)UTPPOBJS:=$(call object_files,$(UTPPSRCS))TESTSSRCS:=$(wildcard $(SUBDIR_TESTS)/*.cpp)TESTSOBJS:=$(call object_files_ut,$(TESTSSRCS))ALL_OBJS:=$(OBJS) $(CRC32COBJS)ifeq ($(USE_LUA), 1)ifeq ($(USE_BUNDLED_LUA), 1)ALL_OBJS+=$(LUAOBJS)endifendifALL_OBJS_UT=$(OBJS_UT) $(CRC32COBJS_UT) $(UTPPOBJS) $(TESTSOBJS)ifeq ($(USE_LUA), 1)ifeq ($(USE_BUNDLED_LUA), 1)ALL_OBJS_UT+=$(LUAOBJS_UT)endifendifALL_COVERAGE_RAW:=$(patsubst %.o,%.gcno,$(ALL_OBJS_UT)) $(patsubst %.o,%.gcda,$(ALL_OBJS_UT))# GCOV options to generate coverage filesifdef COVERALLS_SERVICEGCOV_OPT=-rlpelseGCOV_OPT=-rlpmabendif#implicit rules to compile C/CPP files into $(BUILD_DIR)$(BUILD_DIR)/%.o : %.c@mkdir -p $(@D)$(COMPILE.c) $(OUTPUT_OPTION) $<$(BUILD_DIR)/%.o : %.cpp@mkdir -p $(@D)$(COMPILE.cc) $(OUTPUT_OPTION) $<#implicit rules to compile C/CPP files into $(BUILD_DIR_UT) (with unit tests enabled)$(BUILD_DIR_UT)/%.o : %.c@mkdir -p $(@D)$(COMPILE.c) -DADD_UNIT_TESTS -I$(SUBDIR_UT) $(OUTPUT_OPTION) $<$(BUILD_DIR_UT)/%.o : %.cpp@mkdir -p $(@D)$(COMPILE.cc) -DADD_UNIT_TESTS -I$(SUBDIR_UT) $(OUTPUT_OPTION) $<.PHONY: all install uninstall clean docs tests memcheck coverage upx# "all" will also copy the produced binary into project root directory (to mimick old makefile)all: $(BUILD_EXE)$(INSTALL) $(BUILD_EXE) $(EXE_BASE_NAME)upx: $(BUILD_EXE)cp $(BUILD_EXE) $(EXE_BASE_NAME)upx --best $(EXE_BASE_NAME)EXE="$(CURDIR)/$(EXE_BASE_NAME)" $(BASH) ContinuousIntegration/test_folder_tests.sh# make all sjasm/*.o depend on all sjasm/*.h files (no subtle dependencies, all by all affected)$(OBJS): $(wildcard $(SUBDIR_BASE)/*.h)$(BUILD_EXE): $(ALL_OBJS)$(CXX) -o $(BUILD_EXE) $(CXXFLAGS) $(ALL_OBJS) $(LDFLAGS)ifndef KEEP_SYMBOLS$(STRIP) $(BUILD_EXE)endif$(BUILD_EXE_UT): $(ALL_OBJS_UT)$(CXX) -o $(BUILD_EXE_UT) $(CXXFLAGS) $(ALL_OBJS_UT) $(LDFLAGS)ifndef KEEP_SYMBOLS$(STRIP) $(BUILD_EXE_UT)endifinstall: $(BUILD_EXE)$(INSTALL) -d "$(STAGEDIR)/$(PREFIX)/bin"$(INSTALL) $(BUILD_EXE) "$(STAGEDIR)/$(PREFIX)/bin"uninstall:$(UNINSTALL) "$(STAGEDIR)/$(PREFIX)/bin/$(EXE_BASE_NAME)"tests: $(BUILD_EXE_UT)ifdef TESTEXE=$(EXE_UT_FP) $(BASH) ContinuousIntegration/test_folder_tests.sh "$(TEST)"else$(BUILD_EXE_UT) --unittestEXE=$(EXE_UT_FP) $(BASH) ContinuousIntegration/test_folder_tests.shEXE=$(EXE_UT_FP) $(BASH) ContinuousIntegration/test_folder_examples.shendifmemcheck: $(BUILD_EXE)ifdef TESTMEMCHECK="$(MEMCHECK)" EXE=$(EXE_FP) $(BASH) ContinuousIntegration/test_folder_tests.sh "$(TEST)"elseMEMCHECK="$(MEMCHECK)" EXE=$(EXE_FP) $(BASH) ContinuousIntegration/test_folder_tests.shMEMCHECK="$(MEMCHECK)" EXE=$(EXE_FP) $(BASH) ContinuousIntegration/test_folder_examples.shendifcoverage:$(MAKE) CFLAGS_EXTRA=--coverage testsgcov $(GCOV_OPT) --object-directory $(BUILD_DIR_UT)/$(SUBDIR_BASE) $(SRCS)gcov $(GCOV_OPT) --object-directory $(BUILD_DIR_UT)/$(SUBDIR_CRC32C) $(CRC32CSRCS)ifdef LUA_COVERAGE# by default the "external" lua sources are excluded from coverage report, sjasmplus is not focusing to cover+fix lua itself# to get full coverage report, including the lua sources, use `make DEBUG=1 LUA_COVERAGE=1 coverage`gcov $(GCOV_OPT) --object-directory $(BUILD_DIR_UT)/$(SUBDIR_LUA) $(LUASRCS)endififndef COVERALLS_SERVICE# coversall.io is serviced by 3rd party plugin: https://github.com/eddyxu/cpp-coveralls# (from *.gcov files stored in project root directory, so not moving them here)# local coverage is just moved from project_root to build_dir/coverage/@mkdir -p $(BUILD_DIR_UT)/$(SUBDIR_COV)mv *#*.gcov $(BUILD_DIR_UT)/$(SUBDIR_COV)/endifdocs: $(SUBDIR_DOCS)/documentation.html ;$(SUBDIR_DOCS)/documentation.html: Makefile $(wildcard $(SUBDIR_DOCS)/*.xml) $(wildcard $(SUBDIR_DOCS)/*.xsl)$(DOCBOOKGEN) \--stringparam html.stylesheet docbook.css \--stringparam generate.toc "book toc" \-o $(SUBDIR_DOCS)/documentation.html \$(SUBDIR_DOCS)/docbook-xsl-ns-html-customization-linux.xsl \$(SUBDIR_DOCS)/documentation.xmlclean:$(UNINSTALL) \$(EXE_BASE_NAME) \$(BUILD_EXE) \$(BUILD_EXE_UT) \$(ALL_OBJS) \$(ALL_COVERAGE_RAW) \$(ALL_OBJS_UT) \$(BUILD_DIR_UT)/$(SUBDIR_COV)/*.gcov$(REMOVEDIR) \$(BUILD_DIR)/$(SUBDIR_BASE) \$(BUILD_DIR)/$(SUBDIR_CRC32C) \$(BUILD_DIR)/$(SUBDIR_LUA) \$(BUILD_DIR)/$(SUBDIR_UT)/UnitTest++/Posix \$(BUILD_DIR)/$(SUBDIR_UT)/UnitTest++ \$(BUILD_DIR)/$(SUBDIR_UT) \$(BUILD_DIR) \$(BUILD_DIR_UT)/$(SUBDIR_BASE) \$(BUILD_DIR_UT)/$(SUBDIR_CRC32C) \$(BUILD_DIR_UT)/$(SUBDIR_LUA) \$(BUILD_DIR_UT)/$(SUBDIR_TESTS) \$(BUILD_DIR_UT)/$(SUBDIR_COV) \$(BUILD_DIR_UT)