logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: dee695fa00e3cc7a4970bd6d3f23e86d1d11df1d
parent 3389b0afa340d883467b4cdfd2e5707f9476d8d6
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri,  4 Feb 2022 15:09:36 +0100

configure: Sync with badwolf

Diffstat:

Mconfigure99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 79 insertions(+), 20 deletions(-)

diff --git a/configure b/configure @@ -1,18 +1,32 @@ #!/bin/sh -PREFIX="${PREFIX:-/usr/local}" -BINDIR="${BINDIR:-${PREFIX}/bin}" -SBINDIR="${SBINDIR:-${PREFIX}/sbin}" -MANDIR="${MANDIR:-${PREFIX}/share/man}" - -PKGCONFIG="${PKGCONFIG:-pkg-config}" -MSGFMT="${MSGFMT:-msgfmt}" -CC="${CC:-cc}" -CFLAGS="${CFLAGS:--g -O2 -pie -fPIE} -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wconversion -Wsign-conversion -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla ${EXTRA_CFLAGS}" -LDFLAGS="${LDFLAGS:--Wl,--as-needed}" -MANDOC="mandoc" DEPS="" +usage() { +cat <<END +Usage: [variables] configure [variables] + +Variables: + PREFIX=DIR + BINDIR=DIR + SBINDIR=DIR + MANDIR=DIR + + PKGCONFIG=BIN + MSGFMT=BIN + CC=BIN + CFLAGS=OPTIONS + LDFLAGS=OPTIONS + EXTRA_CFLAGS=OPTIONS + +Variables are set in the following order: Default, Environment, Arguments + +Dependencies: +- libbsd (optionnal), for strings(1) and humanize(1) +- kyua + atf (optional, test dep) +END +} + is_ok() { status="$?" @@ -45,27 +59,67 @@ gen_targets() { echo } +## User configuration + +# defaults +PREFIX="${PREFIX:-/usr/local}" + +PKGCONFIG="${PKGCONFIG:-pkg-config}" +MSGFMT="${MSGFMT:-msgfmt}" +CC="${CC:-cc}" +CFLAGS="${CFLAGS:--g -O2 -pie -fPIE}" +LDFLAGS="${LDFLAGS:--Wl,--as-needed}" + +# Also allow variables through arguments +for i; do + case "$i" in + -h|--help) + usage + exit 1 + ;; + -*) + printf "Unknown argument ā€˜%sā€™\n" "${i}" + usage + exit 1 + ;; + *=*) + # shellcheck disable=SC2163 + export "$i" + shift + ;; + *) + printf "Unknown argument ā€˜%sā€™\n" "${i}" + usage + exit 1 + ;; + esac +done + +# Fallback definitions for dirs, based on $PREFIX +BINDIR="${BINDIR:-${PREFIX}/bin}" +SBINDIR="${SBINDIR:-${PREFIX}/sbin}" +MANDIR="${MANDIR:-${PREFIX}/share/man}" + +# Add some extra CFLAGS +CFLAGS="${CFLAGS} -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wconversion -Wsign-conversion -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla ${EXTRA_CFLAGS}" + printf 'Pruning old configurations ...' rm -f config.mk bin/config.mk sbin/config.mk \ && echo '#' > bin/target_filter \ && echo '#' > sbin/target_filter \ ; or_die +## System checks +# commands printf 'Checking %s command existance ...' "${PKGCONFIG}" command -v "${PKGCONFIG}" >/dev/null ; or_die printf 'Checking %s command existance ...' "${CC}" command -v "${CC}" >/dev/null ; or_die -printf 'Checking %s command existance ...' "${MANDOC}" -if command -v "${CC}" >/dev/null ; is_ok -then - : -else - MANDOC="true" -fi - +echo +# pkg-config for dep in ${DEPS} do pkg_config_check --exists "$dep" || exit 1 @@ -81,6 +135,10 @@ else echo 'bin/humanize.c' >> bin/target_filter; or_die # humanize_number fi +echo + +## Configuration write + printf 'Writing bin/config.mk ...' (cd bin && gen_targets) > bin/config.mk ; or_die @@ -99,7 +157,6 @@ PKGCONFIG = ${PKGCONFIG} CC = ${CC} MSGFMT = ${MSGFMT} DBG = ${DBG} -MANDOC = ${MANDOC} CFLAGS = ${CFLAGS} LDFLAGS = ${LDFLAGS} @@ -109,4 +166,6 @@ LIBBSD_LIBS = ${LIBBSD_LIBS} EOF is_ok +echo + echo 'Done, you can now run make'