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

PKGCONFIG=/usr/bin/pkg-config

if [ \! "$SYSROOT" ]; then
	echo >&2
	echo >&2
	echo "pkg-config: missing \$SYSROOT environment variable" >&2
	echo >&2
	echo >&2
	exit 2
fi

if [ ! "$PKG_CONFIG_LIBDIR" ]; then
    export PKG_CONFIG_LIBDIR=$SYSROOT/lib/pkgconfig:$SYSROOT/usr/lib/pkgconfig
fi

export PKG_CONFIG_LIBDIR
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1

#
# 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. 
# 

OUTPUT=`$PKGCONFIG $*` || exit $?

echo -n $OUTPUT |
	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;"