免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 882 | 回复: 0
打印 上一主题 下一主题

如何制作deb包 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-13 10:10 |只看该作者 |倒序浏览
下面用一个简单的程序例子,来讲解如何制作deb包。首先你需要一个deb包管理的系统,debian, ubuntu等。
这里我用的是
nexenta
. 这些系统默认装好了deb包制作需要的工具,如dpkg-dev, devscripts等。如果没有,你也可以在制作过程中用apt-get install 来手动安装。
1. 创建一个简单的源码包
aubrey@aubrey-nexenta:~/deb$ ls -l hellodeb/
total 2
-rw-r--r-- 1 aubrey staff 203 Feb 16 12:50 Makefile
-rw-r--r-- 1 aubrey staff  73 Feb 16 12:46 hellodeb.cC code与制作deb包关系不大,也不需要修改,我们主要看一下Makefile文件,我们在制作deb包的时候,这个文件是需要修改的。
PROG=hellodeb
CC=gcc
BINDIR=/usr/bin
INSTALL=cp
$(PROG): hellodeb.c
        $(CC) -o $(PROG) hellodeb.c
clean:
        rm -rf $(PROG)
install:
        $(INSTALL) $(PROG) $(BINDIR)
uninstall:
        rm -rf $(BINDIR)/$(PROG)2. 创建GPG key。GPG key在build包的时候需要用到,创建的方法参见
GPG使用指南
。创建完后,检查一下:
aubrey@aubrey-nexenta:~/deb/hellodeb$ gpg --list-keys
/export/home/aubrey/.gnupg/pubring.gpg
--------------------------------------
pub   1024D/7F8F1E57 2008-01-29
uid                  Aubrey Li
sub   2048g/6AF6581E 2008-01-29
3. 要开始对这个包进行deb化了。首先确保源代码目录绝对干净,为了让软件包能够正确地制作,必须把源代码目录的名字改成小写,并且符合-的形式。
aubrey@aubrey-nexenta:~/deb$ ls
hellodeb
aubrey@aubrey-nexenta:~/deb$ mv hellodeb/ hellodeb-1.0
aubrey@aubrey-nexenta:~/deb$ ls
hellodeb-1.04. 在正式deb化之前,我们先要export两个环境变量:
aubrey@aubrey-nexenta:~/deb$ export DEBEMAIL="aubreylee@gmail.com"
aubrey@aubrey-nexenta:~/deb$ export DEBFULLNAME="Aubrey Li"注意,这里的name和email必须和你生成GPG钥匙的时候完全一样。这两个变量值也会在deb包的changelog等多个文件里被用到。
5. 现在可以对源码包进行deb化了。
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$ dh_make
Type of package: single binary, multiple binary, library, kernel module or cdbs?
[s/m/l/k/b] s
Maintainer name : Aubrey Li
Email-Address   : aubreylee@gmail.com
Date            : Sat, 16 Feb 2008 13:19:46 +0800
Package Name    : hellodeb
Version         : 1.0
License         : blank
Type of Package : Single
Hit  to confirm:
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the hellodeb Makefiles install into $DESTDIR and not in / .
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$
这里询问包的类型,这里我们是单个可执行文件,所以我选了s。
还有两个重要的提示:
    Please edit the files in the debian/ subdirectory now.You should also check that the hellodeb Makefiles install into $DESTDIR and not in / .
6. 我们先关注一下第二个提示,修改Makefile。这里主要是安装路径,修改如下:
PROG=hellodeb
CC=gcc
BINDIR=$(DESTDIR)/usr/bin
INSTALL=cp
$(PROG): hellodeb.c
        $(CC) -o $(PROG) hellodeb.c
clean:
        rm -rf $(PROG)
install:
        mkdir -p $(BINDIR)
        $(INSTALL) $(PROG) $(BINDIR)
uninstall:
        rm -rf $(BINDIR)/$(PROG)第一个修改是为了在build包的时候能够把需要的文件安装到正确的目录,从而正确的包含在生成的deb包中。
第二个修改是因为修改后的BINDIR变量的目录并不存在,所以需要手动创建。
7. 然后我们要看一下debian这个生成的目录了
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0/debian$ ls
README.Debian  control    docs                hellodeb-default.ex   manpage.sgml.ex  postrm.ex   watch.ex
changelog      copyright  emacsen-install.ex  hellodeb.doc-base.EX  manpage.xml.ex   preinst.ex
compat         cron.d.ex  emacsen-remove.ex   init.d.ex             menu.ex          prerm.ex
conffiles.ex   dirs       emacsen-startup.ex  manpage.1.ex          postinst.ex      rules这个目录下面的文件很多,不能一一解释。这里列举几个重要的,也是绝大部分软件必须的:
  • control文件: 声明很多重要的变量,dpkg通过这些变量来管理软件包
  • copyright文件: 不用说,版权信息,相当重要
  • changelog文件: 这是一个必需文件,包含软件版本号,修订号,发行版和优先级。
  • rules文件: 这实际上是另外一个Makefile脚本,用来给dpkg-buildpackage用的.
  • compat文件: 这个文件留着是有用的
  • dirs文件:这个文件指出我们需要的但是在缺省情况下不会自动创建的目录
我删除掉其他文件,debian目录现在如下:
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0/debian$ ls
changelog  compat  control  copyright  dirs  rules注意,除了compat文件,其他文件都是需要修改的,根据你自己的软件包的情况。
8. 好了,所有的准备工作都就绪了。我们可以build软件包。dpkg-buildpackage有一项dh_testroot的检查,你必须用root来运行这个命令,或者用fakeroot(需要安装fakeroot包)
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$ dpkg-buildpackage -rfakeroot -sa或者切换到root,注意,你要确保你保持切换后仍旧保持当前用户的路径,否则在build包的时候会找不到GPG key。
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$ sudo -s
Password:
root@aubrey-nexenta:~/deb/hellodeb-1.0# dpkg-buildpackage -sabuild过程中需要输入GPG密匙的密码,两次,其他就没什么事情可做了。
9. 创建完成后,在该目录的上级目录应该得到如下几个文件:
  • hellodeb_1.0-1.tar.gz: 源码包
  • hellodeb_1.0-1.dsc: 源代码总结,根据control文件创建,包含GPG签名
  • hellodeb_1.0-1_solaris-i386.deb: 完整的二进制包,可用dpkg管理
  • hellodeb_1.0-1_solaris-i386.changes: 供dput使用
10. 最后作一下检查和安装工作.
root@aubrey-nexenta:~/deb# dpkg-deb -c hellodeb_1.0-1_solaris-i386.deb
drwxr-xr-x root/root         0 2008-02-16 13:56:12 ./
drwxr-xr-x root/root         0 2008-02-16 13:56:10 ./usr/
drwxr-xr-x root/root         0 2008-02-16 13:56:10 ./usr/share/
drwxr-xr-x root/root         0 2008-02-16 13:56:10 ./usr/share/doc/
drwxr-xr-x root/root         0 2008-02-16 13:56:12 ./usr/share/doc/hellodeb/
-rw-r--r-- root/root       246 2008-02-16 13:19:48 ./usr/share/doc/hellodeb/copyright
-rw-r--r-- root/root       191 2008-02-16 13:19:48 ./usr/share/doc/hellodeb/changelog.Debian.gz
drwxr-xr-x root/root         0 2008-02-16 13:56:11 ./usr/bin/
-rwxr-xr-x root/root      3436 2008-02-16 13:56:11 ./usr/bin/hellodeb
root@aubrey-nexenta:~/deb# dpkg -i hellodeb_1.0-1_solaris-i386.deb
Selecting previously deselected package hellodeb.
(Reading database ... 31630 files and directories currently installed.)
Unpacking hellodeb (from hellodeb_1.0-1_solaris-i386.deb) ...
Setting up hellodeb (1.0-1) ...
root@aubrey-nexenta:~/deb# which hellodeb
/usr/bin/hellodeb
root@aubrey-nexenta:~/deb# hellodeb
hello deb
root@aubrey-nexenta:~/deb# dpkg -r hellodeb
(Reading database ... 31632 files and directories currently installed.)
Removing hellodeb ...
root@aubrey-nexenta:~/deb# which hellodeb
root@aubrey-nexenta:~/deb#
if like this that you meet
Could not find hello_1.0.orig.tar.gz
Either specify an alternate file to use with -f,
or add --createorig to create one.
do like this :
#dh_make --createorig
all is ok now
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/78998/showart_1411490.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP