100 lines
2.2 KiB
Plaintext
100 lines
2.2 KiB
Plaintext
|
#! /usr/bin/bash
|
||
|
|
||
|
usage() {
|
||
|
echo "usage: $0 --platform=<platform> [options...]"
|
||
|
echo ""
|
||
|
echo "Available platforms:"
|
||
|
|
||
|
for file in config/*.cfg; do
|
||
|
platform="${file#config/}"
|
||
|
platform="${platform%.cfg}"
|
||
|
|
||
|
printf ' %-10s' "$platform"
|
||
|
head -1 "$file" | sed 's/^# *//'
|
||
|
done
|
||
|
|
||
|
echo ""
|
||
|
echo "Options for fx9860g and fxcg50:"
|
||
|
echo " --toolchain=<toolchain>"
|
||
|
echo " Target triplet; default is 'sh3eb-elf' for fx9860g and 'sh4eb-elf'"
|
||
|
echo " for fxcg50"
|
||
|
echo " --prefix=<path>"
|
||
|
echo " Library install path, guessed automatically by asking the compiler"
|
||
|
echo " if not specified"
|
||
|
|
||
|
exit ${1:-1}
|
||
|
}
|
||
|
|
||
|
platform=
|
||
|
toolchain=
|
||
|
|
||
|
# Parse command-line arguments
|
||
|
|
||
|
for arg in "$@"; do case "$arg" in
|
||
|
-h|--help|"-?")
|
||
|
usage 0;;
|
||
|
--platform=*)
|
||
|
platform=${arg#*=};;
|
||
|
--toolchain=*)
|
||
|
toolchain=${arg#*=};;
|
||
|
--prefix=*)
|
||
|
prefix=${arg#*=};;
|
||
|
*)
|
||
|
echo "error: unrecognized option '$arg'" 2>&1
|
||
|
error=1;;
|
||
|
esac; done
|
||
|
|
||
|
# Check validity
|
||
|
|
||
|
if [ -z "$platform" ]; then
|
||
|
echo "error: please specify a platform" 2>&1
|
||
|
echo "Try '$0 --help' for more information."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [ ! -f "config/$platform.cfg" ]; then
|
||
|
echo "error: unknown platform '$platform'" 2>&1
|
||
|
echo "Try '$0 --help' for a list of available platforms."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Guess toolchains
|
||
|
|
||
|
[[ $platform == fx9860g && -z $toolchain ]] && toolchain=sh3eb-elf
|
||
|
[[ $platform == fxcg50 && -z $toolchain ]] && toolchain=sh4eb-elf
|
||
|
|
||
|
# Guess compiler paths
|
||
|
|
||
|
if [[ ( $platform == fx9860g || $platform == fxcg50 ) && -z $prefix ]]; then
|
||
|
echo "No prefix specified, let's ask the compiler:"
|
||
|
echo " $toolchain-gcc --print-search-dirs | grep install | sed 's/install: //'"
|
||
|
inst=$($toolchain-gcc --print-search-dirs | grep install | sed 's/install: //')
|
||
|
|
||
|
if [[ $? != 0 ]]; then
|
||
|
echo "Call returned $?, giving up."
|
||
|
fi
|
||
|
|
||
|
echo "Got '$inst'".
|
||
|
|
||
|
if [[ ! -d $inst ]]; then
|
||
|
echo "Directory does not exist (or is not a directory), giving up."
|
||
|
fi
|
||
|
|
||
|
echo ""
|
||
|
prefix=$inst
|
||
|
fi
|
||
|
|
||
|
# Output configuration
|
||
|
|
||
|
output_config() {
|
||
|
echo "PLATFORM=$platform"
|
||
|
|
||
|
if [[ $platform == fx9860g || $platform == fxcg50 ]]; then
|
||
|
echo "TOOLCHAIN=$toolchain"
|
||
|
echo "PREFIX=$prefix"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
output_config > Makefile.cfg
|
||
|
echo "Makefile.cfg now links to the platform file 'config/$platform.cfg'."
|