Add a http performance test script based on wrk
[iec.git] / src / type3_AndroidCloud / anbox-master / cross-compile-chroot.sh
1 #!/bin/bash
2 #
3 # Copyright © 2016 Canonical Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License version 3,
7 # as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Taken from the Mir Project (https://launchpad.net/mir)
18
19 set -e
20
21 usage() {
22   echo "usage: $(basename $0) [-a <arch>] [-c] [-h] [-d <dist>] [-u]"
23   echo "  -a <arch>  Specify target architecture (armhf/arm64/powerpc/ppc64el/amd64/i386/host)"
24   echo "  -c         Clean before building"
25   echo "  -d <dist>  Select the distribution to build for (vivid/wily/xenial)"
26   echo "  -h         This message"
27   echo "  -u         Update partial chroot directory"
28 }
29
30 clean_build_dir() {
31     rm -rf ${1}
32     mkdir ${1}
33 }
34
35 # Default to a dist-agnostic directory name so as to not break Jenkins right now
36 BUILD_DIR=build-android-arm
37 # NUM_JOBS=$(( $(grep -c ^processor /proc/cpuinfo) + 1 ))
38 NUM_JOBS=5
39 _do_update_chroot=0
40
41 # Default to vivid as we don't seem to have any working wily devices right now 
42 dist=vivid
43 clean=0
44 update_build_dir=0
45
46 target_arch=armhf
47
48 while getopts "a:cd:hu" OPTNAME
49 do
50     case $OPTNAME in
51       a )
52         target_arch=${OPTARG}
53         update_build_dir=1
54         ;;
55       c )
56         clean=1
57         ;;
58       d )
59         dist=${OPTARG}
60         update_build_dir=1
61         ;;
62       u )
63         _do_update_chroot=1
64         ;;
65       h )
66         usage
67         exit 0
68         ;;
69       : )
70         echo "Parameter -${OPTARG} needs an argument"
71         usage
72         exit 1;
73         ;;
74       * )
75         echo "invalid option specified"
76         usage
77         exit 1
78         ;;
79     esac
80 done
81
82 shift $((${OPTIND}-1))
83
84 if [ "${target_arch}" = "host" ]; then
85     target_arch=`dpkg-architecture -qDEB_HOST_ARCH`
86 fi
87
88 if [ ${clean} -ne 0 ]; then
89     clean_build_dir ${BUILD_DIR}
90 fi
91
92 if [ ${update_build_dir} -eq 1 ]; then
93     BUILD_DIR=build-${target_arch}-${dist}
94 fi
95
96 if [ "${AC_NDK_PATH}" = "" ]; then
97     export AC_NDK_PATH=~/.cache/anbox-${target_arch}-chroot-${dist}
98 fi
99
100 if [ ! -d ${AC_NDK_PATH} ]; then 
101     echo "no partial chroot dir detected. attempting to create one"
102     _do_update_chroot=1
103 fi
104
105 if [ ! -d ${BUILD_DIR} ]; then 
106     mkdir ${BUILD_DIR}
107 fi
108
109 echo "Building for distro: $dist"
110 echo "Using AC_NDK_PATH: ${AC_NDK_PATH}"
111
112 additional_repositories="-r http://ppa.launchpad.net/ci-train-ppa-service/stable-phone-overlay/ubuntu"
113
114 gcc_variant=
115 if [ "${dist}" = "vivid" ]; then
116     gcc_variant=-4.9
117 fi
118
119 case ${target_arch} in
120     armhf )
121         target_machine=arm-linux-gnueabihf
122         ;;
123     amd64 )
124         target_machine=x86_64-linux-gnu
125         ;;
126     i386 )
127         target_machine=i386-linux-gnu
128         ;;
129     arm64 )
130         target_machine=aarch64-linux-gnu
131         ;;
132     ppc64el )
133         target_machine=powerpc64le-linux-gnu
134         ;;
135     powerpc )
136         target_machine=powerpc-linux-gnu
137         ;;
138     * )
139         # A good guess (assuming you have dpkg-architecture)
140         target_machine=`dpkg-architecture -A${target_arch} -qDEB_HOST_MULTIARCH` || {
141             echo "Unknown architecture ${target_arch}"
142             usage
143             exit 1
144         }
145         ;;
146 esac
147
148 echo "Target architecture: ${target_arch}"
149 echo "Target machine: ${target_machine}"
150
151 if [ ${_do_update_chroot} -eq 1 ] ; then
152     pushd scripts > /dev/null
153         ./setup-partial-chroot.sh -d ${dist} -a ${target_arch} ${additional_repositories} ${AC_NDK_PATH}
154     popd > /dev/null
155     # force a clean build after an update, since CMake cache maybe out of date
156     clean_build_dir ${BUILD_DIR}
157 fi
158
159 pushd ${BUILD_DIR} > /dev/null
160
161     export PKG_CONFIG_PATH="${AC_NDK_PATH}/usr/lib/pkgconfig:${AC_NDK_PATH}/usr/lib/${target_machine}/pkgconfig"
162     export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
163     export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
164     export PKG_CONFIG_SYSROOT_DIR=$AC_NDK_PATH
165     export PKG_CONFIG_EXECUTABLE=`which pkg-config`
166     export AC_TARGET_MACHINE=${target_machine}
167     export AC_GCC_VARIANT=${gcc_variant}
168     export LDFLAGS=-Wl,-rpath-link,${AC_NDK_PATH}/usr/lib/${target_machine}/pulseaudio
169     echo "Using PKG_CONFIG_PATH: $PKG_CONFIG_PATH"
170     echo "Using PKG_CONFIG_EXECUTABLE: $PKG_CONFIG_EXECUTABLE"
171     cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/LinuxCrossCompile.cmake \
172       -DCMAKE_BUILD_TYPE=debug \
173       ..
174
175     make -j${NUM_JOBS} $@
176
177 popd > /dev/null