-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathos.mk
247 lines (209 loc) · 5 KB
/
os.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
ifndef _MK_OS_MK_
_MK_OS_MK_ := 1
#$(info ---> .make/os.mk)
#
#$(info UNAME_M=$(UNAME_M) UNAME_S=$(UNAME_S) UNAME_O=$(UNAME_O) OS=$(OS) a)
CURRENT_INTERACTIVE_SHELL := $(SHELL)
ifeq (/usr/bin/bash,$(wildcard /usr/bin/bash))
SHELL := /usr/bin/bash
else
ifeq (/bin/bash,$(wildcard /bin/bash))
SHELL := /bin/bash
else
$(error Cannot continue without bash)
endif
endif
#ifeq (/usr/bin/zsh,$(wildcard /usr/bin/zsh))
#SHELL := /usr/bin/zsh
#else
#ifeq (/bin/zsh,$(wildcard /bin/zsh))
#SHELL := /bin/zsh
#endif
#endif
export SHELL := $(SHELL)
#$(info SHELL=$(SHELL))
ifndef GIT_ROOT
GIT_ROOT := $(shell git rev-parse --show-toplevel 2>/dev/null)
endif
ifndef MK_DIR
MK_DIR := $(GIT_ROOT)/.make
endif
ifeq ($(shell uname -r | cut -d- -f4),WSL2)
WSL := 1
endif
ifdef WSL
#$(info We are running under WSL2)
OS := GNU/Linux
endif
ifndef UNAME_M
ifeq ($(OS),Windows_NT)
UNAME_M := x86_64
else
UNAME_M := $(shell uname -m)
endif
endif
#$(info UNAME_M=$(UNAME_M) UNAME_S=$(UNAME_S) UNAME_O=$(UNAME_O) OS=$(OS) b)
ifndef UNAME_S
ifeq ($(OS),Windows_NT)
UNAME_S := Windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
else
endif
endif
endif
ifndef UNAME_O
ifeq ($(OS),Windows_NT)
UNAME_O := Windows
else
ifeq ($(UNAME_S),Darwin)
UNAME_O := Darwin
OS := Darwin
else
UNAME_O := $(shell uname -o)
OS := $(UNAME_O)
endif
endif
endif
ifeq ($(UNAME_O),Windows)
UNAME_S_lc := windows
BIN_SUFFIX := .exe
WHICH := where
TMP_DIR ?= $(TMP)
BSDTAR := bsdtar
else
BIN_SUFFIX :=
WHICH := command -v
ifeq ($(UNAME_O),Darwin)
UNAME_S_lc := darwin
TMP_DIR ?: $(shell cd $(TMPDIR) && pwd)
BSDTAR := bsdtar
else
UNAME_S_lc := linux
TMP_DIR ?= /var/tmp
BSDTAR := bsdtar
endif
endif
#$(info UNAME_M=$(UNAME_M) UNAME_S_lc=$(UNAME_S_lc) UNAME_S=$(UNAME_S) UNAME_O=$(UNAME_O) OS=[$(OS)])
ifeq ($(UNAME_M),arm64)
UNAME_M_rust := aarch64
else
UNAME_M_rust := $(UNAME_M)
endif
ifeq ($(AWS_EXECUTION_ENV),CloudShell)
RUNNING_IN_CLOUDSHELL := 1
$(info We are running in AWS CloudShell)
else
RUNNING_IN_CLOUDSHELL := 0
#$(info We are not running in AWS CloudShell)
endif
IS_LINUX_WITH_APT := 0
IS_LINUX_WITH_YUM := 0
ifeq ($(UNAME_S_lc),linux)
ifeq ($(RUNNING_IN_CLOUDSHELL),1)
IS_LINUX_WITH_APT := 0
IS_LINUX_WITH_YUM := 1
else
ifeq ($(shell source /etc/os-release 2>/dev/null; echo $$ID),ubuntu)
IS_LINUX_WITH_APT := 1
IS_LINUX_WITH_YUM := 0
else
ifndef WSL
$(info Unrecognized linux distribution, assuming apt over yum)
endif
IS_LINUX_WITH_APT := 1
IS_LINUX_WITH_YUM := 0
endif
endif
endif
USE_USERPROFILE_AS_HOME := 0
ifdef USERPROFILE
ifeq ($(UNAME_O),Cygwin)
USE_USERPROFILE_AS_HOME := 1
endif
endif
ifeq ($(IS_LINUX_WITH_APT),1)
export DEBIAN_FRONTEND := noninteractive
endif
ifneq ($(wildcard /home/linuxbrew/.linuxbrew/sbin),)
export PATH := /home/linuxbrew/.linuxbrew/sbin:$(PATH)
endif
ifneq ($(wildcard /home/linuxbrew/.linuxbrew/bin),)
export PATH := /home/linuxbrew/.linuxbrew/bin:$(PATH)
endif
#$(info UNAME_S_lc=$(UNAME_S_lc) UNAME_M=$(UNAME_M) UNAME_S=$(UNAME_S) UNAME_O=$(UNAME_O) OS=$(OS) e)
define check-directory
$(shell mkdir -p $1 >/dev/null 2>&1 && echo $1)
endef
define check-file
$(shell mkdir -p $(shell echo $$(dirname $1)) >/dev/null 2>&1 && echo $1)
endef
ifeq ($(UNAME_O),Cygwin)
define where-is-binary
$(shell cygpath --windows $1)
endef
endif
ifneq ($(UNAME_O),Cygwin)
define where-is-binary
$(shell command -v $1 2>/dev/null)
endef
endif
define command-exists
$(shell command -v $1 2>/dev/null)
endef
# Overrule the TMP_DIR definition that we have above for now, just want to keep the tmp directory close by
override TMP_DIR := $(call check-directory,$(GIT_ROOT)/.tmp)
TEST_TMP := $(call check-directory,$(TMP_DIR)/test-data)
ifdef TMP_DIR
#
# We'll be creating a number of (temporary) executable symlinks in the TMP_DIR,
# so we need to make sure that it's in the PATH
#
export PATH := $(TMP_DIR):$(PATH)
else
$(error Cannot continue without a proper value in TMP_DIR)
endif
$(TMP_DIR):
@mkdir -p $@
$(TEST_TMP): $(TMP_DIR)
@mkdir -p $@
PKG_CONFIG_SYSROOT_DIR := /
bold := \033[1m
normal := \033[0m
black := \033[30m
red := \033[31m
green := \033[32m
blue := \033[34m
gray := \033[100m
REALPATH_BIN := $(call where-is-binary,grealpath)
ifndef REALPATH_BIN
ifeq ($(UNAME_S_lc),darwin)
$(error GNU realpath is not installed, please install it using 'brew install coreutils')
else
REALPATH_BIN := $(call where-is-binary,realpath)
endif
endif
SED_BIN := $(call where-is-binary,gsed)
ifndef SED_BIN
SED_BIN := $(call where-is-binary,sed)
endif
GREP_BIN := $(call where-is-binary,ggrep)
ifndef GREP_BIN
GREP_BIN := $(call where-is-binary,grep)
endif
PGREP_BIN := $(call where-is-binary,pgrep)
ifdef PGREP_BIN
PKILL_BIN := $(call where-is-binary,pkill)
endif
# A literal space, using a trick documented here: https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html
nullstring :=
space := $(nullstring) # end of the line
comma := ,
comma_space := ,$(space)
# Joins elements of the list in arg 2 with the given separator.
# 1. Element separator.
# 2. The list.
join-with = $(subst $(space),$1,$(strip $2))
#$(info <--- .make/os.mk)
endif # _MK_OS_MK_