summaryrefslogtreecommitdiffstats
path: root/config/pkg.sh
blob: 6335b4b48503d1ad1205549bb7546f6c7e56ca50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash

# Copyright © Tavian Barnes <tavianator@tavianator.com>
# SPDX-License-Identifier: 0BSD

# pkg-config wrapper that outputs a makefile fragment

set -eu

NAME="${1^^}"
declare -n XUSE="XUSE_$NAME"

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 '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