制作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.oCC=gcc -gall:$(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-makedh-make安装方法:sudo apt-get install dh-make安装好后,,我们就可以使用该命令了dh_make -e linuxidc@ 修改参数,也可以不修改,执行这一步,我们将会看到,邮箱是我们刚才输入的如果不想改为自己的邮箱,可以执行下面命令dh_make上面任一命令后都会出现,一下内容:@linuxidc:~/deb/hello-1.0$ dh_make -e linuxidc@Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch or cdbs? [s/i/m/l/k/n/b]

11、我们输入sMaintainer name : zsxEmail-Address : linuxidc@ Date : Sat, 18 Dec 2010 23:06:25 +0800Package Name : helloVersion : 1.0License : blankUsing dpatch : noType of Package : SingleHit <enter> to confirm:

12、输入回车,确认Skipping creating ../hello_1.0.orig.tar.gz because it already existsDone. Please edit the files in the debian/ subdirectory now. You should alsocheck that the hello Makefiles install into $DESTDIR and not in / .

13、准备工作完成

14、开始打包dpkg-buildpackagedpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor): dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functionsdpkg-buildpackage: 源码包 hellodpkg-buildpackage: 源码版本 1.0-1dpkg-buildpackage: 源码修改者 zsx <linuxidc@>dpkg-buildpackage: 主机架构 i386dpkg-source –before-build hello-1.0fakeroot debian/rules cleandh clean dh_testdir dh_auto_cleanmake[1]: 正在进入目录 `/home/zsx/deb/hello-1.0’rm -f *.o hellomake[1]:正在离开目录 `/home/zsx/deb/hello-1.0′ dh_cleandpkg-source -b hello-1.0dpkg-source: info: using source format `3.0 (quilt)’dpkg-source: info: building hello using existing ./hello_1.0.orig.tar.gzdpkg-source: info: building hello in hello_1.0-1.debian.tar.gzdpkg-source: info: building hello in hello_1.0-1.dscdebian/rules builddh build dh_testdir dh_auto_configure dh_auto_buildmake[1]: 正在进入目录 `/home/zsx/deb/hello-1.0’gcc -g -g -O2 -c -o hello.o hello.cgcc -g -o hello hello.omake[1]:正在离开目录 `/home/zsx/deb/hello-1.0′ dh_auto_testfakeroot debian/rules binarydh 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_gencontroldpkg-gencontrol: 警告: Depends field of package hello: 未知的替换变量 ${shlibs:Depends} dh_md5sums dh_builddebdpkg-deb:正在新建软件包“hello”,包文件为“../hello_1.0-1_i386.deb”。dpkg-genchanges >../hello_1.0-1_i386.changesdpkg-genchanges: 上传数据中包含完整的原始代码dpkg-source –after-build hello-1.0dpkg-buildpackage: 完整上载(包含原始的代码)

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

陪我们走过一段别人无法替代的记忆。在那里,

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

相关文章:

你感兴趣的文章:

标签云: