Adding a new package

From GeeXboX wiki

Jump to: navigation, search

http://www.textoualreltade.com

Contents

What is a package

A package can be described as a component of the GeeXboX distribution. It can be represented by a library, a driver or even by software. It consists of a set of shell scripts that are used by the GeeXboX toolchain to build the program, eventually after being patched and add it to the generated ISO file. The GeeXboX toolchain supports packages dependencies meaning that you can define requirements before doing some actions to your package. Each new package has to be put in the packages/ directory of the sources.

Package definition files

Here is a short list of available package definition files that can be used with the GeeXboX toolchain :

- unpack : the list of actions to be done when unpacking the package archive. It generally consists of editing some configuration files. This file is optional.

- build : the list of actions to be done for building the package from sources. It usually consists of doing a ./configure && make with the good build arguments.

- install : the list of actions to be done when adding the built files to the ISO. It usually simply consists of copying the binary and configuration files to their right location in ISO.


Please note that each of these files have to be executable in order to be processed.

Each time one of these scripts is executed and ends up with success, a file is created in build.arch/.stamps/package/ That way, if this file exists and another script call for it, the actions won't be executed twice.

Each package script can also be executed manually for test purpose doing :

./scripts/{get|unpack|build|install} package

Another required file is the url file, which is a simple text file containing the HTTP/FTP locations of files to be downloaded to build the package.

A package can also contains the following directories :

- config : where the package configuration files are placed.

- init.d : all files from this dir will be automatically copied to /etc/init.d on ISO and will be automatically launched at boot. These files need to have the executable flag.

- patches : all files in this dir will be applied as patch on the sources at unpack time. Theses files need to be unified patches, generated diff -Naur.

If multiple files are present, be sure that they can apply one over another.

- src : this directory may contain C source code that will be compiled at build time.

Scripts dependencies

The different packages are linked together through scripts dependencies. Each package is generated according to the following order :

1. unpack

2. build

3. install

However, you may require that another package be unpacked before building the current one for example. Adding this line to your script :

$SCRIPTS/unpack package1

will force the toolchain to call the unpack script of the package1 package before executing the rest of the currently executed script.

Adding package to build process

In order for a new package to be included in the build process, you must add a line for it in scripts/gentree

Example of url file

The following lines are the content of the url file from the linux package :

http://ftp.ch.kernel.org/pub/linux/kernel/v2.6/linux-2.6.12.3.tar.bz2
ftp://ftp.alsa-project.org/pub/kernel-patches/alsa-git-2005-06-22.patch.gz

It determines URLs to be downloaded to get the package.

Example of unpack script

When this script is called the sources of the package are taken from the sources/ directory and unpacked in the build.arch/package/ directory.

All the optionnal patches present in the packages/package/patches/ directory also are applied.

The following lines are the content of the unpack file from the linux package :

#!/bin/sh
. config/options

This defines a shell script and includes the content of the config/options file.

Each package script has to start with these lines.

$SCRIPTS/install make
$SCRIPTS/install sed
$SCRIPTS/extract $1 "alsa-git*" $BUILD/$1*
$SCRIPTS/unpack lzma

This defines the package requirements. Before doing anything else, the GeeXboX toolchain will proceed with the instllation of the make and sed packages, extract the alsa-git archive into the linux build tree (where $1 always is the name of the current package) and then unpack the lzma package.

LINUX="`ls -d $BUILD/linux*`"
sed "s/CONFIG_BLK_DEV_RAM_SIZE=.*/CONFIG_BLK_DEV_RAM_SIZE=$RAMDISK_SIZE/" $PACKAGES/linux/config/linux.$TARGET_ARCH.conf > $LINUX/.config
cp $BUILD/lzma*/SRC/7zip/Compress/LZMA_C/LzmaDecode.[ch] $LINUX/lib/
sed -i "s%^int Lzma%static int Lzma%g" $LINUX/lib/LzmaDecode.[ch]

Here we edit some configuration files.

yes "" | make config ARCH=$TARGET_ARCH -C $LINUX
make prepare0 ARCH=$TARGET_ARCH -C $LINUX

And then finally prepare the sources from being built.

Example of build script

The following lines are the content of the build file from the linux package :

#!/bin/sh
. config/options

Inclusion of GeeXboX toolchain properties.

$SCRIPTS/build toolchain
$SCRIPTS/build module-init-tools

Ensure that the toolchain has been built, build it otherwise.

DEPMOD="`ls -d $ROOT/$BUILD/module-init-tool*/depmod`"
LINUX="`ls -d $ROOT/$BUILD/linux*`"
MODDIR="$LINUX/modules"
export CROSS_COMPILE=$TARGET_PREFIX
export ARCH=$TARGET_ARCH

Export all build options.

rm -rf $MODDIR
mkdir -p $MODDIR

Remove previously built modules if they exist.

case $TARGET_ARCH in
  i386)
    make bzImage -C "$LINUX"
    ;;
  ppc)
    unset LDFLAGS
    make vmlinux -C "$LINUX"
    ;;
esac
make modules -C "$LINUX"
make INSTALL_MOD_PATH=$MODDIR DEPMOD=$DEPMOD modules_install -C "$LINUX"

Finally build the linux kernel and its drivers as modules.

rm -f $MODDIR/lib/modules/*/build
rm -f $MODDIR/lib/modules/*/source

Remove useless directories to prevent them to be installed in ISO at install time.

Example of install script

The following lines are the content of the install file from the linux package :

#!/bin/sh
. config/options

Inclusion of GeeXboX toolchain properties.

case "$2" in
  image)
    test "$3" != installator && INSTALL="$INSTALL/boot"
    mkdir -p $INSTALL
    case $TARGET_ARCH in
      i386)
        cp $BUILD/$1*/arch/$TARGET_ARCH/boot/bzImage $INSTALL/vmlinuz
        ;;
      ppc)
        cp $BUILD/linux*/vmlinux $INSTALL/vmlinux
        $STRIP $INSTALL/vmlinux
        ;;
    esac
    ;;

Check for the architecture and copy the kernel to the right place in ISO.

  modules)
    cp -r $BUILD/linux*/modules/* $INSTALL
    mkdir -p $INSTALL/etc
    cp $PACKAGES/linux/config/modules $INSTALL/etc
    cp $PACKAGES/linux/config/tvcard $INSTALL/etc
    ;;
esac

Then copy all kernel drivers (modules) in ISO and put some of the runtime configuration files in /etc (of the ISO).

Note that $INSTALL always represents the installation path that will be compressed to generate the ISO.

Personal tools