summaryrefslogtreecommitdiff
path: root/util/pkg-config.sh
blob: 94edf7d95825f930c49e6b5f3208f8862da64a6b (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
#!/bin/bash

#echo 1>&2
#echo ::: "$@" 1>&2

declare -a args
declare -a pkgs
unset dbpf

while [[ $# -ne 0 ]]; do case "$1" in
    (--version)
	echo "0.29.1"
	exit 0
    ;;
    (--atleast-pkgconfig-version)
        exec pkg-config "$1" "$2"
    ;;

    (--cflags|--libs|--libs-only-l|--libs-only-L|--cflags-only-I|--variable=*)
        dbpf=
        args[${#args[@]}]=$1
    ;;

    (--errors-to-stdout|--exists|--modversion|--print-errors|--short-errors|--uninstalled|--debug)
        args[${#args[@]}]=$1
    ;;

    (--atleast-version|--exact-version|--max-version)
        args[${#args[@]}]=$1
        args[${#args[@]}]=$2
        shift
    ;;

		(--atleast-version=*)
        args[${#args[@]}]=--atleast-version
				args[${#args[@]}]=$(echo $1 | cut -d = -f 2)
    ;;

    (--*)
        echo "unknown pkg-config option $1" 1>&2
        exit 1
    ;;

    (*)
        pkgs[${#pkgs[@]}]=$1
    ;;
esac; shift; done

if [[ ${dbpf+@} ]]; then
    source "${PKG_BASE}/folders.sh"
fi

outs=
for pkg in "${pkgs[@]}"; do
    declare -a pkgspec
    pkgspec=( ${pkg} )
    args_=("${args[@]}")

    if [[ ${dbpf+@} ]]; then
        dest=$(for dep in $(find -L "${PKG_DATA}"/_metadata -name '*.dep'); do
            DEP_NAME=$(basename "${dep}" .dep)
            DEP_DEST=$(PKG_DEST_ "${DEP_NAME}")

            find "${DEP_DEST}" -name "${pkgspec}.pc" -printf "${DEP_DEST}\n"
        done | head -n 1) && args_=(--define-variable=prefix="${dest}/usr" "${args_[@]}")
    fi

    echo @@@ pkg-config "${args_[@]}" "${pkg}" 1>&2
    out=$(pkg-config "${args_[@]}" "${pkg}") || exit $?
    #echo "=== ${out}" 1>&2
    outs+=\ ${out}
done

echo "${out#\ }"