簡介
deb編包的本質是:將編譯過程自動化,並生成可執行程序,使得可以通過apt-get中安裝。
源碼,編譯器編譯成指定架構版本的二進制,
不同架構的二進制組織形式不同,如大小端對齊。
DEB源碼介紹
DEB 包的源碼是由:程序源碼+debian 目錄構成,其中 debian 目錄中存放着打包成 DEB 文件所需的全部文件。
通過 debian 目錄中的文件可以定制軟件包的行為。其中最為重要的,對於所有的軟件包都必需的基本文件是:
- control :包的一些基本信息(名字、依賴等)
- 軟件包在構建和運行時的依賴
- 軟件包其他主要信息
- rules :構建包時的規則
- 是用來指定如何構建軟件包的,是包的編譯規則文件;
- 默認可以調用軟件源碼的 make 等編譯程序及規則進行;
- 也可對默認的構建編譯流程進行覆寫,以滿足 DEB 打包的特殊需求。
- changelog : Debian 包的修改記錄
- 記錄當前 DEB 包的變更歷史;
- 同時 DEB 包的版本號也是在此文件中指定;
- install:安裝指定文件到系統目錄
- 文件拷貝列表,聲明 DEB 安裝時所需拷貝的文件及目標位置
- copyright :包的版權信息
- 包含軟件包的版權和授權信息;
准備
安裝依賴
sudo apt install dh-make devscripts build-essential dput gedit
配置用戶名和郵箱
vim ~/.bashrc
DEBEMAIL="chendeqiang@kylinos.cn"
DEBFULLNAME="chendeqiang"
export DEBEMAIL DEBFULLNAME
. ~/.bashrc
新建源碼文件
# 新建文件夾並進入,這里需要注意的是文件夾構成:包名-版本號
mkdir ~/hello-1.0/
cd ~/hello-1.0/
# 新建源碼文件
gedit hello.bash
hello.bash的文件內容:
#!/bin/bash
echo "Hello World!!!"
加執行權限:
sudo chmod +x hello.bash
制作壓縮包
# 制作壓縮包
tar -zcvf ../hello-1.0.tar.gz ../hello-1.0/
生成debian文件夾
使用dh_make
命令生成debian文件夾。
dh_make -n -f ../hello-1.0.tar.gz #-n native
s
y
修改debian文件夾
修改control
gedit debian/control
Source: hello # 源碼包名
Section: shells # 其他分類為x11
Priority: optional
Maintainer: chendeqiang <chendeqiang@kylinos.cn> # 修改此處
Build-Depends: debhelper-compat (= 12) # 添加編譯依賴,debhelper (>= 9)
Standards-Version: 4.4.1
#Homepage: <insert the upstream URL, if relevant>
#Vcs-Browser: https://salsa.debian.org/debian/hello
#Vcs-Git: https://salsa.debian.org/debian/hello.git
Package: hello # 二進制包名
Architecture: any # any,all
Depends: ${shlibs:Depends}, ${misc:Depends} # 與其他包的關系控制,這里是運行依賴
Description: <insert up to 60 chars description>
<insert long description, indented with spaces>
修改changelog
dch
hello (1.0-1) v101; urgency=medium
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
-- chendeqiang <chendeqiang@kylinos.cn> Thu, 28 Jan 2021 21:05:06 +0800
添加install
如果makefile沒有指定一些文件的安裝目錄,則可以在install文件中進行指定。
gedit debian/install
hello.bash /usr/bin/
install 文件格式,目標文件 空格 目標位置
生成gpg密鑰
查看gpg密鑰
gpg --list-key
生成gpg密鑰
如果沒有gpg密鑰,則生成一個gpg密鑰
gpg --generate-key
真實姓名:chendeqiang
電子郵箱地址:chendeqiang@kylinos.cn
o
輸入兩次密碼
pub rsa1234 2021-01-28 [SC] [有效至:2023-01-28]
9B91BDA0F08C1C82F322B25B660EAA39DB4FF519
uid qiangdechen <chenjjjj@kk.cn>
sub rsa1234 2021-01-28 [E] [有效至:2023-01-28]
其中,rsa1234將作為加密的密鑰。
配置默認簽名
echo 'DEBSIGN_KEYID="9B91BDA0F08C1C82F322B25B660EAA39DB4FF519"' >> ~/.devscripts
生成deb包
debuild
本地安裝deb包
cd ~
sudo dpkg -i hello_1.0-1_amd64.deb
# 卸載deb包
# sduo dpkg -r -i hello_1.0-1_amd64.deb
運行可執行文件
hello.bash
#Hello World!!!
上傳公鑰到PPA
上傳gpg公鑰
# 查看秘鑰
gpg --fingerprint
# 上傳公鑰到服務器,可以通過 `nslookup launchpad.dev`查看ip
gpg --keyserver 172.0.0.0 --send-key rsa1234
打開 https://launchpad.dev/~chendeqiang ,修改 OpenPGP keys,
之后launchpad將發送一封用GPG加密的郵件到用戶的郵箱,
然后使用 gpg --decrypt
解密,並點擊鏈接完成認證
上傳ssh公鑰
# 生成秘鑰
ssh-keygen –t rsa
# 一直回車
# 復制公鑰
vim ~/.ssh/id_rsa.pub
打開 https://launchpad.dev/~chendeqiang ,修改 SSH keys,
粘貼剛剛復制的秘鑰
可以使用 seahorse 查看和管理gpg和ssh秘鑰。
更多gpg信息參考:https://www.cnblogs.com/chendeqiang/p/14233944.html
其他
添加域名/etc/hosts 和 ~/.dput.cf可參考《launchpad平台用戶使用手冊》
生成deb源碼包,上傳到PPA進行編譯
#生成源碼包,patch需要添加-sa
debuild -S
cd ~/
dput devppa:chendeqiang/kylinos-desktop/ppatest hello1_1.0-1_source.changes
添加PPA的apt源
訪問應用主頁 https://launchpad.dev/~chendeqiang/+archive/kylinos-desktop/ppatest
添加Technical details about this PPA下的兩個鏈接到source.list
sudo vim /etc/apt/source.list
sudo apt-get update
安裝應用
重新打開一個終端
sudo apt-get install cdqtest
# 運行應用
demo
恢復源碼包
下載以下三個包:
xxx.dsc
xxx.origin.tar.gz
xxx.debian.tar.xz
然后:
dpkg-source -x xxx.dsc
makefile方式構建源碼
hello.c
#include<stdio.h>
int main()
{
printf("helloworld!\n");
return 0;
}
Makefile
hello : hello.o
gcc -o hello hello.o
hello.o : hello.c
gcc -c hello.c
#clean :
# rm hello hello.o
#install:
# install hello /usr/bin/
cmake方式構建源碼
hello.c
#include<stdio.h>
int main()
{
printf("helloworld!\n");
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(hellocdq)
add_executable(hellocdq hello.cpp)
debin/control
Build-Depends: debhelper (>=9) , cmake
debian/rules
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
%:
dh $@
# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
override_dh_auto_configure:
dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
備注
查詢dns
nslookup launchpad.dev
Control和chagelog的包名是除了版本號的包名
參考鏈接:
https://blog.csdn.net/kyle__shaw/article/details/8938787?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.control
https://blog.csdn.net/kyle__shaw/article/details/8938787
其他參考資料:
- gdb參考資料:gdb官方手冊,《Debugging with GDB》,《GDB Pocket Reference》
- make手冊:《Managing Projects with GNU Make》
- deb 詳細規范和高級用法參考資源:
Debian 新維護者指
https://www.debian.org/doc/manuals/maint-guide/index.en.html
Debian 開發者文檔
https://www.debian.org/doc/manuals/developers-reference/index.en.html
Debian 政策文檔 https://www.debian.org/doc/devel-manuals#policy
Ubuntu 打包指南 http://packaging.ubuntu.com/html/