summaryrefslogtreecommitdiffstats
path: root/scripts/pkg-config-wrapper
blob: b51c8e890c8d3565e11dc6d271b8b49e557bae39 (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
#!/bin/bash

PKG_CONFIG_ARRAY=(`type -a -P pkg-config`)
PKG_CONFIG="${PKG_CONFIG_ARRAY[1]}"

check_pipe_status() {
    for i in  "${PIPESTATUS[@]}"; do
	if test $i -ne 0; then
	    exit $i
	fi
    done
}

if test -z "${SYSROOT}"; then
    cat >&2 <<EOF


pkg-config: missing \$SYSROOT environment variable"


EOF
    exit 1
fi

export PKG_CONFIG_LIBDIR="${SYSROOT}/lib/pkgconfig:${SYSROOT}/usr/lib/pkgconfig"
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
unset found_var

if [ -n "${PKG_CONFIG_PATH}" ]; then
    orig_ifs="${IFS}"
    IFS=':'
    pkg_config_path_array=( ${PKG_CONFIG_PATH} )
    IFS="${orig_ifs}"
    unset orig_ifs

    PKG_CONFIG_PATH="${SYSROOT}${pkg_config_path_array[0]}"
    unset pkg_config_path_array[0]

    for p in "${pkg_config_path_array[@]}"; do
	PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${SYSROOT}${p}"
    done

    unset p
    unset pkg_config_path_array
fi

for ((i = 1; i <= ${#}; i++)); do
    case "${!i}" in
	--variable*)
	    found_var=true
	    break
	    ;;
	*)
	    ;;
    esac
done


if [ -n "${found_var}" ]; then
    #
    # if someone asks for a variable, if it looks like a path
    # (starting with /) prefix it with sysroot
    #
    if [ -n "${PTXDIST_PKG_CONFIG_VAR_NO_SYSROOT}" ]; then
	exec "${PKG_CONFIG}" "${@}"
    else
	"${PKG_CONFIG}" "${@}" | sed -e "s~^/~${SYSROOT}/~"
	check_pipe_status
    fi
else
    #
    # 1) protect already given sysroot
    # 2) add sysroot symbol to all absolute paths
    # 3) replace sysroot sign to sysroot path
    #
    "${PKG_CONFIG}" "${@}" |
    sed -e "s~\-L/*${SYSROOT}/*~-L=/~g; s~\-I/*${SYSROOT}/*~-I=/~g;" \
	-e "s~\-L/~-L=/~g; s~\-I/~-I=/~g;"                       \
	-e "s~\-L\=~-L${SYSROOT}~g; s~\-I\=~-I${SYSROOT}~g;"
    check_pipe_status
fi