From 6c8d11e8e5b3457286fcda75b6516e93f1f12f17 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 10 Apr 2024 13:13:19 -0400 Subject: build: Run pkg-config with all packages at once --- config/cc.sh | 8 +------- config/deps.mk | 13 +++++++++++++ config/pkg.mk | 11 +++++++++++ config/pkg.sh | 24 +++--------------------- config/pkgconf.sh | 51 +++++++++++++++++++++++++++++++++++---------------- config/pkgs.mk | 14 ++++++++++++++ config/vars.mk | 21 +++++++++++++++++++++ 7 files changed, 98 insertions(+), 44 deletions(-) create mode 100644 config/deps.mk create mode 100644 config/pkg.mk create mode 100644 config/pkgs.mk create mode 100644 config/vars.mk (limited to 'config') diff --git a/config/cc.sh b/config/cc.sh index 7e5c0d5..2b340c0 100755 --- a/config/cc.sh +++ b/config/cc.sh @@ -7,10 +7,4 @@ set -eux -$XCC \ - $BFS_CPPFLAGS $XCPPFLAGS ${EXTRA_CPPFLAGS:-} \ - $BFS_CFLAGS $XCFLAGS ${EXTRA_CFLAGS:-} \ - $XLDFLAGS ${EXTRA_LDFLAGS:-} \ - "$@" \ - $XLDLIBS ${EXTRA_LDLIBS:-} $BFS_LDLIBS \ - -o /dev/null +$CC $CPPFLAGS $CFLAGS $LDFLAGS "$@" $LDLIBS -o /dev/null diff --git a/config/deps.mk b/config/deps.mk new file mode 100644 index 0000000..7d991ab --- /dev/null +++ b/config/deps.mk @@ -0,0 +1,13 @@ +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +# Makefile that generates gen/deps.mk + +.OBJDIR: . + +include config/vars.mk + +default:: + if config/cc.sh -MD -MP -MF /dev/null config/empty.c; then \ + printf 'DEPFLAGS = -MD -MP -MF $${@:.o=.d}\n'; \ + fi >${TARGET} 2>${TARGET}.log diff --git a/config/pkg.mk b/config/pkg.mk new file mode 100644 index 0000000..9b32b42 --- /dev/null +++ b/config/pkg.mk @@ -0,0 +1,11 @@ +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +# Makefile that generates gen/lib*.mk + +.OBJDIR: . + +include config/vars.mk + +default:: + config/pkg.sh ${TARGET:${GEN}/%.mk=%} >${TARGET} 2>${TARGET}.log diff --git a/config/pkg.sh b/config/pkg.sh index 6335b4b..2ca533e 100755 --- a/config/pkg.sh +++ b/config/pkg.sh @@ -8,37 +8,19 @@ set -eu NAME="${1^^}" -declare -n XUSE="XUSE_$NAME" +declare -n XUSE="USE_$NAME" -if [ "$XUSE" ]; then +if [ "${XUSE:-}" ]; then USE="$XUSE" -elif [[ "$NOLIBS" == *y* ]]; then - USE=n elif config/pkgconf.sh "$1"; then USE=y else USE=n fi -printf '%s := %s\n' "USE_$NAME" "$USE" - if [ "$USE" = y ]; then + printf 'PKGS += %s\n' "$1" printf 'CPPFLAGS += -DBFS_USE_%s=1\n' "$NAME" - - CFLAGS=$(config/pkgconf.sh --cflags "$1") - if [ "$CFLAGS" ]; then - printf 'CFLAGS += %s\n' "$CFLAGS" - fi - - LDFLAGS=$(config/pkgconf.sh --ldflags "$1") - if [ "$LDFLAGS" ]; then - printf 'LDFLAGS += %s\n' "$LDFLAGS" - fi - - LDLIBS=$(config/pkgconf.sh --ldlibs "$1") - if [ "$LDLIBS" ]; then - printf 'LDLIBS += %s\n' "$LDLIBS" - fi else printf 'CPPFLAGS += -DBFS_USE_%s=0\n' "$NAME" fi diff --git a/config/pkgconf.sh b/config/pkgconf.sh index 286c19c..a13b30f 100755 --- a/config/pkgconf.sh +++ b/config/pkgconf.sh @@ -8,29 +8,47 @@ set -eu MODE= -if [[ "$1" == --* ]]; then +if [[ "${1:-}" == --* ]]; then MODE="$1" shift fi +if (($# < 1)); then + exit +fi + +if [[ "$NOLIBS" == *y* ]]; then + exit 1 +fi + if command -v "${PKG_CONFIG:-}" &>/dev/null; then case "$MODE" in + "") + "$PKG_CONFIG" "$@" + ;; --cflags) - "$PKG_CONFIG" --cflags "$@" + OUT=$("$PKG_CONFIG" --cflags "$@") + if [ "$OUT" ]; then + printf 'CFLAGS += %s\n' "$OUT" + fi ;; --ldflags) - "$PKG_CONFIG" --libs-only-L --libs-only-other "$@" + OUT=$("$PKG_CONFIG" --libs-only-L --libs-only-other "$@") + if [ "$OUT" ]; then + printf 'LDFLAGS += %s\n' "$OUT" + fi ;; --ldlibs) - "$PKG_CONFIG" --libs-only-l "$@" - ;; - "") - "$PKG_CONFIG" "$@" + OUT=$("$PKG_CONFIG" --libs-only-l "$@") + if [ "$OUT" ]; then + printf 'LDLIBS := %s ${LDLIBS}\n' "$OUT" + fi ;; esac else - for lib; do - case "$lib" in + LDLIBS="" + for LIB; do + case "$LIB" in libacl) LDLIB=-lacl ;; @@ -47,21 +65,22 @@ else LDLIB=-lonig ;; *) - printf 'error: Unknown package %s\n' "$lib" >&2 + printf 'error: Unknown package %s\n' "$LIB" >&2 exit 1 + ;; esac case "$MODE" in - --ldlibs) - printf ' %s' "$LDLIB" - ;; "") - config/cc.sh "config/$lib.c" "$LDLIB" || exit $? + config/cc.sh "config/$LIB.c" "$LDLIB" || exit $? + ;; + --ldlibs) + LDLIBS="$LDLIBS $LDLIB" ;; esac done - if [ "$MODE" = "--ldlibs" ]; then - printf '\n' + if [ "$MODE" = "--ldlibs" ] && [ "$LDLIBS" ]; then + printf 'LDLIBS :=%s ${LDLIBS}\n' "$LDLIBS" fi fi diff --git a/config/pkgs.mk b/config/pkgs.mk new file mode 100644 index 0000000..54024b2 --- /dev/null +++ b/config/pkgs.mk @@ -0,0 +1,14 @@ +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +# Makefile that generates gen/pkgs.mk + +.OBJDIR: . + +include config/vars.mk +include ${GEN}/pkgs.mk + +default:: + config/pkgconf.sh --cflags ${PKGS} >>${TARGET} 2>>${TARGET}.log + config/pkgconf.sh --ldflags ${PKGS} >>${TARGET} 2>>${TARGET}.log + config/pkgconf.sh --ldlibs ${PKGS} >>${TARGET} 2>>${TARGET}.log diff --git a/config/vars.mk b/config/vars.mk new file mode 100644 index 0000000..a8fae9d --- /dev/null +++ b/config/vars.mk @@ -0,0 +1,21 @@ +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +# Makefile fragment loads and exports variables for config steps + +GEN := ${BUILDDIR}/gen +GEN := ${GEN:./%=%} + +include ${GEN}/vars.mk + +_CC := ${CC} +_CPPFLAGS := ${CPPFLAGS} +_CFLAGS := ${CFLAGS} +_LDFLAGS := ${LDFLAGS} +_LDLIBS := ${LDLIBS} + +export CC=${_CC} +export CPPFLAGS=${_CPPFLAGS} +export CFLAGS=${_CFLAGS} +export LDFLAGS=${_LDFLAGS} +export LDLIBS=${_LDLIBS} -- cgit v1.2.3