Merge lp:~albaguirre/unity-mir/add-cross-compile-scripts into lp:unity-mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Gerry Boland
Approved revision: 182
Merged at revision: 185
Proposed branch: lp:~albaguirre/unity-mir/add-cross-compile-scripts
Merge into: lp:unity-mir
Prerequisite: lp:~albaguirre/unity-mir/cross-compile-link-fix
Diff against target: 222 lines (+201/-0)
4 files modified
cmake/LinuxCrossCompile.cmake (+39/-0)
cross-compile.sh (+85/-0)
scripts/fix-qt-cmake.sh (+10/-0)
scripts/setup-partial-armhf-chroot.sh (+67/-0)
To merge this branch: bzr merge lp:~albaguirre/unity-mir/add-cross-compile-scripts
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Andreas Pokorny (community) Approve
Review via email: mp+206058@code.launchpad.net

Commit message

Add dev scripts to support cross-compilation

Adapted cross compile scripts from mir project to support cross compilation
using a basic armhf chroot environment populated using debootstrap - the build dependencies are parsed from debian/control

These scripts are intended for development purposes only

Description of the change

Add dev scripts to support cross-compilation

Adapted cross compile scripts from mir project to support cross compilation
using a basic armhf chroot environment populated using debootstrap - the build dependencies are parsed from debian/control

These scripts are intended for development purposes only

To post a comment you must log in.
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

worked for me

review: Approve
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

one strange nit .. after running it once, then changing the CMAKE_BUILD_TYPE and INSTALL_PREFIX it forgot the which moc to use. So I had to add to the environment again - Then after the second run it CMake no longer cared bout the env - maybe it needs two runs to settle in the first place.

In the end that information should be fixed for the build when written to Builddir/...../AutomocInfo.cmake ...

Will try again in a bit.

review: Abstain
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

found no clean solution - those env variable need to be set during build

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
179. By Daniel d'Andrada

Unity8 now provides a clipboard service through the mir socket

That service can later be used for other custom messages as well.

180. By PS Jenkins bot

Releasing 0.2+14.04.20140214-0ubuntu1

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
181. By Alberto Aguirre

[cmake] Use XXX_LDFLAGS for libraries found with pkg_check_modules.

Using the pkg given LDFLAGS resolves linking issues when cross-compiling

182. By Alberto Aguirre

Add dev scripts to support cross-compilation

These scripts are adapted from the mir project.
The build dependencies are parsed from debian/control and
given to debootstrap to setup a basic armhf chroot environment for cross-compilation.

These scripts are intended for development purposes only

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

Works nice, thanks! I've been trying using sbuild with chroot to cross build packages, but I've never managed to get it working it (based on https://wiki.ubuntu.com/SimpleSbuild), so this will do nicely in the interim.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'cmake'
2=== added file 'cmake/LinuxCrossCompile.cmake'
3--- cmake/LinuxCrossCompile.cmake 1970-01-01 00:00:00 +0000
4+++ cmake/LinuxCrossCompile.cmake 2014-02-21 21:56:07 +0000
5@@ -0,0 +1,39 @@
6+set(CMAKE_SYSTEM_NAME Linux)
7+set(CMAKE_SYSTEM_VERSION 1)
8+
9+set(UNITYMIR_CHROOT_DIR $ENV{UNITYMIR_CHROOT_DIR} CACHE STRING "directory containing partial chroot for unity-mir cross-compilation")
10+set(UNITYMIR_ARM_EABI "arm-linux-gnueabihf")
11+
12+set(CMAKE_C_COMPILER /usr/bin/${UNITYMIR_ARM_EABI}-gcc)
13+set(CMAKE_CXX_COMPILER /usr/bin/${UNITYMIR_ARM_EABI}-g++)
14+
15+# where to look to find dependencies in the target environment
16+set(CMAKE_FIND_ROOT_PATH "${UNITYMIR_CHROOT_DIR}")
17+
18+#treat the chroot's includes as system includes
19+include_directories(SYSTEM "${UNITYMIR_CHROOT_DIR}/usr/include" "${UNITYMIR_CHROOT_DIR}/usr/include/${UNITYMIR_ARM_EABI}")
20+
21+list(APPEND CMAKE_SYSTEM_INCLUDE_PATH "${UNITYMIR_CHROOT_DIR}/usr/include" "${UNITYMIR_CHROOT_DIR}/usr/include/${UNITYMIR_ARM_EABI}" )
22+
23+# Add the chroot libraries as system libraries
24+list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
25+ "${UNITYMIR_CHROOT_DIR}/lib"
26+ "${UNITYMIR_CHROOT_DIR}/lib/${UNITYMIR_ARM_EABI}"
27+ "${UNITYMIR_CHROOT_DIR}/usr/lib"
28+ "${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}"
29+)
30+
31+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
32+set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
33+set(CMAKE_EXECUTABLE_RUNTIME_C_FLAG "-Wl,-rpath-link,")
34+set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "-Wl,-rpath-link,")
35+set(CMAKE_INSTALL_RPATH "${UNITYMIR_CHROOT_DIR}/lib:${UNITYMIR_CHROOT_DIR}/lib/${UNITYMIR_ARM_EABI}:${UNITYMIR_CHROOT_DIR}/usr/lib:${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}:${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}/mesa-egl")
36+
37+set(ENV{PKG_CONFIG_PATH} "${UNITYMIR_CHROOT_DIR}/usr/lib/pkgconfig:${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}/pkgconfig")
38+set(ENV{PKG_CONFIG_SYSROOT_DIR} "${UNITYMIR_CHROOT_DIR}")
39+
40+#use only the cross compile system
41+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
42+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
43+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
44+
45
46=== added file 'cross-compile.sh'
47--- cross-compile.sh 1970-01-01 00:00:00 +0000
48+++ cross-compile.sh 2014-02-21 21:56:07 +0000
49@@ -0,0 +1,85 @@
50+#!/bin/bash
51+# build script to compile unity-mir for armhf devices
52+
53+set -e
54+
55+usage() {
56+ echo "usage: $(basename $0) [-c] [-u]"
57+ echo "-c clean before building"
58+ echo "-u update partial chroot directory"
59+ echo "-h this message"
60+}
61+
62+clean_build_dir() {
63+ rm -rf ${1}
64+ mkdir ${1}
65+}
66+
67+BUILD_DIR=build-android-arm
68+NUM_JOBS=$(( $(grep -c ^processor /proc/cpuinfo) + 1 ))
69+_do_update_chroot=0
70+
71+while getopts "cuh" OPTNAME
72+do
73+ case $OPTNAME in
74+ c )
75+ clean_build_dir ${BUILD_DIR}
76+ ;;
77+ u )
78+ _do_update_chroot=1
79+ ;;
80+ h )
81+ usage
82+ exit 0
83+ ;;
84+ * )
85+ echo "invalid option specified"
86+ usage
87+ exit 1
88+ ;;
89+ esac
90+done
91+
92+
93+if [ "${UNITYMIR_CHROOT_DIR}" = "" ]; then
94+ export UNITYMIR_CHROOT_DIR=$(pwd)/partial-armhf-chroot
95+fi
96+
97+if [ ! -d ${UNITYMIR_CHROOT_DIR} ]; then
98+ echo "no partial chroot dir detected. attempting to create one"
99+ _do_update_chroot=1
100+fi
101+
102+if [ ! -d ${BUILD_DIR} ]; then
103+ mkdir ${BUILD_DIR}
104+fi
105+
106+if [ ${_do_update_chroot} -eq 1 ] ; then
107+ pushd scripts > /dev/null
108+ ./setup-partial-armhf-chroot.sh ${UNITYMIR_CHROOT_DIR}
109+ popd > /dev/null
110+ # force a clean build after an update, since CMake cache maybe out of date
111+ clean_build_dir ${BUILD_DIR}
112+fi
113+
114+echo "Using UNITYMIR_CHROOT_DIR: ${UNITYMIR_CHROOT_DIR}"
115+
116+pushd ${BUILD_DIR} > /dev/null
117+
118+ export CMAKE_PREFIX_PATH=${UNITYMIR_CHROOT_DIR}/usr/lib/arm-linux-gnueabihf/cmake
119+ export PKG_CONFIG_PATH="${UNITYMIR_CHROOT_DIR}/usr/lib/pkgconfig:${UNITYMIR_CHROOT_DIR}/usr/lib/arm-linux-gnueabihf/pkgconfig"
120+ export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
121+ export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
122+ export PKG_CONFIG_SYSROOT_DIR=${UNITYMIR_CHROOT_DIR}
123+ export PKG_CONFIG_EXECUTABLE=`which pkg-config`
124+ echo "Using PKG_CONFIG_PATH: $PKG_CONFIG_PATH"
125+ echo "Using PKG_CONFIG_EXECUTABLE: $PKG_CONFIG_EXECUTABLE"
126+
127+ # These are used to make cmake select the host machine QT MOC compiler in the AutoMocInfo module
128+ export DEB_HOST_MULTIARCH=arm-linux-gnueabihf
129+ export DEB_BUILD_MULTIARCH=$(gcc -dumpmachine)
130+
131+ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/LinuxCrossCompile.cmake ..
132+ make -j${NUM_JOBS}
133+
134+popd ${BUILD_DIR} > /dev/null
135
136=== added directory 'scripts'
137=== added file 'scripts/fix-qt-cmake.sh'
138--- scripts/fix-qt-cmake.sh 1970-01-01 00:00:00 +0000
139+++ scripts/fix-qt-cmake.sh 2014-02-21 21:56:07 +0000
140@@ -0,0 +1,10 @@
141+#!/bin/bash
142+
143+# $1 must contain path to QT cmake files
144+# Given that path, all hardcoded root paths are fixed up
145+for file in $(find ${1} -type f -name \*.cmake)
146+do
147+ echo "fixing $file"
148+ sed -i 's/NO_DEFAULT_PATH/ONLY_CMAKE_FIND_ROOT_PATH/g' $file
149+ sed -i 's/\/usr/${CMAKE_FIND_ROOT_PATH}\/usr/g' $file
150+done
151
152=== added file 'scripts/setup-partial-armhf-chroot.sh'
153--- scripts/setup-partial-armhf-chroot.sh 1970-01-01 00:00:00 +0000
154+++ scripts/setup-partial-armhf-chroot.sh 2014-02-21 21:56:07 +0000
155@@ -0,0 +1,67 @@
156+#!/bin/bash
157+
158+set -e
159+
160+if [ -z ${1} ]; then
161+ echo "please supply directory to create partial chroot in. (eg, ./setup-partial-armhf-chroot.sh mychroot-dir)"
162+ exit
163+fi
164+
165+echo "creating phablet-compatible armhf partial chroot for unity-mir compilation in directory ${1}"
166+
167+if [ ! -d ${1} ]; then
168+ mkdir -p ${1}
169+fi
170+
171+DEBCONTROL=$(pwd)/../debian/control
172+
173+pushd ${1} > /dev/null
174+
175+# Empty dpkg status file, so that ALL dependencies are listed with dpkg-checkbuilddeps
176+echo "" > status
177+
178+# Manual error code checking is needed for dpkg-checkbuilddeps
179+set +e
180+
181+# Parse dependencies from debian/control
182+# dpkg-checkbuilddeps returns 1 when dependencies are not met and the list is sent to stderr
183+builddeps=$(dpkg-checkbuilddeps -a armhf --admindir=. ${DEBCONTROL} 2>&1 )
184+if [ $? -ne 1 ] ; then
185+ echo "${builddeps}"
186+ exit 2
187+fi
188+
189+# now turn exit on error option
190+set -e
191+
192+# Sanitize dependencies list for submission to debootstrap
193+# build-essential is not needed as we are cross-compiling
194+builddeps=$(echo ${builddeps} | sed -e 's/dpkg-checkbuilddeps://g' -e 's/Unmet build dependencies://g' -e 's/build-essential:native//g')
195+builddeps=$(echo ${builddeps} | sed 's/([^)]*)//g')
196+# TODO: figure out why debootstrap is not finding libunity-api-dev package - it doesn't seem to be needed for cross-compilation - is it needed in debian/control?
197+builddeps=$(echo ${builddeps} | sed 's/libunity-api-dev//g')
198+builddeps=$(echo ${builddeps} | sed 's/ /,/g')
199+
200+fakeroot debootstrap --include=${builddeps} --arch=armhf --download-only --variant=buildd trusty .
201+
202+# Remove libc libraries that confuse the cross-compiler
203+rm var/cache/apt/archives/libc-dev*.deb
204+rm var/cache/apt/archives/libc6*.deb
205+
206+for deb in var/cache/apt/archives/* ; do
207+if [ ! -d ${deb} ] ; then
208+ echo "unpacking: ${deb}"
209+ dpkg -x ${deb} .
210+fi
211+done
212+
213+# Fix up symlinks which asssumed the usual root path
214+for broken_symlink in $(find . -name \*.so -type l -xtype l) ; do
215+ ln -sf $(pwd)$(readlink ${broken_symlink}) ${broken_symlink}
216+done
217+
218+popd > /dev/null
219+
220+# QT CMake files have hardcoded root paths - fix them up
221+./fix-qt-cmake.sh ${1}/usr/lib/arm-linux-gnueabihf/cmake/
222+

Subscribers

People subscribed via source and target branches