Debian Codegraph @

internal/warpc/genwebp/Makefile

raw
1 # The library version to use.
2 # Note that when updating this, you may also need to update the badge in README.md.
3 LIBWEBP_VERSION = v1.6.0
4
5 # The path to the WebAssembly SDK. Can be overridden from the command line.
6 # e.g., make WASI_SDK_PATH=/path/to/wasi-sdk
7 # Download releases from https://github.com/WebAssembly/wasi-sdk/releases.
8 # Note that on MacOS, you may need to add some whitelistings in Privacy & Security > Security.
9 # Note that you also need wasm-validate from WebAssembly Binary Toolkit (WABT) installed.
10 WASI_SDK_PATH ?= /opt/wasi-sdk
11
12 BUILD_DIR := build
13 BUILD_WASM := ${BUILD_DIR}/webp.wasm
14 TARGET_WASM_DIR := ../wasm
15 LIBWEBP_SRC := libwebp
16
17 # Set the compiler and toolchain for WASI
18 CC := $(WASI_SDK_PATH)/bin/clang
19 CMAKE_TOOLCHAIN_FILE := $(WASI_SDK_PATH)/share/cmake/wasi-sdk-p1.cmake
20
21 # Source files for the final WASM binary
22 C_SOURCES := webp.c ../deps/parson/parson.c
23
24 # Include paths
25 C_INCLUDES := -I$(LIBWEBP_SRC)/src -I$(BUILD_DIR)/src -I.
26
27 # Libraries to link against
28 LD_LIBS := $(BUILD_DIR)/libwebpdemux.a $(BUILD_DIR)/libwebp.a $(BUILD_DIR)/libsharpyuv.a $(BUILD_DIR)/libwebpmux.a
29
30 # Compiler flags for the WASM build
31 WASM_CFLAGS := \
32 -O3 \
33 -msimd128 \
34 -mexec-model=command \
35 -mnontrapping-fptoint \
36 -Wl,--export=malloc \
37 -Wl,--export=free \
38 -Wall
39
40 .PHONY: all clean
41
42 # Default target: build the WebAssembly binary
43 all: $(LIBWEBP_SRC) $(BUILD_DIR)
44 @echo ">>> Configuring and building C libraries in $(BUILD_DIR)"
45 cd $(BUILD_DIR) && \
46 cmake $(realpath $(LIBWEBP_SRC)) \
47 -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) \
48 -DCMAKE_BUILD_TYPE=Release \
49 -DBUILD_SHARED_LIBS=0 \
50 -DWEBP_ENABLE_SIMD_DEFAULT=1 \
51 -DWEBP_BUILD_EXTRAS=0 \
52 -DWEBP_USE_THREAD=0 \
53 -DWEBP_BUILD_ANIM_UTILS=0 \
54 -DWEBP_BUILD_CWEBP=0 \
55 -DWEBP_BUILD_DWEBP=0 \
56 -DWEBP_BUILD_IMG2WEBP=0 \
57 -DWEBP_BUILD_WEBPINFO=0 \
58 -DWEBP_BUILD_WEBPMUX=1 && \
59 make VERBOSE=1
60 @echo ">>> Building WebAssembly binary: $(BUILD_WASM)"
61 $(CC) $(WASM_CFLAGS) --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot $(C_INCLUDES) -o $(BUILD_WASM) $(C_SOURCES) $(LD_LIBS)
62 @echo ">>> Moving the WebAssembly binary: $(TARGET_WASM_DIR)"
63 mv $(BUILD_WASM) $(TARGET_WASM_DIR)
64
65
66 # Rule to create the build directory
67 $(BUILD_DIR):
68 @echo ">>> Creating build directory: $(BUILD_DIR)"
69 @mkdir -p $@
70
71 # Rule to clone the libwebp source code
72 $(LIBWEBP_SRC):
73 @echo ">>> Cloning libwebp source code (version: $(LIBWEBP_VERSION))"
74 git clone -b $(LIBWEBP_VERSION) --depth 1 --recursive https://github.com/webmproject/libwebp
75 test -d $@
76
77 # Rule to clean up build artifacts
78 clean:
79 @echo ">>> Cleaning build artifacts"
80 @rm -rf $(BUILD_DIR)
81 @rm -rf $(LIBWEBP_SRC)