15.2. Building your First Package

15.2.1. Meta-Packages or Fake Packages

Fake packages and meta-packages are similar, in that they are empty shells that only exist for the effects their meta-data have on the package handling stack.

The purpose of a fake package is to trick dpkg and apt into believing that some package is installed even though it’s only an empty shell. This allows satisfying dependencies on a package when the corresponding software was installed outside the scope of the packaging system. Such a method works, but it should still be avoided whenever possible, since there is no guarantee that the manually installed software behaves exactly like the corresponding package would and other packages depending on it would not work properly.

On the other hand, a meta-package exists mostly as a collection of dependencies, so that installing the meta-package will actually bring in a set of other packages in a single step.

Both these kinds of packages can be created by the equivs-control and equivs-build commands (in the equivs package). The equivs-control *file* command creates a Debian package header file that should be edited to contain the name of the expected package, its version number, the name of the maintainer, its dependencies, and its description. Other fields without a default value are optional and can be deleted. The Copyright, Changelog, Readme and Extra-Files fields are not standard fields in Debian packages; they only make sense within the scope of equivs-build, and they will not be kept in the headers of the generated package.

例 15.2. libxml-libxml-perl的头文件 虚拟安装包

  1. Section: perl
  2. Priority: optional
  3. Standards-Version: 3.9.6
  4.  
  5. Package: libxml-libxml-perl
  6. Version: 2.0116-1
  7. Maintainer: Raphael Hertzog <hertzog@debian.org>
  8. Depends: libxml2 (>= 2.7.4)
  9. Architecture: all
  10. Description: Fake package - module manually installed in site_perl
  11. This is a fake package to let the packaging system
  12. believe that this Debian package is installed.
  13. .
  14. In fact, the package is not installed since a newer version
  15. of the module has been manually compiled & installed in the
  16. site_perl directory.

The next step is to generate the Debian package with the equivs-build *file* command. Voilà: the package is created in the current directory and it can be handled like any other Debian package would.

15.2.2. Simple File Archive

The Falcot Corp administrators need to create a Debian package in order to ease deployment of a set of documents on a large number of machines. The administrator in charge of this task first reads the “New Maintainer’s Guide”, then starts working on their first package.

https://www.debian.org/doc/manuals/maint-guide/

The first step is creating a falcot-data-1.0 directory to contain the target source package. The package will logically, be named falcot-data and bear the 1.0 version number. The administrator then places the document files in a data subdirectory. Then they invoke the dh_make command (from the dh-make package) to add files required by the package generation process, which will all be stored in a debian subdirectory:

  1. $

The selected type of package (indep binary) indicates that this source package will generate a single binary package that can be shared across all architectures (Architecture: all). single binary acts as a counterpart, and leads to a single binary package that is dependent on the target architecture (Architecture: any). In this case, the former choice is more relevant since the package only contains documents and no binary programs, so it can be used similarly on computers of all architectures.

The multiple binary type corresponds to a source package leading to several binary packages. A particular case, library, is useful for shared libraries, since they need to follow strict packaging rules. In a similar fashion, kernel module or kernel patch should be restricted to packages containing kernel modules.

TIP Maintainer’s name and email address

Most of the programs involved in package maintenance will look for your name and email address in the DEBFULLNAME and DEBEMAIL or EMAIL environment variables. Defining them once and for all will avoid you having to type them multiple times. If your usual shell is bash, it is a simple matter of adding the following two lines in your ~/.bashrc file (you will obviously replace the values with more relevant ones!):

  1. export EMAIL="hertzog@debian.org"
  2. export DEBFULLNAME="Raphael Hertzog"

The dh_make command created a debian subdirectory with many files. Some are required, in particular rules, control, changelog and copyright. Files with the .ex extension are example files that can be used by modifying them (and removing the extension) when appropriate. When they are not needed, removing them is recommended. The compat file should be kept, since it is required for the correct functioning of the debhelper suite of programs (all beginning with the dh_ prefix) used at various stages of the package build process.

The copyright file must contain information about the authors of the documents included in the package, and the related license. In our case, these are internal documents and their use is restricted to within the Falcot Corp company. The default changelog file is generally appropriate; replacing the “Initial release” with a more verbose explanation and changing the distribution from unstable to internal is enough. The control file was also updated: the Section field has been changed to misc and the Homepage, Vcs-Git and Vcs-Browser fields were removed. The Depends fields was completed with iceweasel | www-browser so as to ensure the availability of a web browser able to display the documents in the package.

例 15.3. The control file

  1. Source: falcot-data
  2. Section: misc
  3. Priority: optional
  4. Maintainer: Raphael Hertzog <hertzog@debian.org>
  5. Build-Depends: debhelper (>= 9)
  6. Standards-Version: 3.9.5
  7.  
  8. Package: falcot-data
  9. Architecture: all
  10. Depends: iceweasel | www-browser, ${misc:Depends}
  11. Description: Internal Falcot Corp Documentation
  12. This package provides several documents describing the internal
  13. structure at Falcot Corp. This includes:
  14. - organization diagram
  15. - contacts for each department.
  16. .
  17. These documents MUST NOT leave the company.
  18. Their use is INTERNAL ONLY.

例 15.4. The changelog file

  1. falcot-data (1.0) internal; urgency=low
  2.  
  3. * Initial Release.
  4. * Let's start with few documents:
  5. - internal company structure;
  6. - contacts for each department.
  7.  
  8. -- Raphael Hertzog <hertzog@debian.org> Fri, 04 Sep 2015 12:09:39 -0400

例 15.5. The copyright file

  1. Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
  2. Upstream-Name: falcot-data
  3.  
  4. Files: *
  5. Copyright: 2004-2015 Falcot Corp
  6. License:
  7. All rights reserved.

BACK TO BASICS Makefile file

A Makefile file is a script used by the make program; it describes rules for how to build a set of files from each other in a tree of dependencies (for instance, a program can be built from a set of source files). The Makefile file describes these rules in the following format:

  1. target: source1 source2 ...
  2. command1
  3. command2

The interpretation of such a rule is as follows: if one of the source* files is more recent than the target file, then the target needs to be generated, using command1 and command2.

Note that the command lines must start with a tab character; also note that when a command line starts with a dash character (-), failure of the command does not interrupt the whole process.

The rules file usually contains a set of rules used to configure, build and install the software in a dedicated subdirectory (named after the generated binary package). The contents of this subdirectory is then archived within the Debian package as if it were the root of the filesystem. In our case, files will be installed in the debian/falcot-data/usr/share/falcot-data/ subdirectory, so that installing the generated package will deploy the files under /usr/share/falcot-data/. The rules file is used as a Makefile, with a few standard targets (including clean and binary, used respectively to clean the source directory and generate the binary package).

Although this file is the heart of the process, it increasingly contains only the bare minimum for running a standard set of commands provided by the debhelper tool. Such is the case for files generated by dh_make. To install our files, we simply configure the behavior of the dh_install command by creating the following debian/falcot-data.install file:

  1. data/* usr/share/falcot-data/

At this point, the package can be created. We will however add a lick of paint. Since the administrators want the documents to be easily accessed from the menus of graphical desktop environments, we add a falcot-data.desktop file and get it installed in /usr/share/applications by adding a second line to debian/falcot-data.install.

例 15.6. The falcot-data.desktop file

  1. [Desktop Entry]
  2. Name=Internal Falcot Corp Documentation
  3. Comment=Starts a browser to read the documentation
  4. Exec=x-www-browser /usr/share/falcot-data/index.html
  5. Terminal=false
  6. Type=Application
  7. Categories=Documentation;

The updated debian/falcot-data.install looks like this:

  1. data/* usr/share/falcot-data/
  2. falcot-data.desktop usr/share/applications/

Our source package is now ready. All that’s left to do is to generate the binary package, with the same method we used previously for rebuilding packages: we run the dpkg-buildpackage -us -uc command from within the falcot-data-1.0 directory.