aboutsummaryrefslogtreecommitdiff
path: root/contrib/single_file_libs/build_library_test.sh
blob: 3b8b16a058056f128fccad49f2a2895b2db7244d (plain)
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
#!/bin/sh

# Where to find the sources (only used to copy zstd.h)
ZSTD_SRC_ROOT="../../lib"

# Temporary compiled binary
OUT_FILE="tempbin"

# Optional temporary compiled WebAssembly
OUT_WASM="temp.wasm"

# Amalgamate the sources
./create_single_file_library.sh
# Did combining work?
if [ $? -ne 0 ]; then
  echo "Single file library creation script: FAILED"
  exit 1
fi
echo "Single file library creation script: PASSED"

# Copy the header to here (for the tests)
cp "$ZSTD_SRC_ROOT/zstd.h" zstd.h

# Compile the generated output
cc -Wall -Wextra -Werror -pthread -I. -Os -g0 -o $OUT_FILE zstd.c examples/roundtrip.c
# Did compilation work?
if [ $? -ne 0 ]; then
  echo "Compiling roundtrip.c: FAILED"
  exit 1
fi
echo "Compiling roundtrip.c: PASSED"

# Run then delete the compiled output
./$OUT_FILE
retVal=$?
rm -f $OUT_FILE
# Did the test work?
if [ $retVal -ne 0 ]; then
  echo "Running roundtrip.c: FAILED"
  exit 1
fi
echo "Running roundtrip.c: PASSED"

# Is Emscripten available?
which emcc > /dev/null
if [ $? -ne 0 ]; then
  echo "(Skipping Emscripten test)"
else
  # Compile the the same example as above
  CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
  emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM zstd.c examples/roundtrip.c
  # Did compilation work?
  if [ $? -ne 0 ]; then
    echo "Compiling emscripten.c: FAILED"
    exit 1
  fi
  echo "Compiling emscripten.c: PASSED"
  rm -f $OUT_WASM
fi

exit 0