summaryrefslogtreecommitdiffstats
path: root/config/pkgconf.sh
blob: 286c19c356bfc1b551c6386f404798cf748851b1 (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
#!/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 command -v "${PKG_CONFIG:-}" &>/dev/null; then
    case "$MODE" in
        --cflags)
            "$PKG_CONFIG" --cflags "$@"
            ;;
        --ldflags)
            "$PKG_CONFIG" --libs-only-L --libs-only-other "$@"
            ;;
        --ldlibs)
            "$PKG_CONFIG" --libs-only-l "$@"
            ;;
        "")
            "$PKG_CONFIG" "$@"
            ;;
    esac
else
    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
            --ldlibs)
                printf ' %s' "$LDLIB"
                ;;
            "")
                config/cc.sh "config/$lib.c" "$LDLIB" || exit $?
                ;;
        esac
    done

    if [ "$MODE" = "--ldlibs" ]; then
        printf '\n'
    fi
fi