~andreas-pokorny/mir/09-input-config-authorizer

331.1.26 by Kevin DuBois
add back the old cross compile script
1
#!/bin/bash
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
2
# build script to compile Mir for armhf devices
331.1.26 by Kevin DuBois
add back the old cross compile script
3
#
4
set -e
5
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
6
usage() {
2899.5.1 by Daniel van Vugt
First prototype
7
  echo "usage: $(basename $0) [-a <arch>] [-c] [-h] [-d <dist>] [-u]"
3187.1.1 by Daniel van Vugt
Generalize cross compile support to include the host architecture.
8
  echo "  -a <arch>  Specify target architecture (armhf/arm64/powerpc/ppc64el/amd64/i386/host)"
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
9
  echo "  -c         Clean before building"
3187.1.1 by Daniel van Vugt
Generalize cross compile support to include the host architecture.
10
  echo "  -d <dist>  Select the distribution to build for (vivid/wily/xenial)"
2899.5.1 by Daniel van Vugt
First prototype
11
  echo "  -h         This message"
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
12
  echo "  -u         Update partial chroot directory"
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
13
}
14
15
clean_build_dir() {
16
    rm -rf ${1}
17
    mkdir ${1}
18
}
19
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
20
# Default to a dist-agnostic directory name so as to not break Jenkins right now
2854.2.1 by Daniel van Vugt
eglapp: Add support for the -- parameter to indicate all further
21
BUILD_DIR=build-android-arm
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
22
NUM_JOBS=$(( $(grep -c ^processor /proc/cpuinfo) + 1 ))
23
_do_update_chroot=0
2851.3.3 by Daniel van Vugt
Comments!
24
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
25
# Default to vivid as we don't seem to have any working wily devices right now 
26
dist=vivid
27
clean=0
2899.5.1 by Daniel van Vugt
First prototype
28
update_build_dir=0
3446.2.2 by Kevin DuBois
add a cli option to disable tests while running cross-compile-chroot
29
enable_tests=yes
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
30
target_arch=armhf
2899.5.1 by Daniel van Vugt
First prototype
31
3446.2.2 by Kevin DuBois
add a cli option to disable tests while running cross-compile-chroot
32
while getopts "a:cd:hut:" OPTNAME
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
33
do
34
    case $OPTNAME in
2899.5.1 by Daniel van Vugt
First prototype
35
      a )
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
36
        target_arch=${OPTARG}
2899.5.1 by Daniel van Vugt
First prototype
37
        update_build_dir=1
38
        ;;
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
39
      c )
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
40
        clean=1
41
        ;;
42
      d )
43
        dist=${OPTARG}
2899.5.1 by Daniel van Vugt
First prototype
44
        update_build_dir=1
2851.3.1 by Daniel van Vugt
First prototype
45
        ;;
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
46
      u )
47
        _do_update_chroot=1
48
        ;;
49
      h )
50
        usage
51
        exit 0
52
        ;;
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
53
      : )
54
        echo "Parameter -${OPTARG} needs an argument"
55
        usage
56
        exit 1;
57
        ;;
3446.2.2 by Kevin DuBois
add a cli option to disable tests while running cross-compile-chroot
58
      t )
59
        enable_tests=${OPTARG}
60
        ;;
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
61
      * )
62
        echo "invalid option specified"
63
        usage
64
        exit 1
65
        ;;
66
    esac
67
done
68
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
69
shift $((${OPTIND}-1))
70
3187.1.1 by Daniel van Vugt
Generalize cross compile support to include the host architecture.
71
if [ "${target_arch}" = "host" ]; then
72
    target_arch=`dpkg-architecture -qDEB_HOST_ARCH`
73
fi
74
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
75
if [ ${clean} -ne 0 ]; then
76
    clean_build_dir ${BUILD_DIR}
77
fi
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
78
2899.5.1 by Daniel van Vugt
First prototype
79
if [ ${update_build_dir} -eq 1 ]; then
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
80
    BUILD_DIR=build-${target_arch}-${dist}
2899.5.1 by Daniel van Vugt
First prototype
81
fi
82
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
83
if [ "${MIR_NDK_PATH}" = "" ]; then
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
84
    export MIR_NDK_PATH=~/.cache/mir-${target_arch}-chroot-${dist}
1389.2.1 by Alberto Aguirre
Add options to cross-compile script to make cleaning build directory and updating chroot folder optional.
85
fi
86
87
if [ ! -d ${MIR_NDK_PATH} ]; then 
88
    echo "no partial chroot dir detected. attempting to create one"
89
    _do_update_chroot=1
90
fi
91
92
if [ ! -d ${BUILD_DIR} ]; then 
93
    mkdir ${BUILD_DIR}
94
fi
95
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
96
echo "Building for distro: $dist"
97
echo "Using MIR_NDK_PATH: ${MIR_NDK_PATH}"
98
2906.1.3 by Andreas Pokorny
adding stable phone overlay for vivid
99
additional_repositories=
100
if [ ${dist} == "vivid" ] ; then
2906.1.4 by Andreas Pokorny
in quotes
101
    additional_repositories="-r http://ppa.launchpad.net/ci-train-ppa-service/stable-phone-overlay/ubuntu"
2906.1.3 by Andreas Pokorny
adding stable phone overlay for vivid
102
fi
103
2899.5.4 by Daniel van Vugt
Resolve the FIXME hack
104
gcc_variant=
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
105
if [ "${dist}" = "vivid" ]; then
2899.5.4 by Daniel van Vugt
Resolve the FIXME hack
106
    gcc_variant=-4.9
3626.1.6 by Daniel van Vugt
Set correct compilers for wily and yakkety too.
107
elif [ "${dist}" = "wily" -o "${dist}" = "xenial"  ]; then
3626.1.3 by Daniel van Vugt
As of 9 hours ago, yakkety switched to gcc-6 by default. So to build
108
    gcc_variant=-5
3626.1.6 by Daniel van Vugt
Set correct compilers for wily and yakkety too.
109
elif [ "${dist}" = "yakkety" ]; then
110
    gcc_variant=-6
2857.1.1 by Daniel van Vugt
Start a new branch (because bzr is terrible and remembers spurious
111
fi
2851.3.1 by Daniel van Vugt
First prototype
112
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
113
case ${target_arch} in
2899.5.1 by Daniel van Vugt
First prototype
114
    armhf )
2899.5.7 by Daniel van Vugt
Simplify
115
        target_machine=arm-linux-gnueabihf
116
        mir_platform="android;mesa-kms"
2899.5.1 by Daniel van Vugt
First prototype
117
        ;;
3187.1.1 by Daniel van Vugt
Generalize cross compile support to include the host architecture.
118
    amd64 )
119
        target_machine=x86_64-linux-gnu
120
        mir_platform="android;mesa-kms"
121
        ;;
122
    i386 )
123
        target_machine=i386-linux-gnu
124
        mir_platform="android;mesa-kms"
125
        ;;
2899.5.10 by Daniel van Vugt
Add support for arm64 and ppc64el
126
    arm64 )
127
        target_machine=aarch64-linux-gnu
128
        mir_platform=mesa-kms
129
        ;;
130
    ppc64el )
131
        target_machine=powerpc64le-linux-gnu
132
        mir_platform=mesa-kms
133
        ;;
2899.5.1 by Daniel van Vugt
First prototype
134
    powerpc )
2899.5.7 by Daniel van Vugt
Simplify
135
        target_machine=powerpc-linux-gnu
2899.5.1 by Daniel van Vugt
First prototype
136
        mir_platform=mesa-kms
137
        ;;
138
    * )
3187.1.1 by Daniel van Vugt
Generalize cross compile support to include the host architecture.
139
        mir_platform=mesa-kms
140
        # A good guess (assuming you have dpkg-architecture)
141
        target_machine=`dpkg-architecture -A${target_arch} -qDEB_HOST_MULTIARCH` || {
142
            echo "Unknown architecture ${target_arch}"
143
            usage
144
            exit 1
145
        }
146
        ;;
2899.5.1 by Daniel van Vugt
First prototype
147
esac
148
2899.5.6 by Daniel van Vugt
Typo
149
echo "Target architecture: ${target_arch}"
2899.5.7 by Daniel van Vugt
Simplify
150
echo "Target machine: ${target_machine}"
2899.5.1 by Daniel van Vugt
First prototype
151
3187.1.1 by Daniel van Vugt
Generalize cross compile support to include the host architecture.
152
if [ ${_do_update_chroot} -eq 1 ] ; then
153
    pushd tools > /dev/null
154
        ./setup-partial-armhf-chroot.sh -d ${dist} -a ${target_arch} ${additional_repositories} ${MIR_NDK_PATH}
155
    popd > /dev/null
156
    # force a clean build after an update, since CMake cache maybe out of date
157
    clean_build_dir ${BUILD_DIR}
158
fi
159
331.1.26 by Kevin DuBois
add back the old cross compile script
160
pushd ${BUILD_DIR} > /dev/null 
161
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
162
    export PKG_CONFIG_PATH="${MIR_NDK_PATH}/usr/lib/pkgconfig:${MIR_NDK_PATH}/usr/lib/${target_machine}/pkgconfig"
1252.1.9 by Christopher James Halse Rogers
Replace some twine in cross-compile-chroot.sh
163
    export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
164
    export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
165
    export PKG_CONFIG_SYSROOT_DIR=$MIR_NDK_PATH
802.1.9 by Alan Griffiths
Another empirical trial
166
    export PKG_CONFIG_EXECUTABLE=`which pkg-config`
2899.5.5 by Daniel van Vugt
Resolve confusion between "arch" and "machine"
167
    export MIR_TARGET_MACHINE=${target_machine}
2899.5.4 by Daniel van Vugt
Resolve the FIXME hack
168
    export MIR_GCC_VARIANT=${gcc_variant}
802.1.7 by Alan Griffiths
Random experiment to see if CI builds at last
169
    echo "Using PKG_CONFIG_PATH: $PKG_CONFIG_PATH"
802.1.9 by Alan Griffiths
Another empirical trial
170
    echo "Using PKG_CONFIG_EXECUTABLE: $PKG_CONFIG_EXECUTABLE"
331.1.26 by Kevin DuBois
add back the old cross compile script
171
    cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/LinuxCrossCompile.cmake \
3446.2.2 by Kevin DuBois
add a cli option to disable tests while running cross-compile-chroot
172
      -DMIR_PLATFORM=${mir_platform} -DMIR_ENABLE_TESTS=${enable_tests}\
3626.1.4 by Daniel van Vugt
And don't use precompiled headers. gcc5 doesn't like gcc6's output.
173
      -DMIR_USE_PRECOMPILED_HEADERS=OFF \
331.1.26 by Kevin DuBois
add back the old cross compile script
174
      .. 
175
1907.1.5 by Alberto Aguirre
Pass extra arguments to make so you can specify make targets when calling script
176
    make -j${NUM_JOBS} $@
331.1.26 by Kevin DuBois
add back the old cross compile script
177
1441.1.1 by Daniel van Vugt
Don't pass a parameter to bash's popd command. It doesn't expect one and will
178
popd > /dev/null