aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-10-29 01:17:38 -0400
committerMike Frysinger <vapier@gentoo.org>2008-10-29 01:17:38 -0400
commite889d3a5fcc8b81c516a896f3b658787394fa425 (patch)
tree1bda18d657ba355358413ca5ad0de3973628ffd4 /wrappers/cross-fix-root
parentcross-pkg-config: unify uClinux-dist and Gentoo (diff)
downloadcrossdev-e889d3a5fcc8b81c516a896f3b658787394fa425.tar.gz
crossdev-e889d3a5fcc8b81c516a896f3b658787394fa425.tar.bz2
crossdev-e889d3a5fcc8b81c516a896f3b658787394fa425.zip
cross-fix-root: rewrite with stuff from uClinux-dist
Rewrite the script to fix more things and be safer in general. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'wrappers/cross-fix-root')
-rwxr-xr-xwrappers/cross-fix-root100
1 files changed, 56 insertions, 44 deletions
diff --git a/wrappers/cross-fix-root b/wrappers/cross-fix-root
index a8469c2..3296df2 100755
--- a/wrappers/cross-fix-root
+++ b/wrappers/cross-fix-root
@@ -1,48 +1,60 @@
-#!/bin/bash
+#!/bin/sh
# Copyright 2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
-# - solar
-
-CROSS_ROOT=""
-[[ $1 != "" ]] && [ -e /usr/$1 ] && CROSS_ROOT="/usr/$1"
-[[ -e ${CROSS_ROOT} ]] || exit 0
-
-function strip_path() {
- echo $1 | grep -Eo "[^\/]+$"
-}
-
-function re_safe() {
- echo $1 | gawk '{ gsub("/","\\/"); print }'
-}
-
-fix_la_files() {
- count=0
- for LA in $(find $CROSS_ROOT/usr/lib/ -iname *.la); do
- [ -e $LA ] || continue
- count=$(($count+1))
- sed -i -e "s;libdir='/usr/lib';libdir='$CROSS_ROOT/usr/lib';" \
- -e s@" /usr/lib"@" ${CROSS_ROOT}/usr/lib"@g $LA
- [[ $? != 0 ]] && printf "FAIL $LA or $CROSS_ROOT FAILED sucka\n"
- done
- return $count
-}
-
-fix_pc_files() {
- count=0
- for PC in $CROSS_ROOT/usr/lib/pkgconfig/*.pc; do
- [ -e $PC ] || continue
- sed -i -e "s/^prefix\\=\\/usr$/prefix\=$(re_safe "$CROSS_ROOT")\\/usr/" $PC
- count=$(($count+1))
- [[ $? != 0 ]] && printf "Fixing $PC for $CROSS_ROOT FAILED sucka\n"
- done
- return $count
-}
-
-fix_la_files ${CROSS_ROOT}
-la_count=$?
-fix_pc_files ${CROSS_ROOT}
-pc_count=$?
-:
-( . /sbin/functions.sh ; einfo "Scanned/Fixed $pc_count "'*'".pc and $la_count "'*'".la files" )
+#
+# 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 "$1" ] && [ -e "/usr/$1" ] ; then
+ SYSROOT="/usr/$1"
+ CROSS_BINDIR="/usr/bin"
+ CROSS_PREFIX="$1-"
+fi
+
+cd "${SYSROOT}" || exit 1
+
+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/" -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}.$$"
+ mv "${CROSS_BINDIR}/${CROSS_PREFIX}.$$" "${CROSS_BINDIR}/${CROSS_PREFIX}"
+ done
+ cd ../..
+ fi
+fi
+
+exit 0