]> The Tcpdump Group git mirrors - tcpdump/blob - build.sh
Have a #define to squelch -Wunused-result warnings.
[tcpdump] / build.sh
1 #!/bin/sh -e
2
3 # This script runs one build with setup environment variables: BUILD_LIBPCAP,
4 # REMOTE, CC, CMAKE, CRYPTO and SMB.
5
6 : "${BUILD_LIBPCAP:=no}"
7 : "${REMOTE:=no}"
8 : "${CC:=gcc}"
9 : "${CMAKE:=no}"
10 : "${CRYPTO:=no}"
11 : "${SMB:=no}"
12 : "${TCPDUMP_TAINTED:=no}"
13 : "${TCPDUMP_CMAKE_TAINTED:=no}"
14 : "${MAKE_BIN:=make}"
15 # At least one OS (AIX 7) where this software can build does not have at least
16 # one command (mktemp) required for a successful run of "make releasetar".
17 : "${TEST_RELEASETAR:=yes}"
18
19 . ./build_common.sh
20 # Install directory prefix
21 if [ -z "$PREFIX" ]; then
22 PREFIX=`mktempdir tcpdump_build`
23 echo "PREFIX set to '$PREFIX'"
24 DELETE_PREFIX=yes
25 fi
26 TCPDUMP_BIN="$PREFIX/bin/tcpdump"
27 # For TESTrun
28 export TCPDUMP_BIN
29
30 print_cc_version
31
32 # The norm is to compile without any warnings, but tcpdump builds on some OSes
33 # are not warning-free for one or another reason. If you manage to fix one of
34 # these cases, please remember to remove respective exemption below to help any
35 # later warnings in the same matrix subset trigger an error.
36
37 case `cc_id`/`os_id` in
38 clang-*/SunOS-5.11)
39 # (Clang 9 on OpenIndiana, Clang 11 on OmniOS)
40 # tcpdump.c:2312:51: warning: this function declaration is not a prototype
41 # [-Wstrict-prototypes]
42 # tcpdump.c:2737:11: warning: this function declaration is not a prototype
43 # [-Wstrict-prototypes]
44 [ "`uname -o`" = illumos ] && TCPDUMP_TAINTED=yes
45 ;;
46 esac
47
48 [ "$TCPDUMP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
49
50 # If necessary, set TCPDUMP_CMAKE_TAINTED here to exempt particular cmake from
51 # warnings. Use as specific terms as possible (e.g. some specific version and
52 # some specific OS).
53
54 [ "$TCPDUMP_CMAKE_TAINTED" != yes ] && CMAKE_OPTIONS='-Werror=dev'
55
56 if [ "$CMAKE" = no ]; then
57 if [ "$BUILD_LIBPCAP" = yes ]; then
58 echo "Using PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
59 run_after_echo ./autogen.sh
60 run_after_echo ./configure --with-crypto="$CRYPTO" \
61 --enable-smb="$SMB" --prefix="$PREFIX"
62 LD_LIBRARY_PATH="$PREFIX/lib"
63 export LD_LIBRARY_PATH
64 else
65 run_after_echo ./autogen.sh
66 run_after_echo ./configure --with-crypto="$CRYPTO" \
67 --enable-smb="$SMB" --prefix="$PREFIX" --disable-local-libpcap
68 fi
69 else
70 # See libpcap build.sh for the rationale.
71 run_after_echo rm -rf CMakeFiles/ CMakeCache.txt build/
72 run_after_echo mkdir build
73 run_after_echo cd build
74 if [ "$BUILD_LIBPCAP" = yes ]; then
75 run_after_echo cmake ${CMAKE_OPTIONS:+"$CMAKE_OPTIONS"} \
76 -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" \
77 ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
78 -DCMAKE_INSTALL_PREFIX="$PREFIX" -DCMAKE_PREFIX_PATH="$PREFIX" ..
79 LD_LIBRARY_PATH="$PREFIX/lib"
80 export LD_LIBRARY_PATH
81 else
82 run_after_echo cmake ${CMAKE_OPTIONS:+"$CMAKE_OPTIONS"} \
83 -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" \
84 ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
85 -DCMAKE_INSTALL_PREFIX="$PREFIX" ..
86 fi
87 fi
88 run_after_echo "$MAKE_BIN" -s clean
89 if [ "$CMAKE" = no ]; then
90 run_after_echo "$MAKE_BIN" -s ${CFLAGS:+CFLAGS="$CFLAGS"}
91 else
92 # The "-s" flag is a no-op and CFLAGS is set using -DEXTRA_CFLAGS above.
93 run_after_echo "$MAKE_BIN"
94 fi
95 run_after_echo "$MAKE_BIN" install
96 print_so_deps "$TCPDUMP_BIN"
97 run_after_echo "$TCPDUMP_BIN" -h
98 # The "-D" flag depends on HAVE_PCAP_FINDALLDEVS and it would not be difficult
99 # to run the command below only if the macro is defined. That said, it seems
100 # more useful to run it anyway: every system that currently runs this script
101 # has pcap_findalldevs(), thus if the macro isn't defined, it means something
102 # went wrong in the build process (as was observed with GCC, CMake and the
103 # system libpcap on Solaris 11).
104 run_after_echo "$TCPDUMP_BIN" -D
105 if [ "$CIRRUS_CI" = true ]; then
106 # Likewise for the "-J" flag and HAVE_PCAP_SET_TSTAMP_TYPE.
107 run_after_echo sudo \
108 ${LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$LD_LIBRARY_PATH"} \
109 "$TCPDUMP_BIN" -J
110 run_after_echo sudo \
111 ${LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$LD_LIBRARY_PATH"} \
112 "$TCPDUMP_BIN" -L
113 fi
114 if [ "$BUILD_LIBPCAP" = yes ]; then
115 run_after_echo "$MAKE_BIN" check
116 fi
117 if [ "$CMAKE" = no ]; then
118 [ "$TEST_RELEASETAR" = yes ] && run_after_echo "$MAKE_BIN" releasetar
119 fi
120 if [ "$CIRRUS_CI" = true ]; then
121 run_after_echo sudo \
122 ${LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$LD_LIBRARY_PATH"} \
123 "$TCPDUMP_BIN" -#n -c 10
124 fi
125 handle_matrix_debug
126 if [ "$DELETE_PREFIX" = yes ]; then
127 run_after_echo rm -rf "$PREFIX"
128 fi
129 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :