Linux上でのビルド

    From The Document Foundation Wiki
    This page is a translated version of the page Development/BuildingOnLinux and the translation is 69% complete.

    始める前の注意

    「rootでビルドしないでください!」これは初心者に共通の問題であることが判明したので、注意してください。これはビルド環境を破壊し、その結果、(ccacheも含めて)すべてをクリーンアップしてやり直す必要があります。権限の昇格が必要な場合は、次に続く説明で「sudo」を明示的に使用しています。

    また、ビルド全般のヒントもお読みください。

    ビルドの依存関係パッケージのインストール

    一般的に、LibreOfficeのビルドはLinux上で行うのが簡単です。

    注意: Windows Subsystem for Linux はサポートしていません

    Note pin.svg

    Note:
    新しいブランチ(特に masterブランチ)では通常、ディストリビューションがパッケージングしたものより要件が追加されていること多くがあり、autogen.shでは、それを指摘してくれます。これらの要件はオプションで対応しており、--disable-foo--without-fooで指定をするか、バンドルされたライブラリを使用する--without-system-fooオプションで設定できます(これはデフォルトのはずです)。どちらでもない場合は、システムに開発用パッケージのインストールが必要になります。configureのメッセージをよく読み、apt-cache searchyum searchを使って検索をしてください。通常、パッケージの名前には、-dev-develが付いています。

    Debian / Ubuntu

    依存関係のパッケージをインストールします

    sudo apt-get install git build-essential zip ccache junit4 libkrb5-dev nasm graphviz python3 python3-dev qtbase5-dev libkf5coreaddons-dev libkf5i18n-dev libkf5config-dev libkf5windowsystem-dev libkf5kio-dev libqt5x11extras5-dev autoconf libcups2-dev libfontconfig1-dev gperf openjdk-17-jdk doxygen libxslt1-dev xsltproc libxml2-utils libxrandr-dev libx11-dev bison flex libgtk-3-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev ant ant-optional libnss3-dev libavahi-client-dev libxt-dev
    
    Note pin.svg

    Note:
    2023年9月22日から、gccとg++の最小バージョンは12になりました。sudo apt install gcc-12 g++-12を実行した後、sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 60 --slave /usr/bin/g++ g++ /usr/bin/g++-12を実行してください。

    You may need to first add a PPA (and then get version 13 instead) with sudo add-apt-repository ppa:ubuntu-toolchain-r/test


    openSUSE

    Tumbleweedには次のコマンドで依存関係のパッケージをインストールできます。

    sudo zypper in git autoconf automake bison make gcc gcc-c++ cups-devel fontconfig-devel gperf java-17-openjdk-devel libxslt-devel python3-devel krb5-devel libX11-devel libXext-devel libICE-devel libSM-devel libXt-devel libXrender-devel libXrandr-devel flex gtk3-devel gstreamer-devel gstreamer-plugins-base-devel ant junit nasm ccache binutils-gold mozilla-nss-devel
    

    Fedora/Red Hat

    sudo dnf builddep libreoffice

    Arch Linux

    これらのmake依存関係は、Arch Build Systemの公式PKGBUILDからコピーされています(必要ないものが含まれているため、いくつかの変更が加えています)。

    sudo pacman -S --needed 'base-devel' 'git' 'ccache' 'ant' 'apr' 'beanshell' 'bluez-libs' 'clucene' \
                            'coin-or-mp' 'cppunit' 'curl' 'dbus-glib' \
                            'desktop-file-utils' 'doxygen' 'flex' 'gcc-libs' \
                            'gdb' 'glm' 'gobject-introspection' 'gperf' 'gpgme' \
                            'graphite' 'gst-plugins-base-libs' 'gtk3' \
                            'harfbuzz-icu' 'hicolor-icon-theme' 'hunspell' \
                            'hyphen' 'icu' 'java-environment' 'junit' \
                            'lcms2' 'libabw' 'libatomic_ops' 'libcdr' 'libcmis' \
                            'libe-book' 'libepoxy' 'libepubgen' 'libetonyek' \
                            'libexttextcat' 'libfreehand' 'libgl' 'libjpeg' \
                            'liblangtag' 'libmspub' 'libmwaw' 'libmythes' \
                            'libnumbertext' 'libodfgen' 'liborcus' 'libpagemaker' \
                            'libqxp' 'libstaroffice' 'libtommath' 'libvisio' \
                            'libwpd' 'libwpg' 'libwps' 'libxinerama' 'libxrandr' \
                            'libxslt' 'libzmf' 'lpsolve' 'mariadb-libs' \
                            'mdds' 'nasm' 'neon' 'nspr' 'nss' 'pango' \
                            'plasma-framework5' 'poppler' 'postgresql-libs' \
                            'python' 'qt5-base' 'redland' 'sane' 'serf' 'sh' \
                            'shared-mime-info' 'ttf-liberation' 'unixodbc' \
                            'unzip' 'xmlsec' 'zip' 'gtk4' 'qt6-base' 'zxing-cpp' \
                            'abseil-cpp'

    ほとんどの場合、LibreOfficeは、Javaを使わずに動作するので、Javaを使う予定がないのであれば、このリストからant, beanshell, java-environment, junitを外してください。

    'gcc-libs-multilib'がインストールされている場合は、'gcc-libs'の依存関係を削除する必要があります。

    Slackware

    ./autogen.sh --without-java --disable-postgresql-sdbc --disable-gstreamer-1-0

    BSDs

    • DragonFlyBSD cd /usr/dports/editors/libreoffice && make patch
    • FreeBSD cd /usr/ports/editors/libreoffice && make patch
    • NetBSD cd /usr/pkgsrc/misc/libreoffice && make depends

    クローンとビルド

    次にリポジトリをcloneします。現在のところ、ビルドはUnicode文字を含むパスでは適切に動作しないこと、git cloneは接続速度とサーバトラフィックに基づいて時間がかかる可能性があることに注意してください。

    $ git clone https://gerrit.libreoffice.org/core libreoffice
    $ cd libreoffice


    この時点で、autogenに渡すことが可能なオプションを表示したいかもしれません:

    $ ./autogen.sh --help

    例えば、デバッグオプションを追加することを検討してください。これらのオプションを追加する場合には、フルビルドを行う必要があります。例: --enable-dbgutilを追加する。次のmakeコマンドを初めて実行すると膨大な時間がかかるので、ビルドの最終目的に応じて必要な設定を指定して時間を節約したいと思うのではないでしょうか。疑問がある場合は、#libreoffice-dev IRC://でアドバイスを求めるのが良いでしょう。

    You should have a suitable configuration for the build that you put inside autogen.input file. But, you can start with a minimum set of options and customize them later. A sample autogen.input for building LibreOffice on Linux can be as follows, to enable debug build, and also disable doxygen to save time. Since the make command can take a vast quantity of time to run for the first time, these options are helpful.

    --enable-dbgutil
    --without-doxygen

    Then you can prepare build files using:

    $ ./autogen.sh


    Now you are ready for building using make. Beware that full (all components, non-incremental) build may take up to 24 hours and takes up about 20 GB of drive space. You will also most likely need at least 8 GBs of RAM, otherwise the machine might fall into swap and appear to freeze up.

    It is a good idea to first run make, so you have a working build in case make check later fails.

    $ make
    $ make check

    ビルドしたものを実行

    前の手順で、ローカルにインストールされたファイルを適切に実行できます

    $ instdir/program/soffice --writer
    $ instdir/program/soffice --calc


    ビデオチュートリアル

    LibreOfficeの開発入門

    Please accept this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

    YouTube privacy policy

    ビデオでは開発環境のセットアップとビルドのプロセスを説明しています。ただし、ビデオで見た内容を書き留めるのではなく、セットアップの際はwikiドキュメントを使用してください。

    ヒント

    デバッガーでの実行

    デバッカーでの直接的なビルドを開始するために:

    $ make debugrun

    Then you can open Writer with the command:

       (gdb) run --writer
    

    Note that soffice.bin will be terminated the first time it is run directly (or via make debugrun), this is normal, you simply need to run it again to make use of it. Running soffice will deal with this for you.

    警告を有効にする

    Various versions of GCC are well-known to emit more/unhelpful/bogus warnings at higher optimization levels. Don't even try to combine --disable-debug --enable-werror build with GCC.

    パフォーマンス

    Building LibreOffice takes time, a lot of time. Exactly how much depends on how powerful your machine is. But there are tools you can use to speed-up things.

    ccache

    ccache is a tool that caches the results of C/C++ compilation to try to re-use them later. It will not speed-up your initial build (on the contrary it will slow it down a bit), but it can dramatically speed up later re-building. If you plan to change lots of header files in LibreOffice, it is a worthy tool to have.

    By default, ccache will be enabled automatically if it is found on your system. For best results, you may want to increase the cache size or enable cache compression; `man ccache` is your friend.

    Note that the default cache size is just 5GB which is far too small to be useful for a LibreOffice build; for a build without debug symbols, you should have at least 8GB cache, and for a build with debug symbols for everything probably 32GB is a useful starting point. You can set the size like this (note that this setting is stored inside the cache directory, if you change the location by setting $CCACHE_DIR you have to re-do it):

    ccache --max-size 32G
    

    ccache also supports compression, which is very likely a good idea to enable (does anybody have hard numbers?), especially if you are using a small or slow storage medium, like a SSD or laptop hard disk. You can enable compression by adding this to your .bashrc or equivalent:

    export CCACHE_COMPRESS=1
    

    Icecream / distcc

    If you are in an environment where you have access to multiple machines with spare CPU cycles, you can take a look at icecream or distcc tools for distributed build. Icecream is recommended and easier to setup.

    Support for Icecream is built into LibreOffice, it is enough to add --enable-icecream to ./autogen.sh, and the configure process will pre-set number of jobs to use, and will try to find the icecream gcc wrappers in /usr/lib/icecc/bin or in /opt/icecream/bin. Should you have them somewhere else, please use --with-gcc-home=/path/to/your/icecream/bin switch to override that.

    To make use of distcc, first install and start distccd on all the build machines and make sure all the compiler versions are compatible (this is important for C++ code). Now on the driving machine install and configure distcc to use the other build hosts. Then pass --with-parallelism=N to autogen.sh, where N is the total number of CPUs available in your cluster and run distcc-pump make CC=distcc CXX=distcc to start the distributed build.

    コンパイル済みヘッダー

    Passing --enable-pch to autogen.sh enables use of precompiled headers (PCH), which reduce build time at the expense of more disk space and more source files possibly rebuilt when a header changes. The option has several levels (system, base, normal, full), the higher level the higher possible gain but also disk space usage and chance for larger rebuilds on changes.

    --with-parallelism

    The build process can be told to run multiple tasks in parallel. The parallelism is controlled by the autogen.sh parameter --with-parallelism. If you have enough memory, I found that using --with-parallelism=n where n is your number of cores, or 2 for --with-parallelism if you have only 1 core, give me the fastest build time.

    --with-parallelism already defaults to the number of cores/CPUs on your system, unless you use --enable-icecream - then to 10.

    --with-system-libs

    既存のライブラリを使用してビルドすることで、ビルド速度が向上するかもしれません。しかし、そのためには依存関係を調整する必要があります。

    ビルド時間の目安

    最初のビルド、またはクリーンビルドにかかる時間は、最近のプロセッサーでは約「8/コア数」時間です。ccacheを利用すると、その後のビルド時間は毎回2分から10分の間で変動します(この時間は修正または追加されたファイルの数とその複雑さに依存します)。

    makeのメッセージを冗長にする

    Make will hide the exact command invocations. To see what make does exactly for a single run one can invoke it as

    $ make verbose=1

    Using verbose=1, in turn sets this option for the child make invocations, and also deals with externals. In the verbose mode, every single command used to build LibreOffice is shown, which can be used for troubleshooting build problems.

    複数の作業ディレクトリで作業する

    If you want to work on both the master branch, and the current release branch(es) at the same time, you can share git repos, and external source tarballs (note the savings can be significant, especially if you also use the quite huge l10n repo). Note that switching between different release branches within the same working dir is not recommended; even if there are no dependency problems, the amount of stuff you'd have to rebuild is practically equal to a clean rebuild. If you can afford the disk space, maintaining separate trees is the recommended way.

    There are two methods to share git repos across working directories: git clone --reference and git-new-workdir. A referenced clone can avoid re-downloading the repo, but the new workdir will still have its own .git/config, etc. This is supported by upstream git developers. git-new-workdir, however, is not supported and can cause problems if you try to check out the same branch in two working directories, etc.

    設定

    Prepare the first build on your disk just like explained above. For the second, and all other builds, do this to clone the initial core repo:

    $ git clone --reference /path/to/master --branch name-of-branch ssh://logerrit/core /dir/to/be/created

    You'll notice a much quicker clone operation. After that, setup the new work dir with these two extra configure (or autogen.sh) options:

    $ ./autogen.sh ... --with-referenced-git=/path/to/master --with-external-tar=/path/to/master/external/tarballs

    Again, cloning will be much faster. You have to use an absolute path for the --with-external-tar option. After that, you proceed with building just like for the single-workdir case.

    The --with-referenced-git option is only needed if you enabled some submodules (translations, dictionaries or help) or you're building the libreoffice-4-0 branch (or one that is even older). On newer branches submodules are disabled by default.

    If you want to cherry-pick between the working directories, you can setup your local copy of git to act like a remote, like this:

    $ cd /path/to/stable-workingcopy
    $ git remote add unstable /path/to/master/.git
    $ cd /path/to/master
    $ git remote add stable /path/to/stable-workingcopy/.git

    You then just cherry-pick commits like you would to a "true" remote on another server.

    リリースブランチのチェックアウト

    run autogen.sh on master with the specific parameters you need, then run make fetch to fetch the submodules that may be needed depending on the parameters you passed to autogen.sh

    then switch branch with

    $ ./g checkout -b libreoffice-4-0 origin/libreoffice-4-0

    rpmが見つかりません/antが見つかりません/gnome-vfs-2.0パッケージがありません

    --disable-epm This will fix "rpm not found", as autogen.sh expects to find either dpkg or rpm on the system.

    --without-java このオプションにより、"ant not found"が修正されます。

    As of the master towards LibreOffice 3.6, to build the UNO SDK you need to have Doxygen installed so that HTML documentation for the C++ UNO interface can be generated. One option is to install Doxygen from its website and make sure the doxygen executable is found on the PATH, or specify its exact location via --with-doxygen=pathname configure switch. Another option is to configure --without-doxygen, in which case the HTML documentation for the C++ UNO interface will be missing from the UNO SDK being built. A third option is to configure --disable-odk, in which case the UNO SDK is not built at all.

    Note: Installing 'libgnomevfs2-dev' package on Ubuntu manually will fix "No package 'gnome-vfs-2.0' found" on older release branches. It should not be needed anymore on master by now. Use synaptic package manager or run in terminal

    $ sudo apt-get install libgnomevfs2-dev

    DEBおよび/またはRPMパッケージの構築

    DEBやRPMパッケージをビルドしたい場合は、autogen.inputファイルに適切なオプションを加えて下さい:

    RPM

    --with-package-format=rpm
    --enable-epm

    DEB

    --with-package-format=deb
    --enable-epm

    The basic TDF distro configs can be found in the distro-configs module. For Linux, look at distro-configs/LibreOfficeLinux.conf.

    パッケージはどこにありますか?

    ./workdir/installation/ディレクトリ以下のファイルを探してください。それぞれのパッケージに応じたパッケージの種類(DEB、RPM、または両方)のサブフォルダーがあります。サブフォルダの中には、installと呼ばれる別のフォルダがあり、2つのサブフォルダが含まれています。ひとつのサブフォルダ(..._downloadフォルダー)には、すべてのパッケージをまとめて圧縮したアーカイブが含まれ、もうひとつのサブフォルダには、個々のパッケージが入ったDEBS/RPMSフォルダがあります。あとは自己責任でお願いします!

    改行コードとGitのautocrlfの扱い

    autogen.shが以下のような出力をした場合

    ./autogen.sh: line 1: $':\r': command not found
    ' '--srcdir=/home/user/libreoffice' '--enable-option-checking=fatal'
    configure: WARNING: you should use --build, --host, --target
    configure: WARNING: invalid host type: 
    ********************************************************************
    *
    *   Running LibreOffice build configuration.
    *
    ********************************************************************
    
    ' not recognized system type... Invalid configuration `
     failedre: error: /bin/bash ./config.sub 
    Error running configure at ./autogen.sh line 241.

    ... その場合は、おそらく改行コードが原因でしょう。これは、Gitのcore.autocrlf=trueを間違って設定した場合に起こることがあります。

    問題を修正するには以下のコマンドを実行してください(警告:コミットされていない変更は失われます!)

    git config --unset core.autocrlf
    git rm --cached -r .
    git reset --hard
    git clean -x -f
    ./autogen.sh

    Weblateにある.poファイルで翻訳されたユーザーインターフェースでビルドする

    LibreOfficeのユーザーインターフェースは、Weblateサーバーにホスティングされている、.poファイルを使って翻訳されています。翻訳は、各ブランチのリリースごとに言語パックとしてパッケージ化され更新されています。これは、言語パックがリリースの間に行われた翻訳を反映されていないことを意味してます。また、ナイトリービルド は、少しの言語にしかありません。翻訳者は、新しいリリースが公開される前に自分の仕事をテストすると恩恵が得られるかもしれません。また、アーリーアダプターは、公式リリースの前に翻訳のテストができるでしょう。

    まずは、ビルドの依存関係が解決できているか確認をして、ソースコードのクローンとビルドを始めてください。

    翻訳されたユーザーインターフェースでビルド

    1. # まず、Weblateから.poファイルをダウンロードする必要があります。Weblateにログインをして、.poファイルをダウンロードしてください。
    2. コマンド ./autogen.sh --with-lang="<langCode>"のように、言語パックオプションを付けてソースコードを再ビルドします。<langCode>は実際の言語コードに置き換えることを忘れないでください。autogen.inputファイルを使っている場合は、ダブルクォーテーションは使わないので以下のようになります。 --with-lang=de ja ar
    3. ダウンロードした.poファイルを展開して、コマンドを使ってソースツリーを関連しているディレクトリにコピーします(GNU/Linuxの場合) cp -R <langCode>/libo_ui/* libreoffice/translations/source/<langCode>/ そして、<langCode>(2回出現)を実際の言語コードに置き換えることを忘れないでください。
    4. このステップは厄介かもしれません。抽出された.poファイルの中には、'messages.po'という名前と違う名前の場合のものがあります。必要なのは、すべての.poファイルを.moファイルに変換することで
      1. messages.poという名前 **ではない** ファイルの場合は、make build-l10n-onlyを実行して変換できます。
      2. messages.poという名前のファイルの場合は、そのようなファイルすべてに手動でmsgfmt -o instdir/program/resource/<langCode>/LC_MESSAGES/<moFile> <dir>/messages.poを実行して、.moファイルに変換する必要があります。ここでは、3つの変更を行う必要があります。<langCode>を言語コードにして、<moFile>は下にある表の列の左側のデータに、<dir>は右側の列のデータにします。'<dir>/messages.po'の前には、現在の作業フォルダから宛先までの完全なパスを付けてください。

    手順4で述べたように、.poファイルの中には 'messages.po' という名前のものもあれば別の名前のものもあります。以下の表は、messages.poファイルである可能性があり、手順4の2を適用すべきディレクトリの一覧です。

    <mofile> <dir>
    acc.mo accessibility
    avmedia.mo avmedia
    basctl.mo basctl
    chart.mo chart2
    cnr.mo connectivity
    cui.mo cui
    dba.mo dbaccess
    dkt.mo desktop
    editeng.mo editeng
    filter filter
    for.mo formula
    fps.mo fpciker
    frm.mo forms
    fwk.mo framework
    pcr.mo extensions
    rpt.mo reportdesign
    sb.mo basic
    sc.mo sc
    sca.mo scaddins
    scc.mo sccomp
    sd.mo sd
    sfx.mo sfx2
    sm.mo starmath
    svl.mo svl
    svt.mo svtools
    svx.mo svx
    sw.mo sw
    uui.mo uui
    vcl.mo vcl
    wiz.mo wizards
    wpt.mo writerperfect
    xsc.mo xmlsecurity

    プロセスの最後の手順は、sudo make installを実行して、新しく追加された翻訳のインストールです。

    LibreOffice-masterをビルドして翻訳を確認したい場合は、.poファイルと.potファイルをマージするための "make translations "が必要になるかもしれません。

    翻訳されたヘルプファイルのビルド

    TDF Weblateではヘルプファイルも翻訳されているので、以下の手順で翻訳されたヘルプファイルをビルドできます。

    1. 翻訳された.poファイルをダウンロードする
    2. 言語コードを置き換えて、./autogen.sh --with-help --with-lang="<langCode>"を実行。HTMLファイルとしてヘルプをビルドしたい場合は、--with-help=HTMLも入れてください。autogen.inputファイルを使っている場合、ダブルクォーテーションは使わないので次のようになります。 --with-lang=de ja ar
    3. makeを実行します。
    4. cp -fR <langCode>/libo_help/* libreoffice/translations/source/<langCode>/helpcontent2/source/text/を実行しますが、二つの<langCode>を実際の言語コードに変更することを忘れないでください。そして、現在の作業フォルダーから、このフォルダーへ正しく移動するようにしてください。
    5. mv libreoffice/translations/source/<langCode>/helpcontent2/source/text/auxiliary.po libreoffice/translations/source/<langCode>/helpcontent2/source/を実行します。二つの<langCode>を実際の言語コードに変更し、現在の作業フォルダーから、このフォルダーへ正しく移動していることを確認してください。
    6. make build-l10n-onlyを実行します。
    7. sudo make installを実行します。

    (Kiyotakaさん、Jihuiさん、ありがとうございます)