1Adapted from https://github.com/dlang/tools/commit/6c6a042d1b08e3ec1790bd07a7f69424625ee866.patch
2--- /dev/null
3+++ b/osmodel.mak
4@@ -0,0 +1,75 @@
5+# osmodel.mak
6+#
7+# Detects and sets the macros:
8+#
9+# OS = one of {osx,linux,freebsd,openbsd,netbsd,dragonflybsd,solaris}
10+# MODEL = one of { 32, 64 }
11+# MODEL_FLAG = one of { -m32, -m64 }
12+# ARCH = one of { x86, x86_64, aarch64 }
13+#
14+# Note:
15+# Keep this file in sync between druntime, phobos, and dmd repositories!
16+# Source: https://github.com/dlang/dmd/blob/master/src/osmodel.mak
17+
18+
19+ifeq (,$(OS))
20+ uname_S:=$(shell uname -s)
21+ ifeq (Darwin,$(uname_S))
22+ OS:=osx
23+ endif
24+ ifeq (Linux,$(uname_S))
25+ OS:=linux
26+ endif
27+ ifeq (FreeBSD,$(uname_S))
28+ OS:=freebsd
29+ endif
30+ ifeq (OpenBSD,$(uname_S))
31+ OS:=openbsd
32+ endif
33+ ifeq (NetBSD,$(uname_S))
34+ OS:=netbsd
35+ endif
36+ ifeq (DragonFly,$(uname_S))
37+ OS:=dragonflybsd
38+ endif
39+ ifeq (Solaris,$(uname_S))
40+ OS:=solaris
41+ endif
42+ ifeq (SunOS,$(uname_S))
43+ OS:=solaris
44+ endif
45+ ifeq (,$(OS))
46+ $(error Unrecognized or unsupported OS for uname: $(uname_S))
47+ endif
48+endif
49+
50+# When running make from XCode it may set environment var OS=MACOS.
51+# Adjust it here:
52+ifeq (MACOS,$(OS))
53+ OS:=osx
54+endif
55+
56+ifeq (,$(MODEL))
57+ ifeq ($(OS), solaris)
58+ uname_M:=$(shell isainfo -n)
59+ else
60+ uname_M:=$(shell uname -m)
61+ endif
62+ ifneq (,$(findstring $(uname_M),x86_64 amd64))
63+ MODEL:=64
64+ ARCH:=x86_64
65+ endif
66+ ifneq (,$(findstring $(uname_M),aarch64 arm64))
67+ MODEL:=64
68+ ARCH:=aarch64
69+ endif
70+ ifneq (,$(findstring $(uname_M),i386 i586 i686))
71+ MODEL:=32
72+ ARCH:=x86
73+ endif
74+ ifeq (,$(MODEL))
75+ $(error Cannot figure 32/64 model and arch from uname -m: $(uname_M))
76+ endif
77+endif
78+
79+MODEL_FLAG:=-m$(MODEL)
80--- a/Makefile
81+++ b/Makefile
82@@ -9,9 +9,8 @@ DUB=dub
83 WITH_DOC = no
84 DOC = ../dlang.org
85
86-# Load operating system $(OS) (e.g. linux, osx, ...) and $(MODEL) (e.g. 32, 64) detection Makefile from dmd
87-$(shell [ ! -d $(DMD_DIR) ] && git clone --depth=1 https://github.com/dlang/dmd $(DMD_DIR))
88-include $(DMD_DIR)/compiler/src/osmodel.mak
89+# Load operating system $(OS) (e.g. linux, osx, ...) and $(MODEL) (e.g. 32, 64) detection Makefile
90+include osmodel.mak
91
92 ifeq (windows,$(OS))
93 DOTEXE:=.exe
94@@ -30,7 +29,7 @@ DFLAGS = $(MODEL_FLAG) $(if $(findstring windows,$(OS)),,-fPIC) -preview=dip1000
95 DFLAGS += $(WARNINGS)
96
97 # Default DUB flags (DUB uses a different architecture format)
98-DUBFLAGS = --arch=$(subst 32,x86,$(subst 64,x86_64,$(MODEL)))
99+DUBFLAGS = --arch=$(ARCH)
100
101 TOOLS = \
102 $(ROOT)/catdoc$(DOTEXE) \