summaryrefslogtreecommitdiffstats
path: root/config/pkgconf.sh
blob: 80dcbeeae06121e32a2a8877184675f6284ce9b4 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash

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

# pkg-config wrapper with hardcoded fallbacks

set -eu

MODE=
if [[ "${1:-}" == --* ]]; then
    MODE="$1"
    shift
fi

if (($# < 1)); then
    exit
fi

if [[ "$XNOLIBS" == *y* ]]; then
    exit 1
fi

if command -v "${XPKG_CONFIG:-}" &>/dev/null; then
    case "$MODE" in
        "")
            "$XPKG_CONFIG" "$@"
            ;;
        --cflags)
            OUT=$("$XPKG_CONFIG" --cflags "$@")
            if [ "$OUT" ]; then
                printf 'CFLAGS += %s\n' "$OUT"
            fi
            ;;
        --ldflags)
            OUT=$("$XPKG_CONFIG" --libs-only-L --libs-only-other "$@")
            if [ "$OUT" ]; then
                printf 'LDFLAGS += %s\n' "$OUT"
            fi
            ;;
        --ldlibs)
            OUT=$("$XPKG_CONFIG" --libs-only-l "$@")
            if [ "$OUT" ]; then
                printf 'LDLIBS := %s ${LDLIBS}\n' "$OUT"
            fi
            ;;
    esac
else
    LDLIBS=""
    for LIB; do
        case "$LIB" in
            libacl)
                LDLIB=-lacl
                ;;
            libcap)
                LDLIB=-lcap
                ;;
            libselinux)
                LDLIB=-lselinux
                ;;
            liburing)
                LDLIB=-luring
                ;;
            oniguruma)
                LDLIB=-lonig
                ;;
            *)
                printf 'error: Unknown package %s\n' "$LIB" >&2
                exit 1
                ;;
        esac

        case "$MODE" in
            "")
                config/cc.sh "config/$LIB.c" "$LDLIB" || exit $?
                ;;
            --ldlibs)
                LDLIBS="$LDLIBS $LDLIB"
                ;;
        esac
    done

    if [ "$MODE" = "--ldlibs" ] && [ "$LDLIBS" ]; then
        printf 'LDLIBS :=%s ${LDLIBS}\n' "$LDLIBS"
    fi
fi