forked from node-libraries/wasm-image-optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (96 loc) · 3.92 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
SHELL=/bin/bash
WORKDIR=work
DISTDIR=dist
ESMDIR=$(DISTDIR)/esm
WORKERSDIR=$(DISTDIR)/workers
LIBDIR=libavif/ext
TARGET_ESM_BASE = $(notdir $(basename src/libImage.cpp))
TARGET_ESM = $(ESMDIR)/$(TARGET_ESM_BASE).js
TARGET_WORKERS = $(WORKERSDIR)/$(TARGET_ESM_BASE).js
CFLAGS = -O3 -msimd128 \
-Ilibwebp -Ilibwebp/src -Ilibavif/include -Ilibavif/third_party/libyuv/include -Ilibavif/ext/aom \
-Ilibexif \
-DAVIF_CODEC_AOM_DECODE -DAVIF_CODEC_AOM=LOCAL
CFLAGS_ASM = --bind \
-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s ENVIRONMENT=web -s DYNAMIC_EXECUTION=0 -s MODULARIZE=1 \
-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s USE_SDL_GFX=2 \
-s SDL2_IMAGE_FORMATS='["png","jpg","webp","svg","avif"]'
WEBP_SOURCES := $(wildcard libwebp/src/dsp/*.c) \
$(wildcard libwebp/src/enc/*.c) \
$(wildcard libwebp/src/utils/*.c) \
$(wildcard libwebp/src/dec/*.c) \
$(wildcard libwebp/sharpyuv/*.c)
AVIF_SOURCES := libavif/src/alpha.c \
libavif/src/avif.c \
libavif/src/colr.c \
libavif/src/colrconvert.c \
libavif/src/diag.c \
libavif/src/exif.c \
libavif/src/io.c \
libavif/src/mem.c \
libavif/src/obu.c \
libavif/src/rawdata.c \
libavif/src/read.c \
libavif/src/reformat.c \
libavif/src/reformat_libsharpyuv.c \
libavif/src/reformat_libyuv.c \
libavif/src/scale.c \
libavif/src/stream.c \
libavif/src/utils.c \
libavif/src/write.c \
libavif/src/codec_aom.c \
libavif/third_party/libyuv/source/scale.c \
libavif/third_party/libyuv/source/scale_common.c \
libavif/third_party/libyuv/source/scale_any.c \
libavif/third_party/libyuv/source/row_common.c \
libavif/third_party/libyuv/source/planar_functions.c
EXIF_SOURCES := $(wildcard libexif/libexif/*.c) \
$(wildcard libexif/libexif/canon/*.c) \
$(wildcard libexif/libexif/fuji/*.c) \
$(wildcard libexif/libexif/olympus/*.c) \
$(wildcard libexif/libexif/pentax/*.c)
WEBP_OBJECTS := $(WEBP_SOURCES:.c=.o)
AVIF_OBJECTS := $(AVIF_SOURCES:.c=.o)
EXIF_OBJECTS := $(EXIF_SOURCES:.c=.o)
.PHONY: all esm workers clean
all: esm workers
$(WEBP_OBJECTS) $(AVIF_OBJECTS): %.o: %.c | $(LIBDIR)/aom_build/libaom.a
@emcc $(CFLAGS) -c $< -o $@
$(LIBDIR)/aom_build/libaom.a:
@echo Building aom...
@cd $(LIBDIR) && ./aom.cmd && mkdir aom_build && cd aom_build && \
emcmake cmake ../aom \
-DENABLE_CCACHE=1 \
-DAOM_TARGET_CPU=generic \
-DENABLE_DOCS=0 \
-DENABLE_TESTS=0 \
-DCONFIG_ACCOUNTING=1 \
-DCONFIG_INSPECTION=1 \
-DCONFIG_MULTITHREAD=0 \
-DCONFIG_RUNTIME_CPU_DETECT=0 \
-DCONFIG_WEBM_IO=0 \
-DCMAKE_BUILD_TYPE=Release && \
make aom
$(WORKDIR):
@mkdir -p $(WORKDIR)
$(WORKDIR)/webp.a: $(WORKDIR) $(WEBP_OBJECTS)
@emar rcs $@ $(WEBP_OBJECTS)
$(WORKDIR)/avif.a: $(WORKDIR) $(AVIF_OBJECTS)
@emar rcs $@ $(AVIF_OBJECTS)
$(WORKDIR)/libexif.a: $(EXIF_SOURCES)
@cd libexif && autoreconf -i && emconfigure ./configure && cd libexif && emmake make
@emar rcs $@ $(EXIF_OBJECTS)
$(ESMDIR) $(WORKERSDIR):
@mkdir -p $@
esm: $(TARGET_ESM)
$(TARGET_ESM): src/libImage.cpp $(WORKDIR)/webp.a $(WORKDIR)/avif.a $(WORKDIR)/libexif.a $(LIBDIR)/aom_build/libaom.a | $(ESMDIR)
emcc $(CFLAGS) -o $@ $^ \
$(CFLAGS_ASM) -s EXPORT_ES6=1
workers: $(TARGET_WORKERS)
$(TARGET_WORKERS): src/libImage.cpp $(WORKDIR)/webp.a $(WORKDIR)/avif.a $(WORKDIR)/libexif.a $(LIBDIR)/aom_build/libaom.a | $(WORKERSDIR)
emcc $(CFLAGS) -o $@ $^ \
$(CFLAGS_ASM)
@rm $(WORKERSDIR)/$(TARGET_ESM_BASE).wasm
clean:
@echo Cleaning up...
@rm -rf $(WORKDIR) $(LIBDIR)/aom_build $(DISTDIR)/esm $(DISTDIR)/workers