个人工具

“PackagingGuide”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
1 前言: 翻译
 
(未显示2个用户的10个中间版本)
第1行: 第1行:
 
{{From|http://ubuntusci.meraka.org.za/wiki/Documentation/PackagingGuide}}
 
{{From|http://ubuntusci.meraka.org.za/wiki/Documentation/PackagingGuide}}
  
=Debian打包入門=
+
 
 +
Debian/Ubuntu打包入门
  
 
Lelanthran K. Manickum
 
Lelanthran K. Manickum
第7行: 第8行:
 
2009年1月13日
 
2009年1月13日
  
==1 前言==
+
=前言=
 
+
在Ubuntusci [1]的一部分努力之下,许多尚未在Ubuntu软件仓库中的软件包被添加到仓库中。把其他类UNIX系统上的软件或者其他Linux发行版上的软件移植到Ubuntu Linux是一件复杂的事情,需要比预期更多的时间和努力。
+
  
不考虑Ubuntu软件仓库,任何已经至少出现在Debian软件仓库中4至5年的软件都将可能成为我们打包移植工作可能面临的困难。这还是个保守的假设。如果仅仅只是将源代码拷贝过来,简单地为Ubuntu(或者Debian)编译一下就可以,相信很多人早就做过了。那些特定的、一直以来没有人移植打包的软件主要是因为他们在Debian/Ubuntu上不能完美编译。
+
在Ubuntusci [1]的一部分努力之下,许多没有被Ubuntu软件仓库收录的软件包被添加到了仓库中。把其他类UNIX系统上的软件(或者其他Linux发行版上的软件)移植到Ubuntu Linux中是一件复杂的事情,需要的时间和努力会比预期更多。
  
这份文档针对那些从来没有试过给Debian/Ubuntu软件打包的读者。因为我们发现,打包的实际过程即使软件编译和运行无错,仍然可能会让人觉得困难。希望随着项目的推进,社区把更多的精力花费在软件包检查上面,使得我们打包软件的质量过硬。
+
不考虑Ubuntu软件仓库,任何已经出现在Debian软件仓库中至少4至5年的软件都将可能成为我们移植打包工作可能面临的困难。这还是个保守的假设。如果仅仅只是将源代码拷贝过来,简单地为Ubuntu(或者Debian)编译一下就可以,相信很多人早就做过了。那些特定的、一直以来没有人移植打包的软件主要是因为他们在Debian/Ubuntu上不能完美编译。
  
==2 工具==
+
这份文档针对那些从未试过给Debian/Ubuntu制作软件包的读者。因为我们发现,即使软件编译和运行无错,打包的实际过程仍然可能会让人感到困惑。希望随着项目的推进,社区把更多的精力花费在软件包检查上,使我们制作的软件包质量过硬。
  
There is usually some confusion for the new Ubuntu/Debian developer when using the word source. “Source-code” usually refer to a program or application or package actual source-code. When the word “Sources” is used, it refers to the files used in the creation of a package. For example, the source-code for package Foo would be the text files that are compiled by a GCC to produce binaries while the sources for Foo would be all those files that are needed to produce Foo.deb, including the source-code.
+
=工具=
  
The basic process for packaging is
+
Ubuntu/Debian的开发新手经常会对“source”这个词感到困惑。“Source-code”通常指某个程序(program),或者某个应用(application),或者软件包的源代码。当我们说“Sources”的时候,指的是用于构建软件包的文件。例如,软件包“Foo”的“source-code”(源代码)是一个或者一堆文本文件,通过GCC编译连接之后可以产生二进制可执行文件;而我们所说的“Foo”软件包的“sources”,指的是所有用于构建Foo.deb这个debian包的文件,其中包括源代码文件。
  
    * Download the source-code for the package.
+
构建deb软件包的基本过程如下:
    * Un-archive the package source-code into a directory.
+
    * Create the debianisation directory (./debian).
+
    * Modify the files in the ./debian directory to reflect the package main-
+
          o tainers details, the package descriptions, etc.
+
    * Compile the package source-code.
+
    * Create the actual .deb package.
+
    *
+
  
      Upload the created package to our Launchpad PPA[1] .
+
    * 下载软件的源码包;
 +
    * 把源码包解压缩到某个目录;
 +
    * 在源码目录内创建debian化目录 (./debian).
 +
    * 修改./debian目录内的文件,如包维护者的详细信息、包描述,等等;
 +
    * 在本机编译源代码;
 +
    * 在本机生成.deb包;
 +
    * 把经过我们修改后能成功编译生成deb包的sources上传到Launchpad PPA[1]
  
At this point, after it has been uploaded to Launchpad and has successfully built on Launchpad, our work is mostly done. Our Launchpad PPA URL can be given to people who need to use our package, and eventually we can ask that our package be moved from our PPA to one of the main Ubuntu repositories.
+
当软件成功地上传到Launchpad,并在Launchpad上成功编译生成deb包后,我们的工作就基本上完成了。我们的Launchpad PPA源地址可以分享给其他想使用我们的deb包的人。我们甚至可以申请把我们的deb包移入Ubuntu的官方主软件仓库中。
  
The minimalist list of tools that will be needed are:
+
这过程中需要用到的工具至少有:
  
     * A web-browser or similar tool to grab the source-code of the package.
+
     * 浏览器,或者类似的软件——用于下载软件的源代码包;
     * An archival tool (such as tar, etc) to un-archive the source-code.
+
     * 解压缩软件——用于解压下载回来的源代码包;
     * dh_make (part of package dh-make) to create the ./debian directory and
+
     * dh_make(dh-make包的一部分)——用于自动创建./debian目录和其他用于创建.deb包的骨架模板文件;
          o skeleton files for the .deb creation.  
+
     * make(Gnu make)——构建过程中要用到的工具;
     * make (Gnu make) a tool that is used by the build process.
+
     * debchange/dch(devscripts包的一部分)——用于编辑包的版本号;
     * debchange/dch (part of package devscripts) to manage version numbers
+
     * debuild(devscripts包的一部分)——运行构建过程,包括编译连接,以及生成deb包;
          o of the package.
+
     * fakeroot(fakeroot包的一部分)——这个东西是必须的;
     * debuild (part of package devscripts) to run the build process that will
+
     * dput——上传经过签名的deb文件。
          o both compile the package and generate the .deb file.
+
     * fakeroot is needed (part of package fakeroot).
+
     * dput to upload the signed .deb file.
+
  
I use, and recommend that all packaging efforts be done, on a recent Ubuntu machine, purely because it simplifies the process a great deal.
+
建议所有打包工作都在较新的Ubuntu系统下进行,这样可以大大方便和简化整个过程。
  
==3 Introducing Alien Packages==
+
=引入异种包(Alien Packages)=
  
An Alien package is one that is targetted for a different system. For example a package targetted for a Red Hat system would be in the RPM package format. Porting these packages to Ubuntu is easier than attempting to package nonpackaged software, mainly because all of the package requirements have already been met, such as run-time dependencies, compile-time dependencies, etc.
+
异种包(Alien Packages)是针对其他系统的软件包。例如针对Red Hat系统的软件包,是RPM格式的。比起那些还未打包过的软件来,将这些软件移植到Ubuntu系统相对比较容易,因为所有的包依赖、运行时依赖、编译时依赖等,都是已知的。
  
The package alien (available in the repositories) can be used to automatically convert packages in selected other package formats to the .deb format. Unfortunately, this is only for binary packages; ideally packaging should only be done from source-code. The sources of any package should be source-code.
+
软件包alien(软件仓库中有)能够自动地将其他二进制异种包转换成.deb包。不过,这种转换仅仅只限于二进制包。理想的deb包构应该从源代码开始,所有用于构建deb包的源文件(sources)都应该是源代码(source-code)。
  
==4 編譯為類Unix系統定製的源碼包==
+
=编译专门针对类Unix系统的源码包=
  
After downloading the source-code, un-archive all the sources into a directory with a suitable name, for example Foo-1.2.3[2] .
+
下载源代码后,将其解压到一个目录中,给该源代码目录起个适合的名字,例如“Foo-1.2.3”[2]
  
Changing our working directory to the directory we just created with the applications source-code and running dh_make would create the files needed to package the software. Some of the control files will be created as well as the rules file for compiling the software with a default rule.
+
在终端中,cd进刚才所说的那个源代码目录,执行dh_make,生成打包需要用到的文件,包括一些控制文件(control files)和编译规则文件(rules文件,自动生成的rules文件使用了默认规则)。
  
Most unix packages, having been distributed with a configure script generated by autoconf, should build cleanly without any further work. However, a few applications which have no configure script would need modifications to work. Because the pitfalls inherent in porting and application from a different platform can and do vary[3] , I shall only address the issue of getting a fully working application into Launchpad[4] .
+
大多数包含autoconf工具生成的configure脚本的unix软件源码包都几乎不用其他更深入的工作即可干净地构建。然而有少数源码包里面可能没有configure脚本文件,这需要修改才能工作。由于移植工作固有的缺陷,以及其他不同的平台的软件多种多样[3],我将只涉及将一个可完全正常工作的应用程序源码包在Launchpad打包的问题[4]
  
==5 從源碼倉庫(Working Sources)創建Ubuntu軟件包==
+
=从可正常工作的源码(Working Sources)构建Ubuntu软件包=
  
I assume that the reader has downloaded the source-code to a an application and wishes to create a Debian package out of that application. For my example, I’ve written a script-based application[5] that was written as a standalone application, with an installer and an uninstaller that should run on most Linux distributions.
+
我假设读者已经下载了一个应用程序的源代码,并希望将该应用程序构建成一个Debian包。在我的例子中,我写了一个基于脚本的独立应用程序,以及安装、卸载程序,它应该能在大多数Linux发行版上运行[5]
  
Downloading the Source Code. We can get the version of vob2mpeg that was used for this example from sourceforge. The following command will retrieve the exact version of the application used.
+
==下载源码包==
 +
我们可以从sourceforge下载下面例子中用到的vob2mpeg版本。用下面的命令取得所使用的应用程序的确切版本。
  
 
  $ svn co https://vob2mpeg.svn.sourceforge.net/svnroot/vob2mpeg/tags/vob2mpeg-0.0.1
 
  $ svn co https://vob2mpeg.svn.sourceforge.net/svnroot/vob2mpeg/tags/vob2mpeg-0.0.1
第83行: 第79行:
 
  Checked out revision 7.
 
  Checked out revision 7.
  
No unarchive is necessary in this instance because we retrieved upstream in a form that was not archived. Similarly, no renaming of the directory is needed as the application is already in an appropriately named directory, viz vob2mpeg-0.0.1. What we need to do, however, is create an archive of the original upstream sources so that any changes made to the applications sources can be recorded against the original unchanged upstream sources.
+
此时不需要解压,因为我们取回的上游源代码是未压缩的。同样,源码目录页无需重新命名,它已经是适合的名字了:vob2mpeg-0.0.1。我们需要做的是,创建一个原始上游源代码的压缩包,以便我们对程序源代码所做的任何修改都能记录下来并跟未作修改的原始上游源代码作比较。
  
Creating the Debian Control Files. Happily, dh_make can create the archive of the original upstream sources using the --create-orig flag. All the control files for creation of a package are also created by dh_make:
+
==创建Debian控制文件==
 +
令人高兴的是,dh_make能用--create-orig标志创建原始上游压缩包。同时dh_make还生成所有其他用于构建deb包所需的所有控制文件:
  
 
  $ cd vob2mpeg-0.0.1/
 
  $ cd vob2mpeg-0.0.1/
第118行: 第115行:
 
  docs      manpage.sgml.ex      README.Debian
 
  docs      manpage.sgml.ex      README.Debian
  
As we see, a debian directory has been created. This directory contains all of the information needed by the Debian build tools to build the package, including the build instructions to build the application itself. Since this is an interpreted application, no actual compilation of source code is necessary.
+
可以看到,“debian”目录已经生成。这个目录里面包含所有Debian建包工具创建deb包所需的信息,包括用于编译应用程序自身的构建指令。这些指令是一种解释程序,无需编译任何实际的源代码。
  
Modifying the Control Files. Before we go any further, a few modifications will need to be done on the files in debian. Firstly, the control file must be edited so that each field reflects the correct information. The results of such an edit is below.
+
==修改控制文件==
 +
在我们继续深入之前,debian目录下的文件要作一些修改。首先,必须编辑控制文件,使之反映正确的信息。这样的编辑,结果如下:
  
 
  $ cat debian/control
 
  $ cat debian/control
第128行: 第126行:
 
  Maintainer: Lelanthran Krishna Manickum <[email protected]>
 
  Maintainer: Lelanthran Krishna Manickum <[email protected]>
 
  Build-Depends: debhelper (>= 5)
 
  Build-Depends: debhelper (>= 5)
  Standards-Version: 3.7.2
+
  Standards-Version: 3.7.2<br>
 
+
 
  Package: vob2mpeg
 
  Package: vob2mpeg
 
  Architecture: any
 
  Architecture: any
第154行: 第151行:
 
  $
 
  $
  
Finally, all the example files in the debian directory are not needed for this simple exercise - they are merely examples, so we remove them.
+
最后,在这个简单的打包练习例子中,所有debian目录下的的样板文件(*.[Ee][Xx])都是非必须的——这些文件只不过是例子罢了,故此我们将其删除。
  
 
  $ rm debian/*.[Ee][Xx]
 
  $ rm debian/*.[Ee][Xx]
  
Modifying the Rules File. Before we go ahead and try to create the Debian package, we still need to modify the rules file. The debian/rules file is a Makefile run by make that will build the application. Since we are not compiling anything, this file will be pared down to only what is needed to create a distribution of the software. This application (vob2mpeg) has an installation (and uninstallation) script that must be run. For example, vob2mpeg is installed on a Linux system by executing the installation script with an optional configuration file that specifies the location of the installation. Since we want all the files to install to ./debian/vob2mpeg, we create a configuration file from the example given in the upstream sources.
+
==修改规则文件==
 +
在我们继续尝试创建Debian的软件包之前,还要修改规则文件。debian/rules文件是一个Makefile文件,make将执行它来编译构建程序。在这里,由于我们什么也不编译,这个文件将被削减到仅仅只包含创建一个软件分发所需要的内容。这个应用程序(vob2mpeg)有一个安装(和卸载)脚本必须被执行。例如,vob2mpeg通过执行一个包含可选的配置文件并可指定安装位置的安装脚本,这样安装在Linux系统里面。由于我们希望所有的文件安装到./debian/vob2mpeg,我们从上游源文件提供的例子文件来创建一个配置文件。
  
 
  $ cp vob2mpeg-install.conf debian/
 
  $ cp vob2mpeg-install.conf debian/
第172行: 第170行:
 
  export DEST_ETC=/tmp/test/etc
 
  export DEST_ETC=/tmp/test/etc
 
  export DEST_BIN=/tmp/test/usr/bin
 
  export DEST_BIN=/tmp/test/usr/bin
  export DEST_DOC=/tmp/test/usr/share/doc/vob2mpeg
+
  export DEST_DOC=/tmp/test/usr/share/doc/vob2mpeg<br>
 
+
 
  # The files to actually install, please do not change this
 
  # The files to actually install, please do not change this
 
  export ETC_FILES="vob2mpeg.profile $CONF_FILE"
 
  export ETC_FILES="vob2mpeg.profile $CONF_FILE"
第191行: 第188行:
 
  export DEST_ETC=debian/vob2mpeg/etc
 
  export DEST_ETC=debian/vob2mpeg/etc
 
  export DEST_BIN=debian/vob2mpeg/usr/bin
 
  export DEST_BIN=debian/vob2mpeg/usr/bin
  export DEST_DOC=debian/vob2mpeg/usr/share/doc/vob2mpeg
+
  export DEST_DOC=debian/vob2mpeg/usr/share/doc/vob2mpeg<br>
 
+
 
  # The files to actually install, please do not change this
 
  # The files to actually install, please do not change this
 
  export ETC_FILES="vob2mpeg.profile $CONF_FILE"
 
  export ETC_FILES="vob2mpeg.profile $CONF_FILE"
第200行: 第196行:
 
  $
 
  $
  
So, we ensure that when we run the vob2mpeg installation script, it would install itself to ./debian/vob2mpeg. We can then create the .deb file from the files in that directory. Now we modify the rules file to tell it how to build the package files (the files that will be installed). Because we will only be modifying the build, install and the clean targets, I will <...snip...> out the rest of the file.
+
因此,我们确保当运行vob2mpeg安装脚本时,它会自行安装到./debian/vob2mpeg。然后,我们可以从该目录中的文件创建deb包。现在我们修改规则文件来告诉它如何建立包文件(会被安装的文件)。因为我们将只修改构建(build)、安装(install)和清理(clean)的目标,我将把该文件的其余部分<...喀嚓...>掉。
  
 
  $ cat debian/rules
 
  $ cat debian/rules
 
  #!/usr/bin/make -f
 
  #!/usr/bin/make -f
  <...snipped...>
+
  <...喀嚓...>
 
  build-stamp: configure-stamp
 
  build-stamp: configure-stamp
         dh_testdir
+
         dh_testdir<br>
 
+
 
           # Add here commands to compile the package.
 
           # Add here commands to compile the package.
 
           $(MAKE)
 
           $(MAKE)
           #docbook-to-man debian/vob2mpeg.sgml > vob2mpeg.1
+
           #docbook-to-man debian/vob2mpeg.sgml > vob2mpeg.1<br>
 
+
           touch $@<br>
           touch $@
+
 
+
 
  clean:
 
  clean:
 
           dh_testdir
 
           dh_testdir
 
           dh_testroot
 
           dh_testroot
           rm -f build-stamp configure-stamp
+
           rm -f build-stamp configure-stamp<br>
 
+
 
           # Add here commands to clean up after the build process.
 
           # Add here commands to clean up after the build process.
           -$(MAKE) clean
+
           -$(MAKE) clean<br>
 
+
           dh_clean<br>
           dh_clean
+
 
+
 
  install: build
 
  install: build
 
         dh_testdir
 
         dh_testdir
 
         dh_testroot
 
         dh_testroot
 
         dh_clean -k
 
         dh_clean -k
         dh_installdirs
+
         dh_installdirs<br>
 
+
 
         # Add here commands to install the package into debian/vob2mpeg.
 
         # Add here commands to install the package into debian/vob2mpeg.
 
         $(MAKE) DESTDIR=$(CURDIR)/debian/vob2mpeg install
 
         $(MAKE) DESTDIR=$(CURDIR)/debian/vob2mpeg install
  <...snipped...>
+
  <...喀嚓...>
 
  $ vi debian/rules
 
  $ vi debian/rules
 
  $ cat debian/rules
 
  $ cat debian/rules
 
  #!/usr/bin/make -f
 
  #!/usr/bin/make -f
  <...snipped...>
+
  <...喀嚓...>
 
  build-stamp: configure-stamp
 
  build-stamp: configure-stamp
         dh_testdir
+
         dh_testdir<br>
 
+
           # Add here commands to compile the package.<br>
           # Add here commands to compile the package.
+
           #docbook-to-man debian/vob2mpeg.sgml > vob2mpeg.1<br>
 
+
           touch $@<br>
           #docbook-to-man debian/vob2mpeg.sgml > vob2mpeg.1
+
 
+
           touch $@
+
 
+
 
  clean:
 
  clean:
 
           dh_testdir
 
           dh_testdir
 
           dh_testroot
 
           dh_testroot
           rm -f build-stamp configure-stamp
+
           rm -f build-stamp configure-stamp<br>
 
+
 
           # Add here commands to clean up after the build process.
 
           # Add here commands to clean up after the build process.
           rm -rf ./debian/vob2mpeg
+
           rm -rf ./debian/vob2mpeg<br>
 
+
           dh_clean<br>
           dh_clean
+
 
+
 
  install: build
 
  install: build
 
         dh_testdir
 
         dh_testdir
 
         dh_testroot
 
         dh_testroot
 
         dh_clean -k
 
         dh_clean -k
         dh_installdirs
+
         dh_installdirs<br>
 
+
 
         # Add here commands to install the package into debian/vob2mpeg.
 
         # Add here commands to install the package into debian/vob2mpeg.
 
         ./install-vob2mpeg.sh ./debian/vob2mpeg-install.conf
 
         ./install-vob2mpeg.sh ./debian/vob2mpeg-install.conf
  <...snipped...>
+
  <...喀嚓...>
 
  $
 
  $
  
The only lines that have been changed are those that execute the compilation, the installation of the files and the removal of all the files, so the targets build, install and clean have been modified so that compile does nothing (there is nothing to compile), the target install merely calls the installation program to install the files to the debian/vob2mpeg directory and the clean target only removes that same directory.
+
只有执行编译、文件安装、移除动作相关的行被修改,因此建构(build)、安装(install)和清理(clean)目标被改成不编译(因为在我们这个例子中什么也不用编译)。安装(install)目标仅仅只是调用安装程序把文件复制安装到debian/vob2mpeg目录内,而清理(clean)目标则负责移除上述目录。
  
Note that we have neglected to provide the preinst and postinst scripts in the debian/ directory. These scripts, if present, are respectively run prior to installation of the package and after the removal of the package. This particular application has no need to run any commands before installation nor any commands after removal.
+
注意我们略掉了在debian目录下提供preinst和postinst脚本。如果提供了这些脚本,那么他们会分别在安装deb包之前,或者卸载deb包之后被执行。我们这个例子中的软件无需在安装前执行什么动作,卸载后动作也一样不需要。
  
Package Creation. Now that we are done with all the changes we wish to make, we can issue the commands required to create the .deb file. Before we do so, however, we need to ensure that the correct Debian package version number is reflected in the newly created package. This should not be confused with the applications version number, which is the version number of the application. The package version number is the version of our package. For example, it is possible that for application Foo we decide to package version 1 of the applica- tion. In other words, the directory we use is Foo-1.0.0. After packaging Foo, we assign that package the version number 0.0.1.
+
==打包==
 +
现在我们已经完成了所有想作的修改,就等着发出建立deb包文件的命令了。不过,在打包之前,我们还需要核实一下Debian版本号,确保它能在新建的deb文件中反映出来。不要混淆Debian版本号和应用程序的版本号。Debian版本号是我们deb包的版本号,如对于Foo这个软件我们可能会想给它的版本号为1的版本建包。也就是说,我们用于打包的程序源代码目录为Foo-1.0.0。给Foo打包后,我们指定改包的版本号为0.0.1。
  
Now let’s assume that there was an error in the packaging, for example, perhaps we compiled Foo using a flag that caused it to break on lpia architectures. A user submits a report and we quickly fix the problem. This results in the package having the new version of 0.0.2 while the application itself is still Foo-1.0.0.
+
现在让我们假设在打包过程中发生了小错误,例如,我们可能在编译Foo的时候使用了某个编译标志(flag)使得制作出来的deb包在lpia架构下会安装运行会出现问题。有用户反馈了错误报告,我们很快修复了这个问题。这时我们需要重新给相同的软件版本打包,制作出了版本号为0.0.2的deb包,而该包软件版本仍然是Foo-1.0.0。
  
Updating the Version Number. To automatically manage the version numbers of the package, we use a tool called dch. A plain invocation of dch without any command-line arguments results in an increment of the minor ver- sion number, while invoking it as dch -i results in the package recieving an increment to the major version number.
+
更新版本号。这时我们会用到一个叫dch的工具,它可以自动管理包的版本号。不带任何命令行参数的形式调用dch,会使包的小版本号(minor version number)自动增加,而带 -i 参数(dch -i)方式调用,则使主版本号(major version number)增加。
  
Upon running dch for the first time, we are presented with an editor[6] that should display something similar to the following:
+
第一次运行dch后,会打开一个编辑器,里面出现如下这样的内容:
 
+
vob2mpeg (0.0.1-1) unstable; urgency=low
+
  
 +
vob2mpeg (0.0.1-1) unstable; urgency=low<br>
 
   * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>
 
   * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>
   *
+
   *<br>
 
+
 
   -- Lelanthran Krishna Manickum <lmanickum@esprit>  Mon, 12 Jan 2009 23:39:19 +0200
 
   -- Lelanthran Krishna Manickum <lmanickum@esprit>  Mon, 12 Jan 2009 23:39:19 +0200
  
We edit the above file so that unstable is replaced with the actual Debian distribution name (in this example I use Intrepid, as that is what was used in the production of this document and the package). Each comment should also follow the given convention, starting with an asterisk and indented to the previous line. The changed file looks like this:
+
我们直接在编辑器中修改,把上面的unstable更改成实际的Debian或Ubuntu版本名称(在这个例子中,我把unstable改成intrepid,因为我使用的Debian版本名是Intrepid)(译者注:你的可能是Hardy、Lucid、Marverik,或者其他)。每个注释都应遵循给定的惯例格式,以星号开始,没行对准上一行的缩进。更改后的文件看起来像这个样子:
 
+
vob2mpeg (0.0.1-1) intrepid; urgency=low
+
  
 +
vob2mpeg (0.0.1-1) intrepid; urgency=low<br>
 
   *  Initial release
 
   *  Initial release
 
   *  Edited rules and removed build instructions
 
   *  Edited rules and removed build instructions
 
   *  Edited rules and replaced command for installation
 
   *  Edited rules and replaced command for installation
   *  Edited rules and replaced command for target ’clean’
+
   *  Edited rules and replaced command for target ’clean’<br>
 
+
 
   -- Lelanthran Krishna Manickum <lmanickum@esprit>  Mon, 12 Jan 2009 23:39:19 +0200
 
   -- Lelanthran Krishna Manickum <lmanickum@esprit>  Mon, 12 Jan 2009 23:39:19 +0200
  
Now we can go ahead and create the actual .deb archive by running the debian/rules script, like this:
+
现在我们就可以开始运行debian/rules脚本来建立deb包了:
  
 
  $ fakeroot debian/rules binary-arch
 
  $ fakeroot debian/rules binary-arch
第348行: 第326行:
 
  $
 
  $
  
This creates the debian/vob2mpeg directory tree, and uses that tree, along with the control files, to create the ../vob2mpeg_0.0.1-1_i386.deb file. At this point, we can stop if we only want to create packages for our own use. However, if we need to distribute our packages (such as through Launchpad), then we need to ensure that our package is signed by our Launchpad key.
+
开始它按照我们的设定建立debian/vob2mpeg目录树,把包内容拷贝(安装)到该目录里面,然后读取控制文件(debian/control),将该目录树中的内容打包成 ../vob2mpeg_0.0.1-1_i386.deb,这就是我们最终得到的deb包。如果我们打deb包只是给自己用,那么工作可以到此结束。如果我们想透过诸如Launchpad PPA这样的方式发布我们制作的deb包,我们就必须对我们的deb包用Launchpad密钥签名。
  
==6 上傳並發佈軟件包==
+
=上传并发布软件包=
  
Launchpad provides a very convenient way to redistribute our packages. We simply upload the upstream sources, upload the changes we made to the upstream sources and let Launchpad then build the packages for us. This ensures that, not only do we build our packages on our local machine, but we also find out if the package builds on the various Launchpad virtual machines.
+
Launchpad为我们提供了一个非常方便的个人软件包发布方式。我们只需要简单地吧上游源码包和我们对上游源码包所作的修改一同上传到Launchpad,然后Launchpad就会自动为我们生成deb包。这将确保我们的deb软件包不仅仅只是在我们自己的本地计算机上生成;在若干不同的Launchpad远程虚拟机上,我们也可以检查看看能否正确打包。
  
The very first thing to do, if we haven’t already done so, is to create a Launchpad account for us to use. This account will give us a PPA, or Personal Package Archive. All the packages we upload will go into our PPA, and the URL for our PPA can be added to any sources.list file so that our package can be installed via the normal apt-get or synaptic methods by the user.
+
最开始要做的,当然是要有一个Launchpad账号,如果没有的话,就注册一个。只要注册了Launchpad账号,就能分配到一个自己的PPA(Personal Package Archive)。我们往Launchpad上传的所有软件包都会进入自己的PPA。我们的PPA地址可以直接写到任何source.list文件中,这样用户只需要按照平常那样apt-get或者用synaptic就可以安装我们的包了。
  
All the steps in creating an account on Launchpad is beyond the scope of this report, but full instructions and comprehensive help is available on Launchpad itself - https://launchpad.net/. Part of the creation of the Launchpad account requires the user to generate a cryptography key and use this key to digitally sign the code of conduct. This very same will will be used to generate a digitally signed package.
+
怎样一步步注册Launchpad账号超出了本报告讲述的范围。不过Launchpad的本身有全面的说明和帮助——参看https://launchpad.net 。创建Launchpad帐户的过程中有些步骤要求用户生成一个加密密钥,并使用这个密钥进行数字签名。同样地,我们上传的源码包和个人修改也会被要求用该密钥来生成包含数字签名的包。
  
Signing. Once we have tested that our rules file works, we are ready to send the upstream sources and our changes to Launchpad. The program debuild generates a set of files suitable for Launchpad. We specify the key to use when digitally signing the package.
+
==数字签名==
 +
一旦测试过rules文件能正常工作,我们就已经准备好往Launchpad上传上有源码包和我们的修改了。debuild程序会生成一堆适合上传到Launchpad的文件。我们要指定给包数字签名时使用的密钥。
  
 
  $ debuild -S -kFB43CE54
 
  $ debuild -S -kFB43CE54
  dpkg-buildpackage -rfakeroot -d -us -uc -S
+
dpkg-buildpackage -rfakeroot -d -us -uc -S
 
  dpkg-buildpackage: set CFLAGS to default value: -g -O2
 
  dpkg-buildpackage: set CFLAGS to default value: -g -O2
 
  dpkg-buildpackage: set CPPFLAGS to default value:
 
  dpkg-buildpackage: set CPPFLAGS to default value:
第392行: 第371行:
 
  Finished running lintian.
 
  Finished running lintian.
 
  Now signing changes and any dsc files...
 
  Now signing changes and any dsc files...
   signfile vob2mpeg_0.0.1-1.dsc FB43CE54
+
   signfile vob2mpeg_0.0.1-1.dsc FB43CE54<br>
 
+
 
  You need a passphrase to unlock the secret key for
 
  You need a passphrase to unlock the secret key for
 
  user: "Lelanthran Krishna Manickum (Final) <[email protected]>"
 
  user: "Lelanthran Krishna Manickum (Final) <[email protected]>"
  1024-bit DSA key, ID FB43CE54, created 2008-10-15
+
  1024-bit DSA key, ID FB43CE54, created 2008-10-15<br><br>
 
+
   signfile vob2mpeg_0.0.1-1_source.changes FB43CE54<br>
 
+
   signfile vob2mpeg_0.0.1-1_source.changes FB43CE54
+
 
+
 
  You need a passphrase to unlock the secret key for
 
  You need a passphrase to unlock the secret key for
 
  user: "Lelanthran Krishna Manickum (Final) <[email protected]>"
 
  user: "Lelanthran Krishna Manickum (Final) <[email protected]>"
  1024-bit DSA key, ID FB43CE54, created 2008-10-15
+
  1024-bit DSA key, ID FB43CE54, created 2008-10-15<br><br>
 
+
 
+
 
  Successfully signed dsc and changes files
 
  Successfully signed dsc and changes files
 
  $ ls -F ..
 
  $ ls -F ..
第414行: 第387行:
 
  $
 
  $
  
Uploading. Now that we have a set of files that are signed with our key, all thats left is to upload those files to Launchpad. A program called dput is used. In order to use it, we need a ~/.dput.cf that specifies the Launchpad account to beused. My ~/.dput.cf file looks like this:
+
==上传==
 +
现在我们已经有了一堆经过数字签名的文件,剩下的就是上传了。这时会用到一个叫dput的软件。要使用dput,首先要编辑文件~/.dput.cf,没有就创建。在这个文件里面定义要上传的Launchpad账号。我的~/.dput.cf文件是这个样子的:
  
 
  $ cat ~/.dput.cf
 
  $ cat ~/.dput.cf
第424行: 第398行:
 
  allow_unsigned_uploads = 0
 
  allow_unsigned_uploads = 0
  
When using dput to upload files to my lmanickum account on Launchpad I will tell dput to use the profile my-ppa, like this:
+
当用dput往我的Launchpad账号lmanickum上上传时,我要告诉dput使用~/.dput.cf里面的my-ppa的资料:
  
 
  $ cd ..
 
  $ cd ..
第445行: 第419行:
 
  $
 
  $
  
PPA. If a problem exists, then Launchpad will notify us via email. Once Launchpad has unarchived our upstream sources, applied our changes, run the build and install targets[7] and created the .deb file, then we should see the package listed in ourPPA, as shown in Figure 1. If there are problems, then they will also be listed there, and clicking on the relevant text will take you to the build log, which will help you identify the problem.
+
==PPA==
 +
如果上传的包有问题,Launchpad会自动发邮件告诉我们。Launchpad会尝试解压我们上传的上游源码包,对解开的上游源码应用我们所作的修改,然后运行建构(build)和安装(install)目标,并生成deb包。一旦顺利打包,就应该能在我们的PPA上看到Launchpad为我们生成的deb包(如图一所示)。如果打包过程有问题,Launchpad会一一列出,点击相关的文本就可以看到编译打包日志(build log),以便帮助我们找到问题所在。
 +
 
 +
=深入阅读=
 +
以下连接对读者或许有所帮助:
 +
 
 +
    *[[http://www.debian.org/devel/|Debian Developers Corner]]
 +
    *[[http://www.debian.org/doc/devel-manuals|Debian Developers Manuals]]
 +
    *[[http://www.ibm.com/developerworks/linux/library/l-debpkg.html|Creating Debian Packages]]
 +
    *[[http://help.launchpad.net|Launchpad Help]]
 +
 
 +
=引用=
 +
 
 +
[1] Entire Ubuntusci Team. Ubuntusci project wiki. 2008.
 +
 
 +
    *http://scubuntu.meraka.org.za/wiki.
 +
 
 +
Figure 1: Launchpad PPA with new package
 +
 
 +
Figure 1: Launchpad PPA with new package
 +
 
 +
=脚注=
 +
 
 +
1 Personal Package Archive.
 +
 
 +
2 注意目录名称格式是这样的:<应用程序名称>-<版本号>。把目录名称写成这个样子不是偶然的,所以在你移植打包软件的时候,你必须确保所有软件源码目录都是这样写的。
 +
 
 +
3 In addition, these pitfalls are so numerous and varied that it quite concievable that an entire book can be written in the area of software porting: a mere report such as this cannot even begin to cover even only the most common obstacles to porting.
 +
 
 +
4 The official collaborative development tool of the Ubuntu package developers.
 +
 
 +
5 Hence no compilation problems should exist and porting problems should be minimal.
 +
 
 +
6 Taken from the environment variable EDITOR.
 +
 
 +
7 Strictly speaking, Launchpad will run only the target binary-arch. The other targets are all dependencies.

2010年10月27日 (三) 01:26的最新版本


Debian/Ubuntu打包入门

Lelanthran K. Manickum

2009年1月13日

前言

在Ubuntusci [1]的一部分努力之下,许多没有被Ubuntu软件仓库收录的软件包被添加到了仓库中。把其他类UNIX系统上的软件(或者其他Linux发行版上的软件)移植到Ubuntu Linux中是一件复杂的事情,需要的时间和努力会比预期更多。

不考虑Ubuntu软件仓库,任何已经出现在Debian软件仓库中至少4至5年的软件都将可能成为我们移植打包工作可能面临的困难。这还是个保守的假设。如果仅仅只是将源代码拷贝过来,简单地为Ubuntu(或者Debian)编译一下就可以,相信很多人早就做过了。那些特定的、一直以来没有人移植打包的软件主要是因为他们在Debian/Ubuntu上不能完美编译。

这份文档针对那些从未试过给Debian/Ubuntu制作软件包的读者。因为我们发现,即使软件编译和运行无错,打包的实际过程仍然可能会让人感到困惑。希望随着项目的推进,社区把更多的精力花费在软件包检查上,使我们制作的软件包质量过硬。

工具

Ubuntu/Debian的开发新手经常会对“source”这个词感到困惑。“Source-code”通常指某个程序(program),或者某个应用(application),或者软件包的源代码。当我们说“Sources”的时候,指的是用于构建软件包的文件。例如,软件包“Foo”的“source-code”(源代码)是一个或者一堆文本文件,通过GCC编译连接之后可以产生二进制可执行文件;而我们所说的“Foo”软件包的“sources”,指的是所有用于构建Foo.deb这个debian包的文件,其中包括源代码文件。

构建deb软件包的基本过程如下:

   * 下载软件的源码包;
   * 把源码包解压缩到某个目录;
   * 在源码目录内创建debian化目录 (./debian).
   * 修改./debian目录内的文件,如包维护者的详细信息、包描述,等等;
   * 在本机编译源代码;
   * 在本机生成.deb包;
   * 把经过我们修改后能成功编译生成deb包的sources上传到Launchpad PPA[1]。 

当软件成功地上传到Launchpad,并在Launchpad上成功编译生成deb包后,我们的工作就基本上完成了。我们的Launchpad PPA源地址可以分享给其他想使用我们的deb包的人。我们甚至可以申请把我们的deb包移入Ubuntu的官方主软件仓库中。

这过程中需要用到的工具至少有:

   * 浏览器,或者类似的软件——用于下载软件的源代码包;
   * 解压缩软件——用于解压下载回来的源代码包;
   * dh_make(dh-make包的一部分)——用于自动创建./debian目录和其他用于创建.deb包的骨架模板文件;
   * make(Gnu make)——构建过程中要用到的工具;
   * debchange/dch(devscripts包的一部分)——用于编辑包的版本号;
   * debuild(devscripts包的一部分)——运行构建过程,包括编译连接,以及生成deb包;
   * fakeroot(fakeroot包的一部分)——这个东西是必须的;
   * dput——上传经过签名的deb文件。

建议所有打包工作都在较新的Ubuntu系统下进行,这样可以大大方便和简化整个过程。

引入异种包(Alien Packages)

异种包(Alien Packages)是针对其他系统的软件包。例如针对Red Hat系统的软件包,是RPM格式的。比起那些还未打包过的软件来,将这些软件移植到Ubuntu系统相对比较容易,因为所有的包依赖、运行时依赖、编译时依赖等,都是已知的。

软件包alien(软件仓库中有)能够自动地将其他二进制异种包转换成.deb包。不过,这种转换仅仅只限于二进制包。理想的deb包构应该从源代码开始,所有用于构建deb包的源文件(sources)都应该是源代码(source-code)。

编译专门针对类Unix系统的源码包

下载源代码后,将其解压到一个目录中,给该源代码目录起个适合的名字,例如“Foo-1.2.3”[2]。

在终端中,cd进刚才所说的那个源代码目录,执行dh_make,生成打包需要用到的文件,包括一些控制文件(control files)和编译规则文件(rules文件,自动生成的rules文件使用了默认规则)。

大多数包含autoconf工具生成的configure脚本的unix软件源码包都几乎不用其他更深入的工作即可干净地构建。然而有少数源码包里面可能没有configure脚本文件,这需要修改才能工作。由于移植工作固有的缺陷,以及其他不同的平台的软件多种多样[3],我将只涉及将一个可完全正常工作的应用程序源码包在Launchpad打包的问题[4]。

从可正常工作的源码(Working Sources)构建Ubuntu软件包

我假设读者已经下载了一个应用程序的源代码,并希望将该应用程序构建成一个Debian包。在我的例子中,我写了一个基于脚本的独立应用程序,以及安装、卸载程序,它应该能在大多数Linux发行版上运行[5]。

下载源码包

我们可以从sourceforge下载下面例子中用到的vob2mpeg版本。用下面的命令取得所使用的应用程序的确切版本。

$ svn co https://vob2mpeg.svn.sourceforge.net/svnroot/vob2mpeg/tags/vob2mpeg-0.0.1
A    vob2mpeg-0.0.1/vob2mpeg.profile
A    vob2mpeg-0.0.1/uninstall-vob2mpeg.sh
A    vob2mpeg-0.0.1/vob2mpeg
A    vob2mpeg-0.0.1/LICENCE
A    vob2mpeg-0.0.1/VERSION
A    vob2mpeg-0.0.1/CHANGELOG
A    vob2mpeg-0.0.1/vob2mpeg-install.conf
A    vob2mpeg-0.0.1/CREDITS
A    vob2mpeg-0.0.1/README
A    vob2mpeg-0.0.1/install-vob2mpeg.sh
Checked out revision 7.

此时不需要解压,因为我们取回的上游源代码是未压缩的。同样,源码目录页无需重新命名,它已经是适合的名字了:vob2mpeg-0.0.1。我们需要做的是,创建一个原始上游源代码的压缩包,以便我们对程序源代码所做的任何修改都能记录下来并跟未作修改的原始上游源代码作比较。

创建Debian控制文件

令人高兴的是,dh_make能用--create-orig标志创建原始上游压缩包。同时dh_make还生成所有其他用于构建deb包所需的所有控制文件:

$ cd vob2mpeg-0.0.1/
$ ls -F
CHANGELOG             README                  vob2mpeg-install.conf
CREDITS               uninstall-vob2mpeg.sh* vob2mpeg.profile
install-vob2mpeg.sh* VERSION
LICENCE               vob2mpeg*
$ dh_make --createorig --copyright GPL --email [email protected] --single
Maintainer name : Lelanthran Krishna Manickum
Email-Address   : [email protected]
Date            : Mon, 12 Jan 2009 22:42:04 +0200
Package Name    : vob2mpeg
Version         : 0.0.1
License         : gpl
Type of Package : Single
Hit <enter> to confirm:
Currently there is no top level Makefile. This may require additional tuning.
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the vob2mpeg Makefiles install into $DESTDIR and not in / .
$ ls -F
CHANGELOG install-vob2mpeg.sh* uninstall-vob2mpeg.sh* vob2mpeg-install.conf
CREDITS    LICENCE                VERSION                vob2mpeg.profile
debian/    README                 vob2mpeg*
$ ls -F debian/
changelog emacsen-install.ex manpage.xml.ex rules*
compat     emacsen-remove.ex    menu.ex        vob2mpeg-default.ex
control    emacsen-startup.ex postinst.ex      vob2mpeg.doc-base.EX
copyright init.d.ex             postrm.ex      watch.ex
cron.d.ex init.d.lsb.ex         preinst.ex
dirs       manpage.1.ex         prerm.ex
docs       manpage.sgml.ex      README.Debian

可以看到,“debian”目录已经生成。这个目录里面包含所有Debian建包工具创建deb包所需的信息,包括用于编译应用程序自身的构建指令。这些指令是一种解释程序,无需编译任何实际的源代码。

修改控制文件

在我们继续深入之前,debian目录下的文件要作一些修改。首先,必须编辑控制文件,使之反映正确的信息。这样的编辑,结果如下:

$ cat debian/control
Source: vob2mpeg
Section: unknown
Priority: extra
Maintainer: Lelanthran Krishna Manickum <[email protected]>
Build-Depends: debhelper (>= 5)
Standards-Version: 3.7.2
Package: vob2mpeg Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: <insert up to 60 chars description> <insert long description, indented with spaces> $ vi debian/control $ cat debian/control Source: vob2mpeg Section: graphics Priority: extra Maintainer: Lelanthran Krishna Manickum <[email protected]> Build-Depends: debhelper (>= 5) Standards-Version: 3.7.2 Package: vob2mpeg Architecture: any Depends: ffmpeg, tcl, tk Homepage: http://vob2mpeg.sourceforge.net/ Description: GUI app to convert VOB files to MPEG files A GUI wrapper to convert VOB files to MPEG files using ffmpeg. Allows user to change certain attributes of the movies in the conversion, such as scale, colour (hue, etc), etc. Can be also totally controlled from the command line enabling batch use. $

最后,在这个简单的打包练习例子中,所有debian目录下的的样板文件(*.[Ee][Xx])都是非必须的——这些文件只不过是例子罢了,故此我们将其删除。

$ rm debian/*.[Ee][Xx]

修改规则文件

在我们继续尝试创建Debian的软件包之前,还要修改规则文件。debian/rules文件是一个Makefile文件,make将执行它来编译构建程序。在这里,由于我们什么也不编译,这个文件将被削减到仅仅只包含创建一个软件分发所需要的内容。这个应用程序(vob2mpeg)有一个安装(和卸载)脚本必须被执行。例如,vob2mpeg通过执行一个包含可选的配置文件并可指定安装位置的安装脚本,这样安装在Linux系统里面。由于我们希望所有的文件安装到./debian/vob2mpeg,我们从上游源文件提供的例子文件来创建一个配置文件。

$ cp vob2mpeg-install.conf debian/
$ cat debian/vob2mpeg-install.conf
#
# Installation settings for vob2mpeg installation script
# Store variables in this file so that porting to different
# packaging systems becomes trivial and not hellish
#
# Variables in this file are never over-ridden, uncomment
# the lines below and replace with your own settings
#
export DEST_ETC=/tmp/test/etc
export DEST_BIN=/tmp/test/usr/bin
export DEST_DOC=/tmp/test/usr/share/doc/vob2mpeg
# The files to actually install, please do not change this export ETC_FILES="vob2mpeg.profile $CONF_FILE" export DOC_FILES="README CREDITS LICENCE VERSION CHANGELOG" export BIN_FILES="vob2mpeg install-vob2mpeg.sh uninstall-vob2mpeg.sh" # $ vi debian/vob2mpeg-install.conf $ cat debian/vob2mpeg-install.conf # # Installation settings for vob2mpeg installation script # Store variables in this file so that porting to different # packaging systems becomes trivial and not hellish # # Variables in this file are never over-ridden, uncomment # the lines below and replace with your own settings # export DEST_ETC=debian/vob2mpeg/etc export DEST_BIN=debian/vob2mpeg/usr/bin export DEST_DOC=debian/vob2mpeg/usr/share/doc/vob2mpeg
# The files to actually install, please do not change this export ETC_FILES="vob2mpeg.profile $CONF_FILE" export DOC_FILES="README CREDITS LICENCE VERSION CHANGELOG" export BIN_FILES="vob2mpeg install-vob2mpeg.sh uninstall-vob2mpeg.sh" # $

因此,我们确保当运行vob2mpeg安装脚本时,它会自行安装到./debian/vob2mpeg。然后,我们可以从该目录中的文件创建deb包。现在我们修改规则文件来告诉它如何建立包文件(会被安装的文件)。因为我们将只修改构建(build)、安装(install)和清理(clean)的目标,我将把该文件的其余部分<...喀嚓...>掉。

$ cat debian/rules
#!/usr/bin/make -f
<...喀嚓...>
build-stamp: configure-stamp
        dh_testdir
# Add here commands to compile the package. $(MAKE) #docbook-to-man debian/vob2mpeg.sgml > vob2mpeg.1
touch $@
clean: dh_testdir dh_testroot rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process. -$(MAKE) clean
dh_clean
install: build dh_testdir dh_testroot dh_clean -k dh_installdirs
# Add here commands to install the package into debian/vob2mpeg. $(MAKE) DESTDIR=$(CURDIR)/debian/vob2mpeg install <...喀嚓...> $ vi debian/rules $ cat debian/rules #!/usr/bin/make -f <...喀嚓...> build-stamp: configure-stamp dh_testdir
# Add here commands to compile the package.
#docbook-to-man debian/vob2mpeg.sgml > vob2mpeg.1
touch $@
clean: dh_testdir dh_testroot rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process. rm -rf ./debian/vob2mpeg
dh_clean
install: build dh_testdir dh_testroot dh_clean -k dh_installdirs
# Add here commands to install the package into debian/vob2mpeg. ./install-vob2mpeg.sh ./debian/vob2mpeg-install.conf <...喀嚓...> $

只有执行编译、文件安装、移除动作相关的行被修改,因此建构(build)、安装(install)和清理(clean)目标被改成不编译(因为在我们这个例子中什么也不用编译)。安装(install)目标仅仅只是调用安装程序把文件复制安装到debian/vob2mpeg目录内,而清理(clean)目标则负责移除上述目录。

注意我们略掉了在debian目录下提供preinst和postinst脚本。如果提供了这些脚本,那么他们会分别在安装deb包之前,或者卸载deb包之后被执行。我们这个例子中的软件无需在安装前执行什么动作,卸载后动作也一样不需要。

打包

现在我们已经完成了所有想作的修改,就等着发出建立deb包文件的命令了。不过,在打包之前,我们还需要核实一下Debian版本号,确保它能在新建的deb文件中反映出来。不要混淆Debian版本号和应用程序的版本号。Debian版本号是我们deb包的版本号,如对于Foo这个软件我们可能会想给它的版本号为1的版本建包。也就是说,我们用于打包的程序源代码目录为Foo-1.0.0。给Foo打包后,我们指定改包的版本号为0.0.1。

现在让我们假设在打包过程中发生了小错误,例如,我们可能在编译Foo的时候使用了某个编译标志(flag)使得制作出来的deb包在lpia架构下会安装运行会出现问题。有用户反馈了错误报告,我们很快修复了这个问题。这时我们需要重新给相同的软件版本打包,制作出了版本号为0.0.2的deb包,而该包软件版本仍然是Foo-1.0.0。

更新版本号。这时我们会用到一个叫dch的工具,它可以自动管理包的版本号。不带任何命令行参数的形式调用dch,会使包的小版本号(minor version number)自动增加,而带 -i 参数(dch -i)方式调用,则使主版本号(major version number)增加。

第一次运行dch后,会打开一个编辑器,里面出现如下这样的内容:

vob2mpeg (0.0.1-1) unstable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP> *
-- Lelanthran Krishna Manickum <lmanickum@esprit> Mon, 12 Jan 2009 23:39:19 +0200

我们直接在编辑器中修改,把上面的unstable更改成实际的Debian或Ubuntu版本名称(在这个例子中,我把unstable改成intrepid,因为我使用的Debian版本名是Intrepid)(译者注:你的可能是Hardy、Lucid、Marverik,或者其他)。每个注释都应遵循给定的惯例格式,以星号开始,没行对准上一行的缩进。更改后的文件看起来像这个样子:

vob2mpeg (0.0.1-1) intrepid; urgency=low
* Initial release * Edited rules and removed build instructions * Edited rules and replaced command for installation * Edited rules and replaced command for target ’clean’
-- Lelanthran Krishna Manickum <lmanickum@esprit> Mon, 12 Jan 2009 23:39:19 +0200

现在我们就可以开始运行debian/rules脚本来建立deb包了:

$ fakeroot debian/rules binary-arch
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/vob2mpeg.
./install-vob2mpeg.sh ./debian/vob2mpeg-install.conf
Found installation configuration in ./debian/vob2mpeg-install.conf
-----------./debian/vob2mpeg-install.conf--------------
DEST_ETC is already set to debian/vob2mpeg/etc
DEST_BIN is already set to debian/vob2mpeg/usr/bin
DEST_DOC is already set to debian/vob2mpeg/usr/share/doc/vob2mpeg
ETC_FILES is already set to vob2mpeg.profile ./debian/vob2mpeg-install.conf
DOC_FILES is already set to README CREDITS LICENCE VERSION CHANGELOG
BIN_FILES is already set to vob2mpeg install-vob2mpeg.sh uninstall-vob2mpeg.sh
install: creating directory ‘debian/vob2mpeg/etc’
install: creating directory ‘debian/vob2mpeg/usr/share’
install: creating directory ‘debian/vob2mpeg/usr/share/doc’
install: creating directory ‘debian/vob2mpeg/usr/share/doc/vob2mpeg’
‘vob2mpeg.profile’ -> ‘debian/vob2mpeg/etc/vob2mpeg.profile’
‘./debian/vob2mpeg-install.conf’ -> ‘debian/vob2mpeg/etc/vob2mpeg-install.conf’
‘README’ -> ‘debian/vob2mpeg/usr/share/doc/vob2mpeg/README’
‘CREDITS’ -> ‘debian/vob2mpeg/usr/share/doc/vob2mpeg/CREDITS’
‘LICENCE’ -> ‘debian/vob2mpeg/usr/share/doc/vob2mpeg/LICENCE’
‘VERSION’ -> ‘debian/vob2mpeg/usr/share/doc/vob2mpeg/VERSION’
‘CHANGELOG’ -> ‘debian/vob2mpeg/usr/share/doc/vob2mpeg/CHANGELOG’
‘vob2mpeg’ -> ‘debian/vob2mpeg/usr/bin/vob2mpeg’
‘install-vob2mpeg.sh’ -> ‘debian/vob2mpeg/usr/bin/install-vob2mpeg.sh’
‘uninstall-vob2mpeg.sh’ -> ‘debian/vob2mpeg/usr/bin/uninstall-vob2mpeg.sh’
dh_testdir
dh_testroot
dh_installchangelogs CHANGELOG
dh_installdocs
dh_installexamples
dh_installman
dh_link
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_shlibdeps
dh_gencontrol
dpkg-gencontrol: warning: unknown substitution variable ${shlibs:Depends}
dpkg-gencontrol: warning: unknown substitution variable ${misc:Depends}
dh_md5sums
dh_builddeb
dpkg-deb: building package ‘vob2mpeg’ in ‘../vob2mpeg_0.0.1-1_i386.deb’.
$

开始它按照我们的设定建立debian/vob2mpeg目录树,把包内容拷贝(安装)到该目录里面,然后读取控制文件(debian/control),将该目录树中的内容打包成 ../vob2mpeg_0.0.1-1_i386.deb,这就是我们最终得到的deb包。如果我们打deb包只是给自己用,那么工作可以到此结束。如果我们想透过诸如Launchpad PPA这样的方式发布我们制作的deb包,我们就必须对我们的deb包用Launchpad密钥签名。

上传并发布软件包

Launchpad为我们提供了一个非常方便的个人软件包发布方式。我们只需要简单地吧上游源码包和我们对上游源码包所作的修改一同上传到Launchpad,然后Launchpad就会自动为我们生成deb包。这将确保我们的deb软件包不仅仅只是在我们自己的本地计算机上生成;在若干不同的Launchpad远程虚拟机上,我们也可以检查看看能否正确打包。

最开始要做的,当然是要有一个Launchpad账号,如果没有的话,就注册一个。只要注册了Launchpad账号,就能分配到一个自己的PPA(Personal Package Archive)。我们往Launchpad上传的所有软件包都会进入自己的PPA。我们的PPA地址可以直接写到任何source.list文件中,这样用户只需要按照平常那样apt-get或者用synaptic就可以安装我们的包了。

怎样一步步注册Launchpad账号超出了本报告讲述的范围。不过Launchpad的本身有全面的说明和帮助——参看https://launchpad.net 。创建Launchpad帐户的过程中有些步骤要求用户生成一个加密密钥,并使用这个密钥进行数字签名。同样地,我们上传的源码包和个人修改也会被要求用该密钥来生成包含数字签名的包。

数字签名

一旦测试过rules文件能正常工作,我们就已经准备好往Launchpad上传上有源码包和我们的修改了。debuild程序会生成一堆适合上传到Launchpad的文件。我们要指定给包数字签名时使用的密钥。

$ debuild -S -kFB43CE54
dpkg-buildpackage -rfakeroot -d -us -uc -S
dpkg-buildpackage: set CFLAGS to default value: -g -O2
dpkg-buildpackage: set CPPFLAGS to default value:
dpkg-buildpackage: set LDFLAGS to default value: -Wl,-Bsymbolic-functions
dpkg-buildpackage: set FFLAGS to default value: -g -O2
dpkg-buildpackage: set CXXFLAGS to default value: -g -O2
dpkg-buildpackage: source package vob2mpeg
dpkg-buildpackage: source version 0.0.1-1
dpkg-buildpackage: source changed by Lelanthran Krishna Manickum <lmanickum@esprit>
 fakeroot debian/rules clean
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process.
rm -rf ./debian/vob2mpeg
dh_clean
 dpkg-source -b vob2mpeg-0.0.1
dpkg-source: info: using source format ‘1.0’
dpkg-source: info: building vob2mpeg using existing vob2mpeg_0.0.1.orig.tar.gz
dpkg-source: info: building vob2mpeg in vob2mpeg_0.0.1-1.diff.gz
dpkg-source: info: building vob2mpeg in vob2mpeg_0.0.1-1.dsc
 dpkg-genchanges -S >../vob2mpeg_0.0.1-1_source.changes
dpkg-genchanges: including full source code in upload
dpkg-buildpackage: source only upload (original source is included)
Now running lintian...
E: vob2mpeg_0.0.1-1_source.changes: bad-distribution-in-changes-file intrepid
W: vob2mpeg source: out-of-date-standards-version 3.7.2 (current is 3.8.0)
W: vob2mpeg source: changelog-should-mention-nmu
W: vob2mpeg source: source-nmu-has-incorrect-version-number 0.0.1-1
Finished running lintian.
Now signing changes and any dsc files...
 signfile vob2mpeg_0.0.1-1.dsc FB43CE54
You need a passphrase to unlock the secret key for user: "Lelanthran Krishna Manickum (Final) <[email protected]>" 1024-bit DSA key, ID FB43CE54, created 2008-10-15

signfile vob2mpeg_0.0.1-1_source.changes FB43CE54
You need a passphrase to unlock the secret key for user: "Lelanthran Krishna Manickum (Final) <[email protected]>" 1024-bit DSA key, ID FB43CE54, created 2008-10-15

Successfully signed dsc and changes files $ ls -F .. vob2mpeg-0.0.1/ vob2mpeg_0.0.1-1_source.build vob2mpeg_0.0.1-1.diff.gz vob2mpeg_0.0.1-1_source.changes vob2mpeg_0.0.1-1.dsc vob2mpeg_0.0.1.orig.tar.gz vob2mpeg_0.0.1-1_i386.deb $

上传

现在我们已经有了一堆经过数字签名的文件,剩下的就是上传了。这时会用到一个叫dput的软件。要使用dput,首先要编辑文件~/.dput.cf,没有就创建。在这个文件里面定义要上传的Launchpad账号。我的~/.dput.cf文件是这个样子的:

$ cat ~/.dput.cf
[my-ppa]
fqdn = ppa.launchpad.net
method = ftp
incoming = ~lmanickum/ubuntu/
login = anonymous
allow_unsigned_uploads = 0

当用dput往我的Launchpad账号lmanickum上上传时,我要告诉dput使用~/.dput.cf里面的my-ppa的资料:

$ cd ..
$ dput my-ppa vob2mpeg_0.0.1-1_source.changes
Checking Signature on .changes
gpg: Signature made Tue 13 Jan 2009 08:13:33 SAST using DSA key ID FB43CE54
gpg: Good signature from "Lelanthran Krishna Manickum (Final) <[email protected]>"
Good signature on /home/lelanthran/pack/vob2mpeg_0.0.1-1_source.changes.
Checking Signature on .dsc
gpg: Signature made Tue 13 Jan 2009 08:13:23 SAST using DSA key ID FB43CE54
gpg: Good signature from "Lelanthran Krishna Manickum (Final) <[email protected]>"
Good signature on /home/lelanthran/pack/vob2mpeg_0.0.1-1.dsc.
Uploading to my-ppa (via ftp to ppa.launchpad.net):
  vob2mpeg_0.0.1-1.dsc: done.
  vob2mpeg_0.0.1.orig.tar.gz: done.
  vob2mpeg_0.0.1-1.diff.gz: done.
  vob2mpeg_0.0.1-1_source.changes: done.
Successfully uploaded packages.
Not running dinstall.
$

PPA

如果上传的包有问题,Launchpad会自动发邮件告诉我们。Launchpad会尝试解压我们上传的上游源码包,对解开的上游源码应用我们所作的修改,然后运行建构(build)和安装(install)目标,并生成deb包。一旦顺利打包,就应该能在我们的PPA上看到Launchpad为我们生成的deb包(如图一所示)。如果打包过程有问题,Launchpad会一一列出,点击相关的文本就可以看到编译打包日志(build log),以便帮助我们找到问题所在。

深入阅读

以下连接对读者或许有所帮助:

   *[Developers Corner]
   *[Developers Manuals]
   *[Debian Packages]
   *[Help]

引用

[1] Entire Ubuntusci Team. Ubuntusci project wiki. 2008.

   *http://scubuntu.meraka.org.za/wiki. 

Figure 1: Launchpad PPA with new package

Figure 1: Launchpad PPA with new package

脚注

1 Personal Package Archive.

2 注意目录名称格式是这样的:<应用程序名称>-<版本号>。把目录名称写成这个样子不是偶然的,所以在你移植打包软件的时候,你必须确保所有软件源码目录都是这样写的。

3 In addition, these pitfalls are so numerous and varied that it quite concievable that an entire book can be written in the area of software porting: a mere report such as this cannot even begin to cover even only the most common obstacles to porting.

4 The official collaborative development tool of the Ubuntu package developers.

5 Hence no compilation problems should exist and porting problems should be minimal.

6 Taken from the environment variable EDITOR.

7 Strictly speaking, Launchpad will run only the target binary-arch. The other targets are all dependencies.