Linux Qt deb包制作

前言

Linux系统的软件一般有.deb和.rpm格式的安装包,即Linux系统用的是"Debian Packager"软件包管理器,就可以制作.deb包,下面说的就是.deb的制作。如需了解.rpm制作 ,点击"Red-Hat Package Manager"红帽软件包管理器

制作工具

制作前,系统环境中需要安装有dh-make 、devscripts,可用下面命令安装:

sudo apt-get install dh-make devscripts

制作deb包

这里制作一个Qt开发软件的deb包。该功能是开机启动显示当前时间的小程序。(底部有程序代码)

  • 1、首先创建一个目录文件,件格式最好是:xxx-xxx-1.0.0 (xxx-xxx是名字且不能是大写字母,1.0.0代表版本号);

  • 2、将软件目录下的所有文件移到此文件目录下

kch@kch:~/showTime$ ls 
show-timer-1.0.0
kch@kch:~/showTime$ ls show-timer-1.0.0/
main.cpp          showTime.pro       widget.cpp  widget.ui
showTime.desktop  showTime.pro.user  widget.h
kch@kch:~/showTime$ 
  • 3、将该文件压缩生成tar.gz的压缩包
kch@kch:~/showTime$ tar -zcvf show-timer-1.0.0.tar.gz show-timer-1.0.0/
show-timer-1.0.0/
show-timer-1.0.0/widget.h
show-timer-1.0.0/showTime.desktop
show-timer-1.0.0/widget.ui
show-timer-1.0.0/widget.cpp
show-timer-1.0.0/showTime.pro
show-timer-1.0.0/main.cpp
show-timer-1.0.0/showTime.pro.user
kch@kch:~/showTime$ ls
show-timer-1.0.0  show-timer-1.0.0.tar.gz
kch@kch:~/showTime$ 
  • 4、cd 到show-time-1.0.0目录下,执行 dh_make -e 邮箱 -f …/show-timer-1.0.0.tar.gz ,输入 s,再输入y 。
    会生成debian文件和show-timer_1.0.0.orig.tar.gz 源文件。若命令不存在,
    执行:sudo apt-get install dh-make 安装即可。
kch@kch:~/showTime$ cd show-timer-1.0.0/
kch@kch:~/showTime/show-timer-1.0.0$ ls
main.cpp          showTime.pro       widget.cpp  widget.ui
showTime.desktop  showTime.pro.user  widget.h
kch@kch:~/showTime/show-timer-1.0.0$ dh_make -e kch@email.com -f ../show-timer-1.0.0.tar.gz Type of package: (single, indep, library, python)
[s/i/l/p]?
Email-Address       : kch@email.com
License             : blank
Package Name        : show-timer
Maintainer Name     : kch
Version             : 1.0.0
Package Type        : single
Date                : Thu, 16 Dec 2021 14:14:37 +0800
Are the details correct? [Y/n/q]
Currently there is not top level Makefile. This mayrequire additional tuning
Done. Please edit the files in the debian/ subdirectory now.

kch@kch:~/showTime/show-timer-1.0.0$ ls
debian  main.cpp  showTime.desktop  showTime.pro  showTime.pro.user  widget.cpp  widget.h  widget.ui
kch@kch:~/showTime/show-timer-1.0.0$ ls ../
show-timer-1.0.0  show-timer_1.0.0.orig.tar.gz  show-timer-1.0.0.tar.gz
kch@kch:~/showTime/show-timer-1.0.0$ 
  • 5、修改debian目录文件下的 control 和 install

control文件

control 是一些关于该包依赖、描述等信息 。该软件是Qt开发的,编译时肯定需要一些关于Qt的包,这里就大概写了一些。这个编译的依赖
如果你写多了,本来没用上但是你写了,那你就得装,不装就编译不过;如果写少了,当前编译环境上有还是可以编过,没有就编译不
过。所以依赖最好还是写清楚。

  • Build-Depends: 就是编译依赖

  • Depends:是安装依赖

kch@kch:~/showTime/show-timer-1.0.0$ vim debian/control 
kch@kch:~/showTime/show-timer-1.0.0$ cat debian/control 
Source: show-timer
Section: unknown
Priority: optional
Maintainer: kch <kch@email.com>
Build-Depends: debhelper (>=9), libc6 (>=2.17), libx11-6, qtchooser, qtbase5-dev, qt5-qmake, qt5-default
Standards-Version: 3.9.6
Homepage: <insert the upstream URL, if relevant>
#Vcs-Git: git://anonscm.debian.org/collab-maint/show-timer.git
#Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/show-timer.git

Package: show-timer
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>
kch@kch:~/showTime/show-timer-1.0.0$ 

install文件

install是执行安装,相当于复制,每一行两个参数,第一个参数就是当前文件,第二个就是安装路径,
两个参数中间只要有空格隔开就可以。

注:需要知道的是第一个参数路径,按和debian目录文件同级为一级路径

  • showTime:是生成的二进制可执行程序,即安装到/usr/bin 目录下

  • showTime.desktop:是desktop启动配置文件

  • /etc/xdg/autostart/ :将showTime.desktop安装到此目录下,则会开机启动

  • /usr/share/applications/:将showTime.desktop安装到此目录下,则会将改程序添加到开始菜单

kch@kch:~/showTime/show-timer-1.0.0$ vim debian/install
kch@kch:~/showTime/show-timer-1.0.0$ cat debian/install 
showTime /usr/bin/
showTime.desktop /etc/xdg/autostart/
showTime.desktop /usr/share/applications/
kch@kch:~/showTime/show-timer-1.0.0$ 
  • 6、执行debuild,编译生成.deb包,若命令不存在,则sudo apt-get install devscripts安装即可。

执行完毕,若一切顺利,则在上一级目录会生成show-timer_1.0.0-1_amd64.deb包和其他信息文件

kch@kch:~/showTime/show-timer-1.0.0$ ls ../
show-timer-1.0.0                  show-timer_1.0.0-1_amd64.deb  show-timer_1.0.0.orig.tar.gz
show-timer_1.0.0-1_amd64.build    show-timer_1.0.0-1.diff.gz    show-timer-1.0.0.tar.gz
show-timer_1.0.0-1_amd64.changes  show-timer_1.0.0-1.dsc
kch@kch:~/showTime/show-timer-1.0.0$ 

dpkg 常用命令

  • dpkg -l 列出系统中已安装的包

  • dpkg -i show-timer_1.0.0-1_amd64.deb 则可安装此包

  • dpkg -r show-timer 卸载

  • dpkg --purge show-timer 清除配置

  • 若有 show-timer_1.0.0-1.dsc、show-timer_1.0.0-1.diff.gz、show-timer_1.0.0.orig.tar.gz 这三个文件

则可执行 dpkg-source -x show-timer_1.0.0-1.dsc 获取此包源码 show-timer-1.0.0

debian目录文件介绍

  • preinst.ex:安装前脚本,安装前执行,可加入安装前执行的命令

  • postinst.ex:安装后脚本

  • prerm.ex:卸载前脚本

  • postrm.ex:卸载后脚本

kch@kch:~/showTime/show-timer-1.0.0$ ls debian/
changelog  manpage.1.ex     postrm.ex      show-timer.cron.d.ex
compat     manpage.sgml.ex  preinst.ex     show-timer.default.ex
control    manpage.xml.ex   prerm.ex       show-timer.doc-base.EX
copyright  menu.ex          README.Debian  show-timer-docs.docs
init.d.ex  outfile          README.source  watch.ex
install    postinst.ex      rules
kch@kch:~/showTime/show-timer-1.0.0$ 
  • changelog:可修改版本号和修改日志
kch@kch:~/showTime/show-timer-1.0.0$ cat debian/changelog 
show-timer (1.0.0-1) unstable; urgency=medium

  * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>

 -- kch <kch@email.com>  Thu, 16 Dec 2021 14:14:37 +0800
kch@kch:~/showTime/show-timer-1.0.0$ 

control文件参数介绍

  • Package:指该软件包的名字。如果你的软件包名称有两个词,用一个连字符(-)把它们连起来。软件包的名称只能有小写的英文字母,数字以及"+“和”-"。

  • Version:显然是程序的版本。确保这里的值不包括连字符。

  • Section:列出了你的软件属于的类别,可能的值包括admin(管理),games(游戏),gnome,kde,mail(电子邮件),misc(杂项)<译者注:misc是miscellaneous的简称>,net(网络),sound(声音),text(文本),utils(实用工具)和web(万维网)。

  • Priority:声明这个包的优先级(大部分的时候使用optional(可选的))。

  • Architecture:可以编译本二进制包的体系结构,一般有俩个值,

  • Architecture: any 包含 编译型语言编写的程序 生成的二进制包依赖于具体的体系结构

  • Architecture: all 包含 文本、图像、或解释型语言脚本 生成的二进制包独立于体系结构

  • Eseential:指该软件包是否是必须的(大部分的时候不是)。

  • Depends:此软件包仅当它依赖的软件包均已安装后才可以安装。此处请写明你的程序所必须的软件包,如果没有要求的软件包该软件便不能正常运行(或严重抛锚)的话。

  • Recommends:这项中的软件包不是严格意义上必须安装才可以保证程序运行。当用户安装软件包时,所有前端工具都会询问是否要安装这些推荐的软件包。aptitude 和 apt-get 会在安装你的软件包的时候自动安装推荐的软件包(用户可以禁用这个默认行为)。dpkg 则会忽略此项。

  • Suggests:此项中的软件包可以和本程序更好地协同工作,但不是必须的。当用户安装程序时,所有的前端程序可能不会询问是否安装建议的软件包。aptitude 可以被配置为安装软件时自动安装建议的软件包,但这不是默认。dpkg 和 apt-get 将忽略此项。

  • Maintainer:就是你(写上你的名字,后面的方括号"[ ]"里留下你的电子邮件地址)。

  • Conflicts:仅当所有冲突的软件包都已经删除后此软件包才可以安装。当程序在某些特定软件包存在的情况下根本无法运行或存在严重问题时使用此项。

  • Replaces:当你的程序要替换其他软件包的某些文件,或是完全地替换另一个软件包(与 Conflicts 一起使用)。列出的软件包中的某些文件会被你软件包中的文件所覆盖。。

  • Description:显示你的描述。

desktop文件参数介绍

  • 这是本程序中用到的showTime.desktop
kch@kch:~/showTime/show-timer-1.0.0$ cat showTime.desktop 
[Desktop Entry]
Name=showTimer
Name[zh_CN]=当前时间
Comment=显示当前时间
Comment[zh_CN]=显示当前时间
Exec=/usr/bin/showTime
Terminal=false
Type=Application
NoDisplay=false              
kch@kch:~/showTime/show-timer-1.0.0$ 
  • 该文件是桌面入口文件,下面是关于其参数介绍
    在这里插入图片描述

测试程序代码

git clone 地址 https://gitee.com/kchmmd/qt-test.git
如何配置使用git

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值