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

PKGCONFIG=/usr/bin/pkg-config

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

if test -z "${SYSROOT}"; then
    (
	echo
	echo
	echo "pkg-config: missing \$SYSROOT environment variable"
	echo
	echo
    ) >2
    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

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


if ${found_var}; then
#
# if someone asks for a variable, if it looks like a path (starting with /)
# prefix it with sysroot
#
    ${PKGCONFIG} "${@}" |
    sed -e "s~^/~${SYSROOT}/~"
else
#
# 1) protect already given sysroot
# 2) add sysroot symbol to all absolute paths
# 3) replace sysroot sign to sysroot path
# 4) libtool isn't correctly DESTDIR/SYSROOT aware, it replaces -lfoo by
#    paths leading to host libraries; using -Wl,-lfoo seems to work. 
# 
    ${PKGCONFIG} "${@}" |
    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;"         \
	-e "s~[\t ]\-l~ -Wl,-l~g;"
fi    

check_pipe_status