-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (94 loc) · 3.25 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
.ONESHELL:
SHELL = bash
.SHELLFLAGS = -eo pipefail -c
.DEFAULT: all
.PHONY: all 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
# Containers support.
EMSDK_VERSION ?= 3.1.55@sha256:0d9172d4b153a9a1067db4c753f8ec1bcb1542bfe1ca61a3c2d9115080b1963f
.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/))