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