Product SiteDocumentation Site

15.2. 构建您的第一个软件包

15.2.1. 元软件包或伪装软件包

伪装软件包和元包是相似的,相似点在于它们是空壳,它们只通过其软件包处理栈上的元数据来影响软件包。
假软件包的目的是欺骗 dpkgapt,让它们相信一些软件包已经安装,即使只是个空壳。这允许当对应的软件安装在打包系统的范围之外时满足对软件包的依赖。这样的方法有效,但仍应该尽可能地避免,因为不能保证手动安装的软件包完全像对应的软件包那样工作,并且依赖它的其它软件包会不能正常地工作。
另一方面,元包主要作为一组依赖而存在,从而安装元包将真正一步带进一组其它软件包。
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 伪装软件包的头文件

Section: perl
Priority: optional
Standards-Version: 4.6.2

Package: libxml-libxml-perl
Version: 2.0207-1
Maintainer: Raphael Hertzog <hertzog@debian.org>
Depends: libxml2 (>= 2.9.10)
Architecture: all
Description: Fake package - module manually installed in site_perl
 This is a fake package to let the packaging system
 believe that this Debian package is installed.
 .
 In fact, the package is not installed since a newer version
 of the module has been manually compiled & installed in the
 site_perl directory.
下一步是用 equivs-build file 命令生成 Debian 软件包。看:软件包创建在当前目录中,并且可以像任何其它 Debian 软件包那样处理它。
$ equivs-build file
dpkg-buildpackage: info: source package libxml-libxml-perl
dpkg-buildpackage: info: source version 2.0207-1
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Raphael Hertzog <hertzog@debian.org>
dpkg-buildpackage: info: host architecture amd64
 dpkg-source --before-build .
 debian/rules clean
dh clean
   dh_clean
 debian/rules binary
dh binary
   dh_update_autotools_config
   dh_autoreconf
   create-stamp debian/debhelper-build-stamp
   dh_prep
   dh_auto_install --destdir=debian/libxml-libxml-perl/
   dh_install
   dh_installdocs
   dh_installchangelogs
   dh_perl
   dh_link
   dh_strip_nondeterminism
   dh_compress
   dh_fixperms
   dh_missing
   dh_installdeb
   dh_gencontrol
   dh_md5sums
   dh_builddeb
dpkg-deb: building package 'libxml-libxml-perl' in '../libxml-libxml-perl_2.0207-1_all.deb'.
 dpkg-genbuildinfo --build=binary -O../libxml-libxml-perl_2.0207-1_amd64.buildinfo
 dpkg-genchanges --build=binary -O../libxml-libxml-perl_2.0207-1_amd64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
 dpkg-source --after-build .
dpkg-buildpackage: info: binary-only upload (no source included)

The package has been created.
Attention, the package has been created in the current directory,
not in ".." as indicated by the message above!

15.2.2. 简单文件档案

Falcot 公司的管理员需要创建 Debian 软件包,从而容易在大量机器上布设一组文档。负责这项任务的管理员首先阅读“New Maintainer's 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:
$ cd falcot-data-1.0
$ dh_make --native

Type of package: (single, indep, library, python)
[s/i/l/p]? i

Maintainer Name     : Raphael Hertzog
Email-Address       : hertzog@debian.org
Date                : Sun, 26 May 2024 21:48:41 +0100
Package Name        : falcot-data
Version             : 1.0
License             : gpl3
Package Type        : indep
Are the details correct? [Y/n/q]
Currently there is not top level Makefile. This may require additional tuning
Done. Please edit the files in the debian/ subdirectory now.

$
The selected type of package (indep) indicates that this source package will generate a single binary package that can be shared across all architectures (Architecture: all in debian/control). single 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.
library 的类型与产生几个二进制包的源码包对应。它对共享库有用,因为它们需要遵守严格的打包规则。
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 is not used nor created anymore. Instead of defining the debhelper compatibility level as a number in this file, it is now defined as a build-dependency on the debhelper-compat virtual package in the Build-Depends field in debian/control.
The copyright file must contain information about the authors of the documents included in the package, and the related copyright and license. In our case, these are internal documents and their use is restricted to within the Falcot Corp company. The default format used for this file is defined in the Format field.
The default changelog file is generally appropriate; replacing the “Initial release” with a more verbose explanation and changing the distribution from UNRELEASED or unstable to the target release name is enough.
The control file must also be updated: the Section field can be changed to misc and the Homepage, Vcs-Git and Vcs-Browser fields were removed. The Depends fields was completed with firefox-esr | www-browser so as to ensure the availability of a web browser able to display the documents in the package. If the package does not require to run any commands as root (see 工具fakeroot), the Rules-Requires-Root field can be left as is.

例 15.3. control 文件

Source: falcot-data
Section: misc
Priority: optional
Maintainer: Raphael Hertzog <hertzog@debian.org>
Build-Depends: debhelper-compat (= 13)
Standards-Version: 4.6.2
Rules-Requires-Root: no

Package: falcot-data
Architecture: all
Depends: firefox-esr | www-browser, ${misc:Depends}
Description: Internal Falcot Corp Documentation
 This package provides several documents describing the internal
 structure at Falcot Corp.  This includes:
  - organization diagram
  - contacts for each department.
 .
 These documents MUST NOT leave the company.
 Their use is INTERNAL ONLY.

例 15.4. changelog 文件

falcot-data (1.0) bookworm; urgency=low

  * Initial Release.
  * Let's start with few documents:
    - internal company structure;
    - contacts for each department.

 -- Raphael Hertzog <hertzog@debian.org>  Sun, 26 May 2024 21:48:41 +0100

例 15.5. copyright 文件

Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: falcot-data

Files: *
Copyright: 2004-2024 Falcot Corp
License:
 All rights reserved.
rules 文件通常包含一组用于在专用子目录(以生成的二级制软件包来命令)来配置、构建和安装软件的规则。然后这个子目录的内容在 Debian 软件包内存档,如同这个子目录是文件系统的根。在我们的情况下,文件将安装在 debian/falcot-data/usr/share/falcot-data/ 子目录中,从而安装生成的软件包将在 /usr/share/falcot-data/下部署文件。rules 文件用作 Makefile,带有一些标准的目标(包括 cleanbinary,分别用来清理源目录和生成的二进制软件包)。
尽管这个文件是整个过程的中心,它仍然只逐渐包含了运行 debhelper 工具提供的标准组命令的最低限。这是由 dh_make 生成文件的情况。为了安装我们的文件,我们通过创建后面的 debian/falcot-data.install 文件,来简单地配置 dh_install 命令的行为:
data/* usr/share/falcot-data/
这时可以创建软件包。然而,我们将加点涂料。由于管理员想要文档从图形化桌面环境的菜单中容易地访问,我们添加了 falcot-data.desktop 文件,并通过在 debian/falcot-data.install 中添加第二行,而将它安装在 /usr/share/applications 中。

例 15.6. falcot-data.desktop文件

[Desktop Entry]
Name=Internal Falcot Corp Documentation
Comment=Starts a browser to read the documentation
Exec=x-www-browser /usr/share/falcot-data/index.html
Terminal=false
Type=Application
Categories=Documentation;
已更新的 debian/falcot-data.install 看起来像这样:
data/* usr/share/falcot-data/
falcot-data.desktop usr/share/applications/
我们的源码包现在已经准备好了。所有剩下要做的,是通过我们之前用来重新构建软件包的相同方法来生成二进制软件包:我们从 falcot-data-1.0 目录内运行 dpkg-buildpackage -us -uc 命令。