Build Service/Deb builds

From openSUSE

Contents

Debian Builds

This page will provide info on packaging for the debian based linux distributions supported by the openSUSE Build Service, namely:

  • Debian
    • Debian 4.0 (Etch)
    • Debian 5.0 (Lenny)
  • xUbuntu
    • xUbuntu 6.06
    • xUbuntu 7.04
    • xUbuntu 7.10
    • xUbuntu 8.04
    • xUbuntu 8.10

Debian packages are divided in 2 categories: binary and source. The binary packages have .deb extension and they contain the compiled version of the application you want to distribute. While, the source packages are not a single file (like source .rpm mechanism), but instead they are composed by three files:

  • The pristine tarball
  • A diff file
  • A .dsc file
the Build Service will not create a source repository for .deb-based distributions, but only the .deb will be created


Hence, it is important to keep in mind because a 'standard' Debian repository is composed by at least two directory:

(your repository root)
|
+-binary
+-source

while the Build Service will create directly the binary dir with the name of distribution (e.g. http://download.opensuse.org/repositories/home:/EmmeG/Debian_Etch/ correspond to binary dir and not to repository root... that it is http://download.opensuse.org/repositories/home:/EmmeG/ ).

Also, keep in mind that the 3 parts for creating a source package are not needed in order to create a .deb package, but instead are necessary when you create a source repository and allow for automatically compiling and packaging on user's machine via apt-get.

Build Service will not create source repository, so you simple don't need to know how they are constructed and used.

The build service also uses some magic, some extra information can be given in the .dsc file in the form of 'debtransform' tags. Those are documented in this mail: http://lists.opensuse.org/opensuse-buildservice/2007-03/msg00067.html and the source code can be found here: https://forgesvn1.novell.com/svn/opensuse/trunk/buildservice/src/build/debtransform By looking at it you can see that it accepts three tags:

  • DEBTRANSFORM-TAR
  • DEBTRANSFORM-FILES-TAR
  • DEBTRANSFORM-SERIES

These can be used to specify a .tar.gz file as source, that can be shared between RPM and debian based builds, and can also be used to reuse the RPM patches in the debian builds. You can use multiple tar.gz files for the DEBTRANSFORM-FILES-TAR like this:

Debtransform-Files-Tar: debian.tar.gz debian-control-xUbuntu_6.06.tar.gz

Required rpms on the host system to build .deb packages

The following packages are needed on openSUSE based distributions to build .deb packages locally with osc (osc build ....):

  • deb (for 'dpkg')
  • binutils (for 'ar')

Install them with:

# zypper install deb binutils

Minimum set of files required to create .deb

In order to create a .deb package successfully, you have to create at least these files:

  1. packageName.dsc
  2. debian.changelog
  3. debian.control
  4. debian.rules

And of course a tarball (tar.gz) that contains the package source code to compile.

packageName.dsc

A minimal template for this file is:

Format: 1.0
Source: packageName
Version: 5.6-3
Binary: packageName
Maintainer: FirstName LastName <email@hostname.org>
Architecture: any
Build-Depends: debhelper (>= 4.1.16), nameOfPackageNeededToBuildIt
Files: 
 d57283ebb8157ae919762c58419353c8 133282 packageName_5.6.orig.tar.gz
 2fecf324a32123b08cefc0f047bca5ee 63176 packageName_5.6-1.diff.tar.gz

In the above template are listed only the mandatory fields, but there are many optional fields. You can find all information about these fields at http://www.debian.org/doc/debian-policy/ch-controlfields.html

I explain here a summary for let you to understand what they means:

  1. Format : is the format version of the .deb package. Write 1.0
  2. Source : is the name of source package without .tar.gz
  3. Version : is composed by the version of the source and the revision of the package; in the template 5.6 is the version of the source code, while 3 (after '-') is the revision of the debian package. Everytime you change one of the files necessary to create a .deb you should increment it
  4. Binary : is the name of binary package as seen by the apt manager (e.g: for install it you specify apt-get install theNameYouWriteInBinaryField )
  5. Maintainer : is the name of source maintanier (not your name, or packager name)
  6. Architecture : the list of architecture you want to compile it
  7. Build-Depends : the library necessary for compile it. You Must specify 'debhelper (>= 4.1.16)' because it contains all helper script used by the system for compile
  8. Files: in theory you must specify the MD5SUM and dimension in byte of the .orig.tar.gz and .diff.tar.gz, but in practice just put some values, is not important if they are not correct... the important is that there are two lines with three field as showed in the template. (e.g. you can cat and paste the two lines in the template and substitute packageName with the name of the .deb you want to create and it's ok... Build Service will do the rest)

debian.changelog

The Debian mechanism for creating a .deb is to put inside the source tree a directory called 'debian' with a lot of files necessary to automate the compiling and packaging process.

You don't need to do it by yourself, the Build Service will create the directory for you and it will put all files called debian.fileName

This is valid for all .deb-based distributions!! Hence, also for Ubuntu repository you have to create a file called debian.changelog (and not ubuntu.changelog).

This is the minimal template:

packageName (5.6-3) stable; urgency=low

  * Initial Release

 -- YourName <youremail@hostname.de>  Mon, 25 Dec 2007 10:50:38 +0100

You could think that it's just a changelog... but the syntax is so constrained that a little error (a whitespace missing) that all process of creating package fails !! :-( So, pay attention to the syntax specificed at http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog

debian.control

This file are used to describe the package and the dependencies, this if a minimal template:

Source: packageName
Section: sectionName
Priority: optional
Maintainer: yourName <yourEmail@hostname.de>
Build-Depends: debhelper (>= 4.1.16), nameOfPackageNeededToBuildIt

Package: nameOfPackage
Architecture: any
Depends: ${shlibs:Depends}
Description: This first line is a brief description
 Then, here there is the long description of the package... 
 also here the syntax is very painful (look at the documentation of Debian Policy
 to avoid errors http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f- Description)

Here there are some informations redundant that you can copy from .dsc file: 'Build- Depends', 'Package' is the same of 'Binary', 'Architecture', 'Maintainer' typically is the same of last list of debian.changelog

debian.rules

This is a Makefile style files that contains all rule for extracting, compile, install and package the source. You can change want you want inside this file... but is more simple to change just some lines to compile it... the rest of the file can be left untouched.

#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatibility version to use.
export DH_COMPAT=4

CFLAGS = -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	./configure
	make all
	# --- end custom part for compiling

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	make clean || true
	# --- end custom part for cleaning up

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package
	# The DESTDIR Has To Be Exactly  /usr/src/packages/BUILD/debian/<nameOfPackage>
	make install DESTDIR=/usr/src/packages/BUILD/debian/ace
	# --- end custom part for installing

# Build architecture-independent files here.
binary-indep: build install
	# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

Configuring sources.list

After the creation of .deb packages, you want to add the repository in the sources.list in order to use apt-get to install your package.

In general, should be enough to add the repositories in the /etc/apt/sources.list file, for example:

deb http://download.opensuse.org/repositories/home:/robermann79:/codesounding/Ubuntu_8.10  ./

The problem is that apt-get does not handle HTTP redirections (302) for mirrors, and apt- get consider that as an error.

It is not a bug of apt-get... is a decision of apt developers; they consider a very unsafe choose to use 302 redirection for packages repository (why ?!?! they don't tell to us, they just said that it's unsafe)

But you can solve this problem in two ways:

  1. if you have a server, mirror the repository on your space and point users to that
  2. search on http://en.opensuse.org/Mirrors_Development_Build a server that mirror your repository and point users to that (hoping that the mirror is permanent)

The quick way is getting a mirror list from the repository itself:

  • Go with the browser to the mirror list:
http://download.opensuse.org/repositories/<project>://<package>/<repository>/Packages?mirrorlist

So, for example:

http://download.opensuse.org/repositories/home://robermann79://codesounding/Ubuntu_8.10/Pac kages?mirrorlist
  • pick one of mirrors listed, for example:
http://widehat.opensuse.org/repositories/home:/robermann79:/codesounding/Ubuntu_8.10/Packages

then remove the last "/Packages" path and add the URL to your /etc/apt/sources.list, as follows:

deb http://widehat.opensuse.org/repositories/home:/robermann79:/codesounding/Ubuntu_8.10 ./

Now apt-get commands work as expected.

Adding the apt-key to the system

For modern Debian GNU/Linux based distributions, you will also need to add the project's repository key to the list of keys accepted by apt.

Then you can add the downloaded key:

sudo apt-key add <downloaded-file>

Examples

You can see examples in my home project directory: https://build.opensuse.org/project/show?project=home%3AEmmeG


Common pitfalls

Note on packageName

RPM packages names do not have a strict syntax like the debian ones. So watch out before uploading your archives !

  • Package names (both source and binary, see Package, Section 5.6.7) must consist only of lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.). They must be at least two characters long and must start with an alphanumeric character.

More informations at http://www.debian.org/doc/debian-policy/ch-controlfields.html

Note on tar.bz2

Debian 4.0 and xUbuntu 8.04 and earlier allowed for package.tar.bz2 files to be used. These could be shared between deb and rpm builds. Debian 5.0 and xUbuntu 8.10 only allow for package.tar.gz files as per Debian policy. To share sources between rpm and deb builds for all platforms in OBS, it's recommended to use package.tar.gz files.

Note on "postinst" (post installation) scripts

If you need to run some script on post installation, you could:

  • upload a file named debian.postinst (see the prefix "debian"), as for debian.rules
  • put your package.postinst file (where "package" is your package name) inside the debian.tar.gz

See as example the package https://build.opensuse.org/package/show?package=openvas-server&project=security%3Aopenvas%3ASTABLE

Patch format

Debian 4.0 and xUbuntu < 8.x require the to be patched file and the new one to have the same name for -p0 patches (bnc#492297).

xUbuntu 6.06 additionally doesn't allow content after the @@..@@ line. E.g.
@@ -37,7 +37,7 @@ openvas-libraries.tmpl: openvas-librarie
will fail while
@@ -37,7 +37,7 @@
will work just fine. Simply removing the content after the second @@ should solve this.

Linking -dev packages to their main one

Ubuntu 6.06 doesn't understand "(= ${binary:Version})" in the .control file. There "(= ${Source-Version})" has to be used.