#!/bin/bash
. ./common.inc
set +x
BUILDHOST=/mnt/armlfs
echo $BUILDHOST$PREFIX
#read dummy
LIBS=$(ldd $PREFIX/bin/* | grep "/usr/lib/" | cut -d ' ' -f 1 | sort | uniq | grep -v 'ld-linux')
LIBS="$(echo $LIBS)"
su -c "mkdir -p $BUILDHOST$PREFIX"
su -c "cp -av $PREFIX/* $BUILDHOST$PREFIX/"
#echo $LIBS
#read dummy
cd /usr/lib
set +e
su -c "mkdir -p $BUILDHOST/usr/lib/aarch64"
su -c "cp -vLpn $LIBS $BUILDHOST/usr/lib/aarch64"
su -c "cp -vLpn /lib/ld-linux-aarch64.so.1 $BUILDHOST/lib/"
cd $BUILDHOST$PREFIX/bin
#echo $TARGET-*
#read dummy
for f in $(echo $TARGET-*); do
su -c "ln -vs $f ${f/#$TARGET-/}"
done
cd $BUILDHOST/mnt
su -c "ln -s / armlfs"
echo "Done."