Difference between revisions of "Documentation/Building Guide/Building on Windows with MinGW"

From Apache OpenOffice Wiki
Jump to: navigation, search
(required additional packages: two cygwin pakages that I needed)
(required additional packages: +rsync)
Line 142: Line 142:
 
** openssh
 
** openssh
 
** ncftp
 
** ncftp
 +
** rsync
 
* Category Perl
 
* Category Perl
 
** perl
 
** perl

Revision as of 10:24, 15 December 2009

[[{{{PrevPage}}}|< Previous Page

]]

[[{{{NextPage}}}|Next Page
>]]
Template:Documentation/DraftPage

Overview

Template:Documentation/Windows

what is MinGW?

MinGW stands for Minimalist’s GNU for Windows. It is a set of firee, open source software including compiler, linker,shell environment and other useful tools for developing software. MinGW is intended to support developing software to work on Microsoft 32-bit Windows with minimal support of external libraries. The MinGW community is distributing the g++ compiler from gcc (GNU compiler collection) and GNU ld linker for Windows 32-bit executables in GNU binutils, which is a set of tools to manipulate binary object and executable files.

Cygwin

For building OpenOffice.org Cygwin is needed, a Windows program that emulates a complete Unix command line environment. To use this document you need to be familiar with a command line, but you need not to be a UNIX shell wizard.

Template:Documentation/Tip

Template:Documentation/Note Template:Documentation/Tip

Cygwin compiler v. s. MinGW compiler

Cygwin also includes C++ compiler and linker in its distribution as well as headers and libraries of MinGW. Specifying -mno-cygwin command line switch, the tools can generate the same object code to MinGW compiler. However, as the tools use Cygwin system call to invoke sub programs, the process to build OpenOffice.org with Cygwin’s compiler and linker is a bit slower and more unstable than that with “pure” MinGW tools on Cygwin shell.

versions and problems in compiler and linker

The version of the official release of gcc from MinGW is gcc-3.4.5 for version 3 series and gcc-4.4.0 for version 4 series. 4.4.0 is the first official release of version 4 series and older versions in version 4 series were all experimental. Cygwin includes gcc-3.4.4 and experimental 4.3.2. Compilers of version 3 series have several problems to build OOo and needs patches. You can get the patched binaries of core C compiler and C++ compiler at ooopackages.good-day.net. Available version is only 3.4.4. The source patch is also available there. You can get the patched compilers equivalent to them in Cygwin distribution. You have to get core C compiler, C++ compiler and the MinGW libraries for both C and C++ at ooopackages.good-day.net. Please note that you have to run the postinstall command in /etc/postinstall directory after extracting the distribution of both of the MinGW libraries for C on Cygwin and that for C++ under root directory in Cygwin command prompt. Compilers of version 4 series have no serious problem to build OOo but the standard C++ library distribution included in the official release of gcc-4.4.0 is only partial and needs to be rebuilt using a Cygwin shell script. Gcc version 4 emits better code and useful warning messages. However, you should concern licence agreements of dlls. MinGW gcc compiler has restriction to use dynamic linking of the two library libgcc and libstdc++ for proper exception handling and the dlls will be included in the installation set you will build. In the meantime the licence agreements of these dlls have a rather strict term to follow if you redistribute them. The version of the official release of binutils from both MinGW and Cygwin is 2.19.18 and ld linker has problems to build OOo. The patched binaries and sources are available at ooopackages.good-day.net.

w32api and MinGW runtime library

The set of libraries and headers to let code to use Windows API is distributed as w32api. The version 3.13 is required for building OOo. Some new APIs and constant definitions that are not officially published from Microsoft are not included and you have to use files in Microsoft SDK with smalll patches. MinGW runtime library of version 3.16 is required as well to enable multithreading and fix some C functions. MinGW tools are intended to use Microsoft C runtime library that is always installed in Windows system but some bugs are fixed in MinGW runtime library.

Requirements

hardware requirements

  • 1 or more reasonable fast CPUs (x-way CPU recommended)
  • 1 GB RAM (2 GB recommended)
  • 10 GB free disk space (20 GB when debugging)

software requirements

  • Windows XP/Vista

The following table is placed here, so you can come back to it easily, when you want to use a link. The items are explained below. Here's the list of files to download (with links) and the locations in the source tree where you must put them:


Where to get Place in
Cygwin: Cygwin Toolkit with (dll version 1.5.10) or later (default)
Either of

“pure” gcc 3 series tools including patched “pure” MingW gcc 3 compiler and patched binutils: gcc-core-3.4.4-20050522-1-ooopatched.tar.gz gcc-g++-3.4.4-20050522-1-ooopatched.tar.gz binutils-2.19.1-ooopatched.tar.gz and w32api and MinGW runtime: w32api-3.13-mingw32-dev.tar.gz mingwrt-3.16-mingw32-dev.tar.gz mingwrt-3.16-mingw32-dll.tar.gz or

“pure” gcc 4 series tools including patched binutils and the library rebuilding script: binutils-2.19.1-ooopatched.tar.gz gcc-core-g++-4.4.0-install.sh and MingW gcc 4 compiler, w32api and MinGW runtime: gcc-core-4.4.0-mingw32-bin.tar.gz gcc-core-4.4.0-mingw32-dll.tar.gz gcc-c++-4.4.0-mingw32-bin.tar.gz gcc-c++-4.4.0-mingw32-dll.tar.gz gmp-4.2.4-mingw32-dll.tar.gz mpfr-2.4.1-mingw32-dll.tar.gz pthreads-w32-2.8.0-mingw32-dll.tar.gz w32api-3.13-mingw32-dev.tar.gz mingwrt-3.16-mingw32-dev.tar.gz mingwrt-3.16-mingw32-dll.tar.gz or

Cygwin tools including patched Cygwin gcc 3 compiler and patched binutils (w32api and MinGW runtime for Cygwin compiler/linker are included in Cygwin distribution): gcc-core-3.4.4-3ooopatched.tar.bz2 gcc-g++-3.4.4-3ooopatched.tar.bz2 gcc-mingw-core-20050522-ooopatched-1.tar.bz2 gcc-mingw-g++-20050522-ooopatched-1.tar.bz2 binutils-20080624-2-ooopatched.tar.bz2

(default)
Java: JDK 1.6 for DEV300 milestones >= m37 and all OOo310 versions (older milestones will fail in the hsqldb module) (default)
Windows SDK for Windows Server 2008.[1]
GDI+ Redistributable (Genuine Windows Validation required) external/gdiplus
Only for OOo2.x but due to Issue 88652 in configure still needed for 3.x: unicows.dll from (Microsoft Layer for Unicode)[2] external/unicows
dbghelp.dll[3] external/dbghelp
instmsiw.exe and instmsia.exe external/msi
Apache Ant (version 1.6.5 or later) (default)
either of Mozilla binary distribution for milestone <= DEV300_m52 or Seamonkey for milestone >= DEV300_m53 moz/zipped
optional: Nullsoft Scriptable Install System (NSIS)[4]
optional: Microsoft DirectX SDK[5]
optional: MozillaBuild

adding required files to the build tree

Template:Documentation/Tip

Template:Documentation/Note


Installation and Preparation of Build Tools

setting up cygwin

Go to http://www.cygwin.com/ and download and install the current version.

Documentation caution.png Make sure that you keep the filetype set to “Unix/binary”.

required additional packages

Cygwin consists of some basic and a lot of optional packages. As building OOo needs some of these optional packages you have to select them in the installer. Here's a complete list of the needed packages:

  • Category Archive:
    • cabextract
    • unzip
    • zip
  • Category Devel :
    • autoconf
    • bison
    • flex
    • gcc-g++
    • gperf
    • make
    • openssl-devel (only needed for perl modules for CWS tooling, see below)
    • pkgconfig
    • cvs (for 2.x code line and 3.0 code line)
    • subversion (for 3.x code line, minimum version 1.5.5)
  • Category Libs
    • openssl
  • Category Net
    • openssh
    • ncftp
    • rsync
  • Category Perl
    • perl
  • Category Shells
    • rxvt
  • Category Utils
    • file
    • patch
    • gnupg
  • Category Web
    • lynx
    • wget
Documentation caution.png You have to exclude the package rebase in Category Base if you use Cygwin compiler for OOo build.

Template:Documentation/Note

Template:Documentation/Note

breaking links to executables

Within the Cygwin Toolkit, some executables might be symlinks: awk.exe and gunzip.exe, tar.exe (in older releases only). This can lead to a break of the build later, and the symlinks should be replaced by copies of the command they link to.

To check this, execute:

ls -l /bin/awk.exe

whether e.g. awk.exe is a symlink. In version 1.5.24-2 awk.exe is a link to gawk.exe. The shell will show this by putting out “awk.exe -> gawk.exe”. In this case gawk.exe must be copied to awk.exe by executing:

cd /bin
rm awk.exe
cp gawk.exe awk.exe


In case you overlook something here or you have a newer Cygwin version with additional symlinks not mentioned here it's not a problem. You will get a helpful error message about an existing link in the configuration step (configure) later. The message will tell you which link you have to remove and you can do it following the advice given above for the awk.exe/gawk.exe pair.

installing additional perl modules in cygwin

As explained some perl modules must be installed with CPAN. The necessary command in the cygwin shell is

perl -MCPAN -e shell

If this command is executed the first time CPAN will ask for configuration. Choose autoconfiguration.

Documentation caution.png Please note that CPAN is not able to deal with usernames containing spaces. To work around this fact, when CPAN asks you to specify the CPAN build and cache directory, change the default suggestion to /cpan.

At the end the CPAN shell appeared and is ready to accept commands for installations. Each module is installed by typing install $MODULENAME. The modules that must be installed are:

  • Archive::Zip
  • XML::Parser (though it seems that this is already installed; doesn't hurt to do it)
  • URI
  • LWP::UserAgent
  • Crypt::SSLeay
  • SOAP::Lite

CPAN will detect if a selected module depends on other modules and it will offer to download them also. As explained please just confirm this.

Template:Documentation/Note

Documentation caution.png I got an error message from CPAN somewhat like the following:
C:\cygwin\bin\perl.exe: *** unable to remap C:\cygwin\bin\cygiconv-2.dll to same
address as parent(0x7C0000) != 0x7D0000

To fix this, I had to exit the Cygwin shell, run cmd.exe, then type "c:\cygwin\bin\ash.exe" to start the minimal shell, then type /bin/rebaseall. Then CPAN worked when I ran it again.

Documentation caution.png I got another error when cygwin was performing make install:
ERROR: Can't create '/usr/bin'; Do not have write permissions on '/usr/bin'

I can actually write to /usr/bin; however when I do ls -ld /usr/bin, cygwin reports no write permission; and chmod u+w /usr/bin gives Permission denied. This causes the install process to fail when it checks permissions. As a kludge, I installed vim, and edited line 368 of /usr/lib/perl5/5.10/ExtUtils/Install.pm, replacing this:

return -w $dir;

with this:

return 1;

which allowed installation to proceed.

installing compiler and binutils

installing “pure” MinGW gcc version 3 series compiler and binutils

To install “pure” MinGW gcc version 3 series compiler and binutils, you have to create a unique directory first, say c:/mingw. All you have to do is to extract all tarballs here.

tar -C c:/mingw -xvzpf xxx.tar.gz

installing “pure” MinGW gcc version 4 series compiler and binutils

To install “pure” MinGW gcc version 4 series compiler and binutils, you have to choose a unique directory name, say c:/mingw, put everything you downloaded in one working directory and invoke the following command in the directory.

./gcc-core-g++-4.4.0-install.sh c:/mingw

installing Cygwin gcc version 3 series compiler and binutils

You have to extract all tarballs in root directory.

tar -C / -xvjpf xxx.tar.gz

The tarballs for gcc-mingw-gcc and gcc-mingw-g++ include postinstall scripts. You have to run them to complete installation.

/etc/postinstall/gcc-mingw-core.sh
/etc/postinstall/gcc-mingw-g++.sh

Full Builds

configure

Finally the configure tool is used to create the environment. It checks that all software, hardware, and system requirements for the build are satisfied, and creates configuration files called winmingw.set (for tcsh) and winmingw.set.sh (for bash) that are used to set all necessary build environment variables. Before running configure, make sure that all needed programs are in the system path or start configure with the appropriate command line switches. If configure detects a problem it will stop and give you a useful hint how to fix it.

You will find the configure script in $SRC_ROOT. The resulting configuration files are created there too.

sample configure calls

./configure \
 --with-mingwin=yes \
 --disable-directx \
 --disable-activex \
 --disable-atl \
 --disable-build-mozilla \
 --with-frame-home="/cygdrive/c/PROGRA~1/MI2578~1/Windows/v6.1" \
 --with-psdk-home="/cygdrive/c/PROGRA~1/MI2578~1/Windows/v6.1" \
 --with-midl-path="/cygdrive/c/PROGRA~1/MI2578~1/Windows/v6.1/Bin" \
 --with-jdk-home="/cygdrive/c/PROGRA~1/j2sdk1.4.2_11" \
 --with-csc-path="/cygdrive/c/Windows/Microsoft.NET/Framework/v3.5" \
 --with-ant-home=/ant \
 --with-use-shell=bash
 --with-mozilla-build=/cygdrive/c/mozilla-build/moztools \
 --with-nsis-path=/cygdrive/c/PROGRA~1/NSIS
./configure \
 --with-mingwin=yes \
 --disable-activex \
 --disable-atl \
 --disable-build-mozilla \
 --with-frame-home="/cygdrive/c/PROGRA~1/MI2578~1/Windows/v6.1" \
 --with-psdk-home="/cygdrive/c/PROGRA~1/MI2578~1/Windows/v6.1" \
 --with-midl-path="/cygdrive/c/PROGRA~1/MI2578~1/Windows/v6.1/Bin" \
 --with-jdk-home="/cygdrive/c/PROGRA~1/j2sdk1.4.2_11" \
 --with-csc-path="/cygdrive/c/Windows/Microsoft.NET/Framework/v3.5" \
 --with-ant-home=/ant \
 --with-use-shell=bash
 --with-mozilla-build=/cygdrive/c/mozilla-build/moztools \
 --with-nsis-path=/cygdrive/c/PROGRA~1/NSIS \
 --enable-crashdump \
 --enable-symbols=SMALL \
 --enable-vba \
 --enable-minimizer \
 --enable-presenter-console \
 --enable-pdfimport \
 --enable-wiki-publisher \
 --enable-report-builder \
 --enable-cairo

configure settings tips

Documentation caution.png Make sure that the PATH variable in your cygwin shell does not contain any blanks and quotes.
Documentation caution.png Paths might have problems with spaces. Install requirements into paths without them. Alternatively, feel free to install the various packages using the default path containing spaces and then use the mixed short path for the configure stage. The mixed short path can be obtained using Cygwin's cygpath tool, eg:
$ cygpath -m -s "c:\Program Files\Microsoft SDKs"
 c:/PROGRA~1/MI2578~1

The with-psdk-home setting needs a case-sensitive path name. I recommend to use case-sensitive usage in all cases - it's good to get used to case sensitivity if you are going to work with Cygwin.

Documentation caution.png Beware of using /c/ instead of /cygdrive/c/.
Documentation caution.png Avoid trailing slashes in configure parameters. They sure cause problems for --with-psdk-home.

Template:Documentation/Note Template:Documentation/Tip Template:Documentation/Tip Template:Documentation/Tip Template:Documentation/Tip Template:Documentation/Tip Template:Documentation/Tip Template:Documentation/Tip Template:Documentation/Tip

bootstrap

After running configure you must create the dmake make utility that is needed for the build of OpenOffice.org. This done from the SRC_ROOT directory by calling

./bootstrap

setting the environment

When the configure script has been run successfully a file winmingw.Set.sh was created[6]. Do this:

source winmingw.Set.sh

to set up the environment for the build.

starting the build

Build the software by typing the following in $SRC_ROOT [7]:

dmake

The building procedure will take at least an hour (on a 3 GHz Quad-Core with 8GB RAM).

There are some special things in the way how OOo builds its modules. Every module has an “output” folder (with some subfolders for the different kinds of generated output) that is created the first time a build is done in the module. The name of this folder is “wntgcci.pro” (for the meaning of the "pro" extension see below). After a successful build of a module some of the generated files are copied to the output folder of the “solver” module by executing a tool called “deliver” (this is automatically called by build --all for each of the modules). Other modules will take these “delivered” files (header files, libraries etc.) to resolve their dependencies. The content of the solver module will also be used to pack the installation sets in the final step.

Template:Documentation/Tip


Partial Builds

There are two ways to do partial builds:

  • compatible
  • incompatible

Only do compatible partial builds if you know exactly what you are doing. Template:Documentation/Note

rebuilding from a module (incompatible build)

If you decide to change a module in an incompatible way, you will need to rebuild all modules depending on it (directly or indirectly):

cd $SRC_ROOT/instsetoo_native
build --from $INCOMPATIPLEMODULE --prepare
build --from $INCOMPATIBLEMODULE

rebuilding a module (compatible build)

To rebuild a module you can delete all output directories with, rebuild and redeliver into the solver with:

cd $MODULE
build --from $MODULE --prepare
build && deliver

A simple build in $SRC_ROOT/instsetoo_native will recreate the installation sets, provided all other modules have already been build. [8]


Building a Module with Debug Information

To rebuild a module with debug information and additional assertions and checks, run:

cd $MODULE
build --from $MODULE --prepare # removes old output trees and solver
build debug=true --from $MODULE

Drop the newly created binaries into an existing installation. Building an installation set with them will not help, as binaries are stripped on packing by default.

Template:Documentation/Tip

Finding the Installation Sets

After a successful build you will find the OOo installation set in

instsetoo_native/wntmscixx.pro/OpenOffice/msi/Install/en-US

“instsetoo_native” is the module that packs the installation set.

Template:Documentation/Tip

Tips And Tricks

ccache

For Windows: download from here, do the following:

export CCACHE_DIR="some/place/with/space"
ccache -M 2G -F 10000
export CCACHE_CPP2=TRUE
export CXX="guw.pl ccache cl"
# export USE_PCH=  if you experience trouble with precompiled headers

dependencies

nodep

If you set the environment variable nodep to TRUE, then dependendy information files are not created - the build finishes faster.

Documentation caution.png But only enable that on a clean build. Once you have built OOo and then made modifications, unset the variable again to be on the safe side.

NO_HIDS

Similar to the nodep variable, this one prevents the generation of HIDs (Help IDs) that are mainly used for automated testing - if you only want to build OOo, you don't need those.

parallel builds

If you have a multiprocessor machine or similar, you can run a parallel build. There are two levels of parallelism - one operating on makefile (directory) level, the other one on the global level. The two levels of parallelism result from the two-step build procedure in the OOo build environment. The build script runs through all the directories it reads from the build.lst files in all modules and calls dmake for every directory.

parallelism on the global level

For parallelism on the global level, you have to run build from $SRC_ROOT>/instsetoo_native with the -P<number> switch, for example:

build -P2

This takes build how many dmake processes it is allowd to start in parallel.

parallelism on the directory level

export MAXPROCESS=<numer or processes> 

This tells dmake how many targets it is allowed to build in parallel. When you don't use build.pl but build a single directory (single makefile), you can achieve the same with

dmake -P2

combining both levels

If you want to have parallelism on both levels, you can call

build -P2 -- -P2

"--" is a special build.pl parameter that passes every further parameters to the dmake processes it starts.

Recommendation

Experience tells that using the doubled number of cores in your machine is a good choice, using more threads does not make a big difference, except if the combined option is chosen. So even on single core machines using two threads will speed up the build considerably.

create prebuilt mozilla

For the mozilla-components you have the choice to either build from mozilla sources, to use precompiled packages or to use system-mozilla (the one installed on your buildsystem, not everything might work, depending on the version you got installed). You can easily create your own version of the prepacked binaries if you wish to do so (either because you cannot use the official ones because of mismatch of compiler version used to build them/other technical reasons or because you want to use stuff you didn't build yourself). To do so:

  • build the moz module from the mozilla sources
  • use --enable-build-mozilla when running configure and put the mozilla-source tarball to moz/download
  • in moz run dmake zip to create the zip files
  • you'll find the zips in {platform}.pro/zipped

Copy them to a location of your liking. Now instead of using --enable-build-mozilla, use --disable-build-mozilla and copy the zips you created or downloaded to moz/zipped and these will be used when compiling. This will greatly reduce build-time (you save the time that would otherwise be spent on compiling mozilla).

See Also

Template:Documentation/Note


  1. Template:Documentation/Note
  2. Template:Documentation/Note
  3. Template:Documentation/Note
  4. Template:Documentation/Note
    Documentation caution.png It used to be that newer version of NSIS broke the build (see Issue 85657 ), but it seems that it now works for NSIS up to 2.3.7.
  5. Template:Documentation/Note
    Documentation caution.png Current (as of 2008/01) versions of the DirectX9 SDK and Windows Platform SDK do not fit to each other. To be able to build with DirextX enabled, you need to patch one file in the Platform SDK. See http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID2743771 for details.
    Documentation caution.png Do not use a DirectX10 SDK!
  6. Template:Documentation/Note
  7. Template:Documentation/Note
  8. Documentation caution.png build --all would rebuild changed/missing files. However, it does not check for incompatible modules. If unsure, use build --from --prepare.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools