-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
81 lines (64 loc) · 2.17 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
SRC = src
DIST = dist
RESIZE = 512x512
QUALITY = 80
FONTCHARS = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ,;.:-_<>$$£!+\"*ç%&/~[]{}()=?\`^\'#€öÖäÄüܧ°
#
# Build TARGETS
#
# To summup: src/**/*.{hdr,webp,png,jpg,json,woff,glb,gltf} => dist/**/*.{exr,webp,webp,webp,json,woff,glb,glb}.js
#
# hdr -> exr.js
HDR_FILES := $(wildcard $(SRC)/**/*.hdr)
HDR_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(HDR_FILES:%.hdr=%.exr))
# webp,png,jpg -> webp.js
WEBP_FILES := $(wildcard $(SRC)/**/*.webp)
WEBP_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(WEBP_FILES))
PNG_FILES := $(wildcard $(SRC)/**/*.png)
PNG_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(PNG_FILES:%.png=%.webp))
JPG_FILES := $(wildcard $(SRC)/**/*.jpg)
JPG_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(JPG_FILES:%.jpg=%.webp))
# json -> json.js
JSON_FILES := $(wildcard $(SRC)/**/*.json)
JSON_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(JSON_FILES))
# woff -> woff.js
WOFF_FILES := $(wildcard $(SRC)/**/*.woff)
WOFF_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(WOFF_FILES))
# glb,gltf -> glb.js
GLB_FILES := $(wildcard $(SRC)/**/*.glb)
GLB_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(GLB_FILES))
GLTF_FILES := $(wildcard $(SRC)/**/*.gltf)
GLTF_TARGETS := $(patsubst $(SRC)/%,$(DIST)/%.js,$(GLTF_FILES:%.gltf=%.glb))
TARGETS = $(HDR_TARGETS) \
$(WEBP_TARGETS) $(PNG_TARGETS) $(JPG_TARGETS) \
$(JSON_TARGETS) $(WOFF_TARGETS) \
$(GLB_TARGETS) $(GLTF_TARGETS)
all: $(TARGETS)
$(DIST)/%.js: $(SRC)/%.b64
mkdir -p $(dir $@)
echo "export default 'data:$$(node bin/mime.js $(suffix $*));base64,$$(cat $<)'" > $@
%.b64: %.compressed
cat $^ | openssl base64 | tr -d '\n' > $@
%.exr.compressed: %.exr
convert $< -compress DWAB -resize $(RESIZE) $@
%.exr: %.hdr
convert $< $@
%.webp.compressed: %.webp
convert $< -quality $(QUALITY) -resize $(RESIZE) $@
%.webp: %.png
convert $< $@
%.webp: %.jpg
convert $< $@
%.json.compressed: %.json
cat $< | jq -c > $@
%.woff.compressed: %.woff
node ./bin/subset.js $< "$(FONTCHARS)" $@
%.glb.compressed: %.glb
npx gltf-transform optimize $< $*.tmp.glb
cp $*.tmp.glb $@
rm $*.tmp.glb
%.glb: %.gltf
npx gltf-transform copy $< $@
.PHONY: clean
clean:
rm -rf $(DIST)