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-libexpat-devel mingw32-libexpat mingw32-boost-devel \
82 mingw32-libhyphen-devel mingw32-libhyphen mingw32-hyphen-en \
83 mingw32-liblpsolve mingw32-liblpsolve-devel \
84 mingw32-libxml2-devel mingw32-libxslt-devel mingw32-libicu \
85 mingw32-libicu-devel mingw32-libgraphite2 mingw32-libgraphite2-devel \
86 mingw32-libcairo2 mingw32-cairo-devel mingw32-librsvg mingw32-librsvg-devel \
87 mingw32-hunspell mingw32-hunspell-devel mingw32-libcurl \
88 mingw32-libcurl-devel mingw32-libneon mingw32-libneon-devel \
89 mingw32-libopenssl mingw32-libopenssl-devel mingw32-libexttextcat \
90 mingw32-libexttextcat-devel mingw32-libdb mingw32-libdb-devel \
91 mingw32-cross-pkg-config mingw32-pkg-config mingw32-libcppunit \
92 mingw32-libcppunit-devel mingw32-libredland mingw32-libredland-devel \
93 mingw32-libmythes mingw32-libmythes-devel
95 There might be more that are missing, please read carefully what autogen.sh
96 tells you, and either remove one of the --with-system-*, or install the
99 It also looks like graphite2.pc needs tweaking in order to work right; but
100 that's likely to be fixed in the openSUSE project.
102 It is somewhat unclear how well thought-out the conditionals and code
103 for MinGW inside the OOo-originated code in LibreOffice actually
104 are. It often seems a bit randomish, with copy-pasting having been
105 preferred to factoring out differences.
107 Most of the configuration settings are maintained in the
108 distro-configs/LibreOfficeMinGW.conf file, so in your autogen.lastrun,
111 CC=ccache i686-w64-mingw32-gcc
112 CXX=ccache i686-w64-mingw32-g++
113 CC_FOR_BUILD=ccache gcc
114 CXX_FOR_BUILD=ccache g++
115 --with-distro=LibreOfficeMinGW
117 Alternatively, you can use something like the following; but the
118 preferred way is to keep the LibreOfficeMinGW.conf file up-to-date.
120 CC=ccache i686-w64-mingw32-gcc
121 CXX=ccache i686-w64-mingw32-g++
122 CC_FOR_BUILD=ccache gcc
123 CXX_FOR_BUILD=ccache g++
124 --build=x86_64-unknown-linux-gnu
125 --host=i686-w64-mingw32
126 --with-distro=LibreOfficeWin32
129 --disable-build-mozilla
131 --disable-ext-nlpsolver
132 --disable-ext-pdfimport
133 --disable-ext-presenter-console
134 --disable-ext-presenter-minimizer
135 --disable-ext-report-builder
136 --disable-ext-scripting-beanshell
137 --disable-ext-scripting-javascript
138 --disable-ext-wiki-publisher
139 --disable-ext-wiki-publisher
143 --enable-python=system
144 --with-system-altlinuxhyph
147 --with-system-cppunit
151 --with-system-gettext
152 --with-system-hunspell
159 --with-system-lpsolve
162 --with-system-openssl
163 --with-system-redland
166 --without-helppack-integration
167 --without-myspell-dicts
169 Once you have compiled it, you may want to try to run it, for instance
173 $ 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
174 $ cd LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US/LOdev\ 3.6/program
177 NB. it is important to unpack somewhere low in the hierarchy structure (like
178 in /tmp as advised above), otherwise you'll get BerkeleyDB errors on startup.
180 And if you are brave enough, you can even debug it. First you have to add the
181 URE dll's to the wine's PATH using 'wine regedit' - see
182 http://www.winehq.org/docs/wineusr-guide/environment-variables, and add
183 Z:\tmp\LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US\LOdev 3.6\URE\bin
184 to "Path" in My Computer->HKEY_CURRENT_USER->Environment.
186 Then run linkoo, so that when you rebuild something, you can directly see the
187 changes the next time you run it:
189 solenv/bin/linkoo '/tmp/LibO-Dev_3.6.0alpha0_Win_x86_install-arc_en-US/LOdev 3.6' <your_clone_dir>
193 $ winedbg soffice.bin
195 Would be great to be able to use winedbg --gdb, but it was crashing here :-( -
196 but maybe you'll be more lucky.
198 Tricks of some use with winedbg:
199 --------------------------------
201 To examine OUStrings, you might want to use the following trick (prints 50
202 unicode characters of rLibName OUString - the +10 is where the buffer starts):
204 Wine-dbg>x /50u rLibName->pData+10
205 0x0909b6c8: vnd.sun.star.expand:$LO_LIB_DIR/abplo.dll
210 - so far the make_installer.pl calls makecab.exe, uuidgen.exe, and
211 others; would be best to avoid that if at all possible (using a free
212 cab implementation, part of Wine or something)
214 - if at all possible, the make dev-install installation (with links
215 back to the build) should be done so that it would be directly
216 executable via wine after doing make dev-install :-)
219 - no idea if the entire thing works after the installation at all; I
220 suppose there will be runtime problems to look at too
223 - enable & fix pieces that are currently disabled
224 - --without-myspell-dicts
228 - much of the stuff currently relies on --with-system-*, and
229 consequently on the mingw32-* openSUSE packages; might be good to be
230 able to build with as few dependencies as possible - but that is low
234 - when all the above is sorted out, we should look at the speed of
235 this vs. the speed of the MSVC version
241 iOS is the operating system of Apple's mobile devices. Clearly for a
242 device like the iPad it would be totally unacceptable to run a normal
243 LibreOffice application with a overlapping windows and mouse-oriented
244 GUI widgets. No work has been done (at least publicly) by others to
245 design a touch GUI for LibreOffice, so that is something that needs to
248 Obviously it will make sense to use only a part of LibreOffice's code
249 for iOS. Most likely lots of the GUI-oriented code should be left out,
250 and some iOS app(s) that eventually wants to use the remaining bits
251 will handle all its GUI in a platform-dependent manner. How well it
252 will be possible to do such a split remains to be seen.
254 Technically, one important special aspect of iOS is that apps are not
255 allowed to load own dynamic libraries. (System libraries are used in
256 the form of dynamic libraries, just like on Mac OS X, of which iOS is a
257 variant.) So all the libraries in LibreOffice that normally are shared
258 libraries (DLLs on Windows, shared objects (.so) on Linux, dynamic
259 libraries on Mac OS X (.dylib)) need to be built as static archives
260 instead. Obviously this will have some interesting consequences for
261 how UNO is implemented and used. None of that has been spared much
264 The Apple tool-chain for iOS cross-building is available only for
267 Here is an autogen.lastrun for iOS (device) using Xcode 4.3 and clang,
268 and Xcode 3 for the build platform parts:
269 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
270 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
271 CC_FOR_BUILD=ccache /Xcode3/usr/bin/gcc-4.0 -mmacosx-version-min=10.4
272 CXX_FOR_BUILD=ccache /Xcode3/usr/bin/g++-4.0 -mmacosx-version-min=10.4
273 --with-distro=LibreOfficeiOS
276 --without-helppack-integration
277 --without-myspell-dicts
279 The --with-system-nss doesn't mean that any Mozilla NSS would be used,
280 it's just a trick to bypass some tests in the configure script.
282 For the iOS simulator, using Xcode 4.3 and clang both for the host and
285 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
286 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
287 CC_FOR_BUILD=ccache clang -arch i386 -mmacosx-version-min=10.6
288 CXX_FOR_BUILD=ccache clang++ -arch i386 -mmacosx-version-min=10.6
290 --with-build-platform-configure-options=--with-macosx-version-min-required=10.6 --with-macosx-sdk=10.6
291 --with-distro=LibreOfficeiOS
294 --without-helppack-integration
295 --without-myspell-dicts
297 Note that you will have to install autoconf and automake yourself
298 before running autogen.sh. They are no longer included in Xcode 4.3
299 (not even in the add-on "command line tools").
301 The -mmacosx-version-min=10.6 is necessary when building for the iOS
302 simulator to avoid clang replacing simple calls to fprintf with calls
303 to fwrite$UNIX2003 which Xcode then warns that doesn't exist on iOS.
309 From a technical point of view the core Android OS is Linux, but
310 everything else is different. Unlike iOS, an Android app can use
311 shared objects just fine, so that aspect of UNO doesn't need special
312 handling. Except that there is a silly low limit in the Android
313 dynamic linker on the number of libraries you can dlopen. Note that
314 this is a limitation of user-level code, not the kernel. Here are
315 various ways around this problem that are being examined.
317 As for the GUI, the same holds as said above for iOS.
319 Android cross-compilation work has been done on Linux (openSUSE in
320 particular) and Mac OS X. The Android cross-buld tool-chain (the
321 "Native Development Kit", or NDK) is available for Linux and Mac OS
322 X. Sure, for Windows, too, but trying to cross-compile LO from Windows
323 will probably drive you insane.
325 Here is an autogen.lastrun for Android, when cross-compiling from Mac OS X:
327 CC_FOR_BUILD=ccache /Xcode3/usr/bin/gcc-4.0 -mmacosx-version-min=10.4
328 CXX_FOR_BUILD=ccache /Xcode3/usr/bin/g++-4.0 -mmacosx-version-min=10.4
329 --with-android-ndk=/Users/tml/android-ndk-r7b
330 --with-android-sdk=/Users/tml/android-sdk-macosx
331 --build=x86_64-apple-darwin11
334 --with-distro=LibreOfficeAndroid
336 --without-helppack-integration
337 --without-myspell-dicts
340 And here is an autogen.lastrun for Android when cross-compiling from Linux:
342 CC_FOR_BUILD=ccache gcc
343 CXX_FOR_BUILD=ccache g++
344 --with-android-ndk=/home/tml/android-ndk-r7b
345 --with-android-sdk=/home/tml/android-sdk-linux_x86
346 --with-ant-home=/opt/apache-ant-1.8.2
347 --build=x86_64-unknown-linux-gnu
349 --with-distro=LibreOfficeAndroid
353 --without-helppack-integration
354 --without-myspell-dicts
356 There is no interactive end-user "app" you could run yet that would
357 use LibreOffice code, but you can build some non-interactive unit
358 tests and run them on the emulator (or, presumably, on a device,
359 although that hasn't been tested as nobody with an actual Android
360 device has worked on it yet...) The simple unit tests will succeed,
361 the complex one still fails.
363 These unit tests *are* proper "apps" from Android'd point of view, but
364 they don't have any GUI and thus don't take part in the normal Android
365 message passing and Android thinks they are stuck and offers to kill
368 The activity used for these apps is in android/Bootstrap. See
371 To build the complex unit test for Calc functionality which invokes the
372 "ucalc" unit test code from sc, cd to android/qa/sc and run a "make". The
373 Makefile here is completely manually written, this stuff is so experimental it
374 doesn't make sense yet to try to integrate with the normal gbuild mechanism.
376 Note that lately (as of May 2012) the android/qa/sc test has not been
377 maintained, and might not build cleanly.
379 Then to run the unit test, do "make install" followed by "make
380 run". You most likely want to have an "adb logcat" running in another
383 To debug, do manually what "make run" would do, adding args "-e lo-main-delay
384 20" to the command line, and when the app has started, run
385 ndk-gdb. Unfortunately the gdb in NDK r7 and r8 is a bit broken, you can use
386 the one in a NDK build with newer versions of gcc and gdb from
387 http://code.google.com/p/mingw-and-ndk/ instead.
389 Running strace on the unit test in progress is often useful to find
390 out what is going wrong. Pass something like -e lo-strace '-tt -f -e
391 trace=file,process,network -o /system/sc/strace.out' to the am start
394 The Android test app which has been exercised lately is in
395 android/experimental/DocumentLoader.
401 Cross-compiling for PowerPC Mac OS X from Intel Mac OS X will probably
402 be easy. The APIs available should after all be closely identical to
403 those on Intel Mac OS X, and LibreOffice builds fine natively on
404 PowerPC Mac already. Only a little experimenting has been done with
405 it. An autogen.lastrun looks like this:
407 CC=ccache /Xcode3/usr/bin/gcc-4.0 -arch ppc
408 CXX=ccache /Xcode3/usr/bin/g++-4.0 -arch ppc
409 CC_FOR_BUILD=ccache /Xcode3/usr/bin/gcc-4.0
410 CXX_FOR_BUILD=ccache /Xcode3/usr/bin/g++-4.0
411 --build=i386-apple-darwin10.7.0
412 --host=powerpc-apple-darwin10
414 --disable-build-mozilla