aboutsummaryrefslogtreecommitdiff
path: root/scripts/cross.sh
blob: 6dac8ec085b06a2fb4953ce6b2d596fc87fda184 (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
53
54
#!/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, ala:"
  echo "  ln -s ~/musl-cross-make/ccc ccc"
  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=$(echo "$CCC/$X"-*cross)
Z=$(basename "$Y")
Y=$(readlink -f "$CCC"/$X-*cross)
export TARGET="${Z/-*/}"
X="$Y/bin/${Z/-cross/-}"
[ ! -e "${X}cc" ] && echo "${X}cc not found" && exit 1

CROSS_COMPILE="$X" "$@"