目录
有一句古罗马谚语说得好:“一例胜千言!”
这里给出了从简单的 C 语言源代码创建简单的 Debian 软件包的例子,并假设上游使用了 Makefile 作为其构建系统。
我们假设上游源码压缩包(tarball)名称为 debhello-0.0.tar.gz。
这一类源代码设计可以用这样的方式安装成为非系统文件:
$ tar -xzmf debhello-0.0.tar.gz $ cd debhello-0.0 $ make $ make install
Debian packaging requires changing this “make install” process to install files to the target system image location instead of the normal location under /usr/local.
![]() |
注意 |
---|---|
Examples of creating a Debian package from other complicated build systems are described in 第 8 章 More Examples. |
从上游源码压缩包 debhello-0.0.tar.gz 构建单个非本土 Debian 软件包的大致流程可以总结如下:
The debmake command debianizes the upstream source tree by adding template files only in the debian directory.
debuild 命令基于已 debian 化的源码树构建二进制软件包。
软件包构建的大致流程.
$ tar -xzmf debhello-0.0.tar.gz $ cd debhello-0.0 $ debmake ... manual customization $ debuild ...
![]() |
提示 |
---|---|
The debuild command in this and following examples may be substituted by equivalent commands such as the pdebuild command. |
![]() |
提示 |
---|---|
If the upstream tarball in the .tar.xz format is available, use it instead of the one in the .tar.gz and .tar.bz2 formats. The xz compression format offers the better compression than the gzip and bzip2 compressions. |
文中的 debmake 命令是用于 Debian 打包的一个帮助脚本。
这些特性使得使用 debmake 进行 Debian 打包工作变得简单而现代化。
![]() |
注意 |
---|---|
debmake 命令并不是制作一个 Debian 软件包的唯一途径。许多软件包是打包者模仿其它已有的打包示例,仅仅使用文本编辑器而编写完成打包脚本的。 |
这里给出与 debuild 命令类似的一系列命令的一个汇总。
The dpkg-buildpackage command is the official command to build the Debian binary package. For normal binary build, it executes roughly:
“debsign”(对 *.dsc 和 *.changes 文件进行签名)
![]() |
注意 |
---|---|
如需了解详细内容,请见 dpkg-buildpackage(1)。 |
我们先要获取上游源代码。
下载 debhello-0.0.tar.gz.
$ wget http://www.example.org/download/debhello-0.0.tar.gz ... $ tar -xzmf debhello-0.0.tar.gz $ tree . ├── debhello-0.0 │ ├── LICENSE │ ├── Makefile │ └── src │ └── hello.c └── debhello-0.0.tar.gz 2 directories, 4 files
这里的 C 源代码 hello.c 非常的简单。
hello.c.
$ cat debhello-0.0/src/hello.c #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
这里,源码中的 Makefile 支持 GNU 编码标准 和 FHS(文件系统层级规范)。特别地:
Makefile.
$ cat debhello-0.0/Makefile prefix = /usr/local all: src/hello src/hello: src/hello.c @echo "CFLAGS=$(CFLAGS)" | \ fold -s -w 70 | \ sed -e 's/^/# /' $(CC) $(CPPFLAGS) $(CFLAGS) $(LDCFLAGS) -o $@ $^ install: src/hello install -D src/hello \ $(DESTDIR)$(prefix)/bin/hello clean: -rm -f src/hello distclean: clean uninstall: -rm -f $(DESTDIR)$(prefix)/bin/hello .PHONY: all install clean distclean uninstall
![]() |
注意 |
---|---|
The echo of the $(CFLAGS) variable is used to verify the proper setting of the build flag in the following example. |
![]() |
提示 |
---|---|
如果 debmake 命令调用时使用了 -T 选项,程序将为模板文件产生更加详细的注释内容。 |
debmake 命令的输出十分详细,如下所示,它可以展示程序的具体操作内容。
$ cd debhello-0.0 $ debmake I: set parameters I: sanity check of parameters I: pkg="debhello", ver="0.0", rev="1" I: *** start packaging in "debhello-0.0". *** I: provide debhello_0.0.orig.tar.gz for non-native Debian package I: pwd = "/path/to" I: $ ln -sf debhello-0.0.tar.gz debhello_0.0.orig.tar.gz I: pwd = "/path/to/debhello-0.0" I: parse binary package settings: I: binary package=debhello Type=bin / Arch=any M-A=foreign I: analyze the source tree I: build_type = make I: scan source for copyright+license text and file extensions I: 100 %, ext = c I: check_all_licenses I: .. I: check_all_licenses completed for 2 files. I: bunch_all_licenses I: format_all_licenses I: make debian/* template files I: single binary package I: debmake -x "1" ... I: creating => debian/control I: creating => debian/copyright I: substituting => /usr/share/debmake/extra0/rules I: creating => debian/rules I: substituting => /usr/share/debmake/extra0/changelog I: creating => debian/changelog I: substituting => /usr/share/debmake/extra1/watch I: creating => debian/watch I: substituting => /usr/share/debmake/extra1/compat I: creating => debian/compat I: substituting => /usr/share/debmake/extra1/README.Debian I: creating => debian/README.Debian I: substituting => /usr/share/debmake/extra1source/format I: creating => debian/source/format I: substituting => /usr/share/debmake/extra1source/local-options I: creating => debian/source/local-options I: substituting => /usr/share/debmake/extra1patches/series I: creating => debian/patches/series I: run "debmake -x2" to get more template files I: $ wrap-and-sort
The debmake command generates all these template files based on command line options. Since no options are specified, the debmake command chooses reasonable default values for you:
我们来检查一下自动产生的模板文件。
基本 debmake 命令运行后的源码树。.
$ cd .. $ tree . ├── debhello-0.0 │ ├── LICENSE │ ├── Makefile │ ├── debian │ │ ├── README.Debian │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── copyright │ │ ├── patches │ │ │ └── series │ │ ├── rules │ │ ├── source │ │ │ ├── format │ │ │ └── local-options │ │ └── watch │ └── src │ └── hello.c ├── debhello-0.0.tar.gz └── debhello_0.0.orig.tar.gz -> debhello-0.0.tar.gz 5 directories, 15 files
这里的 debian/rules 文件是应当由软件包维护者提供的构建脚本。此时该文件是由 debmake 命令产生的模板文件。
debian/rules(模板文件):.
$ cat debhello-0.0/debian/rules #!/usr/bin/make -f # You must remove unused comment lines for the released package. #export DH_VERBOSE = 1 #export DEB_BUILD_MAINT_OPTIONS = hardening=+all #export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic #export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed %: dh $@ #override_dh_auto_install: # dh_auto_install -- prefix=/usr #override_dh_install: # dh_install --list-missing -X.pyc -X.pyo
这便是使用 dh 命令时标准的 debian/rules 文件。(某些内容已被注释,可供后续修改使用。)
这里的 debian/control 文件提供了 Debian 软件包的主要元信息。此时该文件是由 debmake 命令产生的模板文件。
debian/control(模板文件):.
$ cat debhello-0.0/debian/control Source: debhello Section: unknown Priority: extra Maintainer: "Firstname Lastname" <email.address@example.org> Build-Depends: debhelper (>=11~) Standards-Version: 4.1.4 Homepage: <insert the upstream URL, if relevant> Package: debhello Architecture: any Multi-Arch: foreign Depends: ${misc:Depends}, ${shlibs:Depends} Description: auto-generated package by debmake This Debian binary package was auto-generated by the debmake(1) command provided by the debmake package.
![]() |
警告 |
---|---|
If you leave “Section: unknown” in the template debian/control file unchanged, the lintian error may cause the build to fail. |
因为这是个 ELF 二进制可执行文件软件包,debmake 命令设置了“Architecture: any”和“Multi-Arch: foreign”两项。同时,它将所需的 substvar 参数设置为“Depends: ${shlibs:Depends}, ${misc:Depends}”。这些内容将在 第 5 章 基本内容 部分进行解释。
![]() |
注意 |
---|---|
请注意这个 debian/control 按照“Debian政策手册”中 5.2 源码包控制文件——debian/control 的内容使用 RFC-822 风格进行编写。文件对空行和行首空格的使用有特别的要求。 |
这里的 debian/copyright 提供了 Debian 软件包版权数据的总结。此时该文件是由 debmake 命令产生的模板文件。
debian/copyright(模板文件):.
$ cat debhello-0.0/debian/copyright Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: debhello Source: <url://example.com> # # Please double check copyright with the licensecheck(1) command. Files: Makefile src/hello.c Copyright: __NO_COPYRIGHT_NOR_LICENSE__ License: __NO_COPYRIGHT_NOR_LICENSE__ #----------------------------------------------------------------------------... # Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following # license/copyright files. #----------------------------------------------------------------------------... # License file: LICENSE License: . All files in this archive are licensed under the MIT License as below. . Copyright 2015 Osamu Aoki <osamu@debian.org> . Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
作为维护者,要制作一个合适的 Debian 软件包当然需要对模板内容进行一些手工的调整。
为了将安装文件变成系统文件的一部分,Makefile 文件中 $(prefix) 默认的 /usr/local 的值需要被覆盖为 /usr。要做到这点,可以按照下面给出的方法,在 debian/rules 文件中添加名为 override_dh_auto_install 的目标,在其中设置“prefix=/usr”。
debian/rules(维护者版本):.
$ vim debhello-0.0/debian/rules ... hack, hack, hack, ... $ cat debhello-0.0/debian/rules #!/usr/bin/make -f export DH_VERBOSE = 1 export DEB_BUILD_MAINT_OPTIONS = hardening=+all export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed %: dh $@ override_dh_auto_install: dh_auto_install -- prefix=/usr
Exporting the DH_VERBOSE environment variable in the debian/rules file as above forces the debhelper tool to make a fine grained build report.
Exporting DEB_BUILD_MAINT_OPTION as above sets the hardening options as described in the “FEATURE AREAS/ENVIRONMENT” in dpkg-buildflags(1). [8]
Exporting DEB_CFLAGS_MAINT_APPEND as above forces the C compiler to emit all the warnings.
Exporting DEB_LDFLAGS_MAINT_APPEND as above forces the linker to link only when the library is actually needed. [9]
The dh_auto_install command for the Makefile based build system essentially runs “$(MAKE) install DESTDIR=debian/debhello”. The creation of this override_dh_auto_install target changes its behavior to “$(MAKE) install DESTDIR=debian/debhello prefix=/usr”.
Here are the maintainer versions of the debian/control and debian/copyright files.
debian/control(维护者版本):.
$ vim debhello-0.0/debian/control ... hack, hack, hack, ... $ cat debhello-0.0/debian/control Source: debhello Section: devel Priority: optional Maintainer: Osamu Aoki <osamu@debian.org> Build-Depends: debhelper (>=9) Standards-Version: 4.1.3 Homepage: http://anonscm.debian.org/cgit/collab-maint/debmake-doc.git/ Package: debhello Architecture: any Multi-Arch: foreign Depends: ${misc:Depends}, ${shlibs:Depends} Description: example package in the debmake-doc package This is an example package to demonstrate the Debian packaging using the debmake command. . The generated Debian package uses the dh command offered by the debhelper package and the dpkg source format `3.0 (quilt)'.
debian/copyright(维护者版本):.
$ vim debhello-0.0/debian/copyright ... hack, hack, hack, ... $ cat debhello-0.0/debian/copyright Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: debhello Source: http://anonscm.debian.org/cgit/collab-maint/debmake-doc.git/tree/base... Files: * Copyright: 2015 Osamu Aoki <osamu@debian.org> License: MIT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
在 debian/ 目录下还有一些其它的模板文件。它们也需要进行更新。
debian/. 下面的模板文件(0.0 版):.
$ tree debhello-0.0/debian debhello-0.0/debian ├── README.Debian ├── changelog ├── compat ├── control ├── copyright ├── patches │ └── series ├── rules ├── source │ ├── format │ └── local-options └── watch 2 directories, 10 files
![]() |
提示 |
---|---|
Configuration files used by the dh_* commands from the debhelper package usually treat # as the start of a comment line. |
你可以使用 debuild 或者等效的命令工具(参见 第 4.3 节 “什么是 debuild?”)在这个源码树内构建一个非本土 Debian 软件包。命令的输出通常十分详细,如下所示,它会对构建中执行的操作进行解释。
$ cd debhello-0.0 $ debuild dpkg-buildpackage -rfakeroot -us -uc -ui -i ... fakeroot debian/rules clean dh clean ... debian/rules build dh build dh_update_autotools_config dh_autoreconf dh_auto_configure dh_auto_build make -j4 "INSTALL=install --strip-program=true" make[1]: Entering directory '/path/to/debhello-0.0' # CFLAGS=-g -O2 # -fdebug-prefix-map=/build/debmake-doc-y0gsuU/debmake-doc-1.10=. # -fstack-protector-strong -Wformat -Werror=format-security ... fakeroot debian/rules binary dh binary ... Now running lintian debhello_0.0-1_amd64.changes ... ... W: debhello: binary-without-manpage usr/bin/hello Finished running lintian. ...
You can verify that CFLAGS is updated properly with -Wall and -pedantic by the DEB_CFLAGS_MAINT_APPEND variable.
The manpage should be added to the package as reported by the lintian package, as shown in later examples (see 第 8 章 More Examples). Let’s move on for now.
现在我们来看看成果如何。
debhello 0.0 版使用 debuild 命令产生的文件:.
$ cd .. $ tree -FL 1 . ├── debhello-0.0/ ├── debhello-0.0.tar.gz ├── debhello-dbgsym_0.0-1_amd64.ddeb ├── debhello_0.0-1.debian.tar.xz ├── debhello_0.0-1.dsc ├── debhello_0.0-1_amd64.build ├── debhello_0.0-1_amd64.buildinfo ├── debhello_0.0-1_amd64.changes ├── debhello_0.0-1_amd64.deb └── debhello_0.0.orig.tar.gz -> debhello-0.0.tar.gz 1 directory, 9 files
你可以看见生成的全部文件。
debhello_0.0-1.debian.tar.xz 包含了 Debian 对上游源代码的修改,具体如下所示。
压缩文件 debhello_0.0-1.debian.tar.xz 的内容:.
$ tar -tzf debhello-0.0.tar.gz debhello-0.0/ debhello-0.0/src/ debhello-0.0/src/hello.c debhello-0.0/LICENSE debhello-0.0/Makefile $ tar --xz -tf debhello_0.0-1.debian.tar.xz debian/ debian/README.Debian debian/changelog debian/compat debian/control debian/copyright debian/patches/ debian/patches/series debian/rules debian/source/ debian/source/format debian/watch
debhello_0.0-1_amd64.deb 包含了将要安装至系统中的文件,如下所示。
debhello_0.0-1_amd64.deb 二进制软件包的内容:.
$ dpkg -c debhello_0.0-1_amd64.deb drwxr-xr-x root/root ... ./ drwxr-xr-x root/root ... ./usr/ drwxr-xr-x root/root ... ./usr/bin/ -rwxr-xr-x root/root ... ./usr/bin/hello drwxr-xr-x root/root ... ./usr/share/ drwxr-xr-x root/root ... ./usr/share/doc/ drwxr-xr-x root/root ... ./usr/share/doc/debhello/ -rw-r--r-- root/root ... ./usr/share/doc/debhello/README.Debian -rw-r--r-- root/root ... ./usr/share/doc/debhello/changelog.Debian.gz -rw-r--r-- root/root ... ./usr/share/doc/debhello/copyright
自动产生的 debhello_0.0-1_amd64.deb 的依赖关系如下所示。
自动产生的 debhello_0.0-1_amd64.deb 的依赖关系:.
$ dpkg -f debhello_0.0-1_amd64.deb pre-depends depends recommends conflicts ... Depends: libc6 (>= 2.2.5)
![]() |
小心 |
---|---|
Many more details need to be addressed before uploading the package to the Debian archive. |
![]() |
注意 |
---|---|
如果跳过了对 debmake 命令自动生成的配置文件的手工调整步骤,所生成的二进制软件包可能缺少有用的软件包描述信息,某些政策的要求也无法满足。这个不正式的软件包对于 dpkg 命令来说可以正常处理,也许这样对你本地的部署来说已经足够好了。 |
上面的例子中,在创建合适的 Debian 软件包时没有修改上游的源代码。
作为维护者,另一个备选的方案是对上游源代码做改动,如修改上游的 Makefile 以将 $(prefix) 的值设定为 /usr。
打包操作基本上和上面的分步示例相同,除了在 第 4.6 节 “第三步:编辑模板文件” 中的两点:
Store the maintainer modifications to the upstream source as the corresponding patch files in the debian/patches/ directory and list their filenames in the debian/patches/series file as indicated in 第 5.8 节 “debian/patches/*”. There are several ways to generate patch files. A few examples are given in these sections:
此时维护者对 debian/rules 文件的修改如下所示,它不包含 override_dh_auto_install 目标:
debian/rules(备选的维护者版本):.
$ cd debhello-0.0 $ vim debian/rules ... hack, hack, hack, ... $ cat debian/rules #!/usr/bin/make -f export DH_VERBOSE = 1 export DEB_BUILD_MAINT_OPTIONS = hardening=+all export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed %: dh $@
This alternative approach to Debian packaging using a series of patch files may be less robust for future upstream changes but more flexible coping with the difficult upstream source. (See 第 7.13 节 “3.0 源代码格式”.)
![]() |
注意 |
---|---|
对当前这个特定的打包场景,前文的 第 4.6 节 “第三步:编辑模板文件” 中使用 debian/rules 文件的方式更好一些。但为了演示起见,此时我们先使用本节的方式继续操作。 |
![]() |
提示 |
---|---|
对更复杂的打包场景,可能需要同时应用 第 4.6 节 “第三步:编辑模板文件” 和 第 4.8 节 “第三步(备选):修改上游源代码” 中的方式。 |
这里我们使用 diff 命令创建一个 000-prefix-usr.patch 文件作为例子。
$ cp -a debhello-0.0 debhello-0.0.orig $ vim debhello-0.0/Makefile ... hack, hack, hack, ... $ diff -Nru debhello-0.0.orig debhello-0.0 >000-prefix-usr.patch $ cat 000-prefix-usr.patch diff -Nru debhello-0.0.orig/Makefile debhello-0.0/Makefile --- debhello-0.0.orig/Makefile 2018-07-29 11:14:27.078982110 +0000 +++ debhello-0.0/Makefile 2018-07-29 11:14:27.190985268 +0000 @@ -1,4 +1,4 @@ -prefix = /usr/local +prefix = /usr all: src/hello $ rm -rf debhello-0.0 $ mv -f debhello-0.0.orig debhello-0.0
请注意,上游的源码树应当恢复到原始状态,补丁文件此时的名字为 000-prefix-usr.patch。
这个 000-prefix-usr.patch 文件随后应当进行编辑以使其符合 DEP-3,并照如下方式移动至正确的位置。
$ cd debhello-0.0 $ echo '000-prefix-usr.patch' >debian/patches/series $ vim ../000-prefix-usr.patch ... hack, hack, hack, ... $ mv -f ../000-prefix-usr.patch debian/patches/000-prefix-usr.patch $ cat debian/patches/000-prefix-usr.patch From: Osamu Aoki <osamu@debian.org> Description: set prefix=/usr patch diff -Nru debhello-0.0.orig/Makefile debhello-0.0/Makefile --- debhello-0.0.orig/Makefile +++ debhello-0.0/Makefile @@ -1,4 +1,4 @@ -prefix = /usr/local +prefix = /usr all: src/hello
这里的例子使用 dquilt 命令(一个 quilt 程序的简单封装)创建 000-prefix-usr.patch。dquilt 命令的语法和功能与 quilt(1) 命令相同,唯一的区别在于补丁存储在 debian/patches/ 目录中。
$ cd debhello-0.0 $ dquilt new 000-prefix-usr.patch Patch debian/patches/000-prefix-usr.patch is now on top $ dquilt add Makefile File Makefile added to patch debian/patches/000-prefix-usr.patch ... hack, hack, hack, ... $ head -1 Makefile prefix = /usr $ dquilt refresh Refreshed patch debian/patches/000-prefix-usr.patch $ dquilt header -e --dep3 ... hack, hack, hack, ... Replaced header of patch 000-prefix-usr.patch $ tree -a . ├── .pc │ ├── .quilt_patches │ ├── .quilt_series │ ├── .version │ ├── 000-prefix-usr.patch │ │ ├── .timestamp │ │ └── Makefile │ └── applied-patches ├── LICENSE ├── Makefile ├── debian │ ├── README.Debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── patches │ │ ├── 000-prefix-usr.patch │ │ └── series │ ├── rules │ ├── source │ │ ├── format │ │ └── local-options │ └── watch └── src └── hello.c 6 directories, 20 files $ cat debian/patches/series 000-prefix-usr.patch $ cat debian/patches/000-prefix-usr.patch Description: set prefix=/usr patch Author: Osamu Aoki <osamu@debian.org> Index: debhello-0.0/Makefile =================================================================== --- debhello-0.0.orig/Makefile +++ debhello-0.0/Makefile @@ -1,4 +1,4 @@ -prefix = /usr/local +prefix = /usr all: src/hello
Here, Makefile in the upstream source tree doesn’t need to be restored to the original state. The dpkg-source command invoked by the Debian packaging procedure in 第 4.7 节 “第四步:使用 debuild 构建软件包”, understands the patch application state recorded by the dquilt program in the .pc/ directory. As long as all the changes are committed by the dquilt command, the Debian source package can be built from the modified source tree.
![]() |
注意 |
---|---|
If the .pc/ directory is missing, the dpkg-source command assumes that no patch was applied. That’s why the more primitive patch generation methods like in 第 4.8.1 节 “使用 diff -u 处理补丁” without generating the .pc/ directory require the upstream source tree to be restored. |
这里给出使用”dpkg-source --commit“命令生成 000-prefix-usr.patch 的例子:
我们先来编辑上游源代码。
$ cd debhello-0.0 $ vim Makefile ... hack, hack, hack, ... $ cat Makefile prefix = /usr all: src/hello src/hello: src/hello.c @echo "CFLAGS=$(CFLAGS)" | \ fold -s -w 70 | \ sed -e 's/^/# /' $(CC) $(CPPFLAGS) $(CFLAGS) $(LDCFLAGS) -o $@ $^ install: src/hello install -D src/hello \ $(DESTDIR)$(prefix)/bin/hello clean: -rm -f src/hello distclean: clean uninstall: -rm -f $(DESTDIR)$(prefix)/bin/hello .PHONY: all install clean distclean uninstall
我们来进行提交。
$ dpkg-source --commit . 000-prefix-usr.patch ... editor to edit the DEP-3 patch header ...
我们来看看效果如何。
$ cat debian/patches/series 000-prefix-usr.patch $ cat debian/patches/000-prefix-usr.patch Description: set prefix to /usr Author: "Firstname Lastname" <email.address@example.org> --- debhello-0.0.orig/Makefile +++ debhello-0.0/Makefile @@ -1,4 +1,4 @@ -prefix = /usr/local +prefix = /usr all: src/hello $ tree -a . ├── .pc │ ├── .quilt_patches │ ├── .quilt_series │ ├── .version │ ├── 000-prefix-usr.patch │ │ └── Makefile │ └── applied-patches ├── LICENSE ├── Makefile ├── debian │ ├── README.Debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── patches │ │ ├── 000-prefix-usr.patch │ │ └── series │ ├── rules │ ├── source │ │ ├── format │ │ ├── local-options │ │ └── local-patch-header │ └── watch └── src └── hello.c 6 directories, 20 files
这里,dpkg-source 命令完成了与 第 4.8.2 节 “使用 dquilt 处理补丁” 一节中使用 dquilt 命令完全相同的流程。
[8] This is a cliché to force a read-only relocation link for the hardening and to prevent the lintian warning “W: debhello: hardening-no-relro usr/bin/hello”. This is not really needed for this example but should be harmless. The lintian tool seems to produce a false positive warning for this case which has no linked library.
[9] This is a cliché to prevent overlinking for the complex library dependency case such as Gnome programs. This is not really needed for this simple example but should be harmless.