git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.5 / build / single_file_libs / build_library_test.sh
1 #!/bin/sh
2
3 # Where to find the sources (only used to copy zstd.h)
4 ZSTD_SRC_ROOT="../../lib"
5
6 # Temporary compiled binary
7 OUT_FILE="tempbin"
8
9 # Optional temporary compiled WebAssembly
10 OUT_WASM="temp.wasm"
11
12 # Source files to compile using Emscripten.
13 IN_FILES="zstd.c examples/roundtrip.c"
14
15 # Emscripten build using emcc.
16 emscripten_emcc_build() {
17   # Compile the same example as above
18   CC_FLAGS="-Wall -Wextra -Wshadow -Werror -Os -g0 -flto"
19   emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
20   # Did compilation work?
21   if [ $? -ne 0 ]; then
22     echo "Compiling ${IN_FILES}: FAILED"
23     exit 1
24   fi
25   echo "Compiling ${IN_FILES}: PASSED"
26   rm -f $OUT_WASM
27 }
28
29 # Emscripten build using docker.
30 emscripten_docker_build() {
31   docker container run --rm \
32     --volume $PWD:/code \
33     --workdir /code \
34     emscripten/emsdk:latest \
35     emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
36   # Did compilation work?
37   if [ $? -ne 0 ]; then
38       echo "Compiling ${IN_FILES} (using docker): FAILED"
39     exit 1
40   fi
41   echo "Compiling ${IN_FILES} (using docker): PASSED"
42   rm -f $OUT_WASM
43 }
44
45 # Try Emscripten build using emcc or docker.
46 try_emscripten_build() {
47   which emcc > /dev/null
48   if [ $? -eq 0 ]; then
49     emscripten_emcc_build
50     return $?
51   fi
52
53   which docker > /dev/null
54   if [ $? -eq 0 ]; then
55     emscripten_docker_build
56     return $?
57   fi
58
59   echo "(Skipping Emscripten test)"
60 }
61
62 # Amalgamate the sources
63 ./create_single_file_library.sh
64 # Did combining work?
65 if [ $? -ne 0 ]; then
66   echo "Single file library creation script: FAILED"
67   exit 1
68 fi
69 echo "Single file library creation script: PASSED"
70
71 # Copy the header to here (for the tests)
72 cp "$ZSTD_SRC_ROOT/zstd.h" examples/zstd.h
73
74 # Compile the generated output
75 cc -Wall -Wextra -Werror -Wshadow -pthread -I. -Os -g0 -o $OUT_FILE zstd.c examples/roundtrip.c
76 # Did compilation work?
77 if [ $? -ne 0 ]; then
78   echo "Compiling roundtrip.c: FAILED"
79   exit 1
80 fi
81 echo "Compiling roundtrip.c: PASSED"
82
83 # Run then delete the compiled output
84 ./$OUT_FILE
85 retVal=$?
86 rm -f $OUT_FILE
87 # Did the test work?
88 if [ $retVal -ne 0 ]; then
89   echo "Running roundtrip.c: FAILED"
90   exit 1
91 fi
92 echo "Running roundtrip.c: PASSED"
93
94 # Try Emscripten build if emcc or docker command is available.
95 try_emscripten_build
96
97 exit 0