Table of Contents
有一句古羅馬諺語說得好:“Longum iter est per praecepta, breve et efficax per exempla”(“一例勝千言!”)。
這裡給出了從簡單的 C 語言原始碼建立簡單的 Debian 套件的例子,並假設上游使用了 Makefile 作為構建系統。
我們假設上游原始碼壓縮包(tarball)名稱為 debhello-0.0.tar.gz。
這一類原始碼設計可以用這樣的方式安裝成為非系統檔案:
$ tar -xzmf debhello-0.0.tar.gz $ cd debhello-0.0 $ make $ make install
Debian 的打包需要對“make install”流程進行改變,從而將檔案安裝至目標系統映象所在位置,而非通常使用的 /usr/local 下的位置。
![]() |
Note |
---|---|
在其它更加複雜的構建系統下構建 Debian 套件的例子可以在 Chapter 8, 更多範例 找到。 |
從上游原始碼壓縮包 debhello-0.0.tar.gz 構建單個非原生 Debian 套件的大致流程可以總結如下:
debmake 命令對上游原始碼樹進行 debian 化(debianize),具體來說,是建立一個 debian 目錄並僅向該目錄中新增各類模板檔案。
debuild 命令基於已 debian 化的原始碼樹構建二進位制套件。
套件構建的大致流程.
$ tar -xzmf debhello-0.0.tar.gz $ cd debhello-0.0 $ debmake ... manual customization $ debuild ...
![]() |
Tip |
---|---|
The debuild command in this and following examples may be substituted by equivalent commands such as the sbuild command. |
![]() |
Tip |
---|---|
如果上游原始碼壓縮包提供了 .tar.xz 格式文件,請使用這樣的壓縮包來替代 .tar.gz 或 .tar.bz2 格式。xz 壓縮與 gzip 或 bzip2 壓縮相比提供了更好的壓縮比。 |
文中的 debmake 命令是用於 Debian 打包的一個輔助腳本。
這些特性使得使用 debmake 進行 Debian 打包工作變得簡單而現代化。
In retrospective, I created debmake to simplify this documentation. I consider debmake to be more-or-less a demonstration session generator for tutorial purpose.
![]() |
Note |
---|---|
Many packages are packaged using only a text editor while imitating how other similar packages are packaged and consulting how the Debian policy requires us to do. This seems to me the most popular method for the real-life packaging activity. |
The debmake command isn’t the only helper script to make a Debian package. If you are interested alternative packaging helper tools, please see:
這裡給出與 debuild 命令類似的一系列命令的一個彙總。
dpkg-buildpackge 是構建 Debian 二進位制套件的正式命令。對於正常的二進位制構建,它大體上會執行以下操作:
“debsign”(對 *.dsc 和 *.changes 檔案進行簽名)
![]() |
Note |
---|---|
如需瞭解詳細內容,請見 dpkg-buildpackage(1)。 |
我們先要取得上游原始碼。
下載 debhello-0.0.tar.gz.
$ wget http://www.example.org/download/debhello-0.0.tar.gz ... $ tar -xzf 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
![]() |
Note |
---|---|
對 $(CFLAGS) 的 echo 命令用於在接下來的例子中驗證所設定的構建引數。 |
![]() |
Tip |
---|---|
如果 debmake 命令呼叫時使用了 -T 選項,程式將為模板檔案產生更加詳細的註釋內容。 |
debmake 命令的輸出十分詳細,如下所示,它可以展示程式的具體操作內容。
$ cd debhello-0.0 $ debmake I: set parameters I: ================================================================= I: package_dir = /usr/lib/python3/dist-packages I: base_path = /usr I: base_lib_path = /usr/lib/debmake I: base_share_path = /usr/share/debmake I: ================================================================= 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/changelog I: creating => debian/changelog I: substituting => /usr/share/debmake/extra0/rules I: creating => debian/rules I: substituting => /usr/share/debmake/extra1/README.Debian I: creating => debian/README.Debian I: substituting => /usr/share/debmake/extra1/watch I: creating => debian/watch I: substituting => /usr/share/debmake/extra1source/format I: creating => debian/source/format I: substituting => /usr/share/debmake/extra1tests/control I: creating => debian/source/control I: substituting => /usr/share/debmake/extra1upstream/metadata I: creating => debian/upstream/metadata I: substituting => /usr/share/debmake/extra1tests/control I: creating => debian/tests/control I: substituting => /usr/share/debmake/extra1patches/series I: creating => debian/patches/series I: substituting => /usr/share/debmake/extra1sourcex/local-options I: creating => debian/source/local-options I: substituting => /usr/share/debmake/extra1sourcex/options I: creating => debian/source/options I: substituting => /usr/share/debmake/extra1sourcex/patch-header I: creating => debian/source/patch-header I: run "debmake -x2" to get more template files I: $ wrap-and-sort
debmake 命令基於命令列選項產生所有這些模板檔案。如果沒有指定具體選項,debmake 命令將為您自動選擇合理的預設值:
我們來檢查一下自動產生的模板檔案。
基本 debmake 命令執行後的原始碼樹。.
$ cd .. $ tree . ├── debhello-0.0 │ ├── LICENSE │ ├── Makefile │ ├── debian │ │ ├── README.Debian │ │ ├── changelog │ │ ├── control │ │ ├── copyright │ │ ├── patches │ │ │ └── series │ │ ├── rules │ │ ├── source │ │ │ ├── control │ │ │ ├── format │ │ │ ├── local-options │ │ │ ├── options │ │ │ └── patch-header │ │ ├── tests │ │ │ └── control │ │ ├── upstream │ │ │ └── metadata │ │ └── watch │ └── src │ └── hello.c ├── debhello-0.0.tar.gz └── debhello_0.0.orig.tar.gz -> debhello-0.0.tar.gz 7 directories, 19 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: optional Maintainer: "Firstname Lastname" <email.address@example.org> Build-Depends: debhelper-compat (= 13) Standards-Version: 4.5.1 Homepage: <insert the upstream URL, if relevant> Rules-Requires-Root: no 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.
![]() |
Warning |
---|---|
如果您對 debian/control 模板檔案中的“Section: unknown”部分不做修改的話,後續的 lintian 錯誤可能導致構建失敗。 |
因為這是個 ELF 二進位制可執行檔案套件,debmake 命令設定了“Architecture: any”和“Multi-Arch: foreign”兩項。同時,它將所需的 substvar 引數設定為“Depends: ${shlibs:Depends}, ${misc:Depends}”。這些內容將在 Chapter 5, 基本內容 部分進行解釋。
![]() |
Note |
---|---|
Please note this debian/control file uses the RFC-822 style as documented in 5.2 Source package control files — debian/control of the “Debian Policy Manual”. The use of the empty line and the leading space are significant. |
這裡的 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 Upstream-Contact: <preferred name and address to reach the upstream project> 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
如上在 debian/rules 檔案中匯出=DH_VERBOSE 環境變數可以強制 debhelper 工具輸出細粒度的構建報告。
如上匯出 DEB_BUILD_MAINT_OPTION 變數可以如 dpkg-buildflags(1) 手冊頁中“FEATURE AREAS/ENVIRONMENT”部分所說,對強化選項進行設定。[9]
如上匯出 DEB_CFLAGS_MAINT_APPEND 可以強制 C 編譯器給出所有型別的警告內容。
如上匯出 DEB_LDFLAGS_MAINT_APPEND 可以強制連結器只對真正需要的程式庫進行連結。[10]
對基於 Makefile 的構建系統來說,dh_auto_install 命令所做的基本上就是“$(MAKE) install DESTDIR=debian/debhello”。這裡建立的 override_dh_auto_install 目標將其行為修改為“$(MAKE) install DESTDIR=debian/debhello prefix=/usr”。
這裡是維護者版本的 debian/control 和 debian/copyright 檔案。
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-compat (= 13) Standards-Version: 4.5.1 Homepage: https://salsa.debian.org/debian/debmake-doc Rules-Requires-Root: no Package: debhello Architecture: any Multi-Arch: foreign Depends: ${misc:Depends}, ${shlibs:Depends} Description: Simple packaging example for debmake This Debian binary package is an example package. (This is an example only)
debian/copyright(維護者版本):.
$ vim debhello-0.0/debian/copyright ... hack, hack, hack, ... $ cat debhello-0.0/debian/copyright Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: debhello Upstream-Contact: Osamu Aoki <osamu@debian.org> Source: https://salsa.debian.org/debian/debmake-doc Files: * Copyright: 2015-2021 Osamu Aoki <osamu@debian.org> License: Expat 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 ├── control ├── copyright ├── patches │ └── series ├── rules ├── source │ ├── control │ ├── format │ ├── local-options │ ├── options │ └── patch-header ├── tests │ └── control ├── upstream │ └── metadata └── watch 4 directories, 14 files
![]() |
Tip |
---|---|
對於來自 debhelper 套件的各個 dh_* 命令來說,它們在讀取所使用的配置文件時通常把以 # 開頭的行視為註釋行。 |
您可以使用 debuild 或者等效的命令工具(參見 Section 4.4, “什麼是 debuild?”)在這個原始碼樹內構建一個非原生 Debian 套件。命令的輸出通常十分詳細,如下所示,它會對構建中執行的操作進行解釋。
$ cd debhello-0.0 $ debuild dpkg-buildpackage -us -uc -ui -i -i ... debian/rules clean dh clean ... debian/rules binary dh binary dh_update_autotools_config dh_autoreconf dh_auto_configure install -d /path/to/debhello-0.0/debian/.debhelper/generated/_source/... dh_auto_build make -j12 "INSTALL=install --strip-program=true" make[1]: Entering directory '/path/to/debhello-0.0' # CFLAGS=-g -O2 # -ffile-prefix-map=/home/osamu/src/public/debmake-doc/debmake-doc/examp ... Now running lintian -i -I --show-overrides debhello_0.0-1_amd64.changes ... ... N: Renamed from: binary-without-manpage N: W: debhello: readme-debian-contains-debmake-template N: ...
這裡驗證了 CFLAGS 已經得到了更新,新增了 -Wall 和 -pendatic 引數;這是我們先前在 DEB_CFLAGS_MAINT_APPEND 變數中所指定的。
根據 lintian 的報告,您應該如同後文中的例子那樣(請見 Chapter 8, 更多範例)為套件新增 man 手冊頁。我們這裡暫且跳過這部分內容。
現在我們來看看成果如何。
debhello 0.0 版使用 debuild 命令產生的文件:.
$ cd .. $ tree -FL 1 . ├── debhello-0.0/ ├── debhello-0.0.tar.gz ├── debhello-dbgsym_0.0-1_amd64.deb ├── 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/control debian/copyright debian/patches/ debian/patches/series debian/rules debian/source/ debian/source/control debian/source/format debian/source/options debian/source/patch-header debian/tests/ debian/tests/control debian/upstream/ debian/upstream/metadata debian/watch
debhello_0.0-1_amd64.deb 包含了將要安裝至目標系統中的檔案。
debhello-debsym_0.0-1_amd64.deb 包含了將要安裝至目標系統中的除錯符號檔案。
所有二進位制包的包內容:.
$ dpkg -c debhello-dbgsym_0.0-1_amd64.deb drwxr-xr-x root/root ... ./ drwxr-xr-x root/root ... ./usr/ drwxr-xr-x root/root ... ./usr/lib/ drwxr-xr-x root/root ... ./usr/lib/debug/ drwxr-xr-x root/root ... ./usr/lib/debug/.build-id/ drwxr-xr-x root/root ... ./usr/lib/debug/.build-id/be/ -rw-r--r-- root/root ... ./usr/lib/debug/.build-id/be/11292eded3fc22396a0b62... drwxr-xr-x root/root ... ./usr/share/ drwxr-xr-x root/root ... ./usr/share/doc/ lrwxrwxrwx root/root ... ./usr/share/doc/debhello-dbgsym -> debhello $ 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
生成的依賴列表會給出所有二進位制套件的依賴。
生成的所有二進位制套件的依賴列表(v=0.0):.
$ dpkg -f debhello-dbgsym_0.0-1_amd64.deb pre-depends \ depends recommends conflicts breaks Depends: debhello (= 0.0-1) $ dpkg -f debhello_0.0-1_amd64.deb pre-depends \ depends recommends conflicts breaks Depends: libc6 (>= 2.2.5)
![]() |
Caution |
---|---|
在將套件上傳至 Debian 倉庫之前,仍然有很多細節需要進行處理。 |
![]() |
Note |
---|---|
如果跳過了對 debmake 命令自動生成的配置檔案的手工調整步驟,所生成的二進位制套件可能缺少有用的套件描述資訊,某些政策的要求也無法滿足。這個不正式的套件對於 dpkg 命令來說可以正常處理,也許這樣對您本地的部署來說已經足夠好了。 |
上面的例子中,在建立合適的 Debian 套件時沒有修改上游的原始碼。
作為維護者,另一個備選的方案是對上游原始碼做改動,如修改上游的 Makefile 以將 $(prefix) 的值設定為 /usr。
打包操作基本上和上面的分步範例相同,除了在 Section 4.7, “第三步:編輯模板檔案” 中的兩點:
要將維護者對上游原始碼的修改形成對應的補丁檔案存放在 debian/patches/ 目錄內,並將它們的檔名寫入 debian/patches/series 檔案,如 Section 5.10, “debian/patches/*” 所述。有數種生成補丁檔案的方式。下面的章節中給出了一些例子:
此時維護者對 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 $@
這個使用一系列補丁檔案進行 Debian 打包的備選方案對於應對上游未來的改變可能不夠健壯,但是在應對更為複雜的上游原始碼時可以更靈活。(參見 Section 7.13, “3.0 原始碼格式”。)
![]() |
Note |
---|---|
對當前這個特定的打包場景,前文的 Section 4.7, “第三步:編輯模板檔案” 中使用 debian/rules 檔案的方式更好一些。但為了演示起見,此時我們先使用本節的方式繼續操作。 |
![]() |
Tip |
---|---|
對更復雜的打包場景,可能需要同時應用 Section 4.7, “第三步:編輯模板檔案” 和 Section 4.9, “第三步(備選):修改上游原始碼” 中的方式。 |
這裡我們使用 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 2021-07-02 16:26:38.734722687 +0900 +++ debhello-0.0/Makefile 2021-07-02 16:26:38.802723496 +0900 @@ -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 ... edit the DEP-3 patch header with editor $ tree -a . ├── .pc │ ├── .quilt_patches │ ├── .quilt_series │ ├── .version │ ├── 000-prefix-usr.patch │ │ ├── .timestamp │ │ └── Makefile │ └── applied-patches ├── LICENSE ├── Makefile ├── debian │ ├── README.Debian │ ├── changelog │ ├── control │ ├── copyright │ ├── patches │ │ ├── 000-prefix-usr.patch │ │ └── series │ ├── rules │ ├── source │ │ ├── control │ │ ├── format │ │ ├── local-options │ │ ├── options │ │ └── patch-header │ ├── tests │ │ └── control │ ├── upstream │ │ └── metadata │ └── watch └── src └── hello.c 8 directories, 24 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
這裡,上游原始碼樹中的 Makefile 檔案沒有恢復到原始狀態的必要。在 Section 4.8, “第四步:使用 debuild 構建套件” 描述的 Debian 打包過程中呼叫的 dpkg-source 命令能夠理解由 dquilt 程式在 .pc/ 目錄中記錄的補丁應用情況。只要所有這些修改都是由 dquilt 命令完成的,那麼 Debian 原始碼套件就可以從經過修改的原始碼樹中進行構建。
![]() |
Note |
---|---|
如果 .pc/ 目錄不存在,dpkg-source 命令就會假定沒有應用任何補丁。這就是更為原始的補丁生成方法,例如 Section 4.9.1, “使用 diff -u 處理補丁” 中未生成 .pc/ 目錄的情況下要求將上游原始碼樹進行恢復的原因。 |
這裡給出使用“dpkg-source --commit”命令生成 000-prefix-usr.patch 的例子。
我們先來編輯上游原始碼。
$ cd debhello-0.0 $ vim Makefile ... hack, hack, hack, ... $ head -n1 Makefile prefix = /usr
我們來進行提交。
$ 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=/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 $ tree -a . ├── .pc │ ├── .quilt_patches │ ├── .quilt_series │ ├── .version │ ├── 000-prefix-usr.patch │ │ ├── .timestamp │ │ └── Makefile │ └── applied-patches ├── LICENSE ├── Makefile ├── debian │ ├── README.Debian │ ├── changelog │ ├── control │ ├── copyright │ ├── patches │ │ ├── 000-prefix-usr.patch │ │ └── series │ ├── rules │ ├── source │ │ ├── control │ │ ├── format │ │ ├── local-options │ │ ├── options │ │ └── patch-header │ ├── tests │ │ └── control │ ├── upstream │ │ └── metadata │ └── watch └── src └── hello.c 8 directories, 24 files
這裡,dpkg-source 命令完成了與 Section 4.9.2, “使用 dquilt 處理補丁” 一節中使用 dquilt 命令完全相同的流程。