8.65. Ninja-1.12.1

Ninja is a small build system with a focus on speed.

Approximate build time: 0.2 SBU
Required disk space: 37 MB

8.65.1. Installation of Ninja

When run, ninja normally utilizes the greatest possible number of processes in parallel. By default this is the number of cores on the system, plus two. This may overheat the CPU, or make the system run out of memory. When ninja is invoked from the command line, passing the -jN parameter will limit the number of parallel processes. Some packages embed the execution of ninja, and do not pass the -j parameter on to it.

Using the optional procedure, in the prepare functoin below allows a user to limit the number of parallel processes via an environment variable, NINJAJOBS. For example, setting:

export NINJAJOBS=4

will limit ninja to four parallel processes.

Create the PKGBUILD for the Ninja package with the following commands:

mkdir /sources/ninja
cd /sources/ninja
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="ninja"
pkgver="1.12.1"
pkgrel="1"
pkgdesc="Ninja is a small build system with a focus on speed."
arch=('x86'
      'x86_64')
url="https://ninja-build.org/"
license=('Apachev2')
groups=('core')
depends=('gcc'
         'glibc'
         'rootfs')
makedepends=('binutils'
             'coreutils'
             'python')
checkdepends=('cmake')
optdepends=('asciidoc'
            'doxygen'
            'emacs'
            're2c')
source=('https://github.com/ninja-build/ninja/archive/v1.12.1/ninja-1.12.1.tar.gz')
md5sums=('6288992b05e593a391599692e2f7e490')
    
prepare(){
  cd "${pkgname}-${pkgver}"
  
  # Add NINJAJOBS environment variable to limit number of jobs
  sed -i '/int Guess/a \
  int   j = 0;\
  char* jobs = getenv( "NINJAJOBS" );\
  if ( jobs != NULL ) j = atoi( jobs );\
  if ( j > 0 ) return j;\
' src/ninja.cc
}

build(){
  cd ${pkgname}-${pkgver}
  python3 configure.py --bootstrap --verbose
}

check(){
  cd ${pkgname}-${pkgver}
  ./ninja ninja_test
  ./ninja_test --gtest_filter=-SubprocessTest.SetWithLots
}

package(){
  cd ${pkgname}-${pkgver}
  install -vm755 ninja ${pkgdir}/usr/bin/
  install -vDm644 misc/bash-completion ${pkgdir}/usr/share/bash-completion/completions/ninja
  install -vDm644 misc/zsh-completion  ${pkgdir}/usr/share/zsh/site-functions/_ninja
}
REALEOF

The meaning of the build option:

--bootstrap

This parameter forces Ninja to rebuild itself for the current system.

--verbose

This parameter makes configure.py show the progress building Ninja.

Prepare the build directory for the pacman user and build the package:

The package tests cannot run in the chroot environment. They require cmake. But the basic function of this package is already tested by rebuilding itself (with the --bootstrap option) anyway.

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps --nocheck'

Add the newly created package to the central package repository:

cp ninja-1.12.1-1-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/ninja-1.12.1-1-$(uname -m).pkg.tar.xz

Update the local cache and install the Ninja package:

pacman -Syu
pacman -S ninja --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/ninja
cp PKGBUILD /srv/pacman/source/LFS/ninja
cd /sources
rm -rf ninja

8.65.2. Contents of Ninja

Installed programs: ninja

Short Descriptions

ninja

is the Ninja build system