My first Debian package: klayout

All Debian based Linux distributions (Debian, Ubuntu, Mint) use the same Debian packaging method for distributing and updating software released by the community. Although many open source software packages are already handled by this method, still enough interesting software is currently (still) out-of-scope. With an interest in using open source Electronic Design Automation (EDA) software tools in a professional environment, I’ll try to create my first Debian package.

What is a Debian package? It’s simple an archive, created by the unix command ar, and consists of three main files: debian-binary, control.tar.gz and data.tar.gz. A brief descriptions:

  • debian-binary: just a two bytes sized file containing the version number , a single ’2′ character, followed a typical C-style end-of-string character ‘�’.
  • control.tar.gz: contains a file control which describes what should be done to install or remove this package, and a checksum verification file md5sums using the  md5sum algorithm, and optionally pre- and post-installation of removal control files called preinst, postinst, prerm and postrm.
  • data.tar.gz: all executables, source and data files, templates etc. related to the package are stored in this file. The content of it should follow the Filesystem Hierarchy Standard (FHS) to comply to the rules of the Debian package method.

The software I want to package is the layout viewer (and editor!) klayout of a.o. GDSII data files. Especially the XOR function to test the difference between to two GDSII files makes it very interesting for comparing layouts and/or debugging the design flow.

The control files

The most important control file control contains information regarding the package’s name (of course), the CPU architecture for which it is built, the maintainers name and e-mail address, and last but certainly not least the dependency of required software libraries. Debian uses a nice relative specified install mechanism, see chapter 7 of the manual. The program klayout needs e.g. the Qt widget library, as also the accompanying XML parser, the (de-)compression library routines and the standard C++ library. The required versions of these packages are simple specified between parentheses in a relational description: as an example: libabc (>=x.y.z) means it requires a package containing library libabc of version x.y.z or later. For klayout the dependencies are written in the control file, in this human readable syntax, as follows:

Depends: libqtgui4 (>= 4:4.2.3), libqt4-xml (>= 4.6.2), zlib1g (>= 1:1.2.3), libc6 (>= 2.11.1)

The version number of the package follows the original package version number, 0.21.14 klayout,  however an minus separator is added followed by the version of this package itself, in total  0.21.14-1. Future patches of this release can than be numberer as 0.21.14-2, 0.21.14-3.   Furthermore, a brief description is needed in the control file, so the end-user knows what kind of program (s)he is trying to install. Three lines will suffice to decide ‘Yes, I want to use this!’ or ‘No way!’.

The data files

As mentioned before the data files should follow the FHS standard to guarantee a consistent directory layout of documentation, executables etc. even when combining several unrelated packages. The binary executable of klayout needs to be placed in the /usr/bin directory to allow all (non-root) users of the system to use the program. This binary executable can be build in the normal way, see here. After doing this symbol table needs to be removed using the following command:

strip ./usr/bin/klayout

By doing this the size of the executable shrinks from 23032 to 19574kByte, saving 15% storage space. Apart from starting klayout direct from the command line, one would also like to have an (sub)entry in one of the pull down menus. Therefore a brief description in the newly created file /usr/share/applications/klayout.desktop is needed. The name of the program, a small comment, references to the executable and icon’s name are added, as also a base and subclass categories are written in this file using the freedesktop standard:

[Desktop Entry]
Name=Klayout, viewer and editor of mask layouts.
GenericName=layout viewer
Comment=Klayout is a viewer (and editor) of mask layout in a.o. GDSII and CIF format.

Accompanying with the text of the pull down menu’s entry box a small picture can be placed. This one will be recognized by its name (without suffix) is placed in the /usr/share/pixmaps folder as klayout.png. The results look like this:

Nice, isn’t it?

As the software is released under the Gnu Public License (GPL) a copyright file is also required in the /usr/share/doc/klayout directory, alongside two change-logs: one of the source code itself and one of the Debian package. The first can be copied from the release notes on the website of klayout, the second one, has to be maintained in the future by the package maintainer, me. The directory layout before packing and compressing it, now looks like:


Packing and compressing

With all content present, we can start zipping the change-log files first, while using the best available compression method of gzip:

gzip --best usr/share/doc/klayout/changelog
gzip --best usr/share/doc/klayout/changelog.Debian

To guarantee correct transfer it makes sense to generate a md5sum checksum of each file. This can be done by the following one-liner, using the most complex Unix command find (so if you succeed in understanding it, you’re certainly not a novice anymore :-) )

find usr -type f -exec md5sum {} \; > md5sums

To avoid static paths in the tar-file make sure to add “./” at beginning of path name:

fakeroot tar -cvf data.tar ./usr
gzip data.tar

The command fakeroot is used to strip user ownership and rights from the file properties so it looks like full root access inside the tar file. In a similar way we can make the control.tar.gz file by typing:

fakeroot tar -cvf control.tar control md5sums postinst postrm
gzip control.tar

Finally, apply the ar command to add, in correct following order, the Debian version file first, control information as second and the data as third file:

fakeroot ar cr klayout_0.21.14-1_i386.deb debian-binary control.tar.gz data.tar.gz


To verify the packaging is done correctly, the program lintian is called:

lintian klayout_0.21.14-1_i386.deb

The result of this verification look like:

W: klayout: new-package-should-close-itp-bug
W: klayout: binary-without-manpage usr/bin/klayout
W: klayout: postinst-has-useless-call-to-update-menus
W: klayout: postrm-has-useless-call-to-update-menus

No real problems, only warnings left; all well understood. The files postinst and postrm were copied from an example tkdiff package, possibly these triggers are not required for all kind of desktop icons, as I assumed? Also the Intent-To-Package bug (ITP), will do no harm but reminds me of the need of finding an Debian promotor for this klayout package. And I should also spent some time on writing my first man page :-) )

The final result in 32-bit (i386) format is located here, the 64-bit (amd64) version here. The latest version is 0.22.1, here, also as 64-bit (amd64) version here

4 thoughts on “My first Debian package: klayout

  1. Thanks for this very informative tutorial on packaging software for Debian.
    The fact that you used an EDA tool not yet available through the normal channels (repositories) makes it even better!

Comments are closed.