Linux制作deb

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


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

3、编写我们的程序

我们以我们最熟悉的helloworld程序做起,
hello.c代码如下
#include <stdio.h>
int main()
{
     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、我们sudo make一下,测试程序编译是否有问题,然后在./hello检查程序是否正确执行

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

6、我们清理下刚才编译程序的垃圾,sudo 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 [email protected] 修改参数,也可以不修改,执行这一步,我们将会看到,邮箱是我们刚才输入的
如果不想改为自己的邮箱,可以执行下面命令
dh_make
上面任一命令后都会出现,一下内容:
www.linuxidc.com@linuxidc:~/deb/hello-1.0$ dh_make -e [email protected]
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 : [email protected] 
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

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

猜你喜欢

转载自www.cnblogs.com/Frank-dev-blog/p/9459516.html