123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623 |
- #!/bin/sh
- ### Automatic build configuration script for Dinit.
- ### This script generates an "mconfig" file suitable for building on the current system.
- ## Initial preparation
- set -eu
- cd "$(dirname "$0")"
- ## Helper functions
- # POSIX "echo" behaviour has unspecified behavior in some cases, for example when the first
- # argument is "-n" or backslash ("\"). So, replace the shell built-in echo with a printf-based
- # function. For more information see: http://www.etalabs.net/sh_tricks.html
- echo()
- {
- IFS=" " printf %s\\n "$*"
- }
- # Output a line of information, may be followed by call to sub_info to provide additional information
- info()
- {
- echo "$*"
- }
- # Output additional information (intended to follow call to info)
- sub_info()
- {
- echo " ... $*"
- }
- # Output an error message, may be followed by a call to sub_error to provide additional information
- error()
- {
- >&2 echo "Error: $*"
- exit 1
- }
- # Output additional error information (intended to follow call to error)
- sub_error()
- {
- >&2 echo " ... Error: $*"
- exit 1
- }
- # Output a warning, with an optional "extra information" field
- # $1: Info, $2: Extra info (optional)
- warning()
- {
- >&2 echo
- >&2 echo "Warning: $1"
- [ -n "${2:-}" ] && >&2 echo " ... $2"
- >&2 echo
- }
- # Produce (as output) a random number from 0-65535
- randomnumber()
- {
- awk 'BEGIN {
- srand()
- printf("%d\n", 65536 * rand())
- }'
- }
- # Create a temporary directory and output its full path
- mktmpdir()
- {
- rn1=`randomnumber`
- rn2=`randomnumber`
- dirname="${TMPDIR:-/tmp}/dinit-cfg-${rn1}-${rn2}"
- mkdir "$dirname"
- echo "$dirname"
- }
- # Check whether the compiler ($CXX) seems to work
- cxx_works()
- {
- info Checking whether \""$1"\" is a working C++ compiler...
- if $CXX -o "$configtmpdir"/testfile "$configtmpdir"/testfile.cc; then
- rm -f "$configtmpdir"/testfile
- sub_info Yes.
- else
- rm -f "$configtmpdir"/testfile*
- sub_error It seems like \""$CXX"\" is not working a working C++ compiler. Please specify compiler.
- fi
- }
- # Test if the compiler accepts an argument (for compilation only); if so add it to named variable.
- # Note: this function will return failure if the flag is unsupported (use try_optional_cxx_argument
- # instead, to avoid errorring out).
- # $1 - the name of the variable to potentially add the argument to
- # $2 - the argument to test/add
- # CXX - the name of the compiler
- # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
- try_cxx_argument()
- {
- info Checking whether "$2" is accepted for compilation...
- if $CXX $CXXFLAGS $2 $CXXFLAGS_EXTRA $LDFLAGS $LDFLAGS_EXTRA "$configtmpdir"/testfile.cc \
- -c -o "$configtmpdir"/testfile.o > /dev/null 2>&1; then
- rm "$configtmpdir"/testfile.o
- sub_info Yes.
- eval "$1=\"\${$1} \$2\""
- eval "$1=\${$1# }"
- return 0
- else
- sub_info No.
- return 1
- fi
- }
- # Test if the compiler accepts an argument; same as try_cxx_argument, but doesn't return failure
- # if the flag is unsupported.
- # $1 - the name of the variable to potentially add the argument to
- # $2 - the argument to test/add
- # CXX - the name of the compiler
- # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
- try_optional_cxx_argument()
- {
- try_cxx_argument "$1" "$2" || :
- }
- # Test if an argument is supported during linking.
- # $1 - the name of the variable to potentially add the argument to
- # $2 - the argument to test/add
- # CXX - the name of the compiler
- # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
- try_ld_argument()
- {
- info Checking whether "$2" is accepted as a link-time option...
- if [ ! -e "$configtmpdir"/testfile.o ]; then
- # If the object file doesn't exist yet, need to compile
- if ! $CXX $CXXFLAGS $CXXFLAGS_EXTRA "$configtmpdir"/testfile.cc \
- -c -o "$configtmpdir"/testfile.o > /dev/null 2>&1; then
- sub_info "No (compilation failed)."
- return
- fi
- fi
- if $CXX $LDFLAGS $LDFLAGS_EXTRA $2 "$configtmpdir"/testfile.o \
- -o "$configtmpdir"/testfile > /dev/null 2>&1; then
- sub_info Yes.
- rm "$configtmpdir"/testfile
- eval "$1=\"\${$1} \$2\""
- eval "$1=\${$1# }"
- else
- sub_info No.
- fi
- }
- # Test if an argument is supported during both compiling and linking.
- # $1 - the name of the compiler-flags variable to potentially add the argument to
- # $2 - the name of the link-flags variable to potentially add the argument to
- # $3 - the argument to test/add
- # CXX - the name of the compiler
- # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
- try_both_argument()
- {
- info Checking whether "$3" is accepted for compiling and linking...
- if $CXX $CXXFLAGS $CXXFLAGS_EXTRA $LDFLAGS $LDFLAGS_EXTRA $3 "$configtmpdir"/testfile.cc \
- -o "$configtmpdir"/testfile > /dev/null 2>&1; then
- sub_info Yes.
- rm "$configtmpdir"/testfile
- eval "$1=\"\${$1} \$3\""
- eval "$1=\${$1# }"
- eval "$2=\"\${$2} \$3\""
- eval "$2=\${$2# }"
- else
- sub_info No.
- fi
- }
- usage()
- {
- cat << _EOF
- Usage: $0 [OPTION]...
- Generates build configuration for Dinit.
- Defaults for the options are specified in brackets.
- -h, --help This help message.
- -q, --quiet Don't print normal messages, just errors.
- -c, --clear Clear mconfig and configure's temporary files.
- Target options:
- --platform=PLATFORM Set the platform manually (for cross compilation)
- Note: for all cross-compiles please specify correct CXX and
- CXX_FOR_BUILD!
- Installation directories:
- --prefix=PREFIX Main installation prefix [/usr]
- --exec-prefix=EPREFIX Main executables prefix [/]
- --sbindir=SBINDIR Dinit executables [EPREFIX/sbin]
- --mandir=MANDIR Dinit man-pages location [PREFIX/share/man]
- --syscontrolsocket=SOCKETPATH Dinitctl socket location [/run/dinitctl] on Linux systems
- [/var/run/dinitctl] on other systems
- Optional options:
- --enable-strip Strip debug information in installation process [Enabled]
- --disable-strip Don't strip debug information in installation process
- --shutdown-prefix=PREFIX Name prefix for shutdown, poweroff, reboot, soft-reboot, halt
- programs []
- --enable-shutdown Build shutdown, poweroff, reboot, soft-reboot, halt programs
- [Enabled only on Linux]
- --disable-shutdown Don't build shutdown, poweroff, reboot, soft-reboot, halt
- programs
- --enable-cgroups Enable Cgroups support [Enabled only on Linux]
- --disable-cgroups Disable Cgroups support
- --enable-capabilities Enable capabilities support
- [Enabled on Linux if libcap available]
- --disable-capabilities Disable capabilities support
- --enable-utmpx Enable manipulating the utmp/utmpx database via the related
- POSIX functions [Depends on system]
- --disable-utmpx Disable manipulating the utmp/utmpx database via the related
- POSIX functions
- --enable-initgroups Enable initialization of supplementary groups for run-as
- [Enabled]
- --disable-initgroups Disable initialization of supplementary groups for run-as
- --enable-auto-restart Enable auto-restart for services by default (Deprecated;
- use --default-auto-restart=...)
- --disable-auto-restart Disable auto-restart for services by default (Deprecated;
- use --default-auto-restart=...)
- --default-start-timeout=sec Default start-timeout for services [60]
- --default-stop-timeout=sec Default stop-timeout for services [10]
- --default-auto-restart=(never|on-failure|always)
- When to automatically restart services. This controls the
- default value for the "restart" service setting; see the
- dinit-service(5) man page for details. [always]
- Build variables:
- Note: build variables can be passed in the environment, or as $0 argument (as "var=VALUE").
- Note: values for some options will be determined automatically, if not specified.
- Note: CXXFLAGS, TEST_CXXFLAGS, LDFLAGS and TEST_LDFLAGS by default will be set to options
- considered suitable for the platform, filtered to remove any options not supported by the
- compiler/linker. To disable this, specify the values explicitly (an empty string is accepted).
- To add options without removing the defaults, set the variable with _EXTRA appended to the
- name (eg CXXFLAGS_EXTRA).
- CXX C++ compiler
- CXX_FOR_BUILD C++ compiler generating code for the build system (for
- cross-compiles).
- CXXFLAGS_FOR_BUILD Flags to use when generating code for the build system.
- Defaults to the value of CXXFLAGS.
- CPPFLAGS_FOR_BUILD Preprocessor flags to use when generating code for the build
- system.
- Defaults to the value of CPPFLAGS.
- LDFLAGS_FOR_BUILD Link flags to use when generating code for the build system.
- Defaults to the value of LDFLAGS.
- CXXFLAGS Flags to use when compiling C++ code.
- CXXFLAGS_EXTRA Additional flags to use when compiling C++ code.
- TEST_CXXFLAGS Flags to use when compiling C++ code in tests.
- TEST_CXXFLAGS_EXTRA Additional flags to use when compiling C++ code in tests.
- CPPFLAGS Preprocessor flags to use when compiling C++ code.
- LDFLAGS Link flags.
- LDFLAGS_EXTRA Additional link flags.
- LDFLAGS_BASE Link flags to use in addition to any link-time optimisation
- (LTO)-related options. Set this to control link options without
- disabling LTO. Ignored if LDFLAGS is set.
- TEST_LDFLAGS Link flags when building test executables.
- TEST_LDFLAGS_EXTRA Additional link flags when building test executables.
- TEST_LDFLAGS_BASE Link flags to use when building test executables, in addition to
- LTO-releated options.
-
- LDFLAGS_LIBCAP Additional Link flags to link capabilities support (libcap).
- Note: paths specified via --prefix/--exec-prefix/--sbindir/--mandir, and build variable values,
- must be escaped for use in a makefile and in shell commands. If there are spaces in paths it is
- recommended to prepend a backslash (\) to them.
- For example: ./configure --prefix="/home/my\ home"
- See BUILD file for more information.
- _EOF
- exit 0
- }
- ## Don't take values from environment for these variables:
- for var in PREFIX \
- EPREFIX \
- SBINDIR \
- MANDIR \
- SHUTDOWN_PREFIX \
- BUILD_SHUTDOWN \
- SUPPORT_CGROUPS \
- SUPPORT_CAPABILITIES \
- SUPPORT_IOPRIO \
- SUPPORT_OOM_ADJ \
- USE_UTMPX \
- USE_INITGROUPS \
- SYSCONTROLSOCKET \
- STRIPOPTS
- do
- unset $var
- done
- ## Flag parser
- for arg in "$@"; do
- case "$arg" in
- -h|--help) usage ;;
- -q|--quiet)
- info() { true; }
- sub_info() { true; }
- warning() { true; }
- ;;
- -c|--clear) rm -f test* & rm -f mconfig && exit 0 ;;
- --platform=*) PLATFORM="${arg#*=}" && shift ;;
- --prefix=*) PREFIX="${arg#*=}" && shift ;;
- --exec-prefix=*) EPREFIX="${arg#*=}" && shift;;
- --sbindir=*) SBINDIR="${arg#*=}" && shift ;;
- --mandir=*) MANDIR="${arg#*=}" && shift ;;
- --default-start-timeout=*) DEFAULT_START_TIMEOUT="${arg#*=}" && shift ;;
- --default-stop-timeout=*) DEFAULT_STOP_TIMEOUT="${arg#*=}" && shift ;;
- --syscontrolsocket=*) SYSCONTROLSOCKET="${arg#*=}" && shift ;;
- --shutdown-prefix=*) SHUTDOWN_PREFIX="${arg#*=}" && shift ;;
- --enable-shutdown|--enable-shutdown=yes) BUILD_SHUTDOWN=yes ;;
- --disable-shutdown|--enable-shutdown=no) BUILD_SHUTDOWN=no ;;
- --enable-cgroups|--enable-cgroups=yes) SUPPORT_CGROUPS=1 ;;
- --disable-cgroups|--enable-cgroups=no) SUPPORT_CGROUPS=0 ;;
- --enable-capabilities|--enable-capabilities=yes) SUPPORT_CAPABILITIES=1 ;;
- --disable-capabilities|--enable-capabilities=no) SUPPORT_CAPABILITIES=0 ;;
- --enable-ioprio|--enable-ioprio=yes) SUPPORT_IOPRIO=1 ;;
- --disable-ioprio|--enable-ioprio=no) SUPPORT_IOPRIO=0 ;;
- --enable-oom-adj|--enable-oom-adj=yes) SUPPORT_OOM_ADJ=1 ;;
- --disable-oom-adj|--enable-oom-adj=no) SUPPORT_OOM_ADJ=0 ;;
- --enable-utmpx|--enable-utmpx=yes) USE_UTMPX=1 ;;
- --disable-utmpx|--enable-utmpx=no) USE_UTMPX=0 ;;
- --enable-initgroups|--enable-initgroups=yes) USE_INITGROUPS=1 ;;
- --disable-initgroups|--enable-initgroups=no) USE_INITGROUPS=0 ;;
- --enable-auto-restart|--enable-auto-restart=yes) DEFAULT_AUTO_RESTART=ALWAYS ;; # Deprecated
- --disable-auto-restart|--enable-auto-restart=no) DEFAULT_AUTO_RESTART=NEVER ;; # Deprecated
- --enable-strip|--enable-strip=yes) STRIPOPTS="-s" ;;
- --disable-strip|--enable-strip=no) STRIPOPTS="" ;;
- --default-auto-restart=never) DEFAULT_AUTO_RESTART=NEVER ;;
- --default-auto-restart=always) DEFAULT_AUTO_RESTART=ALWAYS ;;
- --default-auto-restart=on-failure) DEFAULT_AUTO_RESTART=ON_FAILURE ;;
- CXX=*|CXX_FOR_BUILD=*|CXXFLAGS_FOR_BUILD=*|CPPFLAGS_FOR_BUILD=*\
- |LDFLAGS_FOR_BUILD=*|CXXFLAGS=*|CXXFLAGS_EXTRA=*|TEST_CXXFLAGS=*\
- |TEST_CXXFLAGS_EXTRA=*|LDFLAGS=*|LDFLAGS_EXTRA=*|TEST_LDFLAGS=*\
- |TEST_LDFLAGS_EXTRA=*|CPPFLAGS=*|LDFLAGS_BASE=*|TEST_LDFLAGS_BASE=*\
- |LDFLAGS_LIBCAP) eval "${arg%%=*}=\${arg#*=}" ;;
- *=*) warning "Unknown variable: ${arg%%=*}" ;;
- *) warning "Unknown argument: $arg" ;;
- esac
- done
- ## Defaults for variables not specified by user
- : "${PLATFORM:=$(uname)}"
- : "${PREFIX:="/usr"}"
- : "${EPREFIX:="/"}"
- : "${SBINDIR:="${EPREFIX%%/}/sbin"}"
- : "${MANDIR:="${PREFIX%%/}/share/man"}"
- : "${SHUTDOWN_PREFIX:=""}"
- : "${CXXFLAGS_EXTRA:=""}"
- : "${TEST_CXXFLAGS_EXTRA:=""}"
- : "${CPPFLAGS:=""}"
- : "${LDFLAGS_EXTRA:=""}"
- : "${TEST_LDFLAGS_EXTRA:=""}"
- : "${DEFAULT_AUTO_RESTART:="ALWAYS"}"
- : "${DEFAULT_START_TIMEOUT:="60"}"
- : "${DEFAULT_STOP_TIMEOUT:="10"}"
- : "${USE_INITGROUPS:="1"}"
- if [ "$PLATFORM" = "Linux" ]; then
- : "${BUILD_SHUTDOWN:="yes"}"
- : "${SUPPORT_CGROUPS:="1"}"
- : "${SUPPORT_CAPABILITIES:="AUTO"}"
- : "${SUPPORT_IOPRIO:="1"}"
- : "${SUPPORT_OOM_ADJ:="1"}"
- : "${SYSCONTROLSOCKET:="/run/dinitctl"}"
- else
- : "${BUILD_SHUTDOWN:="no"}"
- : "${SUPPORT_CGROUPS:="0"}"
- : "${SUPPORT_CAPABILITIES:="0"}"
- : "${SUPPORT_IOPRIO:="0"}"
- : "${SUPPORT_OOM_ADJ:="0"}"
- : "${SYSCONTROLSOCKET:="/var/run/dinitctl"}"
- fi
- HAS_LTO=""
- ## Finalize $CXXFLAGS, $TEST_CXXFLAGS, $LDFLAGS, $TEST_LDFLAGS, $STRIPOPTS
- if [ -z "${CXXFLAGS+IS_SET}" ]; then
- CXXFLAGS=""
- AUTO_CXXFLAGS="true"
- else
- AUTO_CXXFLAGS="false"
- fi
- if [ -z "${TEST_CXXFLAGS+IS_SET}" ]; then
- TEST_CXXFLAGS=""
- AUTO_TEST_CXXFLAGS="true"
- else
- AUTO_TEST_CXXFLAGS="false"
- fi
- if [ -z "${LDFLAGS+IS_SET}" ]; then
- LDFLAGS=""
- AUTO_LDFLAGS="true"
- else
- AUTO_LDFLAGS="false"
- fi
- if [ -z "${TEST_LDFLAGS+IS_SET}" ]; then
- TEST_LDFLAGS=""
- AUTO_TEST_LDFLAGS="true"
- else
- AUTO_TEST_LDFLAGS="false"
- fi
- if [ -z "${LDFLAGS_BASE+IS_SET}" ]; then
- LDFLAGS_BASE=""
- AUTO_LDFLAGS_BASE="true"
- else
- AUTO_LDFLAGS_BASE="false"
- fi
- if [ -z "${TEST_LDFLAGS_BASE+IS_SET}" ]; then
- TEST_LDFLAGS_BASE=""
- AUTO_TEST_LDFLAGS_BASE="true"
- else
- AUTO_TEST_LDFLAGS=BASE="false"
- fi
- if [ -z "${LDFLAGS_LIBCAP+IS_SET}" ]; then
- LDFLAGS_LIBCAP=""
- AUTO_LDFLAGS_LIBCAP="true"
- else
- AUTO_LDFLAGS_LIBCAP="false"
- fi
- [ -z "${STRIPOPTS+IS_SET}" ] && STRIPOPTS="-s"
- ## Verify PLATFORM value
- if [ "$PLATFORM" != "Linux" ] && [ "$PLATFORM" != "FreeBSD" ] && \
- [ "$PLATFORM" != "OpenBSD" ] && [ "$PLATFORM" != "Darwin" ]; then
- warning "$PLATFORM platform is unknown!" "Known Platforms are: Linux, FreeBSD, OpenBSD, Darwin"
- fi
- ## Create testfile.cc to test c++ compiler
- configtmpdir=`mktmpdir`
- echo "int main(int argc, char **argv) { return 0; }" > "$configtmpdir"/testfile.cc || error "Can't create temporary file"
- ## Find and test C++ compiler
- if [ -z "${CXX:-}" ]; then
- info Checking C++ compiler...
- for guess in g++ clang++ c++; do
- if type "$guess" > /dev/null 2>&1; then
- CXX="$guess"
- sub_info "$CXX"
- break # Found
- fi
- done
- if [ -z "${CXX:-}" ]; then
- sub_error No C++ compiler found! # Not found
- fi
- fi
- cxx_works "$CXX"
- if [ -n "${CXX_FOR_BUILD:-}" ]; then
- cxx_works "$CXX_FOR_BUILD"
- fi
- ## Test compiler/linker supported arguments
- if [ "$AUTO_CXXFLAGS" = "true" ]; then
- if ! try_cxx_argument CXXFLAGS -std=c++11; then
- sub_error "The C++ compiler ($CXX) doesn't accept '-std=c++11' and may be too old."
- fi
- for argument in -Wall \
- -Os \
- -fno-plt
- do
- try_optional_cxx_argument CXXFLAGS $argument
- done
- if [ "$PLATFORM" != "Darwin" ]; then
- try_optional_cxx_argument CXXFLAGS -fno-rtti
- fi
- fi
- if [ "$AUTO_LDFLAGS" = true ] && [ "$AUTO_CXXFLAGS" = true ]; then
- DUMMY_LDFLAGS=""
- # -flto must work for both compiling and linking, but we don't want to add it to LDFLAGS as,
- # if LTO is used, CXXFLAGS will always be used alongside LDFLAGS.
- if try_both_argument CXXFLAGS DUMMY_LDFLAGS -flto; then
- HAS_LTO="true"
- else
- HAS_LTO="false"
- fi
- unset DUMMY_LDFLAGS
- fi
- if [ "$AUTO_LDFLAGS_BASE" = true ] && [ "$PLATFORM" = FreeBSD ]; then
- try_ld_argument LDFLAGS_BASE -lrt
- fi
- if [ "$SUPPORT_CAPABILITIES" != 0 ]; then
- if [ "$AUTO_LDFLAGS_LIBCAP" = true ]; then
- try_ld_argument LDFLAGS_LIBCAP -lcap
- if [ "$SUPPORT_CAPABILITIES" = AUTO ]; then
- if [ -z "$LDFLAGS_LIBCAP" ]; then
- SUPPORT_CAPABILITIES=0
- else
- SUPPORT_CAPABILITIES=1
- fi
- fi
- else
- # SUPPORT_CAPABILITIES may be set to AUTO, fix that:
- SUPPORT_CAPABILITES=1
- fi
- else
- LDFLAGS_LIBCAP=""
- fi
- if [ "$AUTO_TEST_LDFLAGS_BASE" = true ]; then
- TEST_LDFLAGS_BASE="\$(LDFLAGS_BASE)"
- established_TEST_LDFLAGS="$LDFLAGS_BASE"
- else
- established_TEST_LDFLAGS="$TEST_LDFLAGS_BASE"
- fi
- # Determine LDFLAGS/TEST_LDFLAGS. In the case of TEST_LDFLAGS we may still add sanitisation
- # options, shortly.
- if [ "$HAS_LTO" = true ]; then
- if [ "$AUTO_LDFLAGS" = true ]; then
- LDFLAGS="\$(LDFLAGS_BASE) \$(CXXFLAGS)"
- fi
- if [ "$AUTO_TEST_LDFLAGS" = true ]; then
- TEST_LDFLAGS="\$(TEST_LDFLAGS_BASE) \$(TEST_CXXFLAGS)"
- established_TEST_LDFLAGS="$established_TEST_LDFLAGS $TEST_CXXFLAGS"
- else
- established_TEST_LDFLAGS="$TEST_LDFLAGS"
- fi
- else
- # default LDFLAGS are just $(LDFLAGS_BASE)
- if [ "$AUTO_LDFLAGS" = true ]; then
- LDFLAGS="\$(LDFLAGS_BASE)"
- fi
- if [ "$AUTO_TEST_LDFLAGS" = true ]; then
- TEST_LDFLAGS="\$(TEST_LDFLAGS_BASE)"
- else
- established_TEST_LDFLAGS="$TEST_LDFLAGS"
- fi
- fi
- # Default for test flags (TEST_CXXFLAGS, TEST_LDFLAGS) is to use the build flags
- if [ "$AUTO_TEST_CXXFLAGS" = "true" ]; then
- TEST_CXXFLAGS="\$(CXXFLAGS)"
- established_TEST_CXXFLAGS="$CXXFLAGS"
- else
- established_TEST_CXXFLAGS="$TEST_CXXFLAGS"
- fi
- # Check whether sanitizers can be used for tests
- if [ "$AUTO_TEST_LDFLAGS" = "true" ] && [ "$AUTO_TEST_CXXFLAGS" = "true" ]; then
- DUMMY_LDFLAGS=""
- if [ "$HAS_LTO" = true ]; then
- # Avoid doubling-up sanitizer options
- LDFLAGS_VAR=DUMMY_LDFLAGS
- else
- LDFLAGS_VAR=TEST_LDFLAGS
- fi
- CXXFLAGS="$established_TEST_CXXFLAGS" CXXFLAGS_EXTRA="$TEST_CXXFLAGS_EXTRA" \
- LDFLAGS="$established_TEST_LDFLAGS" LDFLAGS_EXTRA="$TEST_LDFLAGS_EXTRA" \
- try_both_argument TEST_CXXFLAGS $LDFLAGS_VAR -fsanitize=address,undefined
- unset DUMMY_LDFLAGS
- fi
- ## Create mconfig
- rm -r "$configtmpdir"
- info Creating mconfig...
- cat << _EOF > mconfig
- ## Auto-generated by "$0" for "$PLATFORM"
- # All changes will be lost if "$0" is re-run.
- # See BUILD for help on all variables.
- # Installation path options.
- SBINDIR=$SBINDIR
- MANDIR=$MANDIR
- SYSCONTROLSOCKET=$SYSCONTROLSOCKET
- # General build options.
- CXX=$CXX
- CXXFLAGS=$CXXFLAGS
- CXXFLAGS_EXTRA=$CXXFLAGS_EXTRA
- TEST_CXXFLAGS=$TEST_CXXFLAGS
- TEST_CXXFLAGS_EXTRA=$TEST_CXXFLAGS_EXTRA
- CPPFLAGS=$CPPFLAGS
- LDFLAGS_BASE=$LDFLAGS_BASE
- LDFLAGS=$LDFLAGS
- LDFLAGS_EXTRA=$LDFLAGS_EXTRA
- TEST_LDFLAGS_BASE=$TEST_LDFLAGS_BASE
- TEST_LDFLAGS=$TEST_LDFLAGS
- TEST_LDFLAGS_EXTRA=$TEST_LDFLAGS_EXTRA
- BUILD_SHUTDOWN=$BUILD_SHUTDOWN
- STRIPOPTS=$STRIPOPTS
- # Dependencies
- LDFLAGS_LIBCAP=$LDFLAGS_LIBCAP
- # Feature settings
- SUPPORT_CGROUPS=$SUPPORT_CGROUPS
- USE_INITGROUPS=$USE_INITGROUPS
- SUPPORT_CAPABILITIES=$SUPPORT_CAPABILITIES
- SUPPORT_IOPRIO=$SUPPORT_IOPRIO
- SUPPORT_OOM_ADJ=$SUPPORT_OOM_ADJ
- # Optional settings
- SHUTDOWN_PREFIX=${SHUTDOWN_PREFIX:-}
- # Service defaults
- DEFAULT_AUTO_RESTART=$DEFAULT_AUTO_RESTART
- DEFAULT_START_TIMEOUT=$DEFAULT_START_TIMEOUT
- DEFAULT_STOP_TIMEOUT=$DEFAULT_STOP_TIMEOUT
- _EOF
- if [ -n "${USE_UTMPX:-}" ]; then
- echo "USE_UTMPX=$USE_UTMPX" >> mconfig
- fi
- if [ -n "${CXX_FOR_BUILD:-}" ]; then
- {
- echo ""
- echo "# For cross-compiling"
- echo "CXX_FOR_BUILD=$CXX_FOR_BUILD"
- } >> mconfig
- fi
- if [ -n "${CXXFLAGS_FOR_BUILD:-}" ]; then
- echo "CXXFLAGS_FOR_BUILD=$CXXFLAGS_FOR_BUILD" >> mconfig
- fi
- if [ -n "${CPPFLAGS_FOR_BUILD:-}" ]; then
- echo "CPPFLAGS_FOR_BUILD=$CPPFLAGS_FOR_BUILD" >> mconfig
- fi
- if [ -n "${LDFLAGS_FOR_BUILD:-}" ]; then
- echo "LDFLAGS_FOR_BUILD=$LDFLAGS_FOR_BUILD" >> mconfig
- fi
- sub_info done.
- info Done!
- exit 0
|