下面用一个简单的程序例子,来讲解如何制作deb包。首先你需要一个deb包管理的系统,debian, ubuntu等。
这里我用的是nexenta. 这些系统默认装好了deb包制作需要的工具,如dpkg-dev, devscripts等。如果没有,你也可以在制作过程中用apt-get install <packagename>来手动安装。
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.c
C 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 <aubreylee@gmail.com>
sub 2048g/6AF6581E 2008-01-29
3. 要开始对这个包进行deb化了。首先确保源代码目录绝对干净,为了让软件包能够正确地制作,必须把源代码目录的名字改成小写,并且符合<packagename>-<version>的形式。
aubrey@aubrey-nexenta:~/deb$ ls
hellodeb
aubrey@aubrey-nexenta:~/deb$ mv hellodeb/ hellodeb-1.0
aubrey@aubrey-nexenta:~/deb$ ls
hellodeb-1.0
4. 在正式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 <enter> 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。
还有两个重要的提示:
亿恩科技地址(ADD):郑州市黄河路129号天一大厦608室 邮编(ZIP):450008 传真(FAX):0371-60123888
联系:亿恩小凡
QQ:89317007
电话:0371-63322206 本文出自:亿恩科技【www.enkj.com】
服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]
|