制作Ubuntu的deb格式包 从Hello World做起


1、新建一个我们临时的工作目录
mkdir deb


2、新建我们程序的目录
mkdir hello

3、编写我们的程序
我们以我们最熟悉的helloworld程序做起,
hello.c代码如下
#include <stdio.h>
int main(int argc, char* argv[])
{
     printf("Hello world!\n");
     return 0;
}
Makefile文件如下:
OBJS=hello.o
CC=gcc -g
all:$(OBJS)
    $(CC) -o hello $(OBJS)
clean:
rm -f *.o hello
.PHONY:all clean

4、我们make一下,测试程序编译是否有问题,然后在./hello检查程序是否正确执行

5、如果没问题进行下一步,如果有问题我们检查程序代码

6、我们清理下刚才编译程序的垃圾,make clean一下

7、输入命令,切回上级目录
cd ..

8、进行一次压缩打包(为什么做这一步,我也不太明白,查资料说,这一步是为了给生成的deb文件进行对比,确保我们deb文件没有错误)
改名:因为文件名必须包含文件名还有版本号
mv hello hello-1.0
说明:文件名后必须用-,不能用_
tar zcvf hello_1.0.orig.tar.gz hello-1.0
说明:压缩包的名字必须是包含文件名及版本号

9、进入我们的hello-1.0目录
cd hello-1.0

10、我们需要dh_make工具进行打包前的配置,如果是第一使用请先安装dh-make
dh-make安装方法:
sudo apt-get install dh-make
安装好后,我们就可以使用该命令了
dh_make -e bkjia@www.bkjia.com 修改参数,也可以不修改,执行这一步,我们将会看到,邮箱是我们刚才输入的
如果不想改为自己的邮箱,可以执行下面命令
dh_make
上面任一命令后都会出现,一下内容:
www.bkjia.com@bkjia:~/deb/hello-1.0$ dh_make -e bkjia@www.bkjia.com
Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch or cdbs?
  [s/i/m/l/k/n/b]

11、我们输入s
Maintainer name : zsx
Email-Address : bkjia@www.bkjia.com
Date : Sat, 18 Dec 2010 23:06:25 +0800
Package Name : hello
Version : 1.0
License : blank
Using dpatch : no
Type of Package : Single
Hit <enter> to confirm:

12、输入回车,确认
Skipping creating ../hello_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 hello Makefiles install into $DESTDIR and not in / .

13、准备工作完成

14、开始打包
dpkg-buildpackage
dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor):
dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functions
dpkg-buildpackage: 源码包 hello
dpkg-buildpackage: 源码版本 1.0-1
dpkg-buildpackage: 源码修改者 zsx <bkjia@www.bkjia.com>
dpkg-buildpackage: 主机架构 i386
 dpkg-source --before-build hello-1.0
 fakeroot debian/rules clean
dh clean
   dh_testdir
   dh_auto_clean
make[1]: 正在进入目录 `/home/zsx/deb/hello-1.0'
rm -f *.o hello
make[1]:正在离开目录 `/home/zsx/deb/hello-1.0'
   dh_clean
 dpkg-source -b hello-1.0
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building hello using existing ./hello_1.0.orig.tar.gz
dpkg-source: info: building hello in hello_1.0-1.debian.tar.gz
dpkg-source: info: building hello in hello_1.0-1.dsc
 debian/rules build
dh build
   dh_testdir
   dh_auto_configure
   dh_auto_build
make[1]: 正在进入目录 `/home/zsx/deb/hello-1.0'
gcc -g -g -O2   -c -o hello.o hello.c
gcc -g -o hello hello.o
make[1]:正在离开目录 `/home/zsx/deb/hello-1.0'
   dh_auto_test
 fakeroot debian/rules binary
dh binary
   dh_testroot
   dh_prep
   dh_installdirs
   dh_auto_install
   dh_install
   dh_installdocs
   dh_installchangelogs
   dh_installexamples
   dh_installman
   dh_installcatalogs
   dh_installcron
   dh_installdebconf
   dh_installemacsen
   dh_installifupdown
   dh_installinfo
   dh_pysupport
   dh_installinit
   dh_installmenu
   dh_installmime
   dh_installmodules
   dh_installlogcheck
   dh_installlogrotate
   dh_installpam
   dh_installppp
   dh_installudev
   dh_installwm
   dh_installxfonts
   dh_bugfiles
   dh_lintian
   dh_gconf
   dh_icons
   dh_perl
   dh_usrlocal
   dh_link
   dh_compress
   dh_fixperms
   dh_strip
   dh_makeshlibs
   dh_shlibdeps
   dh_installdeb
   dh_gencontrol
dpkg-gencontrol: 警告: Depends field of package hello: 未知的替换变量 ${shlibs:Depends}
   dh_md5sums
   dh_builddeb
dpkg-deb:正在新建软件包“hello”,包文件为“../hello_1.0-1_i386.deb”。
 dpkg-genchanges  >../hello_1.0-1_i386.changes
dpkg-genchanges: 上传数据中包含完整的原始代码
 dpkg-source --after-build hello-1.0
dpkg-buildpackage: 完整上载(包含原始的代码)

15、打包成功,切回上级目录就可看到我们的helloworld的deb包
cd ..
ls后就会看到 hello_1.0-1_i386.deb

相关内容