Differences in Revisions: Build

Removed DokuWiki NOTRANS keyword. reformatted wiki. reformatted wiki
~~NOTRANS~~
 
# Build
 
The build part of a NM file contains all necessary information, dependencies and build instructions. May there exist some packages which contains only parts or doesn't need anything of this section.
 
| Note! |
|---|
\\ Please respect all existing [packaging rules](/devel/pakfire/guidelines)!</WRAP>
| Please respect all existing [packaging rules](/devel/pakfire/guidelines)! |
 
||
| --- |
 
The buildsystem splits the build process into several stages. The following stages will always passed though:
 
* **prepare:**
##prepare
* The source tarballs will be decompressed
* The source tarballs will be decompressed
* Existing patches will be applied
* Existing patches will be applied
 
* **build**
##build
* The configure script will be executed ( if there is one present )
* The configure script will be executed ( if there is one present )
* Hardcoded rpath's from libtool will be removed
* Hardcoded rpath's from libtool will be removed
* The code will be compiled
* The code will be compiled
 
* **install**
##install
* All compiled binaries, libraries and other stuff will be installed
* All compiled binaries, libraries and other stuff will be installed
 
```bash
||
| --- |
```
build
requires
`audit-devel`
audit-devel
`expat-devel`
expat-devel
`libselinux-devel`
libselinux-devel
end
 
configure_options += \
`--sysconfdir=/etc \`
--sysconfdir=/etc \
`--localstatedir=/var \`
--localstatedir=/var \
`--libdir=/lib \`
--libdir=/lib \
`--libexecdir=/lib \`
--libexecdir=/lib \
`--enable-libaudit \`
--enable-libaudit \
`--enable-selinux=yes \`
--enable-selinux=yes \
`--with-systemdsystemunitdir=/lib/systemd/system/ \`
--with-systemdsystemunitdir=/lib/systemd/system/ \
`--with-dbus-user=dbus`
--with-dbus-user=dbus
 
install_cmds
`mkdir -pv %{BUILDROOT}/usr/lib`
mkdir -pv %{BUILDROOT}/usr/lib
`mv -v %{BUILDROOT}/lib/pkgconfig %{BUILDROOT}/usr/lib/`
mv -v %{BUILDROOT}/lib/pkgconfig %{BUILDROOT}/usr/lib/
 
`#change the arch-deps.h include directory to /usr/lib instead of /lib`
#change the arch-deps.h include directory to /usr/lib instead of /lib
`sed -e 's@-I${libdir}@-I${prefix}/lib@' -i %{BUILDROOT}/usr/lib/pkgconfig/dbus-1.pc`
sed -e 's@-I${libdir}@-I${prefix}/lib@' -i %{BUILDROOT}/usr/lib/pkgconfig/dbus-1.pc
 
`mkdir -pv %{BUILDROOT}/usr/lib/dbus-1.0/include`
mkdir -pv %{BUILDROOT}/usr/lib/dbus-1.0/include
mv -v %{BUILDROOT}/lib/dbus-1.0/include/* %{BUILDROOT}/usr/lib/dbus-1.0/include
`rm -rvf %{BUILDROOT}/lib/dbus-1.0`
rm -rvf %{BUILDROOT}/lib/dbus-1.0
 
`rm -vf %{BUILDROOT}/lib/libdbus-1.so`
rm -vf %{BUILDROOT}/lib/libdbus-1.so
`ln -svf ../../lib/libdbus-1.so.3 %{BUILDROOT}/usr/lib/libdbus-1.so`
ln -svf ../../lib/libdbus-1.so.3 %{BUILDROOT}/usr/lib/libdbus-1.so
end
end
```
 
## requires
 
Contains a list of development packages or tools that are needed to build the package.
 
<WRAP center round alert 80%***Warning!***
| Note! |
|---|
\\ You have to add your dependencies with a *+=* because some tools already has been added by default and they would be overwritten if you only use a simple *=*.</WRAP>
| You have to add your dependencies with a *+=* because some tools already has been added by default and they would be overwritten if you only use a simple *=*. |
 
On multiple requirements its recommended to create a "requires block" instead of a simple line, to keep the syntax as clear as possible.
 
```
requires
` autoconf`
autoconf
` automake`
automake
` bison`
bison
` ncurses-devel`
ncurses-devel
` readline-devel`
readline-devel
end
```
 
## DIR_APP
 
Sometimes a maintainer of a source package uses different names for the folder inside the source tarball and the filename of the tarball. The build system wouldn't be able to change into the correct directory so this variable needs to be overwritten to fix this issue.
 
For example the package libjpeg: The tarball is*jpegsrc.v8a.tar.gz* and the folder inside which contains the configure script and source files is*jpeg-8a* so we have to overwrite the DIR_APP with:
 
`DIR_APP = %{DIR_SRC}/jpeg-%{version}`
 
The variable %{DIR_SRC} points to the source folder inside the chroot environment. The variable %{version} contains the defined version of the package. The builder will decompress the tarball, change into the defined folder and run the configure script.
 
## CFLAGS / CXXFLAGS
 
With this flags you are able to set your own package specified CFLAGS and CXXFLAGS.
 
<WRAP center round alert 80%***Warning!***
| Note! |
|---|
\\ You have to add them with a **+=** to prevent from overwriting the default flags.</WRAP>
| You have to add them with a **+=** to prevent from overwriting the default flags. |
 
 
 
## PARALLELISMFLAGS
 
Overwrite and set this flag to zero if the package doesn't allow a parallelism build.
 
`PARALELLISMFLAGS = # No parallel build`
 
 
## CONFIGURE_OPTIONS
 
With this variable you can add your own*switches* to the configure script of the package.
 
```
`CONFIGURE_OPTIONS += \`
CONFIGURE_OPTIONS += \
--mandir=/usr/share/man
```
 
<WRAP center round info 80%***Note!***
| Note! |
|---|
\\ At default the switch, **- -prefix=/usr** is already set, so you don't need to use it.
| At default the switch, **- -prefix=/usr** is already set, so you don't need to use it. |
 
 
## prepare
 
It is the first stage of all. In this stage, the tarball with the package source will be decompressed and patches will be applied.
 
### Decompressing
 
The buildsystem automatically will decompress all defined source tarballs, so you don't have to add some commands to the NM for that. It also will determine and use the correct decompress command for the specified tarballs.
 
### Patching
 
If there are any patches inside the **/ipfire-3.x/pkgs/<packagename>/patches/** folder, the buildsystem automatically will apply them. Supported Patchfiles are:
 
```
**-Np0* Format | File has to be named *.patch0 or *.diff0
-Np0* Format | File has to be named *.patch0 or *.diff0
**-Np1* Format | Default format *.patch or *.diff
-Np1* Format | Default format *.patch or *.diff
```
 
If you have to apply the patches in a special order add something like the following example to the header section of your file.
 
```
# Manual list patches because they need to be applied in special order
patches = \
` Patchfile1.patch \`
Patchfile1.patch \
` Patchfile2.patch0 \`
Patchfile2.patch0 \
` Patchfile3.diff`
Patchfile3.diff
 
```
 
## prepare_cmds
 
If your package requires commands after decompressing and patching, you can determine them here.
Example for that are to change something by using*sed*, copy or remove files.
 
Example from the package bash:
 
```
prepare_cmds
` # Bash uses the RTLD_LAZY option when loading libraries. We want to use`
# Bash uses the RTLD_LAZY option when loading libraries. We want to use
` # RTLD_NOW (it is defined from <dlfcn.h>:`
# RTLD_NOW (it is defined from <dlfcn.h>:
` sed -e "s/filename, RTLD_LAZY/filename, RTLD_NOW/" \`
sed -e "s/filename, RTLD_LAZY/filename, RTLD_NOW/" \
` -i builtins/enable.def`
-i builtins/enable.def
 
` sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/%{thisapp}|" \`
sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/%{thisapp}|" \
` Makefile.in`
Makefile.in
end
```
 
## CONFIGURE_SCRIPT
 
Sometimes a package maintainer named his "configure" script like "Configure" or "configure-linux".
To prevent from build errors or overwrite the full build stage, it is possible to tell the build system to use an other "configure script" then the default*configure*.
 
## build
 
In this stage, the configure script will be executed and the package will get compiled and linked.
 
### configure
 
At default, the buildsystem will switch to to the package folder and run the configure script of the package.
 
### build_targets
 
This command is used if you have to add some commands directly to the make command.
 
Example from chrony:
 
```
build_targets += getdate all docs
```
 
### FIX LIBTOOL
 
If there are any hardcoded RUNPATH's instructions from libtool, they will be automatically removed.
 
### configure_cmds
 
If your package requires commands after executing the configure script, you can determine them here.
 
### Compiling
 
The source code will be compiled by using a hardened gcc and binutils. If needed by your package you can add additional instructions with*build_targets* or change the*PARALLELISMFLAGS*.
 
## build_cmds
 
Here you can execute your own commands after building if it's necessary for your package.
 
An example from the package util-linux-ng.
 
```
# Build nolodin
build_cmds
` gcc %{CFLAGS} -o nologin %{DIR_SOURCE}/nologin.c`
gcc %{CFLAGS} -o nologin %{DIR_SOURCE}/nologin.c
end
```
 
## test
 
This stage is not enabled at default, but if your package contains a testsuite it is recommended to check your compiled package.
 
To do that, you have to define the complete stage like that:
 
```
test
` make check`
make check
end
```
 
## install
 
In this stage, the package get's installed. If you want to add own install flags, you can to do that with*install_targets*.
In this stage, the package get's installed. If you want to add own install flags, you can to do that with *install_targets*.
 
* Services files for Systemd will be automatically installed if they are placed in **/ipfire-3.x/pkgs/<pkgname>/systemd/**
* tmpfiles for Systemd will be installed if they are placed as **/ipfire-3.x/pkgs/<pkgname>/*.tmpfiles**
* Pam files will be installed if they are placed in **/ipfire-3.x/pkgs/<pkgname>/pam.d/** or named *.pam in the main folder.
* Files for logrotate will be installed if they are placed in **/ipfire-3.x/pkgs/<pkgname>/logrotate/** or named *.logrotate in the main folder.
 
 
## install_targets
 
This command is needed if you have to add some flags to the install command itself like install directories or something like that.
 
| Note! |
|---|
\\ You have to add them with a **+=** to prevent from overwriting the default flag (install).</WRAP>
| You have to add them with a **+=** to prevent from overwriting the default flag (install). |
 
Example from dmraid:
 
```
make_install_targets += sbindir=%{BUILDROOT}/sbin
```
 
 
## install_cmds
 
In this section you can execute commands after installing your package, like creation of symlinks copy or delete unwanted files and folders.
 
You don't need to type any commands here to install:
 
* Systemd service files
* Tmpfiles for systemd
* pam files
* Files for logrotate
 
More information at*install* at this article.
 
Example from bash:
 
```
install_cmds
` mkdir -pv %{BUILDROOT}/{bin,etc/profile.d,root}`
mkdir -pv %{BUILDROOT}/{bin,etc/profile.d,root}
 
` # Bash startup files`
# Bash startup files
` cp -vf %{DIR_SOURCE}/dot_bash_logout %{BUILDROOT}/root/.bash_logout`
cp -vf %{DIR_SOURCE}/dot_bash_logout %{BUILDROOT}/root/.bash_logout
` cp -vf %{DIR_SOURCE}/dot_bash_profile %{BUILDROOT}/root/.bash_profile`
cp -vf %{DIR_SOURCE}/dot_bash_profile %{BUILDROOT}/root/.bash_profile
` cp -vf %{DIR_SOURCE}/dot_bashrc %{BUILDROOT}/root/.bashrc`
cp -vf %{DIR_SOURCE}/dot_bashrc %{BUILDROOT}/root/.bashrc
 
` # /etc/profile.d`
# /etc/profile.d
cp -vf %{DIR_SOURCE}/profile.d/* %{BUILDROOT}/etc/profile.d
 
` ln -svf bash %{BUILDROOT}/bin/sh`
ln -svf bash %{BUILDROOT}/bin/sh
end
```