Start developing LibreOffice! Download the source code, and build on Windows

Please don’t use these instructions in practice – they become obsolete over time. Instead, follow the wiki article for building on Windows.

(This post was originally written in Hungarian by Adam Kovacs for his blog. Thanks Adam!)

In our previous post in this series, we looked at building on Linux. But it’s also possible to download and compile the LibreOffice source code on Windows, so that’s what we’ll demonstrate here!


Step 1: Download and install Visual Studio Community version (free)

Get it from the Visual Studio website. Add these components during installation:

  • MSVC v142 – VS 2019 C++ x64/x86 build tools (v14.2x)
  • C++ core features
  • Windows 10 SDK (10.0.xxxxx.x)
  • Windows Universal C Runtime
  • C++ ATL for v142 build tools (x86 & x64)
  • .NET Framework 4.x.x SDK
  • C++ 2019 Redistributable MSMm (only required to build MSI installer)

Step 2: Download and install openJDK

Get these:


Step 3: Download and install Cygwin

Get it from here. Then, in a command prompt, access the Cygwin installer directory, for example:

cd c:\Users\username\Desktop\

And run the following command:

setup-x86_64.exe -P autoconf -P automake -P bison -P cabextract -P doxygen -P flex -P gcc-g++ ^
-P gettext-devel -P git -P gnupg -P gperf -P make -P mintty ^
-P nasm -P openssh -P openssl -P patch -P perl -P python -P python3 ^
-P pkg-config -P rsync -P unzip -P vim -P wget -P zip -P perl-Archive-Zip ^
-P perl-Font-TTF -P perl-IO-String

(This command installs different dependencies, including packages and programs, that are needed to compile LibreOffice.)

If you later want to install new programs or packages in Cygwin, you can also restart the installer. Then, when you can select the programs from the list, look for the appropriate name (eg nano, mc, wdiff) and in the drop-down list, change pending to full.


Step 4: Download JUnit and Ant

From now on, all commands are run in Cygwin.

mkdir -p /cygdrive/c/sources
cd /cygdrive/c/sources
wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.5-bin.tar.bz2
tar -xjvf apache-ant-1.9.5-bin.tar.bz2
wget http://downloads.sourceforge.net/project/junit/junit/4.10/junit-4.10.jar

(These commands will download JUnit and Ant to the c:\sources folder. The path of Ant will be, for example: c:\sources\apache-ant-1.9.5, which should be specified later in autogen.input.)


Step 5: Download Make

mkdir -p /opt/lo/bin
cd /opt/lo/bin
wget http://dev-www.libreoffice.org/bin/cygwin/make-4.2.1-msvc.exe
mv make-4.2.1-msvc.exe make
chmod a+x make

(This will allow you to start the actual compilation later.)


Step 6: Download the LibreOffice source code

Create a directory for LibreOffice somewhere (eg in your home directory), and then go into it:

mkdir ~/libreoffice
cd ~/libreoffice

This command downloads the source files to the current directory (the “.” character):

git clone git://gerrit.libreoffice.org/core .

If the current directory is not specified as a parameter, it will create a “core” directory and download the files.

Another example: this command creates a directory called “libreoffice” in the current directory, and downloads the source code into this newly created directory:

git clone git://gerrit.libreoffice.org/core libreoffice

In the event of a download error, try replacing git:// with https://.


Step 7: Edit autogen.input

In the LibreOffice folder, create a file named autogen.input with the following content (replace the paths with the actual ones):

--enable-64-bit
--enable-debug
--with-ant-home=/cygdrive/c/cygwin64/source/apache-ant-1.9.5
--with-jdk-home=/cygdrive/c/Program Files (x86)/ojdkbuild/java-1.8.0-openjdk-1.8.0.181-1 
--disable-odk
--with-visual-studio=2019

If you still need some settings in autogen.input, you can use the ./autogen.sh –help command to list all possible settings.


Step 8: Run autogen.sh

cd ~/libreoffice
./autogen.sh

Step 9: Run “make” (this starts the actual compilation)

/opt/lo/bin/make

If you would like to compile without unit tests (so if you don’t want to check that what you have changed in the source code will cause regressions), use the “build-nocheck” parameter:

/opt/lo/bin/make build-nocheck

Note: if you forget to add a specific option (such as –enable-debug) to autogen.input, and then add it and run “autogen.sh” and “make” again, it no longer updates the existing files, so the new settings do not apply. You must then run a “make clean” first, and then run “make” again:

/opt/lo/bin/make clean
/opt/lo/bin/make

(The latter can of course be run with the “build-nocheck” parameter.)


Step 10: Run the newly built version of LibreOffice

When compilation has finished, you can start it from the LibreOffice directory:

./instdir/program/soffice
./instdir/program/soffice --writer
./instdir/program/soffice --calc

At this point, a lot of information is written to the command line while running LibreOffice. We can turn them off like this:

SAL_LOG=-INFO instdir/program/soffice

Now only SAL_DEBUG type values will be written to the command line (if they are already placed in the code somewhere).

If you just want to convert a file (for example, to fix export errors), you can do so. The converted file is then created in the LibreOffice directory (it is therefore advisable not to place the files to be converted in the LibreOffice directory, to avoid confusing them with the files that have already been converted). For instance:

SAL_LOG=-INFO instdir/program/soffice --convert-to docx ../chart_borderline.docx

Additional information

When the compilation is finished, and we modify the contents of one of the source files, we will start the compilation again. But this will not compile the entire codebase from scratch (unless we run the “make clean” command), but it only compiles the files we modified, which is a significant time saving.

If we forget to include a setting in autogen.input, but the compilation has already been done, then it is not enough to add the setting and start the compilation again – we also need to run make clean before.

For example, if we compiled without –enable-debug, add –enable-debug to the autogen.input file, then run make clean, followed by make or make build-nocheck.

You can also compile specific modules of LibreOffice:

/opt/lo/bin/make sw

Or:

/opt/lo/bin/make build-nocheck sw

These are the names of the modules:

  • sw: Writer (formerly StarWriter)
  • sc: the spreadsheet (Calc)
  • sd: Impress and Draw
  • dbaccess: database manager (Base)
  • starmath: formula editor
  • oox: source code files for importing and exporting Office Open XML files (docx, xlsx, pptx, …)
  • chart2: source code files for managing charts

For more modules, see here.

Comments

  1. By Rosmaninho