Convert posix.mak to generic Makefile

Usable on Windows too, with a GNU make.
This commit is contained in:
Martin Kinkelin 2023-12-03 17:47:42 +01:00
parent 2dea31b3bb
commit ff698ba103
5 changed files with 121 additions and 82 deletions

View file

@ -157,7 +157,7 @@ check_clean_git()
rm -f compiler/test/compilable/vcg-ast.d.cg rm -f compiler/test/compilable/vcg-ast.d.cg
rm -f compiler/test/compilable/vcg-ast-arraylength.d.cg rm -f compiler/test/compilable/vcg-ast-arraylength.d.cg
# Ensure that there are no untracked changes # Ensure that there are no untracked changes
make -f posix.mak check-clean-git make check-clean-git
} }
# sanitycheck for the run_individual_tests script # sanitycheck for the run_individual_tests script

View file

@ -1,20 +1,33 @@
INSTALL_DIR=$(PWD)/../install include compiler/src/osmodel.mak
INSTALL_DIR=$(shell pwd)/../install
ECTAGS_LANGS = Make,C,C++,D,Sh ECTAGS_LANGS = Make,C,C++,D,Sh
ECTAGS_FILES = compiler/dmd/*.[chd] compiler/dmd/backend/*.[chd] compiler/dmd/root/*.[chd] ECTAGS_FILES = compiler/dmd/*.[chd] compiler/dmd/backend/*.[chd] compiler/dmd/root/*.[chd]
GENERATED = generated EXE=$(if $(findstring windows,$(OS)),.exe,)
HOST_DMD?=dmd
HOST_DMD?=$(DMD)
ifeq (,$(HOST_DMD))
HOST_DMD=dmd$(EXE)
endif
export HOST_DMD
GENERATED=generated
BUILD_EXE=$(GENERATED)/build$(EXE)
RUN_EXE=$(GENERATED)/run$(EXE)
.PHONY: all clean test install auto-tester-build auto-tester-test toolchain-info .PHONY: all clean test install auto-tester-build auto-tester-test toolchain-info
all: $(GENERATED)/build all: $(BUILD_EXE)
$(GENERATED)/build dmd $(BUILD_EXE) dmd
ifneq (windows,$(OS))
$(QUIET)$(MAKE) -C druntime -f posix.mak target $(QUIET)$(MAKE) -C druntime -f posix.mak target
endif
$(GENERATED)/build: compiler/src/build.d $(BUILD_EXE): compiler/src/build.d
$(HOST_DMD) -of$@ -g $< $(HOST_DMD) -of$@ -g $<
$(GENERATED)/run: compiler/test/run.d $(RUN_EXE): compiler/test/run.d
$(HOST_DMD) -of$@ -g -i -Icompiler/test -release $< $(HOST_DMD) -of$@ -g -i -Icompiler/test -release $<
auto-tester-build: auto-tester-build:
@ -25,35 +38,39 @@ auto-tester-test:
buildkite-test: test buildkite-test: test
toolchain-info: $(GENERATED)/build toolchain-info: $(BUILD_EXE)
$(GENERATED)/build $@ $(BUILD_EXE) $@
clean: clean:
rm -Rf $(GENERATED) rm -rf $(GENERATED)
cd compiler/test && rm -rf test_results *.lst trace.log trace.def cd compiler/test && rm -rf test_results *.lst trace.log trace.def
$(RM) tags $(RM) tags
ifneq (windows,$(OS))
$(QUIET)$(MAKE) -C druntime -f posix.mak clean $(QUIET)$(MAKE) -C druntime -f posix.mak clean
endif
test: all $(GENERATED)/build $(GENERATED)/run test: all $(BUILD_EXE) $(RUN_EXE)
$(GENERATED)/build unittest $(BUILD_EXE) unittest
$(GENERATED)/run --environment HOST_DMD=$(HOST_DMD) $(RUN_EXE) --environment
ifneq (windows,$(OS))
$(QUIET)$(MAKE) -C druntime -f posix.mak unittest $(QUIET)$(MAKE) -C druntime -f posix.mak unittest
endif
html: $(GENERATED)/build html: $(BUILD_EXE)
$(GENERATED)/build $@ $(BUILD_EXE) $@
# Creates Exuberant Ctags tags file # Creates Exuberant Ctags tags file
tags: posix.mak $(ECTAGS_FILES) tags: Makefile $(ECTAGS_FILES)
ctags --sort=yes --links=no --excmd=number --languages=$(ECTAGS_LANGS) \ ctags --sort=yes --links=no --excmd=number --languages=$(ECTAGS_LANGS) \
--langmap='C++:+.c,C++:+.h' --extra=+f --file-scope=yes --fields=afikmsSt --totals=yes posix.mak $(ECTAGS_FILES) --langmap='C++:+.c,C++:+.h' --extra=+f --file-scope=yes --fields=afikmsSt --totals=yes Makefile $(ECTAGS_FILES)
ifneq (,$(findstring Darwin_64_32, $(PWD))) ifneq (,$(findstring Darwin_64_32, $(PWD)))
install: install:
echo "Darwin_64_32_disabled" echo "Darwin_64_32_disabled"
else else
install: all $(GENERATED)/build install: all $(BUILD_EXE)
$(GENERATED)/build man $(BUILD_EXE) man
$(GENERATED)/build install INSTALL_DIR=$(INSTALL_DIR) $(BUILD_EXE) install INSTALL_DIR=$(if $(findstring $(OS),windows),$(shell cygpath -w "$(INSTALL_DIR)"),$(INSTALL_DIR))
cp -r compiler/samples $(INSTALL_DIR) cp -r compiler/samples $(INSTALL_DIR)
mkdir -p $(INSTALL_DIR)/man mkdir -p $(INSTALL_DIR)/man
cp -r generated/docs/man/* $(INSTALL_DIR)/man/ cp -r generated/docs/man/* $(INSTALL_DIR)/man/
@ -69,8 +86,8 @@ check-clean-git:
exit 1; \ exit 1; \
fi fi
style: $(GENERATED)/build style: $(BUILD_EXE)
$(GENERATED)/build $@ $(BUILD_EXE) $@
.DELETE_ON_ERROR: # GNU Make directive (delete output files on error) .DELETE_ON_ERROR: # GNU Make directive (delete output files on error)

View file

@ -2,17 +2,19 @@
# #
# Detects and sets the macros: # Detects and sets the macros:
# #
# OS = one of {osx,linux,freebsd,openbsd,netbsd,dragonflybsd,solaris} # OS = one of {windows,osx,linux,freebsd,openbsd,netbsd,dragonflybsd,solaris}
# MODEL = one of { 32, 64 } # MODEL = one of { 32, 64 }
# MODEL_FLAG = one of { -m32, -m64 } # MODEL_FLAG = one of { -m32, -m64 }
# ARCH = one of { x86, x86_64, aarch64 } # ARCH = one of { x86, x86_64, aarch64 }
# #
# Note: # On Windows, also sets up a bash shell.
# Keep this file in sync between druntime, phobos, and dmd repositories!
# Source: https://github.com/dlang/dmd/blob/master/src/osmodel.mak
ifeq (,$(OS)) ifeq (,$(OS))
ifneq (,$(LOCALAPPDATA))
# assume Windows
OS:=windows
else
uname_S:=$(shell uname -s) uname_S:=$(shell uname -s)
ifeq (Darwin,$(uname_S)) ifeq (Darwin,$(uname_S))
OS:=osx OS:=osx
@ -41,6 +43,7 @@ ifeq (,$(OS))
ifeq (,$(OS)) ifeq (,$(OS))
$(error Unrecognized or unsupported OS for uname: $(uname_S)) $(error Unrecognized or unsupported OS for uname: $(uname_S))
endif endif
endif
endif endif
# When running make from XCode it may set environment var OS=MACOS. # When running make from XCode it may set environment var OS=MACOS.
@ -49,7 +52,25 @@ ifeq (MACOS,$(OS))
OS:=osx OS:=osx
endif endif
# Windows predefines OS to e.g. `Windows_NT`
ifneq (,$(findstring Win,$(OS)))
OS:=windows
endif
# set up bash shell on Windows
ifeq (windows,$(OS))
# Note: setting SHELL to an absolute path to bash.exe does NOT suffice.
# The GNU tools like {rm,cp,mkdir}.exe need to be in PATH.
export PATH:=C:\Program Files\Git\usr\bin;$(PATH)
SHELL=bash.exe
$(info Using make SHELL "$(SHELL)", should be bash.)
endif
ifeq (,$(MODEL)) ifeq (,$(MODEL))
ifeq (windows,$(OS))
MODEL:=64
ARCH:=x86_64
else
ifeq ($(OS), solaris) ifeq ($(OS), solaris)
uname_M:=$(shell isainfo -n) uname_M:=$(shell isainfo -n)
else else
@ -70,6 +91,7 @@ ifeq (,$(MODEL))
ifeq (,$(MODEL)) ifeq (,$(MODEL))
$(error Cannot figure 32/64 model and arch from uname -m: $(uname_M)) $(error Cannot figure 32/64 model and arch from uname -m: $(uname_M))
endif endif
endif
endif endif
MODEL_FLAG:=-m$(MODEL) MODEL_FLAG:=-m$(MODEL)

View file

@ -351,7 +351,7 @@ $(IMPDIR)/%.h : src/%.h
######################## Build DMD if non-existent ############################## ######################## Build DMD if non-existent ##############################
$(DMD): $(DMD):
$(MAKE) -C .. -f posix.mak generated/build $(MAKE) -C .. generated/build DMD=""
../generated/build dmd BUILD=$(BUILD) OS=$(OS) MODEL=$(MODEL) ../generated/build dmd BUILD=$(BUILD) OS=$(OS) MODEL=$(MODEL)
################### C/ASM Targets ############################ ################### C/ASM Targets ############################

View file

@ -2,31 +2,31 @@
all: all:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
buildkite-test: buildkite-test:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
toolchain-info: toolchain-info:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
clean: clean:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
test: test:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
html: html:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
tags: tags:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
install: install:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
check-clean-git: check-clean-git:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@
style: style:
$(QUIET)$(MAKE) -C .. -f posix.mak $@ $(QUIET)$(MAKE) -C .. $@