Mon Oct 16 09:31:15 2017 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 the top of this file:

dir /mnt/hd/usr/ports/perso

You are now ready to proceed with your chroot.

Installation of your chroot

Depending on the branch you want to use, you can specify it when naming the script:

The stable branch

VERSION="stable" install-nutyx

The development branch

VERSION="development" 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 do a little:

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 be all 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 and as expected.

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

The produced binaries are compressed in xz format.

I want to keep my binaries onces installed.

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

Binaries synchronisation via rsync

This operation consist of 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 stable branch

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

The development branch

for i in base cli gui
do
  rsync -avz --delete-after rsync://downloads.nutyx.org/nutyx/`uname -m`/development/$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 to create the folder where you want to locate your new package. Let's call it mypackage (you need to adjust to your real one)

mkdir /usr/ports/perso/mypackage

We just need to create the recept of our package (you need to adjust to your real one):

# Depends on: python gtk3 librsvg
description="My first package with plenty of  dependancies"
packager="francis perrin"
url="http://www.my-first-package.org/"
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 main page of cards to understand the way cards create -r this works.

man cards

Conclusion

Following commands should be used:

cards level
cards base -r
cards create -r