aboutsummaryrefslogtreecommitdiff
blob: b440c48d48451c8488d457dd84371a23143531c8 (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
#!/bin/sh
# Copyright 2008-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

#
# fix library perms, mung paths in pkg-config files, libtool linker scripts,
# and random -config scripts to point to our build directory, and cross-compile
# symlinks for the -config scripts as autotool packages will search for
# prefixed -config scripts when cross-compiling.  note: the ugly ln/mv is to
# work around a possible race condition if multiple make jobs are generating
# the same symlink at the same time.  a `mv` is "atomic" (it uses rename())
# while a `ln` is actually unlink();symlink();.
#

LIBDIR="usr/lib"
SYSROOT=${SYSROOT:-${ROOT:-${STAGEDIR}}}
CROSS_BINDIR=""
if [ -n "${ROOTDIR}" ] ; then
	# uClinux-dist mojo
	CROSS_BINDIR="${ROOTDIR}/tools"
fi
CROSS_PREFIX=${CROSS_COMPILE}
if [ -n "$3" ] ; then
	SYSROOT="$1"
	CROSS_BINDIR="$2"
	CROSS_PREFIX="$3"
elif [ -n "$1" ] ; then
	if [ -e "/usr/$1" ] ; then
		SYSROOT="/usr/$1"
		CROSS_BINDIR="/usr/bin"
		CROSS_PREFIX="$1-"
	else
		exit 1
	fi
fi

cd "${SYSROOT}" || exit 0

if [ -d "${LIBDIR}" ] ; then
	find "./${LIBDIR}/" -name 'lib*.so*' -print0 | xargs -0 -r chmod 755
	find "./${LIBDIR}/" -name 'lib*.la' -o -name 'lib*.a' -print0 | xargs -0 -r chmod 644
	find "./${LIBDIR}/" -name 'lib*.la' -print0 | xargs -0 -r \
		sed -i \
			-e "/^libdir=/s:=.*:='${SYSROOT}/usr/lib':" \
			-e "/^dependency_libs=/s: /usr/lib/: ${SYSROOT}/usr/lib/:g"
fi

if [ -d "${LIBDIR}/pkgconfig" ] ; then
	find "./${LIBDIR}/pkgconfig/" ./usr/share/pkgconfig/ -name '*.pc' -print0 | xargs -0 -r \
		sed -i "/^prefix=/s:=.*:='${SYSROOT}/usr':"
fi

if [ -d usr/bin ] ; then
	find ./usr/bin/ -name '*-config' -print0 | xargs -0 -r \
		sed -i "/^prefix=/s:=.*:='${SYSROOT}/usr':"

	if [ -n "${CROSS_BINDIR}" ] && [ -d "${CROSS_BINDIR}" ] && [ -n "${CROSS_PREFIX}" ] ; then
		cd usr/bin || exit 1
		for config in *-config ; do
			ln -s "${SYSROOT}/usr/bin/${config}" "${CROSS_BINDIR}/${CROSS_PREFIX}${config}.$$"
			mv "${CROSS_BINDIR}/${CROSS_PREFIX}${config}.$$" "${CROSS_BINDIR}/${CROSS_PREFIX}${config}"
		done
		cd ../..
	fi
fi

exit 0