blob: 58b13b348173d5e541f8702961e6e10422538d98 [file] [log] [blame]
Andrew Jeffery22778042017-01-13 22:37:26 +10301#!/bin/sh
2
Andrew Jeffery72b854b2017-05-29 16:56:36 +09303set -eu
4
Andrew Jeffery22778042017-01-13 22:37:26 +10305AUTOCONF_FILES="Makefile.in aclocal.m4 ar-lib autom4te.cache compile \
6 config.guess config.h.in config.sub configure depcomp install-sh \
7 ltmain.sh missing *libtool test-driver"
8
Andrew Jeffery58b3cc02017-05-29 16:41:30 +09309BOOTSTRAP_MODE=""
10
11if [ $# -gt 0 ];
12then
13 BOOTSTRAP_MODE="${1}"
14 shift 1
15fi
16
17case "${BOOTSTRAP_MODE}" in
Andrew Jeffery81589cc2017-05-29 16:06:48 +093018 dev)
19 AX_CODE_COVERAGE_PATH="$(aclocal --print-ac-dir)"/ax_code_coverage.m4
Patrick Williamsad5dd0f2022-12-04 15:07:33 -060020 if [ ! -e "${AX_CODE_COVERAGE_PATH}" ];
Andrew Jeffery81589cc2017-05-29 16:06:48 +093021 then
22 echo "Failed to find AX_CODE_COVERAGE macro file at ${AX_CODE_COVERAGE_PATH}" 1>&2
23 exit 1
24 fi
25 LCOV_VERSION=$(lcov --version | tr ' ' '\n' | tail -1)
26
27 # Ubuntu Zesty ships with lcov v1.13, but Zesty's autoconf-archive
28 # package (the provider of the AX_CODE_COVERAGE macro) doesn't support
29 # it.
30 #
31 # sed-patch ax_code_coverage.m4 as it's GPLv3, and this is an Apache v2
32 # licensed repository. The licenses are not compatible in our desired
33 # direction[1].
34 #
35 # [1] https://www.apache.org/licenses/GPL-compatibility.html
36
Patrick Williamsad5dd0f2022-12-04 15:07:33 -060037 cp "${AX_CODE_COVERAGE_PATH}" m4/
38 # shellcheck disable=SC2086
Andrew Jeffery81589cc2017-05-29 16:06:48 +093039 sed -ri 's|(lcov_version_list=)"([ 0-9.]+)"$|\1"'${LCOV_VERSION}'"|' \
40 m4/ax_code_coverage.m4
41 ;;
Andrew Jeffery22778042017-01-13 22:37:26 +103042 clean)
43 test -f Makefile && make maintainer-clean
Patrick Williamsad5dd0f2022-12-04 15:07:33 -060044 test -d linux && find linux -type d -empty -exec rm -rf {} \;
Andrew Jeffery22778042017-01-13 22:37:26 +103045 for file in ${AUTOCONF_FILES}; do
Patrick Williamsad5dd0f2022-12-04 15:07:33 -060046 find . -name "$file" -exec rm -rf {} \;
Andrew Jeffery22778042017-01-13 22:37:26 +103047 done
48 exit 0
49 ;;
Andrew Jeffery58b3cc02017-05-29 16:41:30 +093050 *) ;;
Andrew Jeffery22778042017-01-13 22:37:26 +103051esac
52
53autoreconf -i
Andrew Jeffery56b2aa32017-04-13 13:25:05 +093054
Andrew Jeffery58b3cc02017-05-29 16:41:30 +093055case "${BOOTSTRAP_MODE}" in
Andrew Jeffery56b2aa32017-04-13 13:25:05 +093056 dev)
Andrew Jefferybcefd402017-05-29 16:42:14 +093057 FLAGS="-fsanitize=address -fsanitize=leak -fsanitize=undefined -Wall -Werror"
Andrew Jeffery56b2aa32017-04-13 13:25:05 +093058 ./configure \
Andrew Jefferybcefd402017-05-29 16:42:14 +093059 CFLAGS="${FLAGS}" \
60 CXXFLAGS="${FLAGS}" \
Andrew Jeffery58b3cc02017-05-29 16:41:30 +093061 --enable-code-coverage \
62 "$@"
Andrew Jeffery56b2aa32017-04-13 13:25:05 +093063 ;;
64 *)
Patrick Williamsad5dd0f2022-12-04 15:07:33 -060065 # shellcheck disable=SC2016
Andrew Jeffery56b2aa32017-04-13 13:25:05 +093066 echo 'Run "./configure ${CONFIGURE_FLAGS} && make"'
67 ;;
68esac