blob: 5d3592edaf54c49b292875f282211cf690aff079 [file] [log] [blame]
Elliott Hughes820eced2021-08-20 18:00:50 -07001#!/usr/bin/env bash
2
3# This script runs one build with setup environment variables: BUILD_LIBPCAP,
4# REMOTE, CC, CMAKE, CRYPTO and SMB
5# (default: BUILD_LIBPCAP=no, REMOTE=no, CC=gcc, CMAKE=no, CRYPTO=no, SMB=no).
6
7set -e
8
9# BUILD_LIBPCAP: no or yes
10BUILD_LIBPCAP=${BUILD_LIBPCAP:-no}
11# REMOTE: no or yes
12REMOTE=${REMOTE:-no}
13# CC: gcc or clang
14CC=${CC:-gcc}
15# GCC and Clang recognize --version and print to stdout. Sun compilers
16# recognize -V and print to stderr.
17"$CC" --version 2>/dev/null || "$CC" -V || :
18# CMAKE: no or yes
19CMAKE=${CMAKE:-no}
20# CRYPTO: no or yes
21CRYPTO=${CRYPTO:-no}
22# SMB: no or yes
23SMB=${SMB:-no}
24# Install directory prefix
25if [ -z "$PREFIX" ]; then
26 PREFIX=$(mktemp -d -t tcpdump_build_XXXXXXXX)
27 echo "PREFIX set to '$PREFIX'"
28fi
29# For TESTrun
30export TCPDUMP_BIN="$PREFIX/bin/tcpdump"
31
32travis_fold() {
33 local action=${1:?}
34 local name=${2:?}
35 if [ "$TRAVIS" != true ]; then return; fi
36 echo -ne "travis_fold:$action:$LABEL.script.$name\\r"
37 sleep 1
38}
39
40# Run a command after displaying it
41run_after_echo() {
42 echo -n '$ '
43 echo "$@"
44 # shellcheck disable=SC2068
45 $@
46}
47
48# LABEL is needed to build the travis fold labels
49LABEL="$BUILD_LIBPCAP.$REMOTE.$CC.$CMAKE.$CRYPTO.$SMB"
50if [ "$CMAKE" = no ]; then
51 echo '$ ./configure [...]'
52 travis_fold start configure
53 if [ "$BUILD_LIBPCAP" = yes ]; then
54 echo "Using PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
55 ./configure --with-crypto="$CRYPTO" --enable-smb="$SMB" --prefix="$PREFIX"
56 export LD_LIBRARY_PATH="$PREFIX/lib"
57 else
58 ./configure --disable-local-libpcap --with-crypto="$CRYPTO" --enable-smb="$SMB" --prefix="$PREFIX"
59 fi
60 travis_fold end configure
61else
62 rm -rf build
63 mkdir build
64 cd build
65 echo '$ cmake [...]'
66 travis_fold start cmake
67 if [ "$BUILD_LIBPCAP" = yes ]; then
68 cmake -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" -DCMAKE_PREFIX_PATH="$PREFIX" -DCMAKE_INSTALL_PREFIX="$PREFIX" ..
69 export LD_LIBRARY_PATH="$PREFIX/lib"
70 else
71 cmake -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" -DCMAKE_INSTALL_PREFIX="$PREFIX" ..
72 fi
73 travis_fold end cmake
74fi
75run_after_echo "make -s clean"
76run_after_echo "make -s CFLAGS=-Werror"
77echo '$ make install'
78travis_fold start make_install
79make install
80travis_fold end make_install
81run_after_echo "$TCPDUMP_BIN --version"
82run_after_echo "$TCPDUMP_BIN -h"
83run_after_echo "$TCPDUMP_BIN -D"
84system=$(uname -s)
85if [ "$system" = Linux ]; then
86 run_after_echo "ldd $TCPDUMP_BIN"
87fi
88if [ "$TRAVIS" = true ]; then
89 if [ -n "$LD_LIBRARY_PATH" ]; then
90 run_after_echo "sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $TCPDUMP_BIN -J"
91 run_after_echo "sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $TCPDUMP_BIN -L"
92 else
93 run_after_echo "sudo $TCPDUMP_BIN -J"
94 run_after_echo "sudo $TCPDUMP_BIN -L"
95 fi
96fi
97if [ "$BUILD_LIBPCAP" = yes ]; then
98 run_after_echo "make check"
99fi
100if [ "$CMAKE" = no ]; then
101 system=$(uname -s)
102 if [ "$system" = Darwin ] || [ "$system" = Linux ]; then
103 run_after_echo "make releasetar"
104 fi
105fi
106if [ "$TRAVIS" = true ]; then
107 if [ "$TRAVIS_OS_NAME" = linux ] && [ "$TRAVIS_CPU_ARCH" != ppc64le ] && [ "$TRAVIS_CPU_ARCH" != s390x ] && [ "$TRAVIS_CPU_ARCH" != arm64 ]; then
108 if [ -n "$LD_LIBRARY_PATH" ]; then
109 run_after_echo "sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $TCPDUMP_BIN -#n -c 10"
110 else
111 run_after_echo "sudo $TCPDUMP_BIN -#n -c 10"
112 fi
113 fi
114fi
115# The DEBUG_BUILD variable is not set by default to avoid Travis error message:
116# "The job exceeded the maximum log length, and has been terminated."
117# Setting it needs to reduce the matrix cases.
118if [ "$TRAVIS" = true ] && [ -n "$DEBUG_BUILD" ] ; then
119 echo '$ cat Makefile [...]'
120 travis_fold start cat_makefile
121 sed '/DO NOT DELETE THIS LINE -- mkdep uses it/q' < Makefile
122 travis_fold end cat_makefile
123 echo '$ cat config.h'
124 travis_fold start cat_config_h
125 cat config.h
126 travis_fold end cat_config_h
127 if [ "$CMAKE" = no ]; then
128 echo '$ cat config.log'
129 travis_fold start cat_config_log
130 cat config.log
131 travis_fold end cat_config_log
132 fi
133fi
134if [ "$DELETE_PREFIX" = yes ]; then
135 rm -rf "$PREFIX"
136fi
137# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :