aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cirrus.yml2
-rwxr-xr-xbuild.sh69
-rw-r--r--build_common.sh149
-rwxr-xr-xbuild_matrix.sh46
4 files changed, 194 insertions, 72 deletions
diff --git a/.cirrus.yml b/.cirrus.yml
index 43dd183f..83376f8e 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -39,7 +39,7 @@ linux_task:
- apt-get -qy update
- apt-get -qy install libdbus-1-dev libbluetooth-dev libnl-genl-3-dev libibverbs-dev
- apt-get -qy install flex bison autoconf make clang gcc
- - apt-get -qy install cmake git # for build_matrix.sh and build.sh
+ - apt-get -qy install cmake git bc # for build_matrix.sh and build.sh
- apt list --installed 'lib*-dev'
- ./build_matrix.sh
diff --git a/build.sh b/build.sh
index c2b80479..c28a83b7 100755
--- a/build.sh
+++ b/build.sh
@@ -1,69 +1,44 @@
#!/bin/sh -e
# This script runs one build with setup environment variables: CC, CMAKE and
-# REMOTE (default: CC=gcc, CMAKE=no, REMOTE=no).
+# REMOTE.
+: "${CC:=gcc}"
+: "${CMAKE:=no}"
+: "${REMOTE:=no}"
-# CC: gcc or clang
-CC=${CC:-gcc}
-# GCC and Clang recognize --version and print to stdout. Sun compilers
-# recognize -V and print to stderr.
-"$CC" --version 2>/dev/null || "$CC" -V || :
-# CMAKE: no or yes
-CMAKE=${CMAKE:-no}
-# REMOTE: no or yes
-REMOTE=${REMOTE:-no}
+. ./build_common.sh
# Install directory prefix
if [ -z "$PREFIX" ]; then
- PREFIX=$(mktemp -d -t libpcap_build_XXXXXXXX)
+ # shellcheck disable=SC2006
+ PREFIX=`mktempdir libpcap_build`
echo "PREFIX set to '$PREFIX'"
DELETE_PREFIX=yes
fi
-# Run a command after displaying it
-run_after_echo() {
- printf '$ '
- echo "$@"
- # shellcheck disable=SC2068
- $@
-}
-
+print_cc_version
if [ "$CMAKE" = no ]; then
- echo '$ ./configure [...]'
- ./configure --prefix="$PREFIX" --enable-remote="$REMOTE"
+ run_after_echo ./configure --prefix="$PREFIX" --enable-remote="$REMOTE"
else
# Remove the leftovers from any earlier in-source builds, so this
# out-of-source build does not break because of that.
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#what-is-an-out-of-source-build
- rm -rf CMakeFiles/ CMakeCache.txt
- [ ! -d build ] && mkdir build
- cd build
- echo '$ cmake [...]'
- cmake -DCMAKE_INSTALL_PREFIX="$PREFIX" -DENABLE_REMOTE="$REMOTE" ..
+ run_after_echo rm -rf CMakeFiles/ CMakeCache.txt
+ [ ! -d build ] && run_after_echo mkdir build
+ run_after_echo cd build
+ run_after_echo cmake -DCMAKE_INSTALL_PREFIX="$PREFIX" -DENABLE_REMOTE="$REMOTE" ..
fi
-run_after_echo "make -s clean"
-run_after_echo "make -s"
-run_after_echo "make -s testprogs"
-echo '$ make install'
-make install
+run_after_echo make -s clean
+run_after_echo make -s
+run_after_echo make -s testprogs
+run_after_echo make install
if [ "$CMAKE" = no ]; then
- run_after_echo "testprogs/findalldevstest"
+ run_after_echo testprogs/findalldevstest
+ run_after_echo make releasetar
else
- run_after_echo "run/findalldevstest"
-fi
-if [ "$CMAKE" = no ]; then
- run_after_echo "make releasetar"
-fi
-if [ "$MATRIX_DEBUG" = true ]; then
- echo '$ cat Makefile [...]'
- sed '/^# DO NOT DELETE THIS LINE -- mkdep uses it.$/q' < Makefile
- echo '$ cat config.h'
- cat config.h
- if [ "$CMAKE" = no ]; then
- echo '$ cat config.log'
- cat config.log
- fi
+ run_after_echo run/findalldevstest
fi
+handle_matrix_debug
if [ "$DELETE_PREFIX" = yes ]; then
- rm -rf "$PREFIX"
+ run_after_echo rm -rf "$PREFIX"
fi
# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :
diff --git a/build_common.sh b/build_common.sh
new file mode 100644
index 00000000..0209806e
--- /dev/null
+++ b/build_common.sh
@@ -0,0 +1,149 @@
+#!/bin/sh -e
+
+# The only purpose of the above shebang is to orient shellcheck right.
+# To make CI scripts maintenance simpler, copies of this file in the
+# libpcap, tcpdump and tcpslice git repositories should be identical.
+# Please mind that Solaris /bin/sh before 11 does not support the $()
+# command substitution syntax, hence the SC2006 directives.
+
+# A poor man's mktemp(1) for OSes that don't have one (e.g. AIX 7, Solaris 9).
+mktempdir_diy() {
+ while true; do
+ # /bin/sh implements $RANDOM in AIX 7, but not in Solaris before 11,
+ # thus use dd and od instead.
+ # shellcheck disable=SC2006
+ mktempdir_diy_suffix=`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -t x -A n | head -1 | tr -d '\t '`
+ [ -z "$mktempdir_diy_suffix" ] && return 1
+ mktempdir_diy_path="${TMPDIR:-/tmp}/${1:?}.${mktempdir_diy_suffix}"
+ # "test -e" would be more appropriate, but it is not available in
+ # Solaris /bin/sh before 11.
+ if [ ! -d "$mktempdir_diy_path" ]; then
+ mkdir "$mktempdir_diy_path"
+ chmod go= "$mktempdir_diy_path"
+ echo "$mktempdir_diy_path"
+ break
+ fi
+ # Try again (AIX /dev/urandom returns zeroes quite often).
+ done
+}
+
+mktempdir() {
+ mktempdir_prefix=${1:-tmp}
+ # shellcheck disable=SC2006
+ case `uname -s` in
+ Darwin|FreeBSD|NetBSD)
+ # In these operating systems mktemp(1) always appends an implicit
+ # ".XXXXXXXX" suffix to the requested template when creating a
+ # temporary directory.
+ mktemp -d -t "$mktempdir_prefix"
+ ;;
+ AIX)
+ mktempdir_diy "$mktempdir_prefix"
+ ;;
+ SunOS)
+ # shellcheck disable=SC2006
+ case `uname -r` in
+ 5.10|5.11)
+ mktemp -d -t "${mktempdir_prefix}.XXXXXXXX"
+ ;;
+ *)
+ mktempdir_diy "$mktempdir_prefix"
+ ;;
+ esac
+ ;;
+ *)
+ # At least Linux and OpenBSD implementations require explicit trailing
+ # X'es in the template, so make it the same suffix as above.
+ mktemp -d -t "${mktempdir_prefix}.XXXXXXXX"
+ ;;
+ esac
+}
+
+print_sysinfo() {
+ uname -a
+ date
+}
+
+print_cc_version() {
+ # shellcheck disable=SC2006
+ case `basename "$CC"` in
+ gcc*|clang*)
+ # GCC and Clang recognize --version, print to stdout and exit with 0.
+ "$CC" --version
+ ;;
+ xl*)
+ # XL C for AIX recognizes -qversion, prints to stdout and exits with 0,
+ # but on an unknown command-line flag displays its man page and waits.
+ "$CC" -qversion
+ ;;
+ sun*)
+ # Sun compilers recognize -V, print to stderr and exit with an error.
+ "$CC" -V 2>&1 || :
+ ;;
+ *)
+ "$CC" --version || "$CC" -V || :
+ ;;
+ esac
+}
+
+increment() {
+ # No arithmetic expansion in Solaris /bin/sh before 11.
+ echo "${1:?} + 1" | bc
+}
+
+# Display text in magenta.
+echo_magenta() {
+ # ANSI magenta, the imploded text, ANSI reset, newline.
+ printf '\033[35;1m%s\033[0m\n' "$*"
+}
+
+# Run a command after displaying it.
+run_after_echo() {
+ : "${1:?}" # Require at least one argument.
+ printf '$ %s\n' "$*"
+ "$@"
+}
+
+print_so_deps() {
+ case `uname -s` in
+ Darwin)
+ run_after_echo otool -L "${1:?}"
+ ;;
+ *)
+ run_after_echo ldd "${1:?}"
+ ;;
+ esac
+}
+
+# Beware that setting MATRIX_DEBUG for tcpdump or tcpslice will produce A LOT
+# of additional output there and in any nested libpcap builds. Multiplied by
+# the matrix size, the full output log size might exceed limits of some CI
+# systems (as it had previously happened with Travis CI). Use with caution on
+# a reduced matrix.
+handle_matrix_debug() {
+ [ "$MATRIX_DEBUG" != yes ] && return
+ echo '$ cat Makefile [...]'
+ sed '/^# DO NOT DELETE THIS LINE -- mkdep uses it.$/q' <Makefile
+ run_after_echo cat config.h
+ [ "$CMAKE" = yes ] || run_after_echo cat config.log
+}
+
+purge_directory() {
+ # shellcheck disable=SC2006
+ if [ "`uname -s`" = SunOS ] && [ "`uname -r`" = 5.11 ]; then
+ # In Solaris 11 /bin/sh the pathname expansion of "*" always includes
+ # "." and "..", so the straightforward rm would always fail.
+ (
+ cd "${1:?}"
+ for pd_each in *; do
+ if [ "$pd_each" != . ] && [ "$pd_each" != .. ]; then
+ rm -rf "$pd_each"
+ fi
+ done
+ )
+ else
+ rm -rf "${1:?}"/*
+ fi
+}
+
+# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :
diff --git a/build_matrix.sh b/build_matrix.sh
index dbaec9b6..c2c9e3c6 100755
--- a/build_matrix.sh
+++ b/build_matrix.sh
@@ -1,54 +1,52 @@
#!/bin/sh -e
# This script executes the matrix loops, exclude tests and cleaning.
-# The matrix can be configured with environment variables MATRIX_CC,
-# MATRIX_CMAKE and MATRIX_REMOTE (default: MATRIX_CC='gcc clang',
-# MATRIX_CMAKE='no yes', MATRIX_REMOTE='no yes').
+# The matrix can be configured with the following environment variables: MATRIX_CC,
+# MATRIX_CMAKE and MATRIX_REMOTE.
+: "${MATRIX_CC:=gcc clang}"
+: "${MATRIX_CMAKE:=no yes}"
+: "${MATRIX_REMOTE:=no yes}"
# It calls the build.sh script which runs one build with setup environment
-# variables : CC, CMAKE and REMOTE (default: CC=gcc, CMAKE=no, REMOTE=no).
+# variables: CC, CMAKE and REMOTE.
-uname -a
-date
+. ./build_common.sh
+print_sysinfo
# Install directory prefix
if [ -z "$PREFIX" ]; then
- PREFIX=$(mktemp -d -t libpcap_build_matrix_XXXXXXXX)
+ # shellcheck disable=SC2006
+ PREFIX=`mktempdir libpcap_build_matrix`
echo "PREFIX set to '$PREFIX'"
export PREFIX
fi
COUNT=0
-# Display text in magenta
-echo_magenta() {
- printf '\033[35;1m' # ANSI magenta
- echo "$@"
- printf '\033[0m' # ANSI reset
-}
-
touch .devel configure
-for CC in ${MATRIX_CC:-gcc clang}; do
+for CC in $MATRIX_CC; do
export CC
# Exclude gcc on macOS (it is just an alias for clang).
- if [ "$CC" = gcc ] && [ "$(uname -s)" = Darwin ]; then
+ # shellcheck disable=SC2006
+ if [ "$CC" = gcc ] && [ "`uname -s`" = Darwin ]; then
echo '(skipped)'
continue
fi
- for CMAKE in ${MATRIX_CMAKE:-no yes}; do
+ for CMAKE in $MATRIX_CMAKE; do
export CMAKE
- for REMOTE in ${MATRIX_REMOTE:-no yes}; do
+ for REMOTE in $MATRIX_REMOTE; do
export REMOTE
- COUNT=$((COUNT+1))
+ # shellcheck disable=SC2006
+ COUNT=`increment $COUNT`
echo_magenta "===== SETUP $COUNT: CC=$CC CMAKE=$CMAKE REMOTE=$REMOTE ====="
# Run one build with setup environment variables: CC, CMAKE and REMOTE
- ./build.sh
+ run_after_echo ./build.sh
echo 'Cleaning...'
if [ "$CMAKE" = yes ]; then rm -rf build; else make distclean; fi
- rm -rf "${PREFIX:?}"/*
- git status -suall
+ purge_directory "$PREFIX"
+ run_after_echo git status -suall
# Cancel changes in configure
- git checkout configure
+ run_after_echo git checkout configure
done
done
done
-rm -rf "$PREFIX"
+run_after_echo rm -rf "$PREFIX"
echo_magenta "Tested setup count: $COUNT"
# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :