]> The Tcpdump Group git mirrors - libpcap/blob - build.sh
ATM: Simplify protocol and message type handling.
[libpcap] / build.sh
1 #!/bin/sh -e
2
3 # This script runs one build with setup environment variables: CC, CMAKE, IPV6
4 # and REMOTE.
5 : "${CC:=gcc}"
6 : "${CMAKE:=no}"
7 : "${IPV6:=no}"
8 : "${REMOTE:=no}"
9 : "${LIBPCAP_TAINTED:=no}"
10 : "${LIBPCAP_CMAKE_TAINTED:=no}"
11 : "${MAKE_BIN:=make}"
12 # At least one OS (AIX 7) where this software can build does not have at least
13 # one command (mktemp) required for a successful run of "make releasetar".
14 : "${TEST_RELEASETAR:=yes}"
15
16 . ./build_common.sh
17 # Install directory prefix
18 if [ -z "$PREFIX" ]; then
19 PREFIX=`mktempdir libpcap_build`
20 echo "PREFIX set to '$PREFIX'"
21 DELETE_PREFIX=yes
22 fi
23
24 print_cc_version
25
26 # The norm is to compile without any warnings, but libpcap builds on some OSes
27 # are not warning-free for one or another reason. If you manage to fix one of
28 # these cases, please remember to remove respective exemption below to help any
29 # later warnings in the same matrix subset trigger an error.
30 # shellcheck disable=SC2221,SC2222
31 case `cc_id`/`os_id` in
32 tcc-*/*)
33 # At least one warning is expected because TCC does not implement
34 # thread-local storage.
35 LIBPCAP_TAINTED=yes
36 ;;
37 clang-3.4/Linux-*)
38 # pcap-netfilter-linux.c:427:10: error: will never be executed
39 # [-Werror,-Wunreachable-code]
40 # pcap.c:3812:4: error: will never be executed
41 # [-Werror,-Wunreachable-code]
42 # scanner.l:662:3: warning: will never be executed [-Wunreachable-code]
43 # gencode.c:7061:3: warning: will never be executed [-Wunreachable-code]
44 LIBPCAP_TAINTED=yes
45 ;;
46 suncc-5.15/SunOS-5.10)
47 # (Sun C 5.15 on Solaris 11.4 does not generate any of these warnings.)
48 # "./gencode.c", line 599: warning: function "bpf_error" marked as not
49 # returning, might return
50 # "optimize.c", line 2409: warning: function "opt_error" marked as not
51 # returning, might return
52 # "optimize.c", line 2915: warning: function "conv_error" marked as not
53 # returning, might return
54 # "./can_set_rfmon_test.c", line 95: warning: function "error" marked as
55 # not returning, might return
56 # "./capturetest.c", line 314: warning: function "usage" marked as not
57 # returning, might return
58 # "./capturetest.c", line 333: warning: function "error" marked as not
59 # returning, might return
60 # "./filtertest.c", line 163: warning: function "error" marked as not
61 # returning, might return
62 # "./filtertest.c", line 478: warning: function "usage" marked as not
63 # returning, might return
64 # "./opentest.c", line 222: warning: function "usage" marked as not
65 # returning, might return
66 # "./opentest.c", line 241: warning: function "error" marked as not
67 # returning, might return
68 # "./nonblocktest.c", line 69: warning: function "error" marked as not
69 # returning, might return
70 # "./nonblocktest.c", line 94: warning: function "usage" marked as not
71 # returning, might return
72 # "./reactivatetest.c", line 89: warning: function "error" marked as not
73 # returning, might return
74 # "./selpolltest.c", line 375: warning: function "usage" marked as not
75 # returning, might return
76 # "./selpolltest.c", line 394: warning: function "error" marked as not
77 # returning, might return
78 # "./threadsignaltest.c", line 339: warning: function "usage" marked as
79 # not returning, might return
80 # "./threadsignaltest.c", line 358: warning: function "error" marked as
81 # not returning, might return
82 # "./writecaptest.c", line 490: warning: function "usage" marked as not
83 # returning, might return
84 # "./writecaptest.c", line 509: warning: function "error" marked as not
85 # returning, might return
86 LIBPCAP_TAINTED=yes
87 ;;
88 *)
89 ;;
90 esac
91 [ "$LIBPCAP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
92
93 case `cc_id`/`os_id` in
94 clang-*/SunOS-5.11)
95 # Work around https://www.illumos.org/issues/16369
96 [ "`uname -o`" = illumos ] && grep -Fq OpenIndiana /etc/release && CFLAGS="-Wno-fuse-ld-path${CFLAGS:+ $CFLAGS}"
97 ;;
98 esac
99
100 # If necessary, set LIBPCAP_CMAKE_TAINTED here to exempt particular cmake from
101 # warnings. Use as specific terms as possible (e.g. some specific version and
102 # some specific OS).
103
104 [ "$LIBPCAP_CMAKE_TAINTED" != yes ] && CMAKE_OPTIONS='-Werror=dev'
105
106 if [ "$CMAKE" = no ]; then
107 run_after_echo ./autogen.sh
108 run_after_echo ./configure --prefix="$PREFIX" --enable-ipv6="$IPV6" --enable-remote="$REMOTE"
109 else
110 # Remove the leftovers from any earlier in-source builds, so this
111 # out-of-source build does not break because of that.
112 # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#what-is-an-out-of-source-build
113 # (The contents of build/ remaining after an earlier unsuccessful attempt
114 # can fail subsequent build attempts too, sometimes in non-obvious ways,
115 # so remove that directory as well.)
116 run_after_echo rm -rf CMakeFiles/ CMakeCache.txt build/
117 run_after_echo mkdir build
118 run_after_echo cd build
119 run_after_echo cmake --version
120 run_after_echo cmake ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
121 ${CMAKE_OPTIONS:+"$CMAKE_OPTIONS"} \
122 -DCMAKE_INSTALL_PREFIX="$PREFIX" -DINET6="$IPV6" -DENABLE_REMOTE="$REMOTE" ..
123 fi
124 run_after_echo "$MAKE_BIN" -s clean
125 if [ "$CMAKE" = no ]; then
126 run_after_echo "$MAKE_BIN" -s ${CFLAGS:+CFLAGS="$CFLAGS"}
127 run_after_echo "$MAKE_BIN" -s testprogs ${CFLAGS:+CFLAGS="$CFLAGS"}
128 else
129 # The "-s" flag is a no-op and CFLAGS is set using -DEXTRA_CFLAGS above.
130 run_after_echo "$MAKE_BIN"
131 run_after_echo "$MAKE_BIN" testprogs
132 fi
133 run_after_echo "$MAKE_BIN" install
134
135 run_after_echo "$PREFIX/bin/pcap-config" --help
136 run_after_echo "$PREFIX/bin/pcap-config" --version
137 run_after_echo "$PREFIX/bin/pcap-config" --cflags
138 run_after_echo "$PREFIX/bin/pcap-config" --libs
139 run_after_echo "$PREFIX/bin/pcap-config" --additional-libs
140 run_after_echo "$PREFIX/bin/pcap-config" --libs --static
141 run_after_echo "$PREFIX/bin/pcap-config" --additional-libs --static
142 run_after_echo "$PREFIX/bin/pcap-config" --libs --static-pcap-only
143 run_after_echo "$PREFIX/bin/pcap-config" --additional-libs --static-pcap-only
144
145 [ "$REMOTE" = yes ] && run_after_echo "$PREFIX/sbin/rpcapd" -h
146
147 # VALGRIND_CMD is meant either to collapse or to expand.
148 # shellcheck disable=SC2086
149 if [ "$CMAKE" = no ]; then
150 FILTERTEST_BIN="$VALGRIND_CMD testprogs/filtertest"
151 export FILTERTEST_BIN
152 run_after_echo "$MAKE_BIN" -s check
153 run_after_echo $VALGRIND_CMD testprogs/findalldevstest
154 [ "$TEST_RELEASETAR" = yes ] && run_after_echo "$MAKE_BIN" releasetar
155 else
156 FILTERTEST_BIN="$VALGRIND_CMD run/filtertest"
157 export FILTERTEST_BIN
158 run_after_echo "$MAKE_BIN" -s check
159 run_after_echo $VALGRIND_CMD run/findalldevstest
160 fi
161 handle_matrix_debug
162 if [ "$DELETE_PREFIX" = yes ]; then
163 run_after_echo rm -rf "$PREFIX"
164 fi
165 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :