diff --git a/.circleci/run.sh b/.circleci/run.sh index 4798b8b386..bb4d4ac52b 100755 --- a/.circleci/run.sh +++ b/.circleci/run.sh @@ -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 diff --git a/posix.mak b/Makefile similarity index 64% rename from posix.mak rename to Makefile index 419066069b..3c530452c8 100644 --- a/posix.mak +++ b/Makefile @@ -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) diff --git a/compiler/src/osmodel.mak b/compiler/src/osmodel.mak index 353ec80f2f..3c507e43ac 100644 --- a/compiler/src/osmodel.mak +++ b/compiler/src/osmodel.mak @@ -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 diff --git a/druntime/posix.mak b/druntime/posix.mak index 3a5d1b9295..28023dadc8 100644 --- a/druntime/posix.mak +++ b/druntime/posix.mak @@ -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 ############################ diff --git a/src/posix.mak b/src/posix.mak index ce52f955e3..eab8d0227d 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -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 .. $@