1 Cross-compiling LibreOffice
2 ===========================
4 Cross-compilation work has been done, to various degrees, for four
5 platforms: Windows, iOS, Android and PowerPC Mac OS X.
11 In GNU Autoconf terminology, "build" is the platform on which you are
12 running a build of some software and "host" is the platform on which
13 the software you are building will run. Only in the specific case of
14 building compilers and other programming tools is the term "target"
15 used to indicate the platform for which the tools your are building
16 will produce code. As LibreOffice is not a compiler, the "target" term
17 should not be used in the context of cross-compilation.
19 (For a case where all three of "build", "host" and "target" are
20 different: consider a gcc cross-compiler running on Windows, producing
21 code for Android, where the cross-compiler itself was built on
22 Linux. (This is a real case.) An interesting tidbit is that such
23 configurations are called "Canadian Cross".)
25 Even though the LibreOffice build mechanism is highly unorthodox, the
26 configure script takes the normal --build and --host options like any
27 GNU Autoconf -based configure script. To cross-compile, you basically
28 need just to specify a suitable --host option and things should work
29 out nicely. In practise, many details needed to be handled. See
33 What is so hard, then?
34 ----------------------
36 Despite the fact that the configure script takes normal --build and
37 --host options, that is just the beginning. In practise a lot of work
38 was necessary to separate tests for "host" and "build" platforms in
39 the configure script. See the git log for details. And the reasonably
40 "standard" configure.in is just the top level; when we get down to the
41 actual makefilery used to build the bits of LibreOffice, it gets much
48 There is some support in LibreOffice already (from OpenOffice.org) for
49 building it locally on Windows with the GNU tool-chain
50 (MinGW). Apparently, that work has never attempted cross-compilation.
52 This OOo-originated MinGW support attempts to support both running
53 Cygwin gcc in its -mno-cygwin mode, and a native MinGW compiler. The
54 -mno-cygwin mechanism in the Cygwin gcc is rapidly being obsoleted, if
55 it isn't already, and we have not attempted to try to keep it working;
56 in fact we have activly cleaned out mechanisms related to this. Ditto
57 for native MinGW. If one compiles natively on Windows, just use
58 Microsoft's compiler. OOo/LO has been built for Windows all the time
61 The only case where it makes sense to use MinGW is for
62 cross-compilation. There is just too much crack on Windows anyway, and
63 it is a semi-miracle (well, make that the result of years of work)
64 that the MSVC build under Cygwin works as nicely as it does.
66 MinGW is available as cross-build toolchains pre-packaged in more or
67 less official packages for many Linux distros including Debian,
68 Fedora, openSUSE and SLE. For instance the mingw32 packages in the
69 Open Build Service, running on openSUSE:
71 http://download.opensuse.org/repositories/windows:/mingw:/win32/
73 For example, you can install it like this:
75 zypper ar http://download.opensuse.org/repositories/windows:/mingw:/win32/<your_os>/windows:mingw:win32.repo
77 where <your_os> is one of SLE_11, SLE_11_SP1, openSUSE_11.3, openSUSE_11.4 or
80 zypper in mingw32-cross-gcc mingw32-cross-gcc-c++ mingw32-python-devel \
81 mingw32-python mingw32-libboost_date_time \
82 mingw32-libexpat-devel mingw32-libexpat mingw32-boost-devel \
83 mingw32-libhyphen-devel mingw32-libhyphen mingw32-hyphen-en \
84 mingw32-liblpsolve mingw32-liblpsolve-devel \
85 mingw32-libxml2-devel mingw32-libxslt-devel mingw32-libicu \
86 mingw32-libicu-devel mingw32-libgraphite2 mingw32-libgraphite2-devel \
87 mingw32-libcairo2 mingw32-cairo-devel mingw32-librsvg mingw32-librsvg-devel \
88 mingw32-hunspell mingw32-hunspell-devel mingw32-libcurl \
89 mingw32-libcurl-devel mingw32-libneon mingw32-libneon-devel \
90 mingw32-libopenssl mingw32-libopenssl-devel mingw32-libexttextcat \
91 mingw32-libexttextcat-devel mingw32-libdb mingw32-libdb-devel \
92 mingw32-cross-pkg-config mingw32-pkg-config mingw32-libcppunit \
93 mingw32-libcppunit-devel mingw32-libredland mingw32-libredland-devel \
94 mingw32-libmythes mingw32-libmythes-devel mingw32-mozilla-nss \
95 mingw32-mozilla-nss-devel mingw32-mozilla-nspr \
96 mingw32-mozilla-nspr-devel mingw32-libpoppler mingw32-libpoppler-devel
98 You also need wine, ideally:
100 zypper ar http://download.opensuse.org/repositories/Emulators:/Wine/<your_os>/Emulators:Wine.repo
102 zypper in wine wine-devel wine-devel-32bit
104 And in order to be able to use 'winegcc -m32', also
106 zypper in glibc-devel-32bit gcc-32bit
108 There might be more that are missing, please read carefully what autogen.sh
109 tells you, and either remove one of the --with-system-*, or install the
112 It also looks like graphite2.pc needs tweaking in order to work right; but
113 that's likely to be fixed in the openSUSE project.
115 It is somewhat unclear how well thought-out the conditionals and code
116 for MinGW inside the OOo-originated code in LibreOffice actually
117 are. It often seems a bit randomish, with copy-pasting having been
118 preferred to factoring out differences.
120 Most of the configuration settings are maintained in the
121 distro-configs/LibreOfficeMinGW.conf file, so in your autogen.lastrun,
124 CC=ccache i686-w64-mingw32-gcc
125 CXX=ccache i686-w64-mingw32-g++
126 CC_FOR_BUILD=ccache gcc
127 CXX_FOR_BUILD=ccache g++
128 --with-distro=LibreOfficeMinGW
130 Alternatively, you can use something like the following; but the
131 preferred way is to keep the LibreOfficeMinGW.conf file up-to-date.
133 CC=ccache i686-w64-mingw32-gcc
134 CXX=ccache i686-w64-mingw32-g++
135 CC_FOR_BUILD=ccache gcc
136 CXX_FOR_BUILD=ccache g++
137 --build=x86_64-unknown-linux-gnu
138 --host=i686-w64-mingw32
139 --with-distro=LibreOfficeWin32
141 --disable-build-mozilla
143 --disable-ext-nlpsolver
144 --disable-ext-presenter-minimizer
145 --disable-ext-report-builder
146 --disable-ext-scripting-beanshell
147 --disable-ext-scripting-javascript
148 --disable-ext-wiki-publisher
149 --disable-ext-wiki-publisher
154 --enable-python=system
155 --with-system-altlinuxhyph
158 --with-system-cppunit
161 --with-system-hunspell
168 --with-system-lpsolve
171 --with-system-openssl
172 --with-system-redland
175 --without-helppack-integration
176 --without-myspell-dicts
178 Once you have compiled it, you may want to try to run it, for instance
182 $ tar xf <your-build-dir>/instsetoo_native/wntgcci.pro/LibreOffice_Dev/archive/install/en-US/LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US.tar.gz
183 $ cd LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US/LOdev\ 3.6/program
186 NB. it is important to unpack somewhere low in the hierarchy structure (like
187 in /tmp as advised above), otherwise you'll get BerkeleyDB errors on startup.
189 And if you are brave enough, you can even debug it. First you have to add the
190 URE dll's to the wine's PATH using 'wine regedit' - see
191 http://www.winehq.org/docs/wineusr-guide/environment-variables, and add
192 Z:\tmp\LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US\LOdev 3.6\URE\bin
193 to "Path" in My Computer->HKEY_CURRENT_USER->Environment.
195 Then run linkoo, so that when you rebuild something, you can directly see the
196 changes the next time you run it:
198 solenv/bin/linkoo '/tmp/LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US/LOdev 3.6' <your_clone_dir>
202 $ winedbg soffice.bin
204 Would be great to be able to use winedbg --gdb, but it was crashing here :-( -
205 but maybe you'll be more lucky.
207 Tricks of some use with winedbg:
208 --------------------------------
210 To examine OUStrings, you might want to use the following trick (prints 50
211 unicode characters of rLibName OUString - the +10 is where the buffer starts):
213 Wine-dbg>x /50u rLibName->pData+10
214 0x0909b6c8: vnd.sun.star.expand:$LO_LIB_DIR/abplo.dll
218 - make the debugging more convenient on (native) Windows
219 - check possibilities like WinGDB - http://www.wingdb.com/
220 - or find / write a MSVS / WinDBG extension that can read MinGW debugging
221 symbols natively; more info
222 http://windbg.info/forum/12-symbol-and-source-files-/21-debugging-mingwgcc-built-dll-in-visual-studio.html
225 - so far the make_installer.pl calls makecab.exe, uuidgen.exe, and
226 others; would be best to avoid that if at all possible (using a free
227 cab implementation, part of Wine or something)
229 - if at all possible, the make dev-install installation (with links
230 back to the build) should be done so that it would be directly
231 executable via wine after doing make dev-install :-)
234 - no idea if the entire thing works after the installation at all; I
235 suppose there will be runtime problems to look at too
238 - enable & fix pieces that are currently disabled
239 - --without-myspell-dicts
243 - much of the stuff currently relies on --with-system-*, and
244 consequently on the mingw32-* openSUSE packages; might be good to be
245 able to build with as few dependencies as possible - but that is low
249 - when all the above is sorted out, we should look at the speed of
250 this vs. the speed of the MSVC version
256 iOS is the operating system of Apple's mobile devices. Clearly for a
257 device like the iPad it would be totally unacceptable to run a normal
258 LibreOffice application with a overlapping windows and mouse-oriented
259 GUI widgets. No work has been done (at least publicly) by others to
260 design a touch GUI for LibreOffice, so that is something that needs to
263 Obviously it will make sense to use only a part of LibreOffice's code
264 for iOS. Most likely lots of the GUI-oriented code should be left out,
265 and some iOS app(s) that eventually wants to use the remaining bits
266 will handle all its GUI in a platform-dependent manner. How well it
267 will be possible to do such a split remains to be seen.
269 Technically, one important special aspect of iOS is that apps are not
270 allowed to load own dynamic libraries. (System libraries are used in
271 the form of dynamic libraries, just like on Mac OS X, of which iOS is a
272 variant.) So all the libraries in LibreOffice that normally are shared
273 libraries (DLLs on Windows, shared objects (.so) on Linux, dynamic
274 libraries on Mac OS X (.dylib)) need to be built as static archives
275 instead. Obviously this will have some interesting consequences for
276 how UNO is implemented and used. None of that has been spared much
279 The Apple tool-chain for iOS cross-building is available only for
282 Here is an autogen.lastrun for iOS (device) using Xcode 4.3 and clang,
283 and Xcode 3 for the build platform parts:
284 CXX=ccache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
285 CC=ccache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
286 CC_FOR_BUILD=ccache /Xcode3/usr/bin/gcc-4.0 -mmacosx-version-min=10.4
287 CXX_FOR_BUILD=ccache /Xcode3/usr/bin/g++-4.0 -mmacosx-version-min=10.4
288 --with-distro=LibreOfficeiOS
290 --without-helppack-integration
291 --without-myspell-dicts
293 For the iOS simulator, using Xcode 4.4.1 and clang both for the host and
296 CXX=ccache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -mmacosx-version-min=10.6
297 CC=ccache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -mmacosx-version-min=10.6
299 --with-build-platform-configure-options=--with-macosx-version-min-required=10.6
300 --with-distro=LibreOfficeiOS
302 --without-helppack-integration
303 --without-myspell-dicts
305 Note that you will have to install autoconf and automake yourself
306 before running autogen.sh. They are no longer included in Xcode 4.3
307 (not even in the add-on "command line tools").
309 The -mmacosx-version-min=10.6 is necessary when building for the iOS
310 simulator to avoid clang replacing simple calls to fprintf with calls
311 to fwrite$UNIX2003 which Xcode then warns that doesn't exist on iOS.
317 From a technical point of view the core Android OS is Linux, but
318 everything else is different. Unlike iOS, an Android app can use
319 shared objects just fine, so that aspect of UNO doesn't need special
320 handling. Except that there is a silly low limit in the Android
321 dynamic linker on the number of libraries you can dlopen. Note that
322 this is a limitation of user-level code, not the kernel. Here are
323 various ways around this problem that are being examined.
325 As for the GUI, the same holds as said above for iOS.
327 Android cross-compilation work has been done on Linux (openSUSE in
328 particular) and Mac OS X. The Android cross-buld tool-chain (the
329 "Native Development Kit", or NDK) is available for Linux and Mac OS
330 X. Sure, for Windows, too, but trying to cross-compile LO from Windows
331 will probably drive you insane.
333 You will also need the SDK as full "make" also builds a couple of
334 Android apps (written in Java). Use the "android" tool from the SDK to
335 install the SDK Tools, SDK Platform Tools, the API 14 SDK Platform + ARM EABI
336 v7a System Image, and the Android Support Library.
338 Here is an autogen.lastrun for Android, when cross-compiling from Mac
339 OS X 10.8 with Xcode 4.4.1:
344 --with-android-ndk=/Users/tml/android-ndk-r8b
345 --with-android-ndk-toolchain-version=4.6
346 --with-android-sdk=/Users/tml/android-sdk-macosx
347 --with-distro=LibreOfficeAndroid
349 --without-helppack-integration
350 --without-myspell-dicts
352 And here is an autogen.lastrun for Android when cross-compiling from Linux:
354 --with-distro=LibreOfficeAndroid
355 --build=x86_64-unknown-linux-gnu
356 --with-android-ndk=/home/tml/android-ndk-r8b
357 --with-android-ndk-toolchain-version=4.6
358 --with-android-sdk=/home/tml/android-sdk-linux
360 And here is an autogen.lastrun for Android when cross-compiling to x86 from Linux:
362 --with-android-ndk=/opt/libreoffice/android-ndk-r8b
363 --with-android-ndk-toolchain-version=4.6
364 --with-android-sdk=/opt/libreoffice/android-sdk-linux
365 --build=i586-suse-linux
368 --with-distro=LibreOfficeAndroidX86
372 There are a couple of (more or less) interactive apps that you can run
373 on the emulator or on a device that use LibreOffice code. Look in
374 android/experimental. DocumentLoader is just a testbench, really for
375 code to load a document (just Writer ones so far) and display one page
376 at a time. LibreOffice4Android is what resulted from a Google Summer
377 of Code project in 2012, a document viewer.
379 There are also a couple of non-interactive unit tests that are also
380 built as real "apps", only the one in android/qa/sc works to any
383 To run some of the apps, do "make install" followed by either "make
384 run" or starting it from Android itself. You most likely want to have
385 an "adb logcat" running in another window.
387 To debug, do manually what "make run" would do, adding args "-e
388 lo-main-delay 20" to the command line, and when the app has started,
389 run ndk-gdb. That works just for the sc unit test. Unfortunately the
390 gdb in NDK r7 and r8 is a bit broken, you can use the one in a NDK
391 build with newer versions of gcc and gdb from
392 http://code.google.com/p/mingw-and-ndk/ instead.
394 Running strace on the unit test in progress is often useful to find
395 out what is going wrong. Pass something like -e lo-strace '-tt -f -e
396 trace=file,process,network -o /system/sc/strace.out' to the am start
397 command line. This too works only for NativeActivity-based apps,
398 i.e. the sc unit test.
404 Cross-compiling for PowerPC Mac OS X from Intel Mac OS X will probably
405 be easy. The APIs available should after all be closely identical to
406 those on Intel Mac OS X, and LibreOffice builds fine natively on
407 PowerPC Mac already. Only a little experimenting has been done with
408 it. An autogen.lastrun looked like this when last tried:
410 CC=ccache /Xcode3/usr/bin/gcc-4.0 -arch ppc
411 CXX=ccache /Xcode3/usr/bin/g++-4.0 -arch ppc
412 CC_FOR_BUILD=ccache /Xcode3/usr/bin/gcc-4.0
413 CXX_FOR_BUILD=ccache /Xcode3/usr/bin/g++-4.0
414 --build=i386-apple-darwin10.7.0
415 --host=powerpc-apple-darwin10
417 --disable-build-mozilla