具有依赖关系的 Debian 打包(从头开始)

具有依赖关系的 Debian 打包(从头开始)

我想将我的软件(C语言)打包成一个.deb文件,但遇到一些困难。如果有人能帮我就好了。

让源代码成为以下玩具示例:

#include <stdio.h>
#include <stdlib.h>
#include <lbfgs.h>

int main(void)
{
    printf("liblbfgs will be used here!\n");
    return 0;
}

在上面的C程序中,库文件将使用库。 liblbfgs 可在存储库中找到。我编写了以下简单的 Makefile:

CXX=gcc
CFLAGS=-Wall -g
LIBS=-lm -llbfgs
OUTPUT=toypackage

$(OUTPUT): $(OUTPUT).o
    $(CXX) -o $(OUTPUT) $(LIBS) $(OUTPUT).o

.PHONY: clean

clean:
    rm -f *~ *.o

synaptic如果我通过/apt-get或手动编译可用源代码并构建上述代码来安装库,则一切正常。但非常希望避免liblbfgs首先安装。出于这个原因,我想将我的软件打包到一个.deb文件中,我应该在其中定义liblbfgs为依赖项。

我创建一个文件夹,例如toypackage_1.0/,在其中存储源代码和 Makefile。然后我将该目录压缩为

tar czvf toypackage_1.0.orig.tar.gz toypackage-1.0/

然后,我运行dh_make如下

$ cd toypackage-1.0/
$ dh_make

Type of package: single binary, indep binary, multiple binary,     library, kernel module, kernel patch?
  [s/i/m/l/k/n] s

  Maintainer name  : geppetto
  Email-Address    : geppetto@phi 
  Date             : Fri, 06 Jun 2014 16:25:22 +0300
  Package Name     : toypackage
  Version          : 1.0
  License          : blank
  Type of Package  : Single
  Hit <enter> to confirm: 
  Skipping creating ../toypackage_1.0.orig.tar.gz because it already exists
  Done. Please edit the files in the debian/ subdirectory now. You should also
  check that the toypackage Makefiles install into $DESTDIR and not in / .

$ debuild

  dpkg-buildpackage -rfakeroot -D -us -uc
  dpkg-buildpackage: source package toypackage
  dpkg-buildpackage: source version 1.0-1
  dpkg-buildpackage: source distribution unstable
  dpkg-buildpackage: source changed by geppetto <geppetto@phi>
  dpkg-source --before-build toypackage-1.0
  dpkg-buildpackage: host architecture amd64
  fakeroot debian/rules clean
  dh clean 
dh_testdir
dh_auto_clean
  make[1]: Entering directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
  rm -f *~ *.o
  make[1]: Leaving directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
dh_clean
  dpkg-source -b toypackage-1.0
  dpkg-source: info: using source format `3.0 (quilt)'
  dpkg-source: info: building toypackage using existing ./toypackage_1.0.orig.tar.gz
  dpkg-source: info: building toypackage in toypackage_1.0-1.debian.tar.xz
  dpkg-source: info: building toypackage in toypackage_1.0-1.dsc
  debian/rules build
  dh build 
dh_testdir
dh_auto_configure
dh_auto_build
  make[1]: Entering directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
  cc -Wall -g -D_FORTIFY_SOURCE=2  -c -o toypackage.o toypackage.c
  gcc -o toypackage -lm -llbfgs toypackage.o
  make[1]: Leaving directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
dh_auto_test
  fakeroot debian/rules binary
  dh binary 
dh_testroot
dh_prep
dh_auto_install
dh_installdocs
dh_installchangelogs
dh_perl
dh_link
dh_compress
dh_fixperms
dh_strip
dh_makeshlibs
dh_shlibdeps
dh_installdeb
dh_gencontrol
  dpkg-gencontrol: warning: Depends field of package toypackage: unknown substitution variable ${shlibs:Depends}
dh_md5sums
dh_builddeb
  dpkg-deb: building package `toypackage' in `../toypackage_1.0-1_amd64.deb'.
  dpkg-genchanges  >../toypackage_1.0-1_amd64.changes
  dpkg-genchanges: including full source code in upload
  dpkg-source --after-build toypackage-1.0
  dpkg-buildpackage: full upload (original source is included)
  Now running lintian...
  E: toypackage changes: changed-by-address-malformed geppetto <geppetto@phi>
  W: toypackage source: dh-make-template-in-source debian/init.d.ex
  W: toypackage source: dh-make-template-in-source debian/manpage.1.ex
  W: toypackage source: dh-make-template-in-source debian/manpage.sgml.ex
  W: toypackage source: dh-make-template-in-source debian/manpage.xml.ex
  W: toypackage source: dh-make-template-in-source debian/menu.ex
  W: toypackage source: dh-make-template-in-source debian/postinst.ex
  W: toypackage source: dh-make-template-in-source debian/postrm.ex
  W: toypackage source: dh-make-template-in-source debian/preinst.ex
  W: toypackage source: dh-make-template-in-source debian/prerm.ex
  W: toypackage source: dh-make-template-in-source debian/toypackage.cron.d.ex
  W: toypackage source: dh-make-template-in-source debian/toypackage.default.ex
  W: toypackage source: dh-make-template-in-source debian/toypackage.doc-base.EX
  W: toypackage source: dh-make-template-in-source debian/watch.ex
  W: toypackage source: package-needs-versioned-debhelper-build-depends 9
  E: toypackage source: maintainer-address-malformed geppetto <geppetto@phi>
  W: toypackage source: superfluous-clutter-in-homepage <insert the upstream URL, if relevant>
  W: toypackage source: bad-homepage <insert the upstream URL, if relevant>
  W: toypackage source: out-of-date-standards-version 3.9.4 (current is 3.9.5)
  W: toypackage: wrong-bug-number-in-closes l3:#nnnn
  E: toypackage: debian-changelog-file-contains-invalid-email-address geppetto@phi
  W: toypackage: new-package-should-close-itp-bug
  E: toypackage: changelog-is-dh_make-template
  E: toypackage: helper-templates-in-copyright
  W: toypackage: copyright-has-url-from-dh_make-boilerplate
  E: toypackage: copyright-contains-dh_make-todo-boilerplate
  W: toypackage: readme-debian-contains-debmake-template
  E: toypackage: description-is-dh_make-template
  E: toypackage: maintainer-address-malformed geppetto <geppetto@phi>
  E: toypackage: section-is-dh_make-template
  W: toypackage: superfluous-clutter-in-homepage <insert the upstream URL, if relevant>
  W: toypackage: bad-homepage <insert the upstream URL, if relevant>
  Finished running lintian.
  Now signing changes and any dsc files...
  signfile toypackage_1.0-1.dsc geppetto <geppetto@phi>
  gpg: skipped "geppetto <geppetto@phi>": secret key not available
  gpg: /tmp/debsign.wQjBHrJP/toypackage_1.0-1.dsc: clearsign failed: secret key not available
  debsign: gpg error occurred!  Aborting....
  debuild: fatal error at line 1283:
  running debsign failed

这似乎有点错误,但如果我

$ cd ..
$ sudo dpkg -i toypackage_1.0-1_amd64.deb

[sudo] password for geppetto: 
Selecting previously unselected package toypackage.
(Reading database ... 426247 files and directories currently installed.)
Preparing to unpack toypackage_1.0-1_amd64.deb ...
Unpacking toypackage (1.0-1) ...
Setting up toypackage (1.0-1) ...

$ cd ./toypackage-1.0/
$ cd ./toypackage

liblbfgs will be used here!

然后我看到代码已正确构建,因为我已经liblbfgs通过apt-get.

这是我的问题:

  • 如果我之前没有安装过怎么办liblbfgs?我应该怎么做才能正确构建我的代码?
  • 对于我的目的来说,什么是有意义的 Makefile?您能否建议我如何更改它$DESTDIR$以便二进制文件存储到/usr/bin/

答案1

  • 如果我之前没有安装 liblbfgs 怎么办?我应该怎么做才能正确构建我的代码?

为了让构建工具注意到这种依赖关系,您需要Build-Dependsdebian/control文件

  • 对于我的目的来说,什么是有意义的 Makefile?您能否建议我如何使用 $DESTDIR$ 更改它,以便将二进制文件存储到 /usr/bin/ ?

Makefile需要有一个install目标,并且需要尊重该目标 $DESTDIR$PREFIX如果你想支持 FreeBSD 之类的东西的话)。一个好的install目标应该是这样的:

PREFIX?=/usr
DESTDIR?=/

install:
    install -m 755 $(OUTPUT) $(DESTDIR)/$(PREFIX)/bin/$(OUTPUT)

请参阅目标目录的部分非常有用的新维护者指南

相关内容