Last active
February 23, 2017 17:34
-
-
Save nezticle/affaee3d3905489c95f7 to your computer and use it in GitHub Desktop.
Change absolute lib paths to relative ones (for creating sysroots)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This script is ugly, feel free to fix it | |
if [ "$#" -ne 2 ]; then | |
echo "usage ./cmd target-rootfs machine-eabi" | |
exit -1 | |
fi | |
#passed args | |
ROOTFS=$1 | |
MACHINE=$2 | |
if [ ! -z $MACHINE ]; then | |
echo "Machine defined" | |
DEB_MULTI_ARCH_USR_LIB=$ROOTFS/usr/lib/$MACHINE | |
DEB_MULTI_ARCH_LIB=$ROOTFS/lib/$MACHINE | |
fi | |
INITIAL_DIR=$PWD | |
function adjustSymLinks | |
{ | |
echo "Adjusting the symlinks in $1 to be relative" | |
cd $1 | |
find . -maxdepth 1 -type l | while read i; | |
do qualifies=$(file $i | sed -e "s/.*\`\(.*\)'/\1/g" | grep ^/lib) | |
if [ -n "$qualifies" ]; then | |
newPath=$(file $i | sed -e "s/.*\`\(.*\)'/\1/g" | sed -e "s,\`,,g" | sed -e "s,',,g" | sed -e "s,^/lib,$2/lib,g"); | |
echo $i | |
echo $newPath; | |
rm $i; | |
ln -s $newPath $i; | |
fi | |
done | |
cd $INITIAL_DIR | |
} | |
adjustSymLinks $ROOTFS/usr/lib "../.." | |
adjustSymLinks $ROOTFS/lib "../" | |
echo "Testing for existence of potential debian multi-arch dir: $DEB_MULTI_ARCH_USR_LIB" | |
if [ -n "$DEB_MULTI_ARCH_USR_LIB" -a -e "$DEB_MULTI_ARCH_USR_LIB" ]; then | |
echo "Debian multiarch dir exists, adjusting" | |
adjustSymLinks $DEB_MULTI_ARCH_USR_LIB "../.." | |
fi | |
echo "Testing for existence of potential debian multi-arch dir: $DEB_MULTI_ARCH_LIB" | |
if [ -n "$DEB_MULTI_ARCH_LIB" -a -e "$DEB_MULTI_ARCH_LIB" ]; then | |
echo "Debian multiarch dir exists, adjusting" | |
adjustSymLinks $DEB_MULTI_ARCH_LIB "../.." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment