Tue Aug 15 21:57:07 2017 UTC

Build in a chroot

Introduction

This article explain 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 the branch you want to use, you can specify it when calling the script:

The stable branch

VERSION="stable" install-nutyx

The development branch

VERSION="development" install-nutyx

Enter the chroot

install-nutyx -ec

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 personnal receipes is added. We do not specify any URL because we don't plan to use cards sync.

Folder/var/log/pkgbuild will contains compilations logs.

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

The folder /usr/ports/base define the base system when the command cards base -r. will be 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

Source code are stored in a common folder. I want to keep them.

The produced binaries are compressed in xz format.

I want to keep my binaries onces installed.

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

Binaries synchronisation via rsync

This operation consist of download all the binaries of the base, cli-extra, gui et gui-extra colletions. It can take from a few minutes to a few hours depending of the speed of your internet connection.

Lucky, 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 takes some times 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 will be 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 you to read the man page of cards to understand the way cards create -r is working.

man cards

Conclusion

Following commands should be used:

cards level
cards base -r
cards create -r