Fix comment typo.
[LibreOffice.git] / README.cross
blobcfeaadc4d45bc39f42a5cde080a19b3a4663cfa8
1 Cross-compiling LibreOffice
2 ***************************
4 Cross-compilation works, to various degree, to the following
5 platforms: Windows, iOS, Android, and Raspbian.
8 General
9 -------
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 practice, many details need to be handled. See examples
30 below.
32 Note that in the case of LibreOffice, it is uncommon to run the
33 configure script directly. Normally one uses the autogen.sh script.
34 The autogen.sh script reads command-line options from file called
35 autogen.input if it exists. The typical way of working is to keep
36 the configure parameters in that file and edit it as needed.
39 What is so hard, then?
40 ----------------------
42 Despite the fact that the configure script takes normal --build and
43 --host options, that is just the beginning. It was necessary to
44 separate tests for "host" and "build" platforms in the configure
45 script. See the git log for details. And the reasonably "standard"
46 configure.in is just the top level; when we get down to the actual
47 makefilery used to build the bits of LibreOffice, it gets much worse.
50 Windows
51 *******
53 There was some support in LibreOffice already from OpenOffice.org days
54 for building it locally on Windows with the GNU tool-chain (MinGW).
55 Apparently, those doing that work never attempted cross-compilation.
57 This OOo-originated MinGW support attempts to be for both running the
58 Cygwin gcc in its -mno-cygwin mode, and a Windows-native MinGW
59 compiler. The -mno-cygwin mechanism in the Cygwin gcc is rapidly being
60 obsoleted, if it isn't already, and we have not attempted to try to
61 keep it working; in fact we have actively cleaned out mechanisms
62 related to this. Ditto for native MinGW. If one compiles natively on
63 Windows, just use a version of Microsoft's compiler. OpenOffice.org
64 and LibreOffice have been built for Windows all the time using that.
66 The only case where it makes sense to use MinGW is for
67 cross-compilation. There is just too much crack involved on Windows
68 anyway, and it is a semi-miracle that the MSVC build under Cygwin
69 works as nicely as it does.
71 MinGW is available as cross-build toolchains pre-packaged in more or
72 less official packages for many Linux distros including Debian, Fedora
73 and openSUSE. For instance, the mingw32 packages in the Open Build
74 Service, running on openSUSE, can be found at:
76 http://download.opensuse.org/repositories/windows:/mingw:/win32/
78 For example, you can install it like this:
80 zypper ar http://download.opensuse.org/repositories/windows:/mingw:/win32/<your_os>/windows:mingw:win32.repo
82 where <your_os> is one of SLE_11, SLE_11_SP1, openSUSE_XX.Y, or
83 openSUSE_Factory.
85 zypper in mingw32-cross-gcc mingw32-cross-gcc-c++ mingw32-python-devel \
86     mingw32-python mingw32-libboost_date_time \
87     mingw32-libexpat-devel mingw32-libexpat mingw32-boost-devel \
88     mingw32-libhyphen-devel mingw32-libhyphen mingw32-hyphen-en \
89     mingw32-liblpsolve mingw32-liblpsolve-devel \
90     mingw32-libxml2-devel mingw32-libxslt-devel mingw32-libicu \
91     mingw32-libicu-devel mingw32-libgraphite2 mingw32-libgraphite2-devel \
92     mingw32-libcairo2 mingw32-cairo-devel mingw32-librsvg mingw32-librsvg-devel \
93     mingw32-hunspell mingw32-hunspell-devel mingw32-libcurl \
94     mingw32-libcurl-devel mingw32-libneon mingw32-libneon-devel \
95     mingw32-libopenssl mingw32-libopenssl-devel mingw32-libexttextcat \
96     mingw32-libexttextcat-devel mingw32-libdb mingw32-libdb-devel \
97     mingw32-cross-pkg-config mingw32-pkg-config mingw32-libcppunit \
98     mingw32-libcppunit-devel mingw32-libredland mingw32-libredland-devel \
99     mingw32-libmythes mingw32-libmythes-devel mingw32-mozilla-nss \
100     mingw32-mozilla-nss-devel mingw32-mozilla-nspr \
101     mingw32-mozilla-nspr-devel mingw32-libpoppler mingw32-libpoppler-devel
103 You also need wine, ideally:
105 zypper ar http://download.opensuse.org/repositories/Emulators:/Wine/<your_os>/Emulators:Wine.repo
107 zypper in wine wine-devel wine-devel-32bit
109 And in order to be able to use 'winegcc -m32', also
111 zypper in glibc-devel-32bit gcc-32bit
113 There might be more that are missing, please read carefully what autogen.sh
114 tells you, and either remove one of the --with-system-*, or install the
115 missing dependency.
117 It also looks like graphite2.pc needs tweaking in order to work right; but
118 that's likely to be fixed in the openSUSE project.
120 It is somewhat unclear how well thought-out the conditionals and code
121 for MinGW inside the OOo-originated code in LibreOffice actually
122 are. It often seems a bit randomish, with copy-pasting having been
123 preferred to factoring out differences.
125 Most of the configuration settings are maintained in the
126 distro-configs/LibreOfficeMinGW.conf file, so in your autogen.input,
127 you can use:
129 CC=ccache i686-w64-mingw32-gcc
130 CXX=ccache i686-w64-mingw32-g++
131 CC_FOR_BUILD=ccache gcc
132 CXX_FOR_BUILD=ccache g++
133 --with-distro=LibreOfficeMinGW
135 Alternatively, you can use something like the following; but the
136 preferred way is to keep the LibreOfficeMinGW.conf file up-to-date.
138 CC=ccache i686-w64-mingw32-gcc
139 CXX=ccache i686-w64-mingw32-g++
140 CC_FOR_BUILD=ccache gcc
141 CXX_FOR_BUILD=ccache g++
142 --build=x86_64-unknown-linux-gnu
143 --host=i686-w64-mingw32
144 --with-distro=LibreOfficeWin32
145 --disable-activex
146 --disable-directx
147 --disable-ext-nlpsolver
148 --disable-report-builder
149 --disable-scripting-beanshell
150 --disable-scripting-javascript
151 --disable-ext-wiki-publisher
152 --disable-pdfimport
153 --enable-python=system
154 --with-system-altlinuxhyph
155 --with-system-boost
156 --with-system-cairo
157 --with-system-cppunit
158 --with-system-curl
159 --with-system-expat
160 --with-system-hunspell
161 --with-system-icu
162 --with-system-libpng
163 --with-system-libwpd
164 --with-system-libwpg
165 --with-system-libwps
166 --with-system-libxml
167 --with-system-lpsolve
168 --with-system-mythes
169 --with-system-neon
170 --with-system-openssl
171 --with-system-redland
172 --with-vendor=no
173 --without-help
174 --without-helppack-integration
175 --without-myspell-dicts
177 Once you have compiled it, you may want to try to run it, for instance
178 using Wine:
180 $ cd /tmp
181 $ tar xf <your-build-dir>/workdir/wntgcci.pro/installation/LibreOffice_Dev/archive/install/en-US/LibO-Dev_4.1.0.0.alpha0_Win_x86_archive.tar.gz
182 $ cd LibO-Dev_4.1.0.0.alpha0_Win_x86_archive/LOdev\ 4.1/program/
183 $ wine soffice.exe
185 NB. it is important to unpack somewhere low in the hierarchy structure (like
186 in /tmp as advised above), otherwise you'll get BerkeleyDB errors on startup.
188 And if you are brave enough, you can even debug it.  First you have to add the
189 URE dll's to the wine's PATH using 'wine regedit' - see
190 http://www.winehq.org/docs/wineusr-guide/environment-variables, and add
191 Z:\tmp\LibO-Dev_4.1.0.0.alpha0_Win_x86_archive/LOdev\ 4.1\URE\bin
192 to "Path" in My Computer->HKEY_CURRENT_USER->Environment.
194 And start debugging:
196 $ winedbg soffice.bin
198 Would be great to be able to use winedbg --gdb, but it was crashing here :-( -
199 but maybe you'll be more lucky.
201 Tricks of some use with winedbg:
202 --------------------------------
204 To examine OUStrings, you might want to use the following trick (prints 50
205 unicode characters of rLibName OUString - the +10 is where the buffer starts):
207 Wine-dbg>x /50u rLibName->pData+10
208 0x0909b6c8: vnd.sun.star.expand:$LO_LIB_DIR/abplo.dll
210 TODO:
212 - make the debugging more convenient on (native) Windows
213   - check possibilities like WinGDB - http://www.wingdb.com/
214   - or find / write a MSVS / WinDBG extension that can read MinGW debugging
215     symbols natively; more info
216     http://windbg.info/forum/12-symbol-and-source-files-/21-debugging-mingwgcc-built-dll-in-visual-studio.html
218 - installation
219   - so far the make_installer.pl calls makecab.exe, uuidgen.exe, and
220     others; would be best to avoid that if at all possible (using a free
221     cab implementation, part of Wine or something)
222   - MSI generation
223   - if at all possible, the make dev-install installation (with links
224     back to the build) should be done so that it would be directly
225     executable via wine after doing make dev-install :-)
227 - runtime
228   - no idea if the entire thing works after the installation at all; I
229     suppose there will be runtime problems to look at too
231 - cleanup
232   - enable & fix pieces that are currently disabled
233     - --without-myspell-dicts
234     - --disable-directx
235     - --disable-activex
236   - much of the stuff currently relies on --with-system-*, and
237     consequently on the mingw32-* openSUSE packages; might be good to be
238     able to build with as few dependencies as possible - but that is low
239     prio
241 - profiling
242   - when all the above is sorted out, we should look at the speed of
243     this vs. the speed of the MSVC version
249 iOS is the operating system on Apple's mobile devices. Clearly for a
250 device like the iPad it would not be acceptable to run a normal
251 LibreOffice application with overlapping windows and mouse-oriented
252 GUI widgets.
254 It makes sense to use only a part of LibreOffice's code for iOS. Lots
255 of the GUI-oriented code should be left out. iOS apps that want to use
256 the applicable LibreOffice code will handle all their GUI in a
257 platform-dependent manner. How well it will be possible to do such a
258 split remains to be seen.
260 Obviously we want it to be possible to eventually distribute apps
261 using LibreOffice code through the App Store. Technically, one
262 important special aspect of iOS is that apps in the App Store are not
263 allowed to load own dynamic libraries. (System libraries are used in
264 the form of dynamic libraries, just like on Mac OS X, of which iOS is
265 a variant.)
267 Thus all the libraries in LibreOffice that normally are shared
268 libraries (DLLs on Windows, shared objects (.so) on Linux, dynamic
269 libraries on Mac OS X (.dylib)) must be built as static archives
270 instead. This has some interesting consequences for how UNO is
271 implemented and used.
273 An iOS app is a "bundle" that contains a single executable, In an app
274 using LibreOffice code, that eecutable then congtains the necessary
275 LibreOffice libraries and UNO components statically linked.
277 The Apple tool-chain for iOS cross-building is available only for OS
278 X. In order to be able to run and debug an app on an actual device
279 (and not just the iOS Simulator) you need to be registered in the iOS
280 Developer Program.
282 Here is an autogen.input for iOS (device) using Xcode 4.6, on OS X 10.8:
284 --build=i386-apple-darwin10.7.0
285 --host=arm-apple-darwin10
286 --enable-dbgutil
287 --enable-debug
288 --enable-werror
290 For the iOS Simulator, but note that building for the simulator is
291 broken at the moment (July 2014):
293 --build=i386-apple-darwin10.7.0
294 --host=arm-apple-darwin10
295 --enable-ios-simulator
296 --enable-dbgutil
297 --enable-debug
298 --enable-werror
300 You will have to install autoconf and automake yourself before running
301 autogen.sh. They are no longer included in Xcode 4.3 and later (not
302 even in the add-on "command line tools").
304 The -mmacosx-version-min=10.7 is necessary when building for the iOS
305 simulator to avoid clang replacing simple calls to fprintf with calls
306 to fwrite$UNIX2003 which Xcode then warns that doesn't exist on iOS.
309 Android
310 *******
312 From a technical point of view the core Android OS (the kernel) is
313 Linux, but everything else is different. Unlike iOS, an Android app
314 can use shared objects just fine, so that aspect of UNO doesn't need
315 special handling. Except that there is a silly low limit in the
316 Android dynamic linker on the number of libraries you can dlopen. This
317 is a limitation in user-level (but system-provided and not really
318 replaceable) code, not the kernel.
320 Thus, just like for iOS, also for Android the LibreOffice libraries
321 and UNO components are built as static archives. For Android, those
322 static archives, and any app-specific native code, are linked into one
323 single app-specific shared library, called liblo-native-code.so.
325 For the GUI, the same holds as said above for iOS. The GUI layer needs
326 to be platform-specific, written in Java.
328 Android cross-compilation work has been done mainly on Linux (openSUSE
329 in particular). Earlier also cross-compiling from OS X was tried. The
330 Android cross-compilation tool-chain (the "Native Development Kit", or
331 NDK) is available for Linux, OS X and Windows, but trying to
332 cross-compile LibreOffice from Windows will probably drive you insane.
334 You will also need the Android SDK as full "make" also builds a couple
335 of Android apps where the upper layer is written in Java.
337 Use the "android" tool from the SDK to install the SDK Tools, SDK
338 Platform Tools, the API 15 SDK Platform and the Android Support
339 Library. If you want to run the Android apps in the emulator, you of
340 course need an appropriate system image for that.
342 Here is an autogen.input for Android on ARM when cross-compiling
343 from Linux:
345 --build=x86_64-unknown-linux-gnu
346 --enable-dbgutil
347 --enable-debug
348 --enable-werror
349 --with-android-ndk=/home/tml/android-ndk-r9c
350 --with-android-ndk-toolchain-version=4.8
351 --with-android-sdk=/home/tml/adt-bundle-linux/sdk
352 --with-distro=LibreOfficeAndroid
354 And here is an (quite old) autogen.input for Android on X86:
356 --with-android-ndk=/opt/libreoffice/android-ndk-r8b
357 --with-android-ndk-toolchain-version=4.6
358 --with-android-sdk=/opt/libreoffice/android-sdk-linux
359 --build=i586-suse-linux
360 --enable-ccache
361 --with-distro=LibreOfficeAndroidX86
363 There are a couple of (more or less) interactive apps that you can run
364 on the emulator or on a device that use LibreOffice code. Look in
365 android/experimental. DocumentLoader is just a testbench, really for
366 code to load a document (just Writer ones so far) and display one page
367 at a time. LibreOffice4Android is what resulted from a Google Summer
368 of Code project in 2012, a document viewer. desktop is a totally
369 different app, where the actual LibreOffice desktop GUI is present.
370 Note that none of these apps in any way are claimed to be ready for
371 end-users. No "beta testing" offers needed, it is painfully obvious
372 what problems they have.
374 To run some of the apps, do "make install" followed by either "make
375 run" or starting it from Android itself. You most likely want to have
376 an "adb logcat" running in another window.
378 To debug, do manually what "make run" would do and when the app has
379 started, run ndk-gdb.
381 NB: If you happen to upgrade to Android SDK Tools 23, and the build (using
382 'make verbose=t android') fails for you with:
384        [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
385        [dx] java.io.FileNotFoundException: /local/libreoffice/android-sdk-linux/tools/support/annotations.jar (Adresář nebo soubor neexistuje)
387 you need to copy the annotations.jar from an older sdk; like
389 wget 'http://dl-ssl.google.com/android/repository/tools_r22.6.2-linux.zip'
390 unzip tools_r22.6.2-linux.zip
391 cp tools/support/annotations.jar <android-sdk-linux>/tools/support/
393 Raspbian
394 ********
396 In theory, this should work also for another Linux, it does not need to be Raspbian.
397 But this cross-compilation work is tested from Debian and openSUSE to Raspbian.
399 You will need headers, pkg-config files and libraries from a Raspbian
400 system to build against. Available at
401 http://dev-www.libreoffice.org/extern/ . Look for the latest
402 raspbian-root-*.tar.gz . For instance:
404 $ wget http://dev-www.libreoffice.org/extern/raspbian-root-20140120.tar.gz
405 $ mkdir raspbian-root
406 $ cd raspbian-root
407 $ tar -xf raspbian-root-20140120.tar.gz
409 You can build cross-compiler yourself or get the executables here:
410 $ git clone git://github.com/raspberrypi/tools
412 tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian is known to work.
414 Then create pkg-config wrapper, something like:
415 $ cat > pkg-config-wrapper-host << _EOF
416 #!/bin/sh
418 if [ "$CROSS_COMPILING" = TRUE ]; then
419    SYSROOT=$HOME/lo/raspbian-root
420    export PKG_CONFIG_PATH=${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig:${SYSROOT}/usr/share/pkgconfig
421    export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig
422    export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
425 exec pkg-config "\$@"
426 _EOF
427 $ chmod +x pkg-config-wrapper-host
429 This does not work with pkg-config 0.23. 0.26 is known to work.
431 And you are ready to build with autogen.input similar to:
433 PKG_CONFIG=<path-to-pkg-config-wrapper-host>
434 CC=<path-to-arm-linux-gnueabihf-gcc> --sysroot=<path-to-raspbian_rootfs>
435 CXX=<path-to-arm-linux-gnueabihf-g++> --sysroot=<path-to-raspbian_rootfs>
436 --build=x86_64-unknown-linux-gnu
437 --host=arm-unknown-linux-gnueabihf
438 --disable-sdk
439 --enable-python=system
440 PYTHON_CFLAGS=-I<path-to-raspbian_rootfs>/usr/include/python2.7
441 PYTHON_LIBS=-lpython2.7
442 --with-java
443 JAVAINC=-I<path-to-raspbian_rootfs>/usr/lib/jvm/java-6-openjdk-armhf/include
444 --with-system-cairo
445 --with-system-cppunit
446 --with-system-icu
447 --with-system-neon
448 --with-system-nss
449 --with-system-openldap
450 --with-system-openssl
451 --with-system-redland
453 Finally, when you are ready to run the binaries in Raspbian,
454 you may need to get more system libraries, who knows.
455 $ sudo apt-get install libreoffice # or similar
456 That installs libreoffice too, which you don't need because you have
457 just built one, but I don't know how to avoid it easily.