aboutsummaryrefslogtreecommitdiff
blob: d2eccfb811a434dac74c402d7a15431008c09812 (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
83
84
85
86
87
88
89
90
91
#!/bin/sh
# Copyright 2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

#
# This creates a pkg-config frontend that has the form TARGET-pkg-config
# as this is the utility that autoconf scripts will automatically search
# for when cross-compiling for TARGET.  Here we setup the pkg config env
# paths so that the .pc files that are searched and used come from the
# staging directory rather than the host system.
#

#
# Helper functions.  So very helpful.
#
msg_to_stderr() { echo "cross-pkg-config: $*" 1>&2 ; }
warn() { msg_to_stderr "warning: $*" ; }
error() {
	msg_to_stderr "error: $*"
	exit 1
}

#
# Sanity/distro checks
#
if ver=$(pkg-config --version) ; then
	if [ ${ver#0.1} != ${ver} ] ; then
		error pkg-config is too old ... upgrade it
	fi
else
	error unable to find pkg-config in PATH
fi

unset EXTRA_PKG_CONFIG_LIBDIR
if [ -n "${ROOT}" ] ; then
	# Gentoo
	SYSROOT=${ROOT}
elif [ -n "${STAGEDIR}" ] ; then
	# uClinux-dist
	SYSROOT=${STAGEDIR}
	EXTRA_PKG_CONFIG_LIBDIR=${UCLINUX_PKG_CONFIG_LIBDIR}
else
	error "Need \$ROOT or \$STAGEDIR set first"
fi
# abort infinite loop due to misconfiguration
[ "${0##*/}" = "pkg-config" ] && error "aborting infinite loop! (make sure to delete uClinux-dist/tools/pkg-config)"

#
# Some distributions pollute the pkg-config environment.
# Time to pull a captain planet on them.
#
unset PKG_CONFIG_PATH
unset PKG_CONFIG_ALLOW_SYSTEM_CFLAGS
unset PKG_CONFIG_ALLOW_SYSTEM_LIBS

#
# Set the pkg-config search paths to our staging directory.
#
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig"
if [ -n "${EXTRA_PKG_CONFIG_LIBDIR}" ] ; then
	EXTRA_CONFIG_LIBDIR="${EXTRA_PKG_CONFIG_LIBDIR}:${PKG_CONFIG_LIBDIR}"
fi

#
# Sanity check the output to catch common errors that do not
# cause failures until much later on.
#
output=$(pkg-config "$@")
ret=$?
case " ${output} " in
	*" -L/usr/lib "*|*" -L/usr/local/lib "*|\
	*" -L /usr/lib "*|*" -L /usr/local/lib "*|\
	*" -L/usr/lib64 "*|*" -L/usr/local/lib64 "*|\
	*" -L /usr/lib64 "*|*" -L /usr/local/lib64 "*)
		warn "### falling down so here is a dump state ######"
		export PKG_CONFIG_DEBUG_SPEW="yes"
		pkg-config --debug "$@" 1>&2
		warn "### end of dump ###############################"
		error "host -L paths detected: ${output}"
		;;
	*" -I/usr/include"*|*" -I/usr/local/include"*)
		warn "### falling down so here is a dump state ######"
		export PKG_CONFIG_DEBUG_SPEW="yes"
		pkg-config --debug "$@" 1>&2
		warn "### end of dump ###############################"
		error "host -I paths detected: ${output}"
		;;
esac
[ -n "${output}" ] && echo "${output}"
exit ${ret}