1.安装环境
sudo apt update
sudo apt install dh-make
sudo apt install devscripts
sudo apt install build-essential
2.创建一个二级目录
mkdir ~/test/hello-1.0 -p
cd ~/test/hello-1.0
3.创建文件
hello.c 文件内容
//cat hello.c
#include <stdio.h>
int main(void)
{
printf("%s\n","Hello");
return 0;
}
Makefile 文件内容
# cat Makefile
hello:hello.o
gcc -o hello hello.o
hello.o:hello.c
gcc -o hello.o -c hello.c
.PHONY:rebuild clean
rebuild:clean hello
clean:
rm -f hello hello.o
4.⽣成debian⽬录
dh_make --createorig -e liruijian@kylinos.cn
5.在debian目录下创建install文件
vi debian/install
install 文件内容
hello /bin
6.编译
debuild
7.查看deb包
ls ..
可以看到编译生成的deb包
cd ..
dpkg -x hello_1.0-1_amd64.deb hello
jian@ubuntu:~/test$ tree hello
hello
├── bin
│ └── hello
└── usr
└── share
└── doc
└── hello
├── changelog.Debian.gz
├── copyright
└── README.Debian
5 directories, 4 files
可以看到hello这个程序放在/bin目录下
8.安装deb包
dpkg -i hello_1.0-1_amd64.deb
9.检验
hello
可以看到hello命令可以执行,说明我们编译的hello可执行程序已经安装到/bin目录下了
10.可能出现的错误的处理方法
a.把debian/source/format文件删除
b.没有gpg key,这个不用处理,这个是在需要把整个包推到launchpad外网或者内网才需要的,本机编译即使报这个错误也会成功编译deb包。
11.备注
以上仅仅适用于本地编译,如果需要在launchpad线上编译,需要修改debian目录下的一些文件才可以成功推送到线上编译。