-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
295 lines (240 loc) · 12.3 KB
/
Makefile
File metadata and controls
295 lines (240 loc) · 12.3 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# -*- makefile -*-
# lind-wasm-apps unified build (hardened, with lmbench build wrapper)
SHELL := /bin/bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
# -------- Paths ---------------------------------------------------------------
LIND_WASM_ROOT ?= $(HOME)/lind-wasm
BASE_SYSROOT ?= $(LIND_WASM_ROOT)/src/glibc/sysroot
APPS_ROOT := $(CURDIR)
APPS_BUILD := $(APPS_ROOT)/build
APPS_OVERLAY := $(APPS_BUILD)/sysroot_overlay
MERGED_SYSROOT := $(APPS_BUILD)/sysroot_merged
APPS_BIN_DIR := $(APPS_BUILD)/bin
APPS_LIB_DIR := $(APPS_BUILD)/lib
LIBTIRPC_STAMP := $(APPS_BUILD)/.stamp_libtirpc
GNULIB_STAMP := $(APPS_BUILD)/.stamp_gnulib
ZLIB_STAMP := $(APPS_BUILD)/.stamp_zlib
OPENSSL_STAMP := $(APPS_BUILD)/.stamp_openssl
MERGE_BASE_STAMP := $(APPS_BUILD)/.stamp_merge_base_sysroot
MERGE_TIRPC_STAMP := $(APPS_BUILD)/.stamp_merge_tirpc
MERGE_GNULIB_STAMP := $(APPS_BUILD)/.stamp_merge_gnulib
MERGE_ZLIB_STAMP := $(APPS_BUILD)/.stamp_merge_zlib
MERGE_OPENSSL_STAMP := $(APPS_BUILD)/.stamp_merge_openssl
MERGE_ALL_STAMP := $(APPS_BUILD)/.stamp_merge_sysroot
TOOL_ENV := $(APPS_BUILD)/.toolchain.env
JOBS ?= $(shell nproc 2>/dev/null || getconf _NPROCESSORS_ONLN || echo 4)
LINDFS_ROOT := $(LIND_WASM_ROOT)/lindfs
# -------- Phonies -------------------------------------------------------------
.PHONY: all preflight dirs print-config libtirpc gnulib zlib openssl merge-base-sysroot merge-sysroot lmbench bash nginx coreutils cpython git curl grep sed postgres clean clean-all rebuild-libs rebuild-sysroot install-bash install-nginx install-git install-curl install-grep install-sed install-lmbench install-coreutils install
all: preflight libtirpc gnulib merge-sysroot lmbench bash
print-config:
@echo "LIND_WASM_ROOT=$(LIND_WASM_ROOT)"
@echo "BASE_SYSROOT=$(BASE_SYSROOT)"
@echo "APPS_OVERLAY=$(APPS_OVERLAY)"
@echo "MERGED_SYSROOT=$(MERGED_SYSROOT)"
@echo "APPS_BIN_DIR=$(APPS_BIN_DIR)"
@echo "APPS_LIB_DIR=$(APPS_LIB_DIR)"
@if [[ -r '$(TOOL_ENV)' ]]; then . '$(TOOL_ENV)'; \
echo "CLANG=$$CLANG"; echo "AR=$$AR"; echo "RANLIB=$$RANLIB"; fi
dirs:
mkdir -p \
'$(APPS_OVERLAY)/usr/include' \
'$(APPS_OVERLAY)/usr/lib/wasm32-wasi' \
'$(APPS_OVERLAY)/lib/wasm32-wasi' \
'$(MERGED_SYSROOT)/include' \
'$(MERGED_SYSROOT)/include/wasm32-wasi' \
'$(MERGED_SYSROOT)/lib/wasm32-wasi' \
'$(MERGED_SYSROOT)/usr/lib/wasm32-wasi' \
'$(APPS_BIN_DIR)' \
'$(APPS_LIB_DIR)'
# TODO:
# Once we have a shared helper in lind-wasm (or a stable
# container path for the toolchain), we should move this into a small
# script (e.g. scripts/detect_toolchain.sh) or reuse a common helper
# so the Makefile itself can stay leaner.
$(TOOL_ENV): | dirs
@echo "[*] preflight checks…"
[ -r '$(BASE_SYSROOT)/include/wasm32-wasi/stdio.h' ] || { echo "ERROR: sysroot headers missing at $(BASE_SYSROOT)"; exit 1; }
{
set -euo pipefail
CLANG_CAND=( \
"$(LIND_WASM_ROOT)/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04/bin/clang" \
"$$(command -v clang-18 || true)" \
"$$(command -v clang || true)" \
)
AR_CAND=( \
"$(LIND_WASM_ROOT)/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-ar" \
"$$(command -v llvm-ar || true)" \
"$$(command -v ar || true)" \
)
RANLIB_CAND=( \
"$(LIND_WASM_ROOT)/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-ranlib" \
"$$(command -v llvm-ranlib || true)" \
"$$(command -v ranlib || true)" \
)
pick() { for x in "$$@"; do [[ -x "$$x" ]] && { echo "$$x"; return; }; done; echo ""; }
CLANG="$$(pick "$${CLANG_CAND[@]}")"
AR="$$(pick "$${AR_CAND[@]}")"
RANLIB="$$(pick "$${RANLIB_CAND[@]}")"
[[ -x "$$CLANG" ]] || { echo "ERROR: clang not found (tried: $${CLANG_CAND[*]})"; exit 1; }
[[ -x "$$AR" ]] || { echo "ERROR: llvm-ar/ar not found (tried: $${AR_CAND[*]})"; exit 1; }
[[ -x "$$RANLIB" ]] || { echo "ERROR: llvm-ranlib/ranlib not found (tried: $${RANLIB_CAND[*]})"; exit 1; }
{
echo "export CLANG='$$CLANG'"
echo "export AR='$$AR'"
echo "export RANLIB='$$RANLIB'"
} > '$(TOOL_ENV)'
echo "[*] preflight OK"
"$$CLANG" --version | head -n1
}
preflight: $(TOOL_ENV)
# ---------------- libtirpc (via compile_libtirpc.sh) -------------------------
$(LIBTIRPC_STAMP): $(APPS_ROOT)/libtirpc/compile_libtirpc.sh | $(TOOL_ENV)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/libtirpc/compile_libtirpc.sh'
touch '$@'
libtirpc: $(LIBTIRPC_STAMP)
# ---------------- gnulib (via compile_gnulib.sh) -----------------------------
$(GNULIB_STAMP): $(APPS_ROOT)/gnulib/compile_gnulib.sh | $(TOOL_ENV)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/gnulib/compile_gnulib.sh'
touch '$@'
gnulib: $(GNULIB_STAMP)
# ---------------- zlib (via compile_zlib.sh) ----------------------------------
$(ZLIB_STAMP): $(APPS_ROOT)/zlib/compile_zlib.sh | $(TOOL_ENV)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/zlib/compile_zlib.sh'
touch '$@'
zlib: $(ZLIB_STAMP)
# ---------------- openssl (via compile_openssl.sh) ----------------------------
$(OPENSSL_STAMP): $(APPS_ROOT)/openssl/compile_openssl.sh | $(TOOL_ENV)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/openssl/compile_openssl.sh'
touch '$@'
openssl: $(OPENSSL_STAMP)
# ---------------- Merge sysroot + overlay -------------------------------------
$(MERGE_BASE_STAMP): | $(TOOL_ENV)
@echo "[merge] refreshing base merged sysroot"
rsync -a --delete '$(BASE_SYSROOT)/' '$(MERGED_SYSROOT)/'
touch '$@'
merge-base-sysroot: $(MERGE_BASE_STAMP)
$(MERGE_TIRPC_STAMP): $(MERGE_BASE_STAMP) $(LIBTIRPC_STAMP)
# libtirpc headers
mkdir -p '$(MERGED_SYSROOT)/include/tirpc' '$(MERGED_SYSROOT)/include/wasm32-wasi/tirpc'
rsync -a '$(APPS_OVERLAY)/usr/include/tirpc/' '$(MERGED_SYSROOT)/include/tirpc/' || true
rsync -a '$(APPS_OVERLAY)/usr/include/tirpc/' '$(MERGED_SYSROOT)/include/wasm32-wasi/tirpc/' || true
rsync -a '$(APPS_OVERLAY)/usr/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
rsync -a '$(APPS_OVERLAY)/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
touch '$@'
$(MERGE_GNULIB_STAMP): $(MERGE_BASE_STAMP) $(GNULIB_STAMP)
# gnulib headers (placed under include/gnulib/)
mkdir -p '$(MERGED_SYSROOT)/include/gnulib' '$(MERGED_SYSROOT)/include/wasm32-wasi/gnulib'
rsync -a '$(APPS_OVERLAY)/usr/include/gnulib/' '$(MERGED_SYSROOT)/include/gnulib/' || true
rsync -a '$(APPS_OVERLAY)/usr/include/gnulib/' '$(MERGED_SYSROOT)/include/wasm32-wasi/gnulib/' || true
rsync -a '$(APPS_OVERLAY)/usr/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
rsync -a '$(APPS_OVERLAY)/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
touch '$@'
$(MERGE_ZLIB_STAMP): $(MERGE_BASE_STAMP) $(ZLIB_STAMP)
# zlib headers
cp -f '$(APPS_OVERLAY)/usr/include/zlib.h' '$(MERGED_SYSROOT)/include/' || true
cp -f '$(APPS_OVERLAY)/usr/include/zconf.h' '$(MERGED_SYSROOT)/include/' || true
cp -f '$(APPS_OVERLAY)/usr/include/zlib.h' '$(MERGED_SYSROOT)/include/wasm32-wasi/' || true
cp -f '$(APPS_OVERLAY)/usr/include/zconf.h' '$(MERGED_SYSROOT)/include/wasm32-wasi/' || true
rsync -a '$(APPS_OVERLAY)/usr/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
rsync -a '$(APPS_OVERLAY)/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
touch '$@'
$(MERGE_OPENSSL_STAMP): $(MERGE_BASE_STAMP) $(OPENSSL_STAMP)
# openssl headers
mkdir -p '$(MERGED_SYSROOT)/include/openssl' '$(MERGED_SYSROOT)/include/wasm32-wasi/openssl'
rsync -a '$(APPS_OVERLAY)/usr/include/openssl/' '$(MERGED_SYSROOT)/include/openssl/' || true
rsync -a '$(APPS_OVERLAY)/usr/include/openssl/' '$(MERGED_SYSROOT)/include/wasm32-wasi/openssl/' || true
rsync -a '$(APPS_OVERLAY)/usr/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
rsync -a '$(APPS_OVERLAY)/lib/wasm32-wasi/' '$(MERGED_SYSROOT)/lib/wasm32-wasi/' || true
touch '$@'
$(MERGE_ALL_STAMP): $(MERGE_TIRPC_STAMP) $(MERGE_GNULIB_STAMP) $(MERGE_ZLIB_STAMP) $(MERGE_OPENSSL_STAMP)
touch '$@'
merge-sysroot: $(MERGE_ALL_STAMP)
# ---------------- lmbench (via compile_lmbench.sh) ---------------------------
lmbench: $(MERGE_TIRPC_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/lmbench/src/compile_lmbench.sh'
# ---------------- bash (WASM build) -------------------------------------------
# Uses bash/compile_bash.sh to build bash as a wasm32-wasi binary using the
# merged sysroot and toolchain detected by preflight, and stages artifacts
# under build/bin/bash/wasm32-wasi/.
bash: $(MERGE_BASE_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/bash/compile_bash.sh'
# ---------------- nginx (WASM build) -------------------------------------------
# Uses nginx/compile_nginx.sh to build nginx as a wasm32-wasi binary using the
# merged sysroot and toolchain detected by preflight, and stages artifacts
# under build/bin/nginx/wasm32-wasi/.
nginx: $(MERGE_BASE_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/nginx/compile_nginx.sh'
# ---------------- coreutils (WASM build) --------------------------------------
# Uses coreutils/compile_coreutils.sh and requires the merged sysroot.
coreutils: $(MERGE_BASE_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/coreutils/compile_coreutils.sh'
# ---------------- git (WASM build) --------------------------------------------
# Uses git/compile_git.sh to build git as a wasm32-wasi binary using the
# merged sysroot and toolchain detected by preflight (zlib + OpenSSL), and
# stages artifacts under build/bin/git/wasm32-wasi/.
git: $(MERGE_ZLIB_STAMP) $(MERGE_OPENSSL_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/git/compile_git.sh'
# ---------------- curl (WASM build) -------------------------------------------
# Uses curl/compile_curl.sh and requires the merged sysroot (OpenSSL + zlib).
curl: $(MERGE_ZLIB_STAMP) $(MERGE_OPENSSL_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/curl/compile_curl.sh'
# ---------------- grep (WASM build) -------------------------------------------
grep: $(MERGE_BASE_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/grep/compile_grep.sh'
# ---------------- sed (WASM build) --------------------------------------------
sed: $(MERGE_BASE_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/sed/compile_sed.sh'
rebuild-libs:
rm -f '$(LIBTIRPC_STAMP)' '$(GNULIB_STAMP)' '$(ZLIB_STAMP)' '$(OPENSSL_STAMP)' \
'$(MERGE_TIRPC_STAMP)' '$(MERGE_GNULIB_STAMP)' '$(MERGE_ZLIB_STAMP)' '$(MERGE_OPENSSL_STAMP)' '$(MERGE_ALL_STAMP)'
rebuild-sysroot:
rm -f '$(MERGE_BASE_STAMP)' '$(MERGE_TIRPC_STAMP)' '$(MERGE_GNULIB_STAMP)' '$(MERGE_ZLIB_STAMP)' '$(MERGE_OPENSSL_STAMP)' '$(MERGE_ALL_STAMP)'
# ---------------- cpython (WASM build) ----------------------------------------
# Placeholder target to preserve the per-app staging/layering pattern.
cpython: merge-sysroot
mkdir -p '$(APPS_BIN_DIR)/cpython/wasm32-wasi'
# ---------------- postgres (WASM build) ---------------------------------------
# Placeholder target to preserve the per-app staging/layering pattern.
postgres: merge-sysroot
mkdir -p '$(APPS_BIN_DIR)/postgres/wasm32-wasi'
install-bash:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' bash
install-nginx:
'$(APPS_ROOT)/nginx/nginx_post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)'
install-git:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' git
install-curl:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' curl
install-grep:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' grep
install-sed:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' sed
install-lmbench:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' lmbench
install-coreutils:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BIN_DIR)' coreutils
install: install-bash install-nginx install-git install-curl install-grep install-sed install-lmbench install-coreutils
clean:
$(MAKE) -C '$(APPS_ROOT)/lmbench/src' clean || true
-rm -rf '$(APPS_BIN_DIR)/lmbench'
-rm -rf '$(APPS_BUILD)/lmbench'
-rm -rf '$(APPS_BIN_DIR)/nginx'
-$(MAKE) -C '$(APPS_ROOT)/nginx' clean || true
-rm -rf '$(APPS_OVERLAY)' '$(MERGED_SYSROOT)' '$(APPS_BIN_DIR)' '$(APPS_LIB_DIR)' '$(TOOL_ENV)'
-rm -f '$(LIBTIRPC_STAMP)' '$(GNULIB_STAMP)' '$(ZLIB_STAMP)' '$(OPENSSL_STAMP)'
-rm -f '$(MERGE_BASE_STAMP)' '$(MERGE_TIRPC_STAMP)' '$(MERGE_GNULIB_STAMP)' '$(MERGE_ZLIB_STAMP)' '$(MERGE_OPENSSL_STAMP)' '$(MERGE_ALL_STAMP)'
$(MAKE) -C '$(APPS_ROOT)/libtirpc' distclean || true