Debian Packaging
Guide for Debian Packaging
This page is based on the debmake guide page.
I changed it very briefly.
Setups
There are some requirements
autotools-dev
build-essential
devscripts
debhelper
equivs
$ sudo apt-get install autotools-dev build-essential devscripts debhelper equivs
These are the minimum debian packages required for packaging operations,
and additional packages required can be found here.
Once you’ve installed all the tools you need,
set your name and email address.
Let’s setup dhese packages by adding the following lines to ~/.bashrc .
DEBEMAIL="your_email_address"
DEBFULLNAME="Firstname Lastname"
export DEBEMAIL DEBFULLNAME
Packaging manual
You just follow the structured file tree format.
Create the required directory/file and add the necessary parts.
Let’s create a Debian package with a simple example.
Simple example
I’m going to make a package that prints a hello message when put in the welcome command.
I will implement hello message in C language with automake .
You can name the package what you want. I chose deb-welcome .
Make debian package directory
$ mkdir -p deb-welcome/debian
$ cd deb-welcome
Make package requirements files
$ touch debian/changelog && \
touch debian/compat && \
touch debian/control && \
touch debian/copyright && \
touch debian/deb-welcome.install && \
touch debian/rules
Edit debian/control
$ vi debian/control
Source: deb-welcome
Secstion: misc
Prioriy: optional
Maintainer: Steve Jeong <steve@how2flow.net>
Build-Depends: debhelper (>= 10)
Package: deb-welcome
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: The Simple example Packages
debian/control contains the most vital information about the source package and about the binary packages it creates.
It is in key-value format, and see feilds each attribute value.
Edit debian/changelog
$ vi debian/changelog
deb-welcome (0.0.1) unstable; urgency=medium
* initial release.
-- Steve Jeong <steve@how2flow.net> Fri, 19 May 2023 14:13:25 +0900
debian/changelog is a release note.
If you improved/modified the package and there is no change in changelog, the package will not be built.
After the first version, you can update debian/changelog with dch -i .
Edit debian/copyright
$ vi debian/copyright
deb-welcome is Copyright (C) 2023 Steve Jeong
deb-template is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
licenses is in /usr/share/common-licenses/ .
I apply the GPL3 license .
The parent path should also indicate license use.
$ sudo cp /usr/share/common-licenses/GPL-3 ../LICENSE
Edit debian/compat
$ vi debian/compat
13
The compat file defines the debhelper compatibility level.
You may use compat level 9 in certain circumstances for compatibility with older systems.
However, using any level below 9 is not recommended and should be avoided for new packages.
In debian/control, debhelper version is >= 10, must be at least 10.
I’m going to use autoconf/automake, so I raise the value more.
Edit debian/rules
$ vi debian/rules
%:
dh $@ --with autoreconf
debian/rules is the packaging rule file.
$@ is one of shell macro. The details will not be covered here.
Then, the package file-tree is:
deb-welcome
|
`debian
|`changelog
| compat
| control
| copyright
| rules
|
`LICENSE
If you have created debian package configuration files, you should now create a file for the automake build.
Autoscan
$ autoscan
$ ls
autoscan.log configure.scan
$ mv configure.scan configure.ac
$ vi configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([debwelcome], [3.0], [steve@how2flow.net])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])
AC_SUBST([EXTRA_CFLAGS], "-Wall -Werror")
AM_INIT_AUTOMAKE([foreign])
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
# Checks for macros.
AC_CONFIG_MACRO_DIRS([m4])
# Checks for library functions.
AC_CONFIG_FILES([
Makefile
src/Makefile])
AC_OUTPUT
Make C source
$ vi Makefile.am
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS = src
$ mkdir -p src
$ vi src/main.c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello???\n");
return 0;
}
$ vi src/Makefile.am
bin_PROGRAMS = welcome
welcome_SOURCES = main.c
Make autoreconf script
$ vi autogen.sh
#!/bin/sh
autoreconf -ivf || exit 1
Then, the package file-tree is:
deb-welcome
|
`debian/
|`changelog
| compat
| control
| copyright
| rules
|
`src/
|`main.c
| Makefile.am
|
`autogen.sh
autoscan.log
configure.ac
LICENSE
All we have left is the package build and installation.
Let’s add a file and proceed with the build and installation.
Package Install
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
Package test
$ welcome
hello???
Output deb file
When you create a Debian file,
You can add commands before-during-after installing and before-during-after removing a package.
It exists in the form of a script or data field.
debian/”package_name”.install is data feild file.
Not only install, but also preinst , postinst , prerm , and postrm .
Let’s just add the install file.
Make ‘install’ script
$ mkdir -p etc/share/deb-welcome
$ vi etc/share/deb-welcome/welcome_docs
hello??? my name is steve
$ vi debian/deb-welcome.install
etc/share/deb-welcome/welcome_docs /usr/share/deb-welcome/
xxx.install copies the first field to the second field. wildcards are also available.
They exist in script form and operate before and after the command upon installation or removal of the package.
I will now create & install the deb package.
Create & install debian package file
$ sudo make uninstall
$ debuild -uc -us -i -b
$ sudo dpkg -i ../deb-welcome_0.0.1_amd64.deb
Check
$ welcome
hello???
$ cat /usr/share/deb-welcome/welcome_docs
hello??? my name is steve
Finally, debian package example code that is released and used package.
Build External Package Repository
If you need to download the package repository and build it locally,
The local environment must have all the Build-Depends packages installed in the debian/control file.
Use mk-build-deps which is part of devscripts .
Package Deployment
how to deploy debian package?
Normally, you have to upload it to Debian server,
You have to be a debian contributor first and the process is cumbersome.
So, many people are use PPA.
PPA is Personal Package Archive.
Launchpad is a representative platform for supporting PPA.
Leave a comment