Trouble shooting: cross-fix-root

File cross-fix-root, 1.4 KB (added by max_posedon, 3 years ago)

dagger's cross-fix-root

Line 
1#!/bin/bash
2# Copyright 2008 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4# $Header: $
5
6# - solar
7
8CROSS_ROOT=""
9[[ $1 != "" ]] && [ -e /usr/$1 ] && CROSS_ROOT="/usr/$1"
10[[ -e ${CROSS_ROOT} ]] || exit 0
11
12function strip_path() {
13        echo $1 | grep -Eo "[^\/]+$"
14}
15
16function re_safe() {
17        echo $1 | gawk '{ gsub("/","\\/"); print }'
18}
19
20fix_la_files() {
21        count=0
22        for LA in $(find $CROSS_ROOT/usr/lib/ -iname *.la); do
23                [ -e $LA ] || continue
24                count=$(($count+1))
25                sed  -i -e "s;libdir='/usr/lib';libdir='$CROSS_ROOT/usr/lib';" \
26                        -e s@" /usr/lib"@" ${CROSS_ROOT}/usr/lib"@g $LA
27                [[ $? != 0 ]] && printf "FAIL $LA or $CROSS_ROOT FAILED sucka\n"
28        done
29        return $count
30}
31
32fix_pc_files() {
33        count=0
34        for PC in $CROSS_ROOT/usr/lib/pkgconfig/*.pc; do
35                [ -e $PC ] || continue
36                sed -i -e "s/^prefix\\=\\/usr$/prefix\=$(re_safe "$CROSS_ROOT")\\/usr/" $PC
37                sed -i -e "s:^exec_prefix=/usr:exec_prefix=\${prefix}:" $PC
38                sed -i -e "s:^libdir=/usr/lib:libdir=\${prefix}/lib:" $PC
39                sed -i -e "s:^includedir=/usr/include:includedir=\${prefix}/include:" $PC
40                count=$(($count+1))
41                [[ $? != 0 ]] && printf "Fixing $PC for $CROSS_ROOT FAILED sucka\n"
42        done
43        return $count
44}
45
46fix_la_files ${CROSS_ROOT}
47la_count=$?
48fix_pc_files ${CROSS_ROOT}
49pc_count=$?
50:
51( . /etc/init.d/functions.sh ; einfo "Scanned/Fixed $pc_count "'*'".pc and $la_count "'*'".la files" )