~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to cross-compile-chroot.sh

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-03-02 14:25:01 UTC
  • mfrom: (119.2.3 support-cross-compile)
  • Revision ID: tarmac-20160302142501-wfzthvz4e91grs7w
Add cross-compilation support.

Approved by PS Jenkins bot, Thomas Voß.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# build script to compile Aethercast for armhf devices
 
3
#
 
4
set -e
 
5
 
 
6
usage() {
 
7
  echo "usage: $(basename $0) [-a <arch>] [-c] [-h] [-d <dist>] [-u]"
 
8
  echo "  -a <arch>  Specify target architecture (armhf/arm64/powerpc/ppc64el/amd64/i386/host)"
 
9
  echo "  -c         Clean before building"
 
10
  echo "  -d <dist>  Select the distribution to build for (vivid/wily/xenial)"
 
11
  echo "  -h         This message"
 
12
  echo "  -u         Update partial chroot directory"
 
13
}
 
14
 
 
15
clean_build_dir() {
 
16
    rm -rf ${1}
 
17
    mkdir ${1}
 
18
}
 
19
 
 
20
# Default to a dist-agnostic directory name so as to not break Jenkins right now
 
21
BUILD_DIR=build-android-arm
 
22
NUM_JOBS=$(( $(grep -c ^processor /proc/cpuinfo) + 1 ))
 
23
_do_update_chroot=0
 
24
 
 
25
# Default to vivid as we don't seem to have any working wily devices right now 
 
26
dist=vivid
 
27
clean=0
 
28
update_build_dir=0
 
29
 
 
30
target_arch=armhf
 
31
 
 
32
while getopts "a:cd:hu" OPTNAME
 
33
do
 
34
    case $OPTNAME in
 
35
      a )
 
36
        target_arch=${OPTARG}
 
37
        update_build_dir=1
 
38
        ;;
 
39
      c )
 
40
        clean=1
 
41
        ;;
 
42
      d )
 
43
        dist=${OPTARG}
 
44
        update_build_dir=1
 
45
        ;;
 
46
      u )
 
47
        _do_update_chroot=1
 
48
        ;;
 
49
      h )
 
50
        usage
 
51
        exit 0
 
52
        ;;
 
53
      : )
 
54
        echo "Parameter -${OPTARG} needs an argument"
 
55
        usage
 
56
        exit 1;
 
57
        ;;
 
58
      * )
 
59
        echo "invalid option specified"
 
60
        usage
 
61
        exit 1
 
62
        ;;
 
63
    esac
 
64
done
 
65
 
 
66
shift $((${OPTIND}-1))
 
67
 
 
68
if [ "${target_arch}" = "host" ]; then
 
69
    target_arch=`dpkg-architecture -qDEB_HOST_ARCH`
 
70
fi
 
71
 
 
72
if [ ${clean} -ne 0 ]; then
 
73
    clean_build_dir ${BUILD_DIR}
 
74
fi
 
75
 
 
76
if [ ${update_build_dir} -eq 1 ]; then
 
77
    BUILD_DIR=build-${target_arch}-${dist}
 
78
fi
 
79
 
 
80
if [ "${AC_NDK_PATH}" = "" ]; then
 
81
    export AC_NDK_PATH=~/.cache/aethercast-${target_arch}-chroot-${dist}
 
82
fi
 
83
 
 
84
if [ ! -d ${AC_NDK_PATH} ]; then 
 
85
    echo "no partial chroot dir detected. attempting to create one"
 
86
    _do_update_chroot=1
 
87
fi
 
88
 
 
89
if [ ! -d ${BUILD_DIR} ]; then 
 
90
    mkdir ${BUILD_DIR}
 
91
fi
 
92
 
 
93
echo "Building for distro: $dist"
 
94
echo "Using AC_NDK_PATH: ${AC_NDK_PATH}"
 
95
 
 
96
additional_repositories=
 
97
if [ ${dist} == "vivid" ] ; then
 
98
    additional_repositories="-r http://ppa.launchpad.net/ci-train-ppa-service/stable-phone-overlay/ubuntu -r http://ppa.launchpad.net/ci-train-ppa-service/landing-000/ubuntu"
 
99
fi
 
100
 
 
101
gcc_variant=
 
102
if [ "${dist}" = "vivid" ]; then
 
103
    gcc_variant=-4.9
 
104
fi
 
105
 
 
106
case ${target_arch} in
 
107
    armhf )
 
108
        target_machine=arm-linux-gnueabihf
 
109
        ;;
 
110
    amd64 )
 
111
        target_machine=x86_64-linux-gnu
 
112
        ;;
 
113
    i386 )
 
114
        target_machine=i386-linux-gnu
 
115
        ;;
 
116
    arm64 )
 
117
        target_machine=aarch64-linux-gnu
 
118
        ;;
 
119
    ppc64el )
 
120
        target_machine=powerpc64le-linux-gnu
 
121
        ;;
 
122
    powerpc )
 
123
        target_machine=powerpc-linux-gnu
 
124
        ;;
 
125
    * )
 
126
        # A good guess (assuming you have dpkg-architecture)
 
127
        target_machine=`dpkg-architecture -A${target_arch} -qDEB_HOST_MULTIARCH` || {
 
128
            echo "Unknown architecture ${target_arch}"
 
129
            usage
 
130
            exit 1
 
131
        }
 
132
        ;;
 
133
esac
 
134
 
 
135
echo "Target architecture: ${target_arch}"
 
136
echo "Target machine: ${target_machine}"
 
137
 
 
138
if [ ${_do_update_chroot} -eq 1 ] ; then
 
139
    pushd scripts > /dev/null
 
140
        ./setup-partial-armhf-chroot.sh -d ${dist} -a ${target_arch} ${additional_repositories} ${AC_NDK_PATH}
 
141
    popd > /dev/null
 
142
    # force a clean build after an update, since CMake cache maybe out of date
 
143
    clean_build_dir ${BUILD_DIR}
 
144
fi
 
145
 
 
146
pushd ${BUILD_DIR} > /dev/null
 
147
 
 
148
    export PKG_CONFIG_PATH="${AC_NDK_PATH}/usr/lib/pkgconfig:${AC_NDK_PATH}/usr/lib/${target_machine}/pkgconfig"
 
149
    export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
 
150
    export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
 
151
    export PKG_CONFIG_SYSROOT_DIR=$AC_NDK_PATH
 
152
    export PKG_CONFIG_EXECUTABLE=`which pkg-config`
 
153
    export AC_TARGET_MACHINE=${target_machine}
 
154
    export AC_GCC_VARIANT=${gcc_variant}
 
155
    echo "Using PKG_CONFIG_PATH: $PKG_CONFIG_PATH"
 
156
    echo "Using PKG_CONFIG_EXECUTABLE: $PKG_CONFIG_EXECUTABLE"
 
157
    cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/LinuxCrossCompile.cmake \
 
158
      ..
 
159
 
 
160
    make -j${NUM_JOBS} $@
 
161
 
 
162
popd > /dev/null