Skip to content

Instantly share code, notes, and snippets.

@ajaysusarla
Last active April 11, 2016 13:18
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 ajaysusarla/29434e288a6f6d6ae2a0baba20774968 to your computer and use it in GitHub Desktop.
Save ajaysusarla/29434e288a6f6d6ae2a0baba20774968 to your computer and use it in GitHub Desktop.
GCC cross compiler
#!/bin/bash
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# NOTE:This script works only with bash
#
# Build a cross compiler(gcc) for a requested platform.
PROGNAME=${0##*/}
OPTIND=1
BUILDDIR=""
PLATFORM=""
function usage() {
echo -e "USAGE: ./${PROGNAME} -p <target-platform> -b <builddir>"
echo -e "WHERE:"
echo -e " <target-platform> - [i686,arm]."
echo -e " <build-dir> - build directory."
}
function validate_builddir() {
if [ "$BUILDDIR" == "" ];
then
echo -e "Need to specify build directory with '-b'.\n"
usage
exit 1
fi
}
function validate_platform() {
if [ "$PLATFORM" == "" ];
then
echo -e "Need to specify platform with '-p'\n"
usage
exit 1
fi
case "$PLATFORM" in
"arm")
return
;;
"i686")
return
;;
esac
echo -e "Invalid platform. Chose one of [arm, i686]"
exit 1
}
while getopts "h?b:p:" opt;
do
case "$opt" in
h|\?)
usage
exit 0
;;
b)
BUILDDIR=$OPTARG
;;
p)
PLATFORM=$OPTARG
;;
esac
done
shift $((OPTIND-1))
validate_builddir
validate_platform
[ "$1" = "--" ] && shift
# What's left will now be available in $@
echo "PLATFORM=$PLATFORM, BUILDDIR=$BUILDDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment