Skip to content

Commit

Permalink
WIP: Merge Makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Dec 13, 2023
1 parent b64bfbf commit bde7212
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1,124 deletions.
14 changes: 7 additions & 7 deletions .circleci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ setup_repos()
# run unittest with coverage
coverage()
{
make -f posix.mak clean
make clean
# remove all existing coverage files (just in case)
find . -name "*.lst" -type f -delete

# Coverage information of the test runner can be missing for some template instatiations.
# https://issues.dlang.org/show_bug.cgi?id=16397
# ENABLE_COVERAGE="1" make -j"$N" -f posix.mak MODEL=$MODEL unittest-debug
# ENABLE_COVERAGE="1" make -j"$N" MODEL=$MODEL unittest-debug

# So instead we run all tests individually (hoping that that doesn't break any tests).
# -cov is enabled by the %.test target itself
make -j"$N" -f posix.mak BUILD=$BUILD $(find std etc -name "*.d" | sed "s/[.]d$/.test/")
make -j"$N" BUILD=$BUILD $(find std etc -name "*.d" | sed "s/[.]d$/.test/")

# Remove coverage information from lines with non-deterministic coverage.
# These lines are annotated with a comment containing "nocoverage".
Expand All @@ -124,12 +124,12 @@ publictests()
{
source "$(CURL_USER_AGENT=\"$CURL_USER_AGENT\" bash ~/dlang/install.sh dmd-$HOST_DMD_VER --activate)"

make -f posix.mak -j"$N" publictests DUB="$DUB" BUILD=$BUILD
make -f posix.mak -j"$N" publictests DUB="$DUB" BUILD=$BUILD NO_BOUNDSCHECKS=1
make -j"$N" publictests DUB="$DUB" BUILD=$BUILD
make -j"$N" publictests DUB="$DUB" BUILD=$BUILD NO_BOUNDSCHECKS=1

# run -betterC tests
make -f posix.mak test_extractor # build in single-threaded mode
make -f posix.mak -j"$N" betterc
make test_extractor # build in single-threaded mode
make -j"$N" betterc
}

# test stdx dub package
Expand Down
64 changes: 37 additions & 27 deletions posix.mak → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ DMD_DIR=../dmd

include $(DMD_DIR)/compiler/src/osmodel.mak

ifeq (windows,$(OS))
DOTEXE:=.exe
DOTDLL:=.dll
DOTLIB:=.lib
DOTOBJ:=.obj
else
DOTEXE:=
DOTDLL:=$(if $(findstring $(OS),osx),.dylib,.so)
DOTLIB:=.a
DOTOBJ:=.o
endif

ifeq (osx,$(OS))
export MACOSX_DEPLOYMENT_TARGET=10.9
endif
Expand All @@ -57,7 +69,7 @@ endif
# default to PIC, use PIC=1/0 to en-/disable PIC.
# Note that shared libraries and C files are always compiled with PIC.
ifeq ($(PIC),)
PIC:=1
PIC:=$(if $(findstring win,$(OS)),,1)
endif
ifeq ($(PIC),1)
override PIC:=-fPIC
Expand Down Expand Up @@ -85,7 +97,7 @@ ifeq (,$(findstring win,$(OS)))
DRUNTIME = $(DRUNTIME_PATH)/../generated/$(OS)/$(BUILD)/$(MODEL)/libdruntime.a
DRUNTIMESO = $(basename $(DRUNTIME)).so.a
else
DRUNTIME = $(DRUNTIME_PATH)/../lib/druntime.lib
DRUNTIME = $(DRUNTIME_PATH)/../generated/$(OS)/$(BUILD)/$(MODEL)/druntime.lib
endif

# Set CC and DMD
Expand All @@ -94,9 +106,11 @@ ifeq ($(OS),win32wine)
DMD = wine dmd.exe
RUN = wine
else
DMD = $(DMD_DIR)/generated/$(OS)/$(BUILD)/$(MODEL)/dmd
ifeq ($(OS),win32)
DMD = $(DMD_DIR)/generated/$(OS)/$(BUILD)/$(MODEL)/dmd$(DOTEXE)
ifeq ($(MODEL),32omf)
CC = dmc
else ifeq ($(OS),windows)
CC = cl.exe
else
CC = cc
endif
Expand All @@ -118,7 +132,7 @@ ifeq (,$(findstring win,$(OS)))
CFLAGS += -O3
endif
else
ifeq ($(OS),win32)
ifeq ($(MODEL),32omf)
CFLAGS=-DNO_snprintf
ifeq ($(BUILD),debug)
CFLAGS += -g
Expand All @@ -127,11 +141,12 @@ else
endif
else # win64/win32coff
OUTFILEFLAG = /Fo
NODEFAULTLIB=-L/NOD:phobos$(MODEL).lib -L/OPT:NOICF
NODEFAULTLIB=-L/NOD:phobos$(if $(findstring 32,$(MODEL)),32mscoff,$(MODEL)).lib -L/OPT:NOICF
CFLAGS += /nologo /Zl
ifeq ($(BUILD),debug)
CFLAGS += /Z7
else
CFLAGS += /Ox
CFLAGS += /O2
endif
endif
endif
Expand Down Expand Up @@ -165,17 +180,6 @@ endif

UDFLAGS=-unittest -version=StdUnittest

# Set DOTOBJ and DOTEXE
ifeq (,$(findstring win,$(OS)))
DOTOBJ:=.o
DOTEXE:=
PATHSEP:=/
else
DOTOBJ:=.obj
DOTEXE:=.exe
PATHSEP:=$(shell echo "\\")
endif

LINKDL:=$(if $(findstring $(OS),linux),-L-ldl,)

# use timelimit to avoid deadlocks if available
Expand All @@ -197,7 +201,13 @@ ifeq (,$(findstring win,$(OS)))
SONAME:=libphobos2.so.$(MAJOR).$(MINOR)
LIBSO:=$(ROOT)/$(SONAME).$(PATCH)
else
LIB:=$(ROOT)/phobos.lib
ifeq ($(MODEL),32omf)
LIB:=phobos.lib
else ifeq ($(MODEL),32)
LIB:=phobos32mscoff.lib
else
LIB:=phobos$(MODEL).lib
endif
endif

################################################################################
Expand Down Expand Up @@ -299,7 +309,7 @@ MAKEFILE = $(firstword $(MAKEFILE_LIST))
# build with shared library support (defaults to true on supported platforms)
SHARED=$(if $(findstring $(OS),linux freebsd),1,)

TESTS_EXTRACTOR=$(ROOT)/tests_extractor
TESTS_EXTRACTOR=$(ROOT)/tests_extractor$(DOTEXE)
PUBLICTESTS_DIR=$(ROOT)/publictests
BETTERCTESTS_DIR=$(ROOT)/betterctests

Expand Down Expand Up @@ -396,7 +406,7 @@ ifneq (1,$(SHARED))

$(UT_D_OBJS): $(DRUNTIME)

$(ROOT)/unittest/test_runner: $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME)
$(ROOT)/unittest/test_runner$(DOTEXE): $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME)
$(DMD) $(DFLAGS) $(UDFLAGS) -of$@ $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME) $(LINKDL) $(NODEFAULTLIB)

else
Expand All @@ -409,7 +419,7 @@ $(UT_LIBSO): override PIC:=-fPIC
$(UT_LIBSO): $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO)
$(DMD) $(DFLAGS) -shared $(UDFLAGS) -of$@ $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO) $(LINKDL) $(NODEFAULTLIB)

$(ROOT)/unittest/test_runner: $(DRUNTIME_PATH)/src/test_runner.d $(UT_LIBSO)
$(ROOT)/unittest/test_runner$(DOTEXE): $(DRUNTIME_PATH)/src/test_runner.d $(UT_LIBSO)
$(DMD) $(DFLAGS) -of$@ $< -L$(UT_LIBSO) $(NODEFAULTLIB)

endif
Expand All @@ -418,7 +428,7 @@ endif
moduleName=$(subst /,.,$(1))

# target for batch unittests (using shared phobos library and test_runner)
unittest/%.run : $(ROOT)/unittest/test_runner
unittest/%.run : $(ROOT)/unittest/test_runner$(DOTEXE)
$(QUIET)$(TIMELIMIT)$(RUN) $< $(call moduleName,$*)

# Target for quickly running a single unittest (using static phobos library).
Expand Down Expand Up @@ -495,7 +505,7 @@ else
# to always invoke druntime's make. Use FORCE instead of .PHONY to
# avoid rebuilding phobos when $(DRUNTIME) didn't change.
$(DRUNTIME): FORCE
$(MAKE) -C $(DRUNTIME_PATH) -f posix.mak MODEL=$(MODEL) DMD=$(abspath $(DMD)) OS=$(OS) BUILD=$(BUILD)
$(MAKE) -C $(DRUNTIME_PATH) MODEL=$(MODEL) DMD=$(abspath $(DMD)) OS=$(OS) BUILD=$(BUILD)

ifeq (,$(findstring win,$(OS)))
$(DRUNTIMESO): $(DRUNTIME)
Expand Down Expand Up @@ -553,7 +563,7 @@ $(TOOLS_DIR)/checkwhitespace.d: | $(TOOLS_DIR)
$(TOOLS_DIR)/tests_extractor.d: | $(TOOLS_DIR)

#################### test for undesired white spaces ##########################
CWS_TOCHECK = posix.mak win32.mak win64.mak
CWS_TOCHECK = Makefile
CWS_TOCHECK += $(ALL_D_FILES) index.dd

checkwhitespace: $(LIB) $(TOOLS_DIR)/checkwhitespace.d
Expand Down Expand Up @@ -641,8 +651,8 @@ style_lint: style_lint_shellcmds dscanner
################################################################################

$(TESTS_EXTRACTOR): $(TOOLS_DIR)/tests_extractor.d | $(LIB)
DFLAGS="$(DFLAGS) $(LIB) $(NODEFAULTLIB) $(LINKDL)" $(DUB) build --force --compiler=$${PWD}/$(DMD) --single $<
mv $(TOOLS_DIR)/tests_extractor $@
DFLAGS="$(DFLAGS) $(LIB) $(NODEFAULTLIB) $(LINKDL)" $(DUB) build --force --compiler=$(abspath $(DMD)) --single $<
mv $(TOOLS_DIR)/tests_extractor$(DOTEXE) $@

test_extractor: $(TESTS_EXTRACTOR)

Expand Down
Loading

0 comments on commit bde7212

Please sign in to comment.