aboutsummaryrefslogtreecommitdiff
path: root/scripts/cross.sh
blob: 34fef0f7a911bc84e5632128a919cc5fbeaa3f7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

# Convenience wrapper to set $CROSS_COMPILE from short name using "ccc"
# symlink (Cross C Compiler) to a directory of cross compilers named
# $TARGET-*-cross. Tested with scripts/mcm-buildall.sh output.

# Usage: scripts/cross.sh $TARGET make distclean defconfig toybox
# With no arguments, lists available targets. Use target "all" to iterate
# through each $TARGET from the list.

CCC="$(dirname "$(readlink -f "$0")")"/../ccc
if [ ! -d "$CCC" ]
then
  echo "Create symlink 'ccc' to cross compiler directory"
  exit 1
fi

unset X Y

# Display target list?
list()
{
  ls "$CCC" | sed 's/-.*//' | sort -u | xargs
}
[ $# -eq 0 ] && list && exit

X="$1"
shift

# build all targets?
if [ "$X" == all ]
then
  for TARGET in $(list)
  do
    {
      export TARGET
      "$0" $TARGET "$@" 2>&1 || mv cross-log-$TARGET.{txt,failed}
    } | tee cross-log-$TARGET.txt
  done

  exit
fi

# Call command with CROSS_COMPILE= as its first argument

Y=$(readlink -f "$CCC"/$X-*cross)
X=$(basename "$Y")
export TARGET="${X/-*/}"
X="$Y/bin/${X/-cross/-}"
[ ! -e "${X}cc" ] && echo "${X}cc not found" && exit 1

CROSS_COMPILE="$X" "$@"