-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (124 loc) · 4.34 KB
/
Makefile
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
.ONESHELL:
SHELL = bash
.SHELLFLAGS = -eo pipefail -c
.DEFAULT: all
.PHONY: all bump-% clean config dist-clean fetch-thirdparty helpers lint re setup serve script
BUILD_DIR ?= build
BUILD_INFO := $(BUILD_DIR)/meson-info/intro-buildoptions.json
CONFIG ?= config.ini
define which
$(eval p:=$(and $1,$(shell which $(firstword $1))))$(and $p,$p $(wordlist 2,$(words $1),$1))
endef
define find_program
$(strip $(or $(call $1),\
$(call which,$2),\
$(call which,$3),\
$(call which,$4),\
$(call which,$5),\
$(error Program '$2' not found or not executable)))
endef
define config
[binaries]
ar = '$(call find_program,EMAR,emar)'
c = ['$(call find_program,CCACHE,ccache,sccache,env)', '$(call find_program,EMCC,emcc)']
ranlib = '$(call find_program,EMRANLIB,emranlib)'
strip = '$(call find_program,EMSTRIP,emstrip)'
[project options]
# Image formats.
gif = $(or $(GIF),true)
webp = $(or $(WEBP),true)
# Output options.
wasm = $(or $(WASM),true)
[libwebp:project options]
disable-stats = true
libwebpdecoder = 'enabled'
libwebpdemux = 'enabled'
near-lossless = false
reduce-csp = true
reduce-size = true
# vim: ft=cfg
endef
define newline
endef
# Programs.
MESON ?= meson
all: script
clean:
rm --force --recursive $(BUILD_DIR)
config: $(CONFIG)
dist-clean:
-rm --force --recursive $(wildcard config.ini config-*.ini build/ build-*/ $(patsubst %.wrap,%*/,$(wildcard subprojects/*.wrap)))
fetch-thirdparty:
$(MESON) subprojects download --num-processes 3
re: clean
@$(MAKE) --no-print-directory all
setup: $(BUILD_INFO)
$(BUILD_INFO): $(CONFIG)
$(strip $(MESON) setup --auto-features=disabled --cross-file=$(CONFIG) $(if $(wildcard $(BUILD_INFO)),--wipe) $(BUILD_DIR))
helpers lint script serve: $(BUILD_INFO)
$(MESON) compile -C $(BUILD_DIR) -v $@
$(CONFIG): Makefile
cat >$@ <<'EOF'
$(config)
EOF
# Helpers for bumping requirements.
CURL = curl --location --silent
bump-emsdk:
@image="$$(
$(CURL) 'https://registry.hub.docker.com/v2/repositories/emscripten/emsdk/tags' |
jq -r '
(.results[] | select(.name == "latest").digest) as $$digest |
.results[] | select(.digest == $$digest) | select(.name != "latest") |
.name + "@" + $$digest
'
)"
echo "bump emsdk to $${image%%@*}"
sed -i -e "s/^EMSDK_VERSION ?= .*/EMSDK_VERSION ?= $$image/" Makefile
bump-esbuild:
@package='$(@:bump-%=%)'
version="$$({ npm outdated --json || true; } | jq -r ".$$package.latest")"
echo "bump esbuild to $$version"
npm install --package-lock-only --save-exact "$$package@$$version"
bump-meson bump-ninja:
@package='$(@:bump-%=%)'
version="$$(
$(CURL) "https://pypi.python.org/pypi/$$package/json" |
jq -r '.info.version'
)"
hashes="$$(
$(CURL) "https://pypi.python.org/pypi/$$package/$$version/json" |
jq -j '.urls | sort[].digests.sha256 | " --hash=sha256:" + .'
)"
echo "bump $$package to $$version"
sed -i -e "s/^$$package==.*/$$package==$$version$$hashes/" requirements.txt
# Containers support.
EMSDK_VERSION ?= 3.1.71@sha256:9922c93314b63a1d9ceba2e76f03737f1f9cc4b7350341211e2d3555633ffdd5
.PHONY: container-build container-config
container-build:
mkdir -p $(BUILD_ROOT)
cp package.json package-lock.json $(BUILD_ROOT)/
npm config set prefix='~/.local/' update-notifier=false
npm ci --prefix $(BUILD_ROOT) --no-audit
python3 -m venv $(BUILD_ROOT)/venv --system-site-packages --without-pip
$(abspath $(BUILD_ROOT)/venv/bin/python) -m pip install --no-warn-script-location --requirement requirements.txt
env PATH="$(abspath $(BUILD_ROOT)/node_modules/esbuild/bin):$(abspath $(BUILD_ROOT)/venv/bin):$$PATH" $(MAKE) all
container-config: config
define container_rules
$1 ?= $2
$1_BUILD ?= build-$2
$1_CONFIG ?= config-$2.ini
.PHONY: $(patsubst %,$2-%,build clean config)
$2-build $2-config:
$$(strip $$(call find_program,$1,$2) run --mount type=bind,source='$$(CURDIR),target=/src' \
--interactive --rm --tty $3 '$4emscripten/emsdk$$(EMSDK_VERSION:%=:%)' \
env MAKEFLAGS='$$(filter-out --jobserver-%,$$(MAKEFLAGS))' \
make BUILD_ROOT='$$($1_BUILD)' BUILD_DIR='$$($1_BUILD)/build' CONFIG='$$($1_CONFIG)' \
-C /src $$(@:$2-%=container-%) \
)
$2-clean:
rm --force --recursive '$$($1_BUILD)' '$$($1_CONFIG)'
endef
# For completion.
docker-build docker-config docker-clean podman-config podman-build podman-clean:
$(eval $(call container_rules,DOCKER,docker,--user "$$$$UID:$$$$GID",))
$(eval $(call container_rules,PODMAN,podman,,docker.io/))