-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
118 lines (93 loc) · 3.85 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
.PHONY = test package clean clean-dist clean-vendor-file clean-submodules docker-builder-build docker-builder-run fmt update-dependencies
SHELL := bash
ts_files := $(wildcard src/*.ts src/test/integration/*.ts types/*.ts)
fmt_files := $(shell echo examples/{worker/*.{mjs,md},stream-detection/*.{js,md}} .github/workflows/*.yml *.js{,on} *.md src/*.js)
num_processors := $(shell nproc || printf "1")
export EMCC_CFLAGS = -msimd128 -O2
test: dist/index.js dist/test/integration/foobar_magic dist/test/integration/png_magic dist/test/integration/jpeg_magic
TZ='UTC' npm run test
dist/test/integration/foobar_magic dist/test/integration/png_magic dist/test/integration/jpeg_magic &:
mkdir -p dist/test/integration \
&& cp src/test/integration/*_magic dist/test/integration/
package: dist/index.js dist/libmagic.LICENSE
dist/index.js: $(ts_files) dist/libmagic-wrapper.js dist/LibmagicModule.d.ts dist/StdioOverrideFunction.d.ts
node ./node_modules/.bin/tsc -d
dist/libmagic-wrapper.js: src/libmagic-wrapper.c dist/magic.mgc dist/libmagic.so dist/libmagic-wrapper.d.ts
emcc -s MODULARIZE -s WASM=1 \
-s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "FS"]' \
-s EXPORTED_FUNCTIONS='["_magic_wrapper_load", "_magic_wrapper_detect", "_malloc", "_free"]' \
-s ALLOW_MEMORY_GROWTH=1 \
--pre-js ./src/pre.js \
--embed-file ./dist/magic.mgc@/magic/magic.mgc \
-I./vendor/file/src -I./dist -L./dist \
-lmagic \
-o dist/libmagic-wrapper.js \
src/libmagic-wrapper.c
dist/libmagic-wrapper.d.ts: src/libmagic-wrapper.d.ts
cp src/libmagic-wrapper.d.ts dist/libmagic-wrapper.d.ts
dist/LibmagicModule.d.ts: src/LibmagicModule.d.ts
cp src/LibmagicModule.d.ts dist/LibmagicModule.d.ts
dist/StdioOverrideFunction.d.ts: src/StdioOverrideFunction.d.ts
cp src/StdioOverrideFunction.d.ts dist/StdioOverrideFunction.d.ts
dist/libmagic.LICENSE: vendor/file/COPYING
cp vendor/file/COPYING dist/libmagic.LICENSE
vendor/file/COPYING:
git submodule init
git submodule update
dist/magic.mgc: vendor/file/COPYING
make clean-vendor-file \
&& cd vendor/file \
&& autoreconf -f -i \
&& ./configure --disable-silent-rules \
&& make -j${num_processors} \
&& cp magic/magic.mgc ../../dist/
dist/libmagic.so: vendor/file/COPYING
make clean-vendor-file \
&& cd vendor/file \
&& autoreconf -f -i \
&& emconfigure ./configure --disable-silent-rules \
&& cd src/ \
&& emmake make -j${num_processors} \
&& { { [[ -e .libs/libmagic.dylib ]] \
&& mv .libs/libmagic.dylib .libs/libmagic.so; } || true; } \
&& mv "$$(realpath .libs/libmagic.so)" ../../../dist/libmagic.so
clean: clean-dist clean-submodules
clean-dist:
git clean -fx dist
clean-vendor-file:
cd vendor/file \
&& git reset --hard \
&& git clean -fdx
clean-submodules:
git submodule foreach git reset --hard
git submodule foreach git clean -fdx
docker-builder-build:
docker build -f Dockerfile.Builder -t wasmagic-builder .
docker-builder-run: docker-builder-build
docker run -ti \
-v "${PWD}:/app" \
--user "$$UID:$$GID" \
wasmagic-builder \
/bin/bash -c "cd /app && make dist/libmagic-wrapper.js"
fmt: $(ts_files) $(fmt_files)
./node_modules/.bin/biome format --write $(ts_files) $(fmt_files)
fmt-check: $(ts_files) $(fmt_files)
./node_modules/.bin/biome format $(ts_files) $(fmt_files)
lint: $(ts_files) $(fmt_files)
./node_modules/.bin/biome lint --write $(ts_files) $(fmt_files)
lint-check: $(ts_files) $(fmt_files)
./node_modules/.bin/biome lint $(ts_files) $(fmt_files)
update-dependencies:
directories=("." "examples/worker" "examples/stream-detection"); \
packageLockFlag=""; \
for i in $${!directories[@]}; do \
if [[ $$i -gt 0 ]]; then \
packageLockFlag="--no-package-lock"; \
fi; \
pushd "$${directories[$$i]}"; \
jq -r '.devDependencies | keys | .[]' < package.json \
| xargs -n1 npm info --json \
| jq -r '"\(.name)@\(.["dist-tags"].latest)"' \
| xargs npm install --save-dev "$$packageLockFlag"; \
popd; \
done