1.. _compiling:
2
3=========
4Compiling
5=========
6
7These instructions are based on Debian 8.0 because it has to be based on
8something. Other Linux distributions will be similar in the broad ideas but may
9differ in the specifics. If you already have a preferred distro, use that (we
10assume you know how to use its package management system). If you don't already
11have a preferred distro, maybe consider using Debian.
12
13First make sure you have a :ref:`copy of the source <getcyrus>`. You can either
14fetch the latest source from git, or download one of our release tarballs.
15
16Setting up dependencies
17=======================
18
19Required Build Dependencies
20---------------------------
21
22Building a basic Cyrus that can send and receive email: the minimum libraries
23required to build a functional cyrus-imapd.
24
25.. csv-table::
26    :header: "Package", "Debian", "RedHat", "Notes"
27
28    `autoconf`_, "autoconf", "autoconf"
29    `automake`_, "automake", "automake"
30    `bison`_, "bison", "bison"
31    `Cyrus SASL`_, "libsasl2-dev", "cyrus-sasl-devel"
32    `flex`_, flex, flex
33    `gcc`_, gcc, gcc
34    `gperf`_, gperf, gperf
35    `jansson`_, libjansson-dev, jansson-devel
36    `libbsd`_, libbsd-dev, libbsd-devel
37    `libtool`_, libtool, libtool
38    `ICU`_, libicu-dev, libicu-devel, "version 55 or newer"
39    `uuid`_, uuid-dev, libuuid-devel
40    `openssl`_ :ref:`(Note about versions) <openssl-versions>`, libssl-dev, openssl-devel
41    `pkgconfig`_, pkg-config, pkgconfig
42    `sqlite`_, libsqlite3-dev, sqlite-devel
43
44.. _autoconf: http://www.gnu.org/software/autoconf/
45.. _automake: http://www.gnu.org/software/automake/
46.. _bison: http://www.gnu.org/software/bison/
47.. _Cyrus SASL: :ref:`Cyrus SASL <cyrussasl:sasl-index>`
48.. _flex: http://flex.sourceforge.net/
49.. _gcc: http://gcc.gnu.org
50.. _gperf: http://www.gnu.org/software/gperf/
51.. _jansson: http://www.digip.org/jansson/
52.. _libbsd: https://libbsd.freedesktop.org/wiki/
53.. _libtool: http://www.gnu.org/software/libtool/
54.. _ICU: http://www.icu-project.org/
55.. _uuid: https://www.kernel.org/pub/linux/utils/util-linux/
56.. _openssl: http://www.openssl.org/
57.. _pkgconfig: http://pkgconfig.freedesktop.org
58.. _sqlite: https://www.sqlite.org/
59
60To install all dependencies from packages on Debian Jessie, use this:
61
62.. include:: /assets/cyrus-build-reqpkg.rst
63
64Build dependencies for additional functionality
65-----------------------------------------------
66
67The following dependencies enable additional functionality, help with
68code maintenance tasks or are required for building the documentation.
69
70Developers only
71###############
72
73The developer dependencies are required if you are building from git sources,
74have modified certain source files from the release tarball, or have configured
75with ``--enable-maintainer-mode`` in order to build a new package.
76
77If you are building normally from a pure release tarball, then you don't need
78these dependencies. The files, these dependencies produce, have been pre-built
79and included in the release, and do not normally need to be re-built.
80
81.. csv-table::
82    :header: "Package", "Debian", "RedHat", "Required", "Notes"
83    :widths: 20,15,15,5,45
84
85    `perl-devel`_, perl-dev, perl-devel, "no", "Needed for building binary perl
86    libraries, version 5+."
87    `perl(ExtUtils::MakeMaker)`_,,, "no", "Needed for building extensions to
88    Perl."
89    `perl(Pod::POM::View::Restructured)`_,,, "no", "Needed to generate man
90    pages. This has to be available to the system-wide perl interpreter, found
91    by ``which``."
92    `python(GitPython)`_,,, "no", "Needed for building the documentation."
93    `python(Sphinx)`_,,, "no", "Needed for building the documentation."
94    `transfig`_, transfig, transfig, "no", "Also known as fig2dev, transfig is
95    an artifact from the old days, and is only used for generation of a couple
96    of png files in the legacy documentation (doc/legacy/murder.png and
97    doc/legacy/netnews.png). One day it should be merged into the current
98    documentation, cause then we can get rid of it: `issues/1769`_."
99    `valgrind`_, valgrind, valgrind, "no", "Performance and memory testing."
100    `xxd`_,vim-common,vim-common, "no", "Needed for the _js.h files, for CalDAV
101    and CardDAV support."
102
103SASL Authentication
104###################
105
106.. csv-table::
107    :header: "Package", "Debian", "RedHat", "Required", "Notes"
108    :widths: 20,15,15,5,45
109
110    `Cyrus SASL Plain`_, libsasl2-modules, cyrus-sasl-plain, "yes/no", "Required
111    to pass Cyrus IMAP's PLAIN authentication unit tests."
112    `Cyrus SASL MD5`_, libsasl2-modules, cyrus-sasl-md5, "yes/no", "Required to
113    pass Cyrus IMAP's DIGEST-MD5 authentication unit tests."
114    `sasl binaries`_, sasl2-bin, sasl2-bin, "no", "Administration tools for
115    managing SASL."
116    `Kerberos`_, libsasl2-modules-gssapi-mit, krb5-devel, "yes/no", "Development
117    headers required to enable Kerberos v5 authentication capabilities, also
118    known as the authentication mechanism *GSSAPI*. Configure option:
119    ``--with-krbimpl=mit``."
120
121Alternate database formats
122##########################
123
124.. csv-table::
125    :header: "Package", "Debian", "RedHat", "Required", "Notes"
126    :widths: 20,15,15,5,45
127
128    `mysql`_ or `mariadb`_, "libmysqlclient-dev or libmariadb-dev", "mysql-devel
129    or mariadb-devel", "yes/no", "MariaDB or MySQL development headers, required
130    to allow Cyrus IMAP to use it as the backend for its databases. Configure
131    options: ``--with-mysql``, ``--with-mysql-incdir``,
132    ``--with-mysql-libdir``."
133    `postgresql`_, postgresql-dev, postgresql-devel, "yes/no", "PostgreSQL
134    development headers, required to allow Cyrus IMAP to use it as the backend
135    for its databases. Configure option: ``--with-pgsql``."
136
137CalDAV, CardDAV, or JMAP (httpd subsystem)
138##########################################
139
140.. csv-table::
141    :header: "Package", "Debian", "RedHat", "Required", "Notes"
142    :widths: 20,15,15,5,45
143
144    `libbrotli`_, libbrotli-dev, brotli-devel, "no", "It provides Brotli
145    compression support for http communications (otherwise only ``deflate`` and
146    ``gzip`` (optionally) would be available)."
147    `libchardet`_, libchardet-dev, libchardet-devel, "yes/no", "It is used
148    by the **JMAP** module of httpd to detect the character set of untagged
149    8-bit headers. Without it, cyrus-imapd will not do character-set detection.
150    If some piece of data has no character set coming in, it will have no
151    character set. Required for JMAP, but otherwise is not needed."
152    `libical`_, libical-dev, libical-devel, "yes", "It provides
153    calendaring functionality for CalDAV, which can't be used without this lib.
154    Version 3.0.0 or higher is required."
155    `libxml`_, libxml2-dev, libxml2-devel, "yes", "A fundamental lib for
156    all \*DAV functionality."
157    `nghttp2`_, libnghttp2-dev, libnghttp2-devel, "no", "HTTP/2 support
158    for the entire **httpd** subsystem (\*DAV & JMAP)."
159    `shapelib`_, shapelib, shapelib, "yes/no", "It is required for
160    **tzdist** service to have geolocation support. Otherwise it is not needed.
161    Version 1.3.0 or higher is required when using it."
162    `wslay`_, libwslay-dev, wslay-devel, "no", "It provides WebSockets support
163    in httpd. Only used with **JMAP**, otherwise not needed. Version 1.1.1 or
164    higher is required when using it."
165    `zlib`_, zlib1g-dev, zlib-devel, "no", "It provides gzip compression
166    support for http communications."
167
168Other
169#####
170
171.. csv-table::
172    :header: "Package", "Debian", "RedHat", "Required", "Notes"
173    :widths: 20,15,15,5,45
174
175    `CUnit`_, libcunit1-dev, cunit-devel, "no", "Development headers for
176    compiling Cyrus IMAP's unit tests. Required to run ``make check``."
177    SSL certificates, ssl-cert-dev, mod_ssl, "no", "Used if you're
178    installing SSL certificates."
179    `ClamAV`_, libclamav-dev, clamav-devel, "no", "It is used by
180    **cyr_virusscan**, otherwise not needed."
181    `CLD2`_, libcld2-dev, cld2-devel, "yes/no", "Compact Language Detector 2
182    (probabilistically detects over 80 languages in Unicode UTF-8 text, either
183    plain text or HTML/XML). Required for **Xapian** (``--enable-xapian``),
184    otherwise not needed."
185    `openldap`_, libldap2-dev, openldap-devel, "no", "Development headers
186    to enable **ptloader** to interface with LDAP directly, for canonification
187    of login usernames to mailbox names, and verification of login usernames,
188    ACL subjects and group membership. Configure option: ``--with-ldap``."
189    `pcre`_, libpcre3-dev, pcre-devel, "yes", "PCRE 1 (8.x) - for utf-8/unicode
190    regular expression matching. Could be replaced by something else in the
191    future. See `issues/1731`_ for more information."
192    `perl(Term::ReadLine)`_,,, "no", "Perl library needed by **cyradm**."
193    `libsrs2`_, *no package*, *no package*, "no", "It is used for
194    implementing Sender Rewriting Scheme (SRS) functionality for messages
195    forwarded by sieve scripts. Without it, messages forwarded by sieve scripts
196    will not have this functionality and might have difficulty delivering to
197    SMTP servers that insist on it."
198
199.. _ClamAV: https://www.clamav.net/
200.. _CUnit: http://cunit.sourceforge.net/
201.. _Cyrus SASL Plain: :ref:`Cyrus SASL <cyrussasl:sasl-index>`
202.. _Cyrus SASL MD5: :ref:`Cyrus SASL <cyrussasl:sasl-index>`
203.. _sasl binaries: :ref:`Cyrus SASL <cyrussasl:sasl-index>`
204.. _Kerberos: http://web.mit.edu/kerberos/www/
205.. _libbrotli: https://github.com/google/brotli
206.. _libchardet: https://github.com/Joungkyun/libchardet
207.. _libical: https://github.com/libical/libical/
208.. _libxml: http://xmlsoft.org/
209.. _mysql: http://www.mysql.com
210.. _mariadb: http://mariadb.org
211.. _nghttp2: https://nghttp2.org/
212.. _openldap: http://www.openldap.org/
213.. _pcre: http://www.pcre.org/
214.. _perl(Term::ReadLine): https://metacpan.org/pod/Term::ReadLine
215.. _perl(ExtUtils::MakeMaker): http://search.cpan.org/dist/ExtUtils-MakeMaker/
216.. _perl(Pod::POM::View::Restructured): https://metacpan.org/pod/Pod::POM::View::Restructured
217.. _perl-devel: http://www.perl.org/
218.. _postgresql: http://www.postgresql.org/
219.. _python(GitPython): https://github.com/gitpython-developers/GitPython
220.. _python(Sphinx): https://www.sphinx-doc.org/
221.. _shapelib: http://shapelib.maptools.org
222.. _libsrs2: https://www.libsrs2.org/
223.. _transfig: http://www.xfig.org/
224.. _valgrind: http://www.valgrind.org/
225.. _wslay: https://tatsuhiro-t.github.io/wslay/
226.. _zlib: http://zlib.net/
227.. _xxd: https://github.com/ConorOG/xxd/
228.. _CLD2: https://github.com/CLD2Owners/cld2
229.. _issues/1769: https://github.com/cyrusimap/cyrus-imapd/issues/1769
230.. _issues/1731: https://github.com/cyrusimap/cyrus-imapd/issues/1731#issuecomment-273064554
231
232
233Install tools for building
234    * ``sudo apt-get install build-essential``
235
236
237Optionally install dependencies for :ref:`building the docs <contribute-docs>`.
238    * ``sudo pip install python-sphinx``
239    * ``sudo cpan install Pod::POM::View::Restructured``
240
241
242Compile Cyrus
243=============
244
245There are additional :ref:`compile and installation steps<imapinstall-xapian>`
246if you are using Xapian for searching, or if you are :ref:`using jmap
247<developer-jmap>`.
248
249Default build: mail only
250------------------------
251
252.. parsed-literal::
253
254    $ :command:`autoreconf -i`
255    $ :command:`./configure` [options]
256
257Check the summary after ``./configure`` completes to ensure it
258matches your expectations.
259
260To view all options, and disable or enable specific features,
261please see:
262
263.. parsed-literal::
264
265    # :command:`./configure --help`
266
267.. tip::
268    Passing environment variables as an argument to configure, rather than
269    setting them in the environment before running configure, allows their
270    values to be logged in config.log.  This is useful for diagnosing problems.
271
272Optional dependencies
273---------------------
274
275Some features are disabled by default and must be explicitly enabled
276via configure.
277
278Sieve is enabled by default.
279
280CalDAV, CardDAV, WebDAV, JMAP
281#############################
282
283    ``./configure --enable-http --enable-calalarmd --enable-jmap``
284
285Murder
286######
287
288    ``./configure --enable-murder``
289
290Replication
291###########
292
293    ``./configure --enable-replication``
294
295Compile
296-------
297
298.. code-block:: bash
299
300    cd /path/to/cyrus-imapd
301
302    autoreconf -i -s   # generates a configure script, and its various dependencies
303
304    ./configure CFLAGS="-W -Wno-unused-parameter -g -O0 -Wall -Wextra -Werror -fPIC" \
305    --enable-coverage --enable-calalarmd --enable-autocreate \
306    --enable-nntp --enable-http --enable-unit-tests \
307    --enable-replication --with-openssl=yes --enable-murder \
308    --enable-idled --prefix=/usr/cyrus
309
310    make lex-fix   # you need this if compile fails with errors from sieve/sieve.c
311
312    make
313
314The ``--prefix`` option sets where Cyrus is installed to.
315
316It may be of use to also add ``--std=gnu99`` to the ``CFLAGS``. That generates
317TONS of warnings.
318
319Having problems with :ref:`compilation <compilationerrors>` or
320:ref:`linking <linker-warnings>`?
321
322If you're running on Debian, and you install to ``/usr/local``, you may need to
323update your library loader. Edit ``/etc/ld.so.conf.d/x86_64-linux-gnu.conf`` so
324it includes the following additional line::
325
326    /usr/local/lib/x86_64-linux-gnu
327
328Without this, when you attempt to start Cyrus, it reports ``error while loading
329shared libraries: libcyrus_imap.so.0: cannot open shared object file: No such
330file or directory`` because it can't find the Cyrus library in /usr/local/lib.
331
332Check
333-----
334
335.. code-block:: bash
336
337    make check    # this runs the cunit tests.
338
339This runs the cunit tests and is used for testing that the libraries support
340all the expected behaviour. If this fails, please :ref:`report it to the
341cyrus-dev mailing list <feedback-mailing-lists>` with details of your source
342version, operating system and affected libraries.
343
344
345Next: :ref:`installing Cyrus <installing>`.
346
347.. _FastMail : https://www.fastmail.com
348