下面用一個簡單的程序例子,來講解如何制作deb包。首先你需要一個deb包管理的系統(tǒng),debian, ubuntu等。
這里我用的是nexenta. 這些系統(tǒng)默認(rèn)裝好了deb包制作需要的工具,如dpkg-dev, devscripts等。如果沒有,你也可以在制作過程中用apt-get install <packagename>來手動安裝。
1. 創(chuàng)建一個簡單的源碼包
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包關(guān)系不大,也不需要修改,我們主要看一下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. 創(chuàng)建GPG key。GPG key在build包的時候需要用到,創(chuàng)建的方法參見GPG使用指南 。創(chuàng)建完后,檢查一下:
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. 要開始對這個包進(jìn)行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兩個環(huán)境變量:
aubrey@aubrey-nexenta:~/deb$ export DEBEMAIL="aubreylee@gmail.com"
aubrey@aubrey-nexenta:~/deb$ export DEBFULLNAME="Aubrey Li"
注意,這里的name和email必須和你生成GPG鑰匙的時候完全一樣。這兩個變量值也會在deb包的changelog等多個文件里被用到。
5. 現(xiàn)在可以對源碼包進(jìn)行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$
這里詢問包的類型,這里我們是單個可執(zhí)行文件,所以我選了s。
還有兩個重要的提示:
億恩科技地址(ADD):鄭州市黃河路129號天一大廈608室 郵編(ZIP):450008 傳真(FAX):0371-60123888
聯(lián)系:億恩小凡
QQ:89317007
電話:0371-63322206 本文出自:億恩科技【www.allwellnessguide.com】
服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|