Debian打包中的规则文件有什么目的和作用?

我正在尝试使用Netbeans 7.3开发的C++应用程序进行Debian打包。下面是其中的一部分Makefile代码。
APPNAME=remotedevicecontroller
install:
    install config.xml /etc/${APPNAME}.conf.xml
    install devices.rules /etc/udev/rules.d/${APPNAME}.rules
    install error.log /var/log/${APPNAME}.log
    install init.conf /etc/init/${APPNAME}.conf
    install init.d /etc/init.d/${APPNAME}
    install ${CND_ARTIFACT_NAME_${CONF}} /usr/local/bin/${APPNAME}
    chmod u+x ${CND_ARTIFACT_NAME_${CONF}}
    ./${CND_ARTIFACT_NAME_${CONF}} -i

我正在按照如何创建一个.deb软件包Debian新维护者指南进行操作。在成功完成上述所有步骤后,当我运行dpkg-buildpackage -rfakeroot时,遇到了以下错误。
$ dpkg-buildpackage -rfakeroot
dpkg-buildpackage: source package remotedevicecontroller
dpkg-buildpackage: source version 1.0-1
dpkg-buildpackage: source changed by satya gowtham kudupudi (gowtham) <gowthamk@newmeksolutions.com>
dpkg-buildpackage: host architecture i386
 dpkg-source --before-build remotedevicecontroller-1.0
 fakeroot debian/rules clean
dh clean
dh: No packages to build.
 dpkg-source -b remotedevicecontroller-1.0
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building remotedevicecontroller using existing ./remotedevicecontroller_1.0.orig.tar.gz
dpkg-source: info: building remotedevicecontroller in remotedevicecontroller_1.0-1.debian.tar.gz
dpkg-source: info: building remotedevicecontroller in remotedevicecontroller_1.0-1.dsc
 debian/rules build
dh build
dh: No packages to build.
 fakeroot debian/rules binary
dh binary
dh: No packages to build.
 signfile remotedevicecontroller_1.0-1.dsc

You need a passphrase to unlock the secret key for
user: "satya gowtham kudupudi (gowtham) <gowthamk@newmeksolutions.com>"
2048-bit RSA key, ID 9A2853A0, created 2013-08-22

gpg: gpg-agent is not available in this session

 dpkg-genchanges  >../remotedevicecontroller_1.0-1_i386.changes
dpkg-genchanges: error: cannot read files list file: No such file or directory
dpkg-buildpackage: error: dpkg-genchanges gave error exit status 2

http://www.debian.org/doc/manuals/maint-guide/dreq.en.html#defaultrules上没有解释rules文件的作用。这个文件是做什么用的?
%:
    dh $@

这是什么意思?为什么在执行dpkg-buildpackage -rfakeroot命令时会显示dh: No packages to build.
2个回答

rules文件是实际创建软件包的关键。它是一个Makefile,其中包含编译和安装应用程序的目标,然后从已安装的文件创建.deb文件。它还有一个目标来清理所有构建文件,以便最终只保留源代码包。正如Debian政策手册所述:

这个文件必须是可执行的Makefile,并包含了编译软件包和从源代码构建二进制软件包的特定于软件包的步骤。

虽然这听起来很不错,但实际上在这里发生了什么呢:
%:
    dh $@

dh 是一个辅助命令,它调用其他 Make 目标并运行一系列的 debhelper 命令。正如 其手册页 Manpage icon 所描述的:

   dh runs a sequence of debhelper commands. The supported sequences
   correspond to the targets of a debian/rules file: build-arch, build-
   indep, build, clean, install-indep, install-arch, install, binary-arch,
   binary-indep, and binary.

再说一遍,这只是一个辅助文件,目的是为了简化事情。你实际上不需要使用它,但使用它会让你的生活变得更加轻松。要查看每个目标实际执行了哪些命令,请运行:
dh binary-arch --no-act

现在来讨论你具体的问题...我不认为这与你的rules文件有任何关系。没有看到实际的源码包,很难确定问题所在。但我敢猜测你的debian/control文件中可能没有二进制软件包stanza部分。在下面的代码片段中,第一个“stanza”描述了源码包,而第二个描述了它将要构建的二进制软件包:

Source: hello
Section: devel
Priority: optional
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
XSBC-Original-Maintainer: Jane Doe <packager@example.com>
Standards-Version: 3.9.1
Build-Depends: debhelper (>= 7)
Homepage: http://www.gnu.org/software/hello/

Package: hello
Architecture: any
Depends: ${shlibs:Depends}
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting. It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them. Seriously, though: this is
 an example of how to do a Debian package. It is the Debian version of
 the GNU Project's `hello world' program (which is itself an example
 for the GNU Project).

$ dh binary-arch --no-act 的输出是 dh: No packages to build. - Necktwi
@neckTwi 包装是在某个版本控制系统中吗? - andrewsomething
抱歉,我犯了一个错误。我没有删除之前试验中创建的“orig”压缩包。但是我遇到了其他问题,已经在这里发布了。 - Necktwi

我在Makefile中犯了一个非常重要的错误,就是没有使用$(DESTDIR)。我将其发布出来,以帮助那些在构建Debian软件包时遇到这个常见错误的人。所以正确的Makefile应该是:
APPNAME=remotedevicecontroller
install:
    install config.xml ${DESTDIR}/etc/${APPNAME}.conf.xml
    install devices.rules ${DESTDIR}/etc/udev/rules.d/${APPNAME}.rules
    install error.log ${DESTDIR}/var/log/${APPNAME}.log
    install init.conf ${DESTDIR}/etc/init/${APPNAME}.conf
    install init.d ${DESTDIR}/etc/init.d/${APPNAME}
    install ${CND_ARTIFACT_NAME_${CONF}} ${DESTDIR}/usr/local/bin/${APPNAME}
    chmod u+x ${CND_ARTIFACT_NAME_${CONF}}
    ./${CND_ARTIFACT_NAME_${CONF}} -i

如果一些“make”目标失败,在“rules”文件中覆盖相应的dh_make目标可能有助于成功打包。
override_dh_auto_test:
%:
    dh clean
    dh binary

我的应用程序中的测试目标出现错误,但这并不重要,所以我已经覆盖了dh_auto_test。
在尝试新的测试之前,请记得清理掉所有由失败尝试留下的跟踪文件。