logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://hacktivis.me/git/badwolf.git
commit: 8fbd2a2f285dd580c19df7786f7901883a97c147
parent 0dd04a60bf19738302702e81e53ed896484f24cb
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 29 Oct 2021 18:08:10 +0200

configure: Parse arguments for variables

Diffstat:

Mconfigure97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 80 insertions(+), 17 deletions(-)

diff --git a/configure b/configure @@ -1,22 +1,33 @@ #!/bin/sh VERSION=1.2.0 VERSION_FULL=${VERSION}$(./version.sh) -PREFIX="${PREFIX:-/usr/local}" -BINDIR="${BINDIR:-${PREFIX}/bin}" -MANDIR="${MANDIR:-${PREFIX}/share/man}" -DOCDIR="${DOCDIR:-${PREFIX}/share/doc/badwolf-${VERSION}}" -DATADIR="${DATADIR:-${PREFIX}/share/badwolf}" -APPSDIR="${APPSDIR:-${PREFIX}/share/applications}" - -PKGCONFIG="${PKGCONFIG:-pkg-config}" -MSGFMT="${MSGFMT:-msgfmt}" -INKSCAPE="${INKSCAPE:-inkscape}" -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}" -MANDOC="mandoc" - +ICON_SIZES="$(for i in 24 32 48 64 128 256; do printf 'icons/hicolor/%sx%s/apps/badwolf.png ' $i $i ; done)" DEPS="gtk+-3.0 libxml-2.0" +usage() { +cat <<END +Usage: [variables] configure [variables] + +Variables: + PREFIX=DIR + BINDIR=DIR + MANDIR=DIR + DOCDIR=DIR + DATADIR=DIR + APPSDIR=DIR + + PKGCONFIG=BIN + MSGFMT=BIN + INKSCAPE=BIN + CC=BIN + CFLAGS=OPTIONS + EXTRA_CFLAGS=OPTIONS + MANDOC=BIN + +Variables are set in the following order: Default, Environment, Arguments +END +} + is_ok() { status="$?" @@ -39,6 +50,53 @@ pkg_config_check() { is_ok } +## User configuration + +# defaults +PREFIX="${PREFIX:-/usr/local}" +PKGCONFIG="${PKGCONFIG:-pkg-config}" +MSGFMT="${MSGFMT:-msgfmt}" +INKSCAPE="${INKSCAPE:-inkscape}" +CC="${CC:-cc}" +CFLAGS="${CFLAGS:--g -O2 -pie -fPIE}" +MANDOC="${MANDOC:-mandoc}" + +IFS='' + +# Also allow variables through arguments +for i; do + case "$i" in + PREFIX=*|BINDIR=*|MANDIR=*|DOCDIR=*|DATADIR=*|APPSDIR=*) + export "${i%%=*}"="${i#*=}" + shift + ;; + PKGCONFIG=*|MSGFMT=*|INKSCAPE=*|CC=*|CFLAGS=*|MANDOC=*) + export "${i%%=*}"="${i#*=}" + shift + ;; + -h|--help) + usage + exit 1 + ;; + *) + printf "Unknown argument ā€˜%sā€™\n" "${i}" + usage + exit 1 + ;; + esac +done + +# Fallback definitions for dirs, based on $PREFIX +BINDIR="${BINDIR:-${PREFIX}/bin}" +MANDIR="${MANDIR:-${PREFIX}/share/man}" +DOCDIR="${DOCDIR:-${PREFIX}/share/doc/badwolf-${VERSION}}" +DATADIR="${DATADIR:-${PREFIX}/share/badwolf}" +APPSDIR="${APPSDIR:-${PREFIX}/share/applications}" + +# 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}" + +## System checks printf 'Checking %s command existance ...' "${PKGCONFIG}" command -v "${PKGCONFIG}" >/dev/null ; required @@ -46,7 +104,7 @@ printf 'Checking %s command existance ...' "${CC}" command -v "${CC}" >/dev/null ; required printf 'Checking %s command existance ...' "${MANDOC}" -if command -v "${CC}" >/dev/null ; is_ok +if command -v "${MANDOC}" >/dev/null ; is_ok then : else @@ -125,12 +183,17 @@ case "${WITH_URI_PARSER}n" in ;; esac +printf 'Using pkg-config to get CFLAGS for %s ...' "${DEPS}" get_cflags() { "${PKGCONFIG}" --cflags "${DEPS}"; } DEPS_cflags="$(get_cflags)" -get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; } +required + +printf 'Using pkg-config to get LIBS for %s ...' "${DEPS}" +get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; } DEPS_libs="$(get_libs)" +required -ICON_SIZES="$(for i in 24 32 48 64 128 256; do printf 'icons/hicolor/%sx%s/apps/badwolf.png ' $i $i ; done)" +## Configuration write printf 'Writing to config.mk ...' cat >config.mk <<EOF