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-arraylength.d.cg
# 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

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_FILES = compiler/dmd/*.[chd] compiler/dmd/backend/*.[chd] compiler/dmd/root/*.[chd]
GENERATED = generated
HOST_DMD?=dmd
EXE=$(if $(findstring windows,$(OS)),.exe,)
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
all: $(GENERATED)/build
$(GENERATED)/build dmd
all: $(BUILD_EXE)
$(BUILD_EXE) dmd
ifneq (windows,$(OS))
$(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 $<
$(GENERATED)/run: compiler/test/run.d
$(RUN_EXE): compiler/test/run.d
$(HOST_DMD) -of$@ -g -i -Icompiler/test -release $<
auto-tester-build:
@ -25,35 +38,39 @@ auto-tester-test:
buildkite-test: test
toolchain-info: $(GENERATED)/build
$(GENERATED)/build $@
toolchain-info: $(BUILD_EXE)
$(BUILD_EXE) $@
clean:
rm -Rf $(GENERATED)
rm -rf $(GENERATED)
cd compiler/test && rm -rf test_results *.lst trace.log trace.def
$(RM) tags
ifneq (windows,$(OS))
$(QUIET)$(MAKE) -C druntime -f posix.mak clean
endif
test: all $(GENERATED)/build $(GENERATED)/run
$(GENERATED)/build unittest
$(GENERATED)/run --environment HOST_DMD=$(HOST_DMD)
test: all $(BUILD_EXE) $(RUN_EXE)
$(BUILD_EXE) unittest
$(RUN_EXE) --environment
ifneq (windows,$(OS))
$(QUIET)$(MAKE) -C druntime -f posix.mak unittest
endif
html: $(GENERATED)/build
$(GENERATED)/build $@
html: $(BUILD_EXE)
$(BUILD_EXE) $@
# Creates Exuberant Ctags tags file
tags: posix.mak $(ECTAGS_FILES)
tags: Makefile $(ECTAGS_FILES)
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)))
install:
echo "Darwin_64_32_disabled"
else
install: all $(GENERATED)/build
$(GENERATED)/build man
$(GENERATED)/build install INSTALL_DIR=$(INSTALL_DIR)
install: all $(BUILD_EXE)
$(BUILD_EXE) man
$(BUILD_EXE) install INSTALL_DIR=$(if $(findstring $(OS),windows),$(shell cygpath -w "$(INSTALL_DIR)"),$(INSTALL_DIR))
cp -r compiler/samples $(INSTALL_DIR)
mkdir -p $(INSTALL_DIR)/man
cp -r generated/docs/man/* $(INSTALL_DIR)/man/
@ -69,8 +86,8 @@ check-clean-git:
exit 1; \
fi
style: $(GENERATED)/build
$(GENERATED)/build $@
style: $(BUILD_EXE)
$(BUILD_EXE) $@
.DELETE_ON_ERROR: # GNU Make directive (delete output files on error)

View file

@ -2,44 +2,47 @@
#
# 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_FLAG = one of { -m32, -m64 }
# ARCH = one of { x86, x86_64, aarch64 }
#
# Note:
# Keep this file in sync between druntime, phobos, and dmd repositories!
# Source: https://github.com/dlang/dmd/blob/master/src/osmodel.mak
# On Windows, also sets up a bash shell.
ifeq (,$(OS))
uname_S:=$(shell uname -s)
ifeq (Darwin,$(uname_S))
OS:=osx
endif
ifeq (Linux,$(uname_S))
OS:=linux
endif
ifeq (FreeBSD,$(uname_S))
OS:=freebsd
endif
ifeq (OpenBSD,$(uname_S))
OS:=openbsd
endif
ifeq (NetBSD,$(uname_S))
OS:=netbsd
endif
ifeq (DragonFly,$(uname_S))
OS:=dragonflybsd
endif
ifeq (Solaris,$(uname_S))
OS:=solaris
endif
ifeq (SunOS,$(uname_S))
OS:=solaris
endif
ifeq (,$(OS))
$(error Unrecognized or unsupported OS for uname: $(uname_S))
ifneq (,$(LOCALAPPDATA))
# assume Windows
OS:=windows
else
uname_S:=$(shell uname -s)
ifeq (Darwin,$(uname_S))
OS:=osx
endif
ifeq (Linux,$(uname_S))
OS:=linux
endif
ifeq (FreeBSD,$(uname_S))
OS:=freebsd
endif
ifeq (OpenBSD,$(uname_S))
OS:=openbsd
endif
ifeq (NetBSD,$(uname_S))
OS:=netbsd
endif
ifeq (DragonFly,$(uname_S))
OS:=dragonflybsd
endif
ifeq (Solaris,$(uname_S))
OS:=solaris
endif
ifeq (SunOS,$(uname_S))
OS:=solaris
endif
ifeq (,$(OS))
$(error Unrecognized or unsupported OS for uname: $(uname_S))
endif
endif
endif
@ -49,26 +52,45 @@ ifeq (MACOS,$(OS))
OS:=osx
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 ($(OS), solaris)
uname_M:=$(shell isainfo -n)
else
uname_M:=$(shell uname -m)
endif
ifneq (,$(findstring $(uname_M),x86_64 amd64))
ifeq (windows,$(OS))
MODEL:=64
ARCH:=x86_64
endif
ifneq (,$(findstring $(uname_M),aarch64 arm64))
MODEL:=64
ARCH:=aarch64
endif
ifneq (,$(findstring $(uname_M),i386 i586 i686))
MODEL:=32
ARCH:=x86
endif
ifeq (,$(MODEL))
$(error Cannot figure 32/64 model and arch from uname -m: $(uname_M))
else
ifeq ($(OS), solaris)
uname_M:=$(shell isainfo -n)
else
uname_M:=$(shell uname -m)
endif
ifneq (,$(findstring $(uname_M),x86_64 amd64))
MODEL:=64
ARCH:=x86_64
endif
ifneq (,$(findstring $(uname_M),aarch64 arm64))
MODEL:=64
ARCH:=aarch64
endif
ifneq (,$(findstring $(uname_M),i386 i586 i686))
MODEL:=32
ARCH:=x86
endif
ifeq (,$(MODEL))
$(error Cannot figure 32/64 model and arch from uname -m: $(uname_M))
endif
endif
endif

View file

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

View file

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