Skip to content

Instantly share code, notes, and snippets.

@Juul
Last active May 16, 2019 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juul/560a245365ef738f061c216acb15f41e to your computer and use it in GitHub Desktop.
Save Juul/560a245365ef738f061c216acb15f41e to your computer and use it in GitHub Desktop.
Switch currently used gcc cross-compiler versions
#!/bin/bash
# This script changes the `arm-linux-gnueabihf-*` (or specified prefix)
# symlinks in /usr/bin to point to the specified version
# e.g. running with "7" as the argument will create the symlink
# /usr/bin/arm-linux-gnueabihf-gcc -> /usr/bin/arm-linux-gnueabihf-gcc-7
# and so on for all the normal cross-compiler commands
CMDS=( "gcc" "gcc-ar" "gcc-nm" "gcc-ranlib" "cpp" "gcov" "gcov-dump" "gcov-tool" )
BINPATH=/usr/bin
set -e
if [ "$#" -lt "1" ] || [ "$#" -gt "2" ]; then
echo "Usage: $0 <version_number> [prefix] " >&2
echo "" >&2
echo " Where [prefix] is the binary prefix e.g. 'arm-linux-gnueabihf' (the default)" >&2
echo "" >&2
exit 1
fi
if [ "$EUID" -ne "0" ]
then echo "This script must be run as root" >&2
exit 1
fi
cd $BINPATH
# First argument is version number
VERSION=$1
# Second (optional) argument is binary prefix
if [ ! -z "$2" ]; then
PREFIX="${2}-"
else
PREFIX="arm-linux-gnueabihf-"
fi
function do_symlink {
ACTUALLY_SYMLINK=$1
if [ ! -z $ACTUALLY_SYMLINK ]; then
echo "Symlinking:"
fi
for CMD in "${CMDS[@]}"
do
SYMPATH="${PREFIX}$CMD"
CMDPATH="${SYMPATH}-$VERSION"
if [ ! -f $CMDPATH ]; then
echo "File does not exist: $CMDPATH" >&2
exit 1
fi
if [ ! -z $ACTUALLY_SYMLINK ]; then
echo "${BINPATH}/$SYMPATH -> ${BINPATH}/$CMDPATH"
rm -f $SYMPATH
ln -s $CMDPATH $SYMPATH
fi
done
}
do_symlink
do_symlink 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment