-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
102 lines (91 loc) · 2.48 KB
/
build.sh
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
#!/bin/bash
set -e
help() {
echo "Build libpng to the appropriate target."
echo
echo "Syntax: bash build.sh [-h|s|w]"
echo "options:"
echo "h Print this help menu."
echo "s Build with SIMD instructions."
echo "w Build to WASM target."
echo
}
edit_libpngconf() {
echo "editing libpngconf.h..."
make pnglibconf.h
sed -i 's/#define PNG_SETJMP_SUPPORTED/#undef PNG_SETJMP_SUPPORTED/g' pnglibconf.h
sed -i 's/#define PNG_SIMPLIFIED_READ_SUPPORTED/#undef PNG_SIMPLIFIED_READ_SUPPORTED/g' pnglibconf.h
sed -i 's/#define PNG_SIMPLIFIED_WRITE_SUPPORTED/#undef PNG_SIMPLIFIED_WRITE_SUPPORTED/g' pnglibconf.h
}
makefile_add_simd() {
sed -i 's/-O2/-O3 -msimd128/g' Makefile
}
# Enable and disable SIMD during build
# Prepare for WASM usage in compilation
while getopts "hsw" OPTION
do
case $OPTION in
h) help
exit;;
s) simd=true
echo "SIMD enabled...";;
w) wasm=true
echo "building to WASM target...";;
esac
done
# Build the libpng library
echo "running make clean..."
cd ./libpng && make clean > /dev/null
if [[ "$simd" = true && "$wasm" = true ]]; then # SIMD instructions and WASM target
CFLAGS="-DPNG_NO_SETJMP \
-D_WASI_EMULATED_SIGNAL \
-O3 \
-msimd128" \
LIBS=-lwasi-emulated-signal \
CPPFLAGS="-I${SIMDE_PATH}/simde/wasm"
LDFLAGS="-L${WASI_SDK_PATH}/share/wasi-sysroot/lib \
-Wl,--no-entry \
-Wl,--export-all \
-Wl,--growable-table $*" \
LD=${WASI_SDK_PATH}/bin/wasm-ld \
CC=${WASI_SDK_PATH}/bin/clang \
./configure \
--with-sysroot=${WASI_SDK_PATH}/share/wasi-sysroot \
--enable-intel-sse=yes \
--host=wasm32 \
--prefix=${WASI_SDK_PATH}/share/wasi-sysroot
edit_libpngconf
makefile_add_simd
make
make install
elif [[ "$simd" = true ]]; then # SSE and native target
CPPFLAGS="-I${SIMDE_PATH}/simde/wasm" \
./configure --enable-intel-sse=yes
make
sudo make install
elif [[ "$wasm" = true ]]; then # no SIMD and WASM target
CFLAGS="-DPNG_NO_SETJMP \
-D_WASI_EMULATED_SIGNAL" \
LIBS=-lwasi-emulated-signal \
LDFLAGS="-L${WASI_SDK_PATH}/share/wasi-sysroot/lib \
-Wl,--no-entry \
-Wl,--export-all \
-Wl,--growable-table $*" \
LD=${WASI_SDK_PATH}/bin/wasm-ld \
CC=${WASI_SDK_PATH}/bin/clang \
./configure \
--with-sysroot=${WASI_SDK_PATH}/share/wasi-sysroot \
--enable-intel-sse=no \
--host=wasm32 \
--prefix=${WASI_SDK_PATH}/share/wasi-sysroot
edit_libpngconf
make
make install
else # no SSE and native target
CPPFLAGS="-I${SIMDE_PATH}/wasm" \
./configure --enable-intel-sse=no
make
sudo make install
fi
# Confirm completion
echo "done"