Sat Sep 7 21:29:38 2019 UTC

Build in a chroot

Introduction

This article explains every step to compile packages in a chroot.

Adjust /etc/cards.conf

To be able to install the compiled packages from your chroot, you need to adjust your /etc/cards.conf file. You will add on to the top of this file:

dir /mnt/hd/usr/ports/perso

You are now ready to proceed with your chroot.

Installation of your chroot

VERSION="rolling" install-nutyx

Enter the chroot

install-nutyx -ec
From now on, everything you do, you do it in your isolated chroot.

Development tools installation

The default installation is already adapted so just install the development packages if not already installed:

get cards.devel

The Configurations files

/etc/cards.conf

cat >/etc/cards.conf << EOF
dir /usr/ports/perso
dir /usr/ports/gui
dir /usr/ports/cli
dir /usr/ports/base
logdir /var/log/pkgbuild
base /usr/ports/base
EOF

A folder containing my personal recipes is added. We do not specify any URL because we don't plan to use cards sync.

Folder /var/log/pkgbuild will contain compilation logs.

I don't need any specific NLS files, they can all be installed.

The folder /usr/ports/base defines the base system when the command cards base -r. is used.

/etc/pkgmk.conf

cat > /etc/pkgmk.conf << EOF
export CFLAGS="-O2 -pipe"
export CXXFLAGS="\${CFLAGS}"
case \${PKGMK_ARCH} in
    "x86_64"|"")
       export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
       ;;
    "i686")
       export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
       export CFLAGS="${CFLAGS} -m32"
       export CXXFLAGS="${CXXFLAGS} -m32"
       export LDFLAGS="${LDFLAGS} -m32"
       ;;
    *)
       echo "Unknown architecture selected! Exiting."
       exit 1
       ;;
esac
PKGMK_SOURCE_DIR="/tmp"
PKGMK_KEEP_SOURCES="yes"
PKGMK_WORK_DIR="/tmp/work"
PKGMK_IGNORE_REPO="no"
PKGMK_IGNORE_COLLECTION="no"
PKGMK_GROUPS=()
PKGMK_LOCALES=()
PKGMK_COMPRESS_PACKAGE="yes"
PKGMK_COMPRESSION_MODE="xz"
PKGMK_CLEAN="no"
PKGMK_IGNORE_RUNTIMEDEPS="no"
EOF

It's very important to check all the variables so that the duo pkgmk/cards works fine as expected.

Source codes are stored in a common folder. I want to keep them even after a successful compilation.

The produced binaries are compressed in xz format.

I want to keep my binaries once installed.

I wish to have the runtime dependencies automatically added into the binary.

Binaries synchronisation via rsync

This operation consists of a download of all the binaries of the base, cli and gui collection. It can take a while depending on the speed of your internet connection.

Luckily, this operation has to be done only once. Laughing Laughing Laughing.

We need to create the root folder first.

mkdir -p /usr/ports/perso

We can now synchronise all the binaries:

The rolling branch

for i in base cli gui
do
  rsync -avz --delete-after rsync://downloads.nutyx.org/nutyx/`uname -m`/rolling/$i/ \
  /usr/ports/$i/
done

This can take some time so go get a coffee or a pizza. Laughing, It can be long...

Compilation and installation of your package

You start by creating the folder where you want to locate your new package. Let's call it mypackage (you need to adjust this name to your package)

mkdir /usr/ports/perso/mypackage

We just need to create the build recipe of our package (you need to adjust this to your real recipe):

description="My first package with plenty of  dependancies"
url="http://www.my-first-package.org/"

packager="francis perrin"

makedepends=(python gtk3 librsvg)

name=mypackage
version=1.0.0
release=1
source=(${url}downloads/$name/$name-$version.tar.xz)
build() {
   cd $name-$version
   ./configure --prefix=/usr
   make
   make DESTDIR=$PKG install
}

We can now launch the process of compilation and installation.

cards create -r mypackage

I suggest that you read the man page of cards to understand the way cards create -r this works.

man cards

Conclusion

The following commands should be used:

cards level
cards base -r
cards create -r