1#!/bin/bash 2 3# Convenience wrapper to set $CROSS_COMPILE from short name using "ccc" 4# symlink (Cross C Compiler) to a directory of cross compilers named 5# $TARGET-*-cross. Tested with scripts/mcm-buildall.sh output. 6 7# Usage: scripts/cross.sh $TARGET make distclean defconfig toybox 8# With no arguments, lists available targets. Use target "all" to iterate 9# through each $TARGET from the list. 10 11CCC="$(dirname "$(readlink -f "$0")")"/../ccc 12if [ ! -d "$CCC" ] 13then 14 echo "Create symlink 'ccc' to cross compiler directory, ala:" 15 echo " ln -s ~/musl-cross-make/ccc ccc" 16 exit 1 17fi 18 19unset X Y 20 21# Display target list? 22list() 23{ 24 ls "$CCC" | sed 's/-.*//' | sort -u | xargs 25} 26[ $# -eq 0 ] && list && exit 27 28X="$1" 29shift 30 31# build all targets? 32if [ "$X" == all ] 33then 34 for TARGET in $(list) 35 do 36 { 37 export TARGET 38 "$0" $TARGET "$@" 2>&1 || mv cross-log-$TARGET.{txt,failed} 39 } | tee cross-log-$TARGET.txt 40 done 41 42 exit 43fi 44 45# Call command with CROSS_COMPILE= as its first argument 46 47Y=$(echo "$CCC/$X"-*cross) 48Z=$(basename "$Y") 49Y=$(readlink -f "$CCC"/$X-*cross) 50export TARGET="${Z/-*/}" 51X="$Y/bin/${Z/-cross/-}" 52[ ! -e "${X}cc" ] && echo "${X}cc not found" && exit 1 53 54CROSS_COMPILE="$X" "$@" 55