Merge pull request #855 from edi33416/make_inc_compilation

Modify makefile to use incremental compilation
This commit is contained in:
Razvan Nitu 2022-02-21 10:08:28 +02:00 committed by GitHub
commit 1597733f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 104 additions and 35 deletions

139
makefile
View File

@ -1,11 +1,11 @@
.PHONY: all test
.PHONY: all test clean
DC ?= dmd
GIT ?= git
DMD := $(DC)
GDC := gdc
LDC := ldc2
OBJ_DIR := obj
LIB_SRC := \
$(shell find containers/src -name "*.d")\
$(shell find dsymbol/src -name "*.d")\
@ -17,6 +17,25 @@ LIB_SRC := \
$(shell find stdx-allocator/source -name "*.d")
PROJECT_SRC := $(shell find src/ -name "*.d")
SRC := $(LIB_SRC) $(PROJECT_SRC)
OBJ_DIR := obj
UT_OBJ_DIR = $(OBJ_DIR)/unittest
OBJ = $(SRC:.d=.o)
PROJECT_OBJ = $(PROJECT_SRC:.d=.o)
LIB_OBJ = $(LIB_SRC:.d=.o)
OBJ_BY_DC = $(addprefix $(OBJ_DIR)/$(DC)/, $(OBJ))
# `sort` also removes duplicates, which is what we want
OBJ_BY_DC_DIR = $(sort $(dir $(OBJ_BY_DC)))
UT_OBJ_BY_DC = $(addprefix $(UT_OBJ_DIR)/$(DC)/, $(PROJECT_OBJ))
UT_OBJ_BY_DC_DIR = $(sort $(dir $(UT_OBJ_BY_DC)))
DSCANNER_BIN = bin/dscanner
DSCANNER_BIN_DIR = $(dir $(DSCANNER_BIN))
UT_DSCANNER_BIN = bin/dscanner-unittest
UT_DSCANNER_LIB = bin/$(DC)/dscanner-unittest-lib.a
UT_DSCANNER_LIB_DIR = $(dir $(UT_DSCANNER_LIB))
INCLUDE_PATHS = \
-Isrc \
-Iinifiled/source \
@ -26,48 +45,98 @@ INCLUDE_PATHS = \
-Ilibddoc/src \
-Ilibddoc/common/source \
-Istdx-allocator/source
VERSIONS =
DEBUG_VERSIONS = -version=dparse_verbose
DMD_FLAGS = -w -release -O -Jbin -od${OBJ_DIR} -version=StdLoggerDisableWarning
override DMD_FLAGS += $(DFLAGS)
override LDC_FLAGS += $(DFLAGS)
override GDC_FLAGS += $(DFLAGS)
DMD_TEST_FLAGS = -w -g -Jbin -version=StdLoggerDisableWarning
override LDC_FLAGS += -O5 -release -oq -d-version=StdLoggerDisableWarning
override GDC_FLAGS += -O3 -frelease -d-version=StdLoggerDisableWarning
DMD_VERSIONS = -version=StdLoggerDisableWarning
DMD_DEBUG_VERSIONS = -version=dparse_verbose
LDC_VERSIONS = -d-version=StdLoggerDisableWarning
LDC_DEBUG_VERSIONS = -d-version=dparse_verbose
GDC_VERSIONS = -fversion=StdLoggerDisableWarning
GDC_DEBUG_VERSIONS = -fversion=dparse_verbose
DC_FLAGS += -Jbin
override DMD_FLAGS += $(DFLAGS) -w -release -O -od${OBJ_DIR}
override LDC_FLAGS += $(DFLAGS) -O5 -release -oq
override GDC_FLAGS += $(DFLAGS) -O3 -frelease
DC_TEST_FLAGS += -g -Jbin
override DMD_TEST_FLAGS += -w
DC_DEBUG_FLAGS := -g -Jbin
ifeq ($(DC), $(filter $(DC), dmd ldmd2 gdmd))
VERSIONS := $(DMD_VERSIONS)
DEBUG_VERSIONS := $(DMD_DEBUG_VERSIONS)
DC_FLAGS += $(DMD_FLAGS)
DC_TEST_FLAGS += $(DMD_TEST_FLAGS) -unittest
WRITE_TO_TARGET_NAME = -of$@
else ifneq (,$(findstring ldc2, $(DC)))
VERSIONS := $(LDC_VERSIONS)
DEBUG_VERSIONS := $(LDC_DEBUG_VERSIONS)
DC_FLAGS += $(LDC_FLAGS)
DC_TEST_FLAGS += $(LDC_TEST_FLAGS) -unittest
WRITE_TO_TARGET_NAME = -of=$@
else ifneq (,$(findstring gdc, $(DC)))
VERSIONS := $(GDC_VERSIONS)
DEBUG_VERSIONS := $(GDC_DEBUG_VERSIONS)
DC_FLAGS += $(GDC_FLAGS)
DC_TEST_FLAGS += $(GDC_TEST_FLAGS) -funittest
WRITE_TO_TARGET_NAME = -o $@
endif
SHELL:=/usr/bin/env bash
all: dmdbuild
ldc: ldcbuild
gdc: gdcbuild
GITHASH = bin/githash.txt
githash:
mkdir -p bin && ${GIT} describe --tags > bin/githash.txt
debug: githash
$(OBJ_DIR)/$(DC)/%.o: %.d
${DC} ${DC_FLAGS} ${VERSIONS} ${INCLUDE_PATHS} -c $< ${WRITE_TO_TARGET_NAME}
$(UT_OBJ_DIR)/$(DC)/%.o: %.d
${DC} ${DC_TEST_FLAGS} ${VERSIONS} ${INCLUDE_PATHS} -c $< ${WRITE_TO_TARGET_NAME}
${DSCANNER_BIN}: ${GITHASH} ${OBJ_BY_DC} | ${DSCANNER_BIN_DIR}
${DC} ${OBJ_BY_DC} ${WRITE_TO_TARGET_NAME}
${OBJ_BY_DC}: | ${OBJ_BY_DC_DIR}
${OBJ_BY_DC_DIR}:
mkdir -p $@
${UT_OBJ_BY_DC}: | ${UT_OBJ_BY_DC_DIR}
${UT_OBJ_BY_DC_DIR}:
mkdir -p $@
${DSCANNER_BIN_DIR}:
mkdir -p $@
${UT_DSCANNER_LIB_DIR}:
mkdir -p $@
all: ${DSCANNER_BIN}
ldc: ${DSCANNER_BIN}
gdc: ${DSCANNER_BIN}
githash: ${GITHASH}
${GITHASH}:
mkdir -p bin && ${GIT} describe --tags --always > ${GITHASH}
debug: ${GITHASH}
${DC} -w -g -Jbin -ofdsc ${VERSIONS} ${DEBUG_VERSIONS} ${INCLUDE_PATHS} ${SRC}
dmdbuild: githash
${DC} ${DMD_FLAGS} -ofbin/dscanner ${VERSIONS} ${INCLUDE_PATHS} ${SRC}
rm -f bin/dscanner.o
gdcbuild: githash
${GDC} ${GDC_FLAGS} -obin/dscanner ${VERSIONS} ${INCLUDE_PATHS} ${SRC} -Jbin
ldcbuild: githash
${LDC} ${LDC_FLAGS} -of=bin/dscanner ${VERSIONS} ${INCLUDE_PATHS} ${SRC} -Jbin
# compile the dependencies separately, s.t. their unittests don't get executed
bin/dscanner-unittest-lib.a: ${LIB_SRC}
${DC} ${DMD_TEST_FLAGS} -c ${INCLUDE_PATHS} ${LIB_SRC} -of$@
${UT_DSCANNER_LIB}: ${LIB_SRC} | ${UT_DSCANNER_LIB_DIR}
${DC} ${DC_DEBUG_FLAGS} -c ${VERSIONS} ${INCLUDE_PATHS} ${LIB_SRC} ${WRITE_TO_TARGET_NAME}
test: bin/dscanner-unittest-lib.a githash
${DC} ${DMD_TEST_FLAGS} -unittest ${INCLUDE_PATHS} bin/dscanner-unittest-lib.a ${PROJECT_SRC} -ofbin/dscanner-unittest
./bin/dscanner-unittest
rm -f bin/dscanner-unittest
test: ${UT_DSCANNER_BIN}
lint: dmdbuild
./bin/dscanner --config .dscanner.ini --styleCheck src
${UT_DSCANNER_BIN}: ${UT_DSCANNER_LIB} ${GITHASH} ${UT_OBJ_BY_DC} | ${DSCANNER_BIN_DIR}
${DC} ${UT_DSCANNER_LIB} ${UT_OBJ_BY_DC} ${WRITE_TO_TARGET_NAME}
./${UT_DSCANNER_BIN}
lint: ${DSCANNER_BIN}
./${DSCANNER_BIN} --config .dscanner.ini --styleCheck src
clean:
rm -rf dsc