Skip to content

Building

Max Kofler edited this page Sep 24, 2022 · 2 revisions

Building leaf

leaf uses cmake as its build system, which allows for flexible and portable builds.

The build process is divided into these steps:

  1. Ensuring dependencies (not needed for static build)

  2. Obtaining the source code

  3. Configuring the build

  4. Building

  5. Installing

Ensuring dependencies

leaf needs 2 dependencies:

  • libcurl

  • libarchive

They can be installed through the package manager of your system.

Note

If you intend to build leaf as a static binary, you can skip this step, these will get built during the leaf build.

Obtaining the source code

To obtain the source code, this simple command will help you:

git clone --recursive https://github.com/AcaciaLinux/leaf

Note the --recursive flag, it will tell git to clone submodules too, they are needed for leaf.

If you missed the --recursive flag, you can pull submodules afterwards using the following command while inside the leaf directory: git submodule update --recursive --init.

Configuring the build

To start the build process, create a directory called build and enter it using the following two commands:

mkdir -pv build
cd build

Starting the cmake process for a standard build, issue the following command:

cmake ..

The cmake build for leaf supports a couple of options:

  • LEAF_STATIC

  • BUILD_DOCS

  • BUILD_TESTS

They can be put into the middle of the cmake command:

cmake -D<your option>=<ON/OFF> ..

LEAF_STATIC

Using this option will lead the leaf binary to be statically linked to make it usable on systems with minimal runtime support: cmake -DLEAF_STATIC=ON ..

Note

You need to configure leaf for this type of build, refer to the Static build section for further information.**

BUILD_DOCS

Using this will create documentation for all the leaf classes and functions: cmake -DBUILD_DOCS=ON ..

BUILD_TESTS

This will lead the build system to building the leaf test suite: cmake -DBUILD_TESTS=ON ..

Note

This option should only be used in development environments, it will insert guards and checks into the leafcore library that will slow it down

You can run tests using the ctest . command when in the build directory.

Building

Normally this should only involve on command (while being in the build directory:

make            #To use only one thread for the build (slower)
make -j$(nproc) #To use all your threads for the build

Installing

Note

To install leaf, you have to have superuser access by either prefixing sudo or doas to the following command, or by logging in as the root user.

The following command will take care of that, always executed from the build directory:

make install

If you want to install leaf into a custom directory, the following command will do the trick:

make DESTDIR=/my/custom/leaf/directory install

Static build

To build leaf into a statically linked binary, you need to clone the libcurl and libarchive source code too. Use the following command when in the root of the leaf repository:

bash ./prepare_static.sh

This will clone the repositories and patch them to work wit leaf.

Note

Do not forget to use the LEAF_STATIC=ON option when running the cmake step!

Clone this wiki locally