blob: f7cb075a6096c4e1a78c01b0c07da25b46d29a35 [file] [log] [blame]
Tor Lillqvistad4a4672011-05-27 18:29:43 +03001Cross-compiling LibreOffice
Tor Lillqvist30fded62013-03-18 09:24:41 +02002***************************
Tor Lillqvistad4a4672011-05-27 18:29:43 +03003
Tor Lillqvist30fded62013-03-18 09:24:41 +02004Cross-compilation works, to various degree, to the following
Tor Lillqvist6dd77982015-12-17 21:22:45 +02005platforms: iOS, Android, and Raspbian.
6
7Note that this document has not been updated very often, and not
8everything here necessarily is true any more.
Tor Lillqvistad4a4672011-05-27 18:29:43 +03009
Tor Lillqvistad4a4672011-05-27 18:29:43 +030010
11General
12-------
13
14In GNU Autoconf terminology, "build" is the platform on which you are
Tor Lillqvistbc229ca2012-05-17 22:57:46 +030015running a build of some software and "host" is the platform on which
Tor Lillqvistad4a4672011-05-27 18:29:43 +030016the software you are building will run. Only in the specific case of
17building compilers and other programming tools is the term "target"
18used to indicate the platform for which the tools your are building
19will produce code. As LibreOffice is not a compiler, the "target" term
20should not be used in the context of cross-compilation.
21
22(For a case where all three of "build", "host" and "target" are
23different: consider a gcc cross-compiler running on Windows, producing
24code for Android, where the cross-compiler itself was built on
25Linux. (This is a real case.) An interesting tidbit is that such
26configurations are called "Canadian Cross".)
27
28Even though the LibreOffice build mechanism is highly unorthodox, the
29configure script takes the normal --build and --host options like any
30GNU Autoconf -based configure script. To cross-compile, you basically
31need just to specify a suitable --host option and things should work
Tor Lillqvist30fded62013-03-18 09:24:41 +020032out nicely. In practice, many details need to be handled. See examples
33below.
34
35Note that in the case of LibreOffice, it is uncommon to run the
36configure script directly. Normally one uses the autogen.sh script.
Tor Lillqvist5011f4c2013-05-01 20:47:02 +030037The autogen.sh script reads command-line options from file called
Chris Sherlock91b27bc2013-05-16 00:49:50 +100038autogen.input if it exists. The typical way of working is to keep
Tor Lillqvist5011f4c2013-05-01 20:47:02 +030039the configure parameters in that file and edit it as needed.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030040
41
42What is so hard, then?
43----------------------
44
45Despite the fact that the configure script takes normal --build and
Tor Lillqvist30fded62013-03-18 09:24:41 +020046--host options, that is just the beginning. It was necessary to
47separate tests for "host" and "build" platforms in the configure
48script. See the git log for details. And the reasonably "standard"
49configure.in is just the top level; when we get down to the actual
50makefilery used to build the bits of LibreOffice, it gets much worse.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030051
52
Tor Lillqvistad4a4672011-05-27 18:29:43 +030053iOS
Tor Lillqvist30fded62013-03-18 09:24:41 +020054***
Tor Lillqvistad4a4672011-05-27 18:29:43 +030055
Tor Lillqvist30fded62013-03-18 09:24:41 +020056iOS is the operating system on Apple's mobile devices. Clearly for a
57device like the iPad it would not be acceptable to run a normal
58LibreOffice application with overlapping windows and mouse-oriented
59GUI widgets.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030060
Tor Lillqvist30fded62013-03-18 09:24:41 +020061It makes sense to use only a part of LibreOffice's code for iOS. Lots
62of the GUI-oriented code should be left out. iOS apps that want to use
63the applicable LibreOffice code will handle all their GUI in a
64platform-dependent manner. How well it will be possible to do such a
65split remains to be seen.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030066
Tor Lillqvist30fded62013-03-18 09:24:41 +020067Obviously we want it to be possible to eventually distribute apps
68using LibreOffice code through the App Store. Technically, one
69important special aspect of iOS is that apps in the App Store are not
Tor Lillqvistad4a4672011-05-27 18:29:43 +030070allowed to load own dynamic libraries. (System libraries are used in
Tor Lillqvist30fded62013-03-18 09:24:41 +020071the form of dynamic libraries, just like on Mac OS X, of which iOS is
72a variant.)
73
74Thus all the libraries in LibreOffice that normally are shared
Tor Lillqvistad4a4672011-05-27 18:29:43 +030075libraries (DLLs on Windows, shared objects (.so) on Linux, dynamic
Tor Lillqvist30fded62013-03-18 09:24:41 +020076libraries on Mac OS X (.dylib)) must be built as static archives
77instead. This has some interesting consequences for how UNO is
78implemented and used.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030079
Andrea Gelmini64a31242017-08-17 16:41:20 +020080An iOS app is a "bundle" that contains a single executable. In an app
81using LibreOffice code, that executable then contains the necessary
Tor Lillqvist30fded62013-03-18 09:24:41 +020082LibreOffice libraries and UNO components statically linked.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030083
Tor Lillqvist30fded62013-03-18 09:24:41 +020084The Apple tool-chain for iOS cross-building is available only for OS
85X. In order to be able to run and debug an app on an actual device
86(and not just the iOS Simulator) you need to be registered in the iOS
87Developer Program.
Tor Lillqvistad4a4672011-05-27 18:29:43 +030088
Tor Lillqvist5011f4c2013-05-01 20:47:02 +030089Here is an autogen.input for iOS (device) using Xcode 4.6, on OS X 10.8:
Tor Lillqvistbc229ca2012-05-17 22:57:46 +030090
Tor Lillqvist5011f4c2013-05-01 20:47:02 +030091--build=i386-apple-darwin10.7.0
92--host=arm-apple-darwin10
Tor Lillqvist30fded62013-03-18 09:24:41 +020093--enable-dbgutil
94--enable-debug
Tor Lillqvist21aec7e2012-02-22 20:41:58 +020095--enable-werror
Tor Lillqvist30fded62013-03-18 09:24:41 +020096
Tor Lillqvistf285ac72014-07-09 12:21:53 +030097For the iOS Simulator, but note that building for the simulator is
98broken at the moment (July 2014):
Tor Lillqvist30fded62013-03-18 09:24:41 +020099
Tor Lillqvist5011f4c2013-05-01 20:47:02 +0300100--build=i386-apple-darwin10.7.0
101--host=arm-apple-darwin10
102--enable-ios-simulator
Tor Lillqvist30fded62013-03-18 09:24:41 +0200103--enable-dbgutil
104--enable-debug
105--enable-werror
Tor Lillqvist21aec7e2012-02-22 20:41:58 +0200106
Tor Lillqvistf285ac72014-07-09 12:21:53 +0300107You will have to install autoconf and automake yourself before running
108autogen.sh. They are no longer included in Xcode 4.3 and later (not
109even in the add-on "command line tools").
Tor Lillqvist21aec7e2012-02-22 20:41:58 +0200110
Tor Lillqvist30fded62013-03-18 09:24:41 +0200111The -mmacosx-version-min=10.7 is necessary when building for the iOS
Tor Lillqvistab4014e2012-06-04 11:19:36 +0300112simulator to avoid clang replacing simple calls to fprintf with calls
113to fwrite$UNIX2003 which Xcode then warns that doesn't exist on iOS.
114
Tor Lillqvist21aec7e2012-02-22 20:41:58 +0200115
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300116Android
Tor Lillqvist30fded62013-03-18 09:24:41 +0200117*******
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300118
Tor Lillqvist30fded62013-03-18 09:24:41 +0200119From a technical point of view the core Android OS (the kernel) is
120Linux, but everything else is different. Unlike iOS, an Android app
121can use shared objects just fine, so that aspect of UNO doesn't need
122special handling. Except that there is a silly low limit in the
123Android dynamic linker on the number of libraries you can dlopen. This
124is a limitation in user-level (but system-provided and not really
125replaceable) code, not the kernel.
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300126
Tor Lillqvist30fded62013-03-18 09:24:41 +0200127Thus, just like for iOS, also for Android the LibreOffice libraries
128and UNO components are built as static archives. For Android, those
129static archives, and any app-specific native code, are linked into one
130single app-specific shared library, called liblo-native-code.so.
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300131
Tor Lillqvist30fded62013-03-18 09:24:41 +0200132For the GUI, the same holds as said above for iOS. The GUI layer needs
133to be platform-specific, written in Java.
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300134
Tor Lillqvist30fded62013-03-18 09:24:41 +0200135Android cross-compilation work has been done mainly on Linux (openSUSE
136in particular). Earlier also cross-compiling from OS X was tried. The
137Android cross-compilation tool-chain (the "Native Development Kit", or
138NDK) is available for Linux, OS X and Windows, but trying to
139cross-compile LibreOffice from Windows will probably drive you insane.
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +0300140
Tor Lillqvist30fded62013-03-18 09:24:41 +0200141You will also need the Android SDK as full "make" also builds a couple
142of Android apps where the upper layer is written in Java.
Tor Lillqvist199d2202012-01-03 13:01:47 +0200143
Tor Lillqvist30fded62013-03-18 09:24:41 +0200144Use the "android" tool from the SDK to install the SDK Tools, SDK
Jan Holesovskyc79e70f2014-06-26 10:57:05 +0200145Platform Tools, the API 15 SDK Platform and the Android Support
Tor Lillqvist30fded62013-03-18 09:24:41 +0200146Library. If you want to run the Android apps in the emulator, you of
147course need an appropriate system image for that.
148
Tor Lillqvist5011f4c2013-05-01 20:47:02 +0300149Here is an autogen.input for Android on ARM when cross-compiling
Tor Lillqvist30fded62013-03-18 09:24:41 +0200150from Linux:
151
Tor Lillqvist30fded62013-03-18 09:24:41 +0200152--enable-dbgutil
Tor Lillqvistab236e12012-08-09 12:59:08 +0300153--enable-werror
Michael Meekse61e51a2012-08-03 16:39:20 +0100154--with-distro=LibreOfficeAndroid
Tor Lillqvist9a6beed2011-12-15 23:54:31 +0200155
Tor Lillqvist2462aa62014-02-21 22:37:47 +0200156And here is an (quite old) autogen.input for Android on X86:
Michael Meekse61e51a2012-08-03 16:39:20 +0100157
Michael Meekse61e51a2012-08-03 16:39:20 +0100158--with-android-ndk=/opt/libreoffice/android-ndk-r8b
159--with-android-ndk-toolchain-version=4.6
160--with-android-sdk=/opt/libreoffice/android-sdk-linux
161--build=i586-suse-linux
162--enable-ccache
Michael Meekse61e51a2012-08-03 16:39:20 +0100163--with-distro=LibreOfficeAndroidX86
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300164
Tor Lillqvist1b530662015-05-21 16:54:28 +0100165A LibreOffice app for Android is being developed progress in the
Miklos Vajna562d8f52015-05-21 17:55:28 +0100166android/source directory.
Tor Lillqvist3ef72932012-01-03 13:48:29 +0200167
Tor Lillqvist1b530662015-05-21 16:54:28 +0100168To run the app, do "make install" followed by either "make run" or
Miklos Vajnab0cb4542015-03-19 16:16:55 +0100169starting it from Android itself. You most likely want to have an "adb logcat"
170running in another window. To debug, run "make debugrun".
Jan Holesovskyc862be02014-10-13 16:51:08 +0200171
Jan Holesovskycfd74ae2014-06-27 15:44:25 +0200172NB: If you happen to upgrade to Android SDK Tools 23, and the build (using
173'make verbose=t android') fails for you with:
174
175 [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
Andrea Gelminida40cac2014-11-10 15:05:25 +0100176 [dx] java.io.FileNotFoundException: /local/libreoffice/android-sdk-linux/tools/support/annotations.jar (no such file or directory)
Jan Holesovskycfd74ae2014-06-27 15:44:25 +0200177
178you need to copy the annotations.jar from an older sdk; like
179
180wget 'http://dl-ssl.google.com/android/repository/tools_r22.6.2-linux.zip'
181unzip tools_r22.6.2-linux.zip
182cp tools/support/annotations.jar <android-sdk-linux>/tools/support/
Tor Lillqvistad4a4672011-05-27 18:29:43 +0300183
Matúš Kukan63a13212013-03-14 17:05:15 +0100184Raspbian
Tor Lillqvist30fded62013-03-18 09:24:41 +0200185********
Matúš Kukan63a13212013-03-14 17:05:15 +0100186
Matúš Kukanee2d7272014-01-16 15:56:30 +0100187In theory, this should work also for another Linux, it does not need to be Raspbian.
Tor Lillqvist661ab312014-02-22 13:48:40 +0200188But this cross-compilation work is tested from Debian and openSUSE to Raspbian.
Matúš Kukanee2d7272014-01-16 15:56:30 +0100189
Tor Lillqvist78a61582014-01-20 15:01:25 +0200190You will need headers, pkg-config files and libraries from a Raspbian
191system to build against. Available at
Paul Menzele8918c42017-05-17 11:55:46 +0200192https://dev-www.libreoffice.org/extern/ . Look for the latest
Tor Lillqvist78a61582014-01-20 15:01:25 +0200193raspbian-root-*.tar.gz . For instance:
194
Paul Menzele8918c42017-05-17 11:55:46 +0200195$ wget https://dev-www.libreoffice.org/extern/raspbian-root-20140120.tar.gz
Tor Lillqvist78a61582014-01-20 15:01:25 +0200196$ mkdir raspbian-root
197$ cd raspbian-root
198$ tar -xf raspbian-root-20140120.tar.gz
Matúš Kukan63a13212013-03-14 17:05:15 +0100199
200You can build cross-compiler yourself or get the executables here:
201$ git clone git://github.com/raspberrypi/tools
Tor Lillqvist78a61582014-01-20 15:01:25 +0200202
Matúš Kukan63a13212013-03-14 17:05:15 +0100203tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian is known to work.
204
205Then create pkg-config wrapper, something like:
206$ cat > pkg-config-wrapper-host << _EOF
207#!/bin/sh
208
Michael Stahld729d162014-02-27 16:19:43 +0100209if [ "$CROSS_COMPILING" = TRUE ]; then
Tor Lillqvist78a61582014-01-20 15:01:25 +0200210 SYSROOT=$HOME/lo/raspbian-root
211 export PKG_CONFIG_PATH=${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig:${SYSROOT}/usr/share/pkgconfig
212 export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig
213 export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
214fi
Matúš Kukan63a13212013-03-14 17:05:15 +0100215
216exec pkg-config "\$@"
217_EOF
218$ chmod +x pkg-config-wrapper-host
Tor Lillqvist78a61582014-01-20 15:01:25 +0200219
Matúš Kukan63a13212013-03-14 17:05:15 +0100220This does not work with pkg-config 0.23. 0.26 is known to work.
221
Tor Lillqvist5011f4c2013-05-01 20:47:02 +0300222And you are ready to build with autogen.input similar to:
Matúš Kukan63a13212013-03-14 17:05:15 +0100223
224PKG_CONFIG=<path-to-pkg-config-wrapper-host>
225CC=<path-to-arm-linux-gnueabihf-gcc> --sysroot=<path-to-raspbian_rootfs>
226CXX=<path-to-arm-linux-gnueabihf-g++> --sysroot=<path-to-raspbian_rootfs>
227--build=x86_64-unknown-linux-gnu
228--host=arm-unknown-linux-gnueabihf
Matúš Kukanee2d7272014-01-16 15:56:30 +0100229--disable-sdk
Matúš Kukan63a13212013-03-14 17:05:15 +0100230--enable-python=system
231PYTHON_CFLAGS=-I<path-to-raspbian_rootfs>/usr/include/python2.7
232PYTHON_LIBS=-lpython2.7
233--with-java
234JAVAINC=-I<path-to-raspbian_rootfs>/usr/lib/jvm/java-6-openjdk-armhf/include
Matúš Kukan63a13212013-03-14 17:05:15 +0100235--with-system-cairo
236--with-system-cppunit
237--with-system-icu
238--with-system-neon
239--with-system-nss
240--with-system-openldap
241--with-system-openssl
242--with-system-redland
243
244Finally, when you are ready to run the binaries in Raspbian,
Matúš Kukanee2d7272014-01-16 15:56:30 +0100245you may need to get more system libraries, who knows.
246$ sudo apt-get install libreoffice # or similar
247That installs libreoffice too, which you don't need because you have
248just built one, but I don't know how to avoid it easily.