PREREQUISITES
-------------

In order to build CFEngine you need the following tools and libraries installed:

* C compiler supporting C90 + selected C99 constructs:
    - _Bool type
    - anonymous aggregates "(MyType) { .foo = 1, .bar = 2 }"
    - declarations in "for" loop
    - named initializers
    - uintmax_t and corresponding printf/scanf formats
  The following compilers are known to work:
    - gcc >= 3.0
    - clang >= 2.6
* GNU make

* PAM library
* OpenSSL library
* PCRE2 library
* POSIX threads (pthreads) library, if not provided by the operating system
* Latest available LMDB (Lightning Memory-mapped DataBase), Tokyo Cabinet or QDBM

* MySQL client library (optional)
* PostgreSQL client library (optional)
* libacl library (optional)

In order to build CFEngine cloned from git, you will need the
following additional tools:

* GNU Automake >= 1.10.1
* GNU Autoconf >= 2.60
* GNU Libtool >= 1.5.24
* Yacc (note: GNU Bison 2.4.2 has troubles invoking m4)
* Lex

Latest stable versions of the tools and libraries are generally advised.

See INSTALL DEPENDENCIES below for example of deps for various systems.

OPERATING SYSTEMS
-----------------

CFEngine is regularly built and tested on the following operating systems:

* GNU/Linux (many distributions)
* Solaris
* Windows with MinGW

HARDWARE PLATFORMS
------------------

CFEngine is regularly built and tested on the following CPU architectures:

* x86-64
* SPARC
* ARM64

OTHER CONFIGURATIONS
--------------------

In case you have successfully compiled CFEngine on a different OS and/or using
different tools or versions of tools, please report it to help-cfengine@ mailing
list[1]. Please consider running a testsuite (see below), and posting results to
mailing list too.

[1] https://groups.google.com/forum/#!forum/help-cfengine

BUILD INSTRUCTIONS
------------------

From tarball:

$ ./configure [configure options]
$ make [-jN]

From git checkout:

$ ./autogen.sh [configure options]
$ make [-jN]

See the available configure options:

$ ./configure --help
or
$ ./autogen.sh --help

INSTALLATION INSTRUCTIONS
-------------------------

CFEngine might be installed in two configurations:

 * (default) Native CFEngine file layout. Everything is installed in
   /var/cfengine, laid out as a "secondary FHS root". This layout is designed to
   keep CFEngine running even if most of the system is broken (e.g. /usr is not
   mounted due to NFS breakage).

* FHS file layout, enabled by --enable-fhs. This layout follows FHS 2.3.

After the build process has completed (see BUILD INSTRUCTIONS above), type:

$ make install

RUNNING TESTSUITE
-----------------

Please refer to the instructions in tests/README file.

INSTALL DEPENDENCIES
--------------------

Here we have examples of command lines for various systems to install dependencies
needed to build. The version and date checked are noted in parenthesis. Please
submit PRs with updates to this information.

* RedHat/CentOS (rhel-9 2023-10-09)

On CentOS:
sudo yum install epel-release && sudo yum update

Or on RHEL, replacing the version number with yours:
sudo subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms && sudo yum update

sudo yum install -y gcc gdb make git libtool autoconf automake byacc flex openssl-devel pcre2-devel lmdb-devel pam-devel flex-devel libyaml-devel fakeroot libxml2-devel librsync-devel

For SELinux support you will need selinux-policy-devel package and specify `--with-selinux-policy` to `autogen.sh` or `configure`

* Debian (Debian 12 2023-10-09)

sudo apt-get install -y build-essential git libtool autoconf automake bison flex libssl-dev libpcre2-dev libbison-dev libacl1 libacl1-dev lmdb-utils liblmdb-dev libpam0g-dev libtool libyaml-dev libxml2-dev librsync-dev

* NetBSD (9.3 2024-03-01)

doas pkgin install automake  autoconf bison pcre2 m4 libtool lmdb gmake
LDFLAGS=-L/usr/pkg/lib CPPFLAGS=-I/usr/pkg/include ./autogen.sh --enable-debug --without-systemd-service --without-systemd-socket
gmake -j8
doas /usr/pkg/bin/gmake install

* OpenBSD (7.4 2025-10-17)

doas pkg_add git automake-1.17 autoconf-2.72p0 bison pcre2 m4 libtool lmdb gmake
MAKE=/usr/local/bin/gmake LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include AUTOMAKE_VERSION=1.17 AUTOCONF_VERSION=2.72 ./autogen.sh --enable-debug
gmake -j8
doas gmake install

* FreeBSD (12.1 2020-04-07)

See docs/BSD.md

* SUSE (Tumbleweed 2020-02-02)

sudo zypper install gdb gcc make lmdb autoconf automake libtool git python3 pcre2-devel libopenssl-devel pam-devel

* Alpine Linux (3.21.3 2025-02-25)

sudo apk add alpine-sdk lmdb-dev openssl-dev bison flex-dev acl-dev pcre2-dev autoconf automake libtool git python3 gdb librsync-dev
./autogen.sh --without-pam

Note that in order for process promises to work you must install the procps package for a "proper" ps command instead of busybox.

* Termux (2020-04-24)

pkg install build-essential git autoconf automake bison flex liblmdb openssl pcre2 libacl libyaml
./autogen.sh --without-pam

* OSX (2021-10-20)

brew install openssl lmdb autoconf automake libtool bison flex pcre2 m4 gcc make librsync
./autogen.sh --enable-debug
