• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
21if [ -z "$PREFIX" ]; then
22    PREFIX=`mktempdir tcpdump_build`
23    echo "PREFIX set to '$PREFIX'"
24    DELETE_PREFIX=yes
25fi
26TCPDUMP_BIN="$PREFIX/bin/tcpdump"
27# For TESTrun
28export TCPDUMP_BIN
29
30print_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
37case `cc_id`/`os_id` in
38suncc-5.1[45]/SunOS-5.11)
39    # Various E_STATEMENT_NOT_REACHED and E_DEPRECATED_ATT warnings.
40    TCPDUMP_TAINTED=yes
41    ;;
42tcc-*/*)
43    # print-802_11.c:3317: warning: assignment discards qualifiers from pointer
44    #   target type
45    TCPDUMP_TAINTED=yes
46    ;;
47*)
48    ;;
49esac
50
51[ "$TCPDUMP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
52
53case `cc_id`/`os_id` in
54clang-*/SunOS-5.11)
55    # Work around https://www.illumos.org/issues/16369
56    [ "`uname -o`" = illumos ] && grep -Fq OpenIndiana /etc/release && CFLAGS="-Wno-fuse-ld-path${CFLAGS:+ $CFLAGS}"
57    ;;
58esac
59
60# If necessary, set TCPDUMP_CMAKE_TAINTED here to exempt particular cmake from
61# warnings. Use as specific terms as possible (e.g. some specific version and
62# some specific OS).
63
64[ "$TCPDUMP_CMAKE_TAINTED" != yes ] && CMAKE_OPTIONS='-Werror=dev'
65
66if [ "$CMAKE" = no ]; then
67    if [ "$BUILD_LIBPCAP" = yes ]; then
68        echo "Using PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
69        run_after_echo ./autogen.sh
70        run_after_echo ./configure --with-crypto="$CRYPTO" \
71            --enable-smb="$SMB" --prefix="$PREFIX"
72        LD_LIBRARY_PATH="$PREFIX/lib"
73        export LD_LIBRARY_PATH
74    else
75        run_after_echo ./autogen.sh
76        run_after_echo ./configure --with-crypto="$CRYPTO" \
77            --enable-smb="$SMB" --prefix="$PREFIX" --disable-local-libpcap
78    fi
79else
80    # See libpcap build.sh for the rationale.
81    run_after_echo rm -rf CMakeFiles/ CMakeCache.txt build/
82    run_after_echo mkdir build
83    run_after_echo cd build
84    if [ "$BUILD_LIBPCAP" = yes ]; then
85        run_after_echo cmake ${CMAKE_OPTIONS:+"$CMAKE_OPTIONS"} \
86            -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" \
87            ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
88            -DCMAKE_INSTALL_PREFIX="$PREFIX" -DCMAKE_PREFIX_PATH="$PREFIX" ..
89        LD_LIBRARY_PATH="$PREFIX/lib"
90        export LD_LIBRARY_PATH
91    else
92        run_after_echo cmake ${CMAKE_OPTIONS:+"$CMAKE_OPTIONS"} \
93            -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" \
94             ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
95            -DCMAKE_INSTALL_PREFIX="$PREFIX" ..
96    fi
97fi
98run_after_echo "$MAKE_BIN" -s clean
99if [ "$CMAKE" = no ]; then
100    run_after_echo "$MAKE_BIN" -s ${CFLAGS:+CFLAGS="$CFLAGS"}
101else
102    # The "-s" flag is a no-op and CFLAGS is set using -DEXTRA_CFLAGS above.
103    run_after_echo "$MAKE_BIN"
104fi
105run_after_echo "$MAKE_BIN" install
106print_so_deps "$TCPDUMP_BIN"
107run_after_echo "$TCPDUMP_BIN" -h
108# The "-D" flag depends on HAVE_PCAP_FINDALLDEVS and it would not be difficult
109# to run the command below only if the macro is defined.  That said, it seems
110# more useful to run it anyway: every system that currently runs this script
111# has pcap_findalldevs(), thus if the macro isn't defined, it means something
112# went wrong in the build process (as was observed with GCC, CMake and the
113# system libpcap on Solaris 11).
114run_after_echo "$TCPDUMP_BIN" -D
115if [ "$CIRRUS_CI" = true ]; then
116    # Likewise for the "-J" flag and HAVE_PCAP_SET_TSTAMP_TYPE.
117    run_after_echo sudo \
118        ${LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$LD_LIBRARY_PATH"} \
119        "$TCPDUMP_BIN" -J
120    run_after_echo sudo \
121        ${LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$LD_LIBRARY_PATH"} \
122        "$TCPDUMP_BIN" -L
123fi
124if [ "$BUILD_LIBPCAP" = yes ]; then
125    run_after_echo "$MAKE_BIN" check
126fi
127if [ "$CMAKE" = no ]; then
128    [ "$TEST_RELEASETAR" = yes ] && run_after_echo "$MAKE_BIN" releasetar
129fi
130if [ "$CIRRUS_CI" = true ]; then
131    run_after_echo sudo \
132        ${LD_LIBRARY_PATH:+LD_LIBRARY_PATH="$LD_LIBRARY_PATH"} \
133        "$TCPDUMP_BIN" -#n -c 10
134fi
135handle_matrix_debug
136if [ "$DELETE_PREFIX" = yes ]; then
137    run_after_echo rm -rf "$PREFIX"
138fi
139# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :
140