From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wolfgang Grandegger Date: Fri, 3 Mar 2017 15:18:49 +0100 Subject: [Buildroot] [RFC PATCH 5/9] support/scripts: add create-relocation-script for toolchain relocation In-Reply-To: <1488550733-3956-1-git-send-email-wg@grandegger.com> References: <1488550733-3956-1-git-send-email-wg@grandegger.com> Message-ID: <1488550733-3956-6-git-send-email-wg@grandegger.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: buildroot@busybox.net It will create the script "relocate-toolchain.sh" in $HOST_DIR/usr/ allowing to adjust the path to the toolchain directory in all text files after it has been moved to a new location. Signed-off-by: Wolfgang Grandegger --- support/scripts/create-relocation-script | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 support/scripts/create-relocation-script diff --git a/support/scripts/create-relocation-script b/support/scripts/create-relocation-script new file mode 100755 index 0000000..0ceaeb2 --- /dev/null +++ b/support/scripts/create-relocation-script @@ -0,0 +1,72 @@ +#!/bin/sh + +# Creates the script "relocate-toolchain.sh" and the "location" file in +# the buildroot toolchain (host/usr). After copying that toolchain tree +# to a new location, the script in the top directory should be executed +# to relocate the toolchain. It actually will replace the string of the +# old location with the new one in *all* text files. + +if [ "$#" -ne 1 -o ! -d "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +# The toolchain is in buildroot's "host/usr" +TOOLCHAINDIR="$1/usr" +# We create the script in the top directory of the toolchain +SCRIPTFILE="${TOOLCHAINDIR}/relocate-toolchain.sh" +# File holding the location of the buildroot toolchain +LOCATIONFILE="share/buildroot/toolchain-location" + +echo "Creating ${SCRIPTFILE} for toolchain relocation ..." + +cat << EOF > "${SCRIPTFILE}" +#!/bin/sh +# +# Automatically generated by $0: don't edit +# +if [ "\$#" -ne 0 ]; then + echo "Run this script to relocate the buildroot toolchain at that location" + exit 1 +fi + +FILEPATH="\$(readlink -f \$0)" +NEWPATH="\$(dirname \${FILEPATH})" + +cd \${NEWPATH} +if [ ! -r ./${LOCATIONFILE} ]; then + echo "Previous location of the buildroot toolchain not found!" + exit 1 +fi +OLDPATH="\$(cat ./${LOCATIONFILE})" + +if [ \${NEWPATH} = \${OLDPATH} ]; then + echo "This buildroot toolchain has already been relocated!" + exit 0 +fi + +echo "Relocating the buildroot toolchain from \${OLDPATH} to \${NEWPATH} ..." + +# Make sure file uses the right language +export LC_ALL=C +# Replace the old path with the new one in all text files +for FILE in \$(grep -r "\${OLDPATH}" . -l ) ; do + if [ ! -h \${FILE} ] && [ -n "\$(file -b --mime-type \${FILE} | grep '^text/' )" ] && [ "\${FILE}" != "./${LOCATIONFILE}" ] + then + sed -i s,"\${OLDPATH}",\${NEWPATH},g \${FILE} + fi +done + +# Finally, we update the location file itself +sed -i s,"\${OLDPATH}",\${NEWPATH},g ./${LOCATIONFILE} + +# Check if the path substitution did work properly +if [ "\${NEWPATH}" != "\$(cat ./${LOCATIONFILE})" ]; then + echo "Something went wrong with substituting the path!" + echo "Please choose another location for your toolchain!" +fi +EOF +chmod +x "${SCRIPTFILE}" +mkdir -p $(dirname "$1/usr/${LOCATIONFILE}") +# Finally write the toolchain location +echo "$TOOLCHAINDIR" > "${TOOLCHAINDIR}/${LOCATIONFILE}" -- 1.9.1