4. The Build System

4.1. Directory structure

Table 3.1. Build system directory structure

Directory Description
build/ Main directory, you find the following files are located here: Makefile, .config and CHANGES.
build/config Holds the /etc directory, which is always included and acts as a common base.
build/scripts The acutal scripts which compile, install and create DL.
build/scripts/build Links (empty files) which define the execution order of the scripts for the make build command.The name after the number (3 digits) is the exact same name as the script in the build/script directory. Each script is called with the parameter "build".
build/scripts/config Configuration files which are needed for build process. You find here for example the initial Kernel configuration file (config_kernel).
build/scripts/config Scripts which are used the generate the menu structure for the command: make menuconfig.
build/scripts/config/help Files which hold the help information for entries in make menuconfig.
build/scripts/install Links (empty files) which define the execution order of the scripts for the make install command.The name after the number (3 digits) is the exact same name as the script in the build/script directory. Each script is called with the parameter "install". This directory is also used, when you execute a make menuconfig, in this case the scripts are called with the parameter "config".
build/scripts/iso Links (empty files) which define the execution order of the scripts for the make iso command.The name after the number (3 digits) is the exact same name as the script in the build/script directory. Each script is called with the parameter "iso".
build/scripts/lxdialog Sources of the lxdialog program, will be automatically compiled when you use make menuconfig
build/scripts/scripts Scripts which are needed for final DL. You find here for example several start/stop scripts for deamons which are optional.
build/dist The finished DL.
build/doc All included documentation.
build/src The source files.
build/tmp Working directory. Here you find the unpacked sources and all other temporary stuff. In this location are also.
build/tmp/ETC These are the contents of the later etc.tar.bz2
build/tmp/ISO/bootimagetree Contents of the bootimage.
build/tmp/ISO/cdtree Contents of the CD.
build/tmp/ISO/initrdtree Contents of the inital ramdisk.
build/tmp/ISO/ramdisktree Contents of the ramdisk.

4.2. The build process

By invoking the command make build, the Makefile will execute the script build/scripts/build.sh with the parameter build.

The script will now look in the folder build/scripts/build for the first build script to call, ,this will be 001prepare. Now the build/tmp directory is checked, if the script was already successfully executed. The flag-file is called in this case .done_build_001_prepare. When this file doesn't exist, the script build/scripts/prepare is called with the parameter build, otherwise the build script will continue with the next file. After a sub-script was successfully executed ( return code 0 ), the flag file is created and the build script starts at the beginning.

This description counts for the make commands build, install and iso, you just have to replace the "build" parts with e.g. "install".

[Tip]

When you test your own scripts, you can easily force a recompilation by executing e.g. rm build/tmp/.done_build_123_foo

[Tip]

While playing around with your own scripts, just place a exit 1 after the command your currently testing or at the end of the script (within the case statement). With that trick you can make sure, that no other scripts are executed and your scripts stops at the right place.

4.3. Adding Programs

Adding Programs to Devil-Linux is much easier then you would expect. The only thing which takes a long time, is to compile the system.

[Note]

In order to be able to add functionality to Devil-Linux, you need to know how to write Bash scripts and need to understand how to compile and install programs from their source code.

Here is a sample script:

#!/bin/bash
# $Source: /cvsroot/devil-linux/build/docs/documentation/sample/ez-ipupdate,v $
# $Revision: 1.14.2.1 $
# $Date: 2003/11/15 15:29:40 $
# http://www.devil-linux.org

# get the directoryname of the script
MYDIR=${0%/*}

# source functions and config
source $MYDIR/settings
source $MYDIR/functions

MYNAME=EZ_IPUPDATE

case $1 in
        build )
                if [ "$CONFIG_EZ_IPUPDATE" = "y" ]; then
                        ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc/ez-ipupdate || exit 1
                        make $PMAKE all || exit 1
                        strip_debug
                fi
                ;;

        install )
                if [ "$CONFIG_EZ_IPUPDATE" = "y" ]; then
                        rm -rf $WORKDIR/tmp || exit 1
                        mkdir -p $WORKDIR/tmp/usr/bin || exit 1
                        make install DESTDIR=$WORKDIR/tmp || exit 1

                        copy_files $WORKDIR/tmp/usr $CDDIR/ || exit 1
                        mkdir -p $ETCDIR/etc/ez-ipupdate || exit 1
                        cp -dpR example*.conf $ETCDIR/etc/ez-ipupdate || exit 1
                        chmod 600 $ETCDIR/etc/ez-ipupdate/* || exit 1
                        rm -rf $WORKDIR/tmp || exit 1
                fi
                ;;

        * )
                echo "ERROR ($0)"
                echo "please add parameter so I know what to do"
                exit 1
                ;;
esac

Now you have to activate that script by creating the links:

touch build/scripts/build/270ez-ipupdate

touch build/scripts/install/270ez-ipupdate

[Caution]

The links below 100 are reserved for system preparation and libraries!

Don't forgett to execute make menuconfig and enable the program you just added.

4.4. Adding Libraries

Libraries are the same as any other script, except that you usually don't have the "install)" part and so also not the link within the build/install directory. Libraries must be installed within the "build)", otherwise they're not available for the other scripts.

4.5. Runlevel configuration

FIXME -> man insserv

4.6. Variables

The following variables are defined within the build environment.

This list is probably outdated, take a look at the file build/scripts/settings to get a closer look what's defined.

Table 3.2. Variables in build environment

variable description example
SCRIPTDIR location of the build scripts /data/build/scripts
DL_VERSION version number of Devil-Linux 0.6
WORKDIR location of temporary files and the unpacked sources /data/build/tmp
SRCDIR location of the packed sources /data/build/src
ISODIR location of the directories for the ISO creation /data/build/tmp/ISO
INITRD location of the Initial Ramdisk /data/build/tmp/ISO/initrdtree
RAMDISKDIR location of the ramdisk (main Devil-Linux system without packages) /data/build/tmp/ISO/ramdisktree
CDDIR location of the root CD folder, everything here you will find later on the CD /data/build/tmp/ISO/cdtree
ETCDIR directory which will be later the etc.tar.bz2 /data/build/tmp/ETC
CONFIGFILE general configuration file (for final system) /data/build/tmp/ETC/etc/sysconfig/config
DL_DIR root of the build system /data/build

4.7. Functions

FIXME