1#!/bin/sh -e
2
3DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
5ECHO=echo
6RM="rm -f"
7GREP="grep"
8INTOVOID="/dev/null"
9
10die() {
11    $ECHO "$@" 1>&2
12    exit 1
13}
14
15isPresent() {
16    $GREP $@ tmplog || die "$@" "should be present"
17}
18
19mustBeAbsent() {
20    $GREP $@ tmplog && die "$@ should not be there !!"
21    $ECHO "$@ correctly not present"  # for some reason, this $ECHO must exist, otherwise mustBeAbsent() always fails (??)
22}
23
24# default compilation : all features enabled
25make clean > /dev/null
26$ECHO "testing default library compilation"
27CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID
28nm $DIR/../lib/libzstd.a | $GREP "\.o" > tmplog
29isPresent "zstd_compress.o"
30isPresent "zstd_decompress.o"
31isPresent "zdict.o"
32isPresent "zstd_v07.o"
33isPresent "zbuff_compress.o"
34$RM $DIR/../lib/libzstd.a tmplog
35
36# compression disabled => also disable zdict and zbuff
37$ECHO "testing with compression disabled"
38ZSTD_LIB_COMPRESSION=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID
39nm $DIR/../lib/libzstd.a | $GREP "\.o" > tmplog
40mustBeAbsent "zstd_compress.o"
41isPresent "zstd_decompress.o"
42mustBeAbsent "zdict.o"
43isPresent "zstd_v07.o"
44mustBeAbsent "zbuff_compress.o"
45$RM $DIR/../lib/libzstd.a tmplog
46
47# decompression disabled => also disable legacy and zbuff
48$ECHO "testing with decompression disabled"
49ZSTD_LIB_DECOMPRESSION=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID
50nm $DIR/../lib/libzstd.a | $GREP "\.o" > tmplog
51isPresent "zstd_compress.o"
52mustBeAbsent "zstd_decompress.o"
53isPresent "zdict.o"
54mustBeAbsent "zstd_v07.o"
55mustBeAbsent "zbuff_compress.o"
56$RM $DIR/../lib/libzstd.a tmplog
57
58# deprecated function disabled => only remove zbuff
59$ECHO "testing with deprecated functions disabled"
60ZSTD_LIB_DEPRECATED=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID
61nm $DIR/../lib/libzstd.a | $GREP "\.o" > tmplog
62isPresent "zstd_compress.o"
63isPresent "zstd_decompress.o"
64isPresent "zdict.o"
65isPresent "zstd_v07.o"
66mustBeAbsent "zbuff_compress.o"
67$RM $DIR/../lib/libzstd.a tmplog
68
69# dictionary builder disabled => only remove zdict
70$ECHO "testing with dictionary builder disabled"
71ZSTD_LIB_DICTBUILDER=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID
72nm $DIR/../lib/libzstd.a | $GREP "\.o" > tmplog
73isPresent "zstd_compress.o"
74isPresent "zstd_decompress.o"
75mustBeAbsent "zdict.o"
76isPresent "zstd_v07.o"
77isPresent "zbuff_compress.o"
78$RM $DIR/../lib/libzstd.a tmplog
79
80# both decompression and dictionary builder disabled => only compression remains
81$ECHO "testing with both decompression and dictionary builder disabled (only compression remains)"
82ZSTD_LIB_DECOMPRESSION=0 ZSTD_LIB_DICTBUILDER=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID
83nm $DIR/../lib/libzstd.a | $GREP "\.o" > tmplog
84isPresent "zstd_compress.o"
85mustBeAbsent "zstd_decompress.o"
86mustBeAbsent "zdict.o"
87mustBeAbsent "zstd_v07.o"
88mustBeAbsent "zbuff_compress.o"
89$RM $DIR/../lib/libzstd.a tmplog
90