日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux 中用 dh_make 将 Qt + CMake 项目打包为 deb 文件

發(fā)布時(shí)間:2024/5/15 linux 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux 中用 dh_make 将 Qt + CMake 项目打包为 deb 文件 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

      • 步驟流程
      • 詳細(xì)說明
        • 源碼包名有個(gè)格式規(guī)定
        • 配置環(huán)境變量
        • dh_make 生成 debian 目錄
          • 修改 `debian/changelog`
          • 修改 `debian/control `
          • 修改 `debian/copyright`
        • dh_make 的參數(shù)含義
        • dpkg-buildpackage 生成 deb 包
        • lintian 檢查包
        • dpkg-deb 查看 deb 的安裝路徑
      • 其它有用命令
      • 系列地址

簡 述: 在 Ubuntu 20.04 中,將基于 Qt5 + CMake 的個(gè)人項(xiàng)目 PicShot ,通過 dh_make 制作一個(gè).deb 安裝包。


本文初發(fā)于 “偕臧的小站”,同步轉(zhuǎn)載于此。


步驟流程

💻: Ubuntu 20.04 中,從源碼包構(gòu)建一個(gè) deb 文件,依次執(zhí)行如下即可:

$ sudo apt install wget tar dh-make debmake lintian # 下載工具包 $ cd ~/Desktop $ mkdir DebExample && cd DebExample # 創(chuàng)建一個(gè)空文件夾并且進(jìn)入 $ git clone --recursive https://github.com/xmuli/PicShot.git # 下載倉庫和子模塊倉庫$ cp -r PicShot/ picshot-0.1.2 # 復(fù)制重命名格式<name>-<version> $ tar -cvzf picshot-0.1.2.tar.gz picshot-0.1.2 # 制作 .tar.gz 的壓縮包$ cat >> ~/.bashrc <<EOF # 配置環(huán)境變量,用于模板填充作者名和郵箱 DEBEMAIL="xmulitech@gmail.com" # 維護(hù)者的郵箱 DEBFULLNAME="XMuli" # 維護(hù)者的姓名 export DEBEMAIL DEBFULLNAME export PATH=~/Qt5.12.11/5.12.11/gcc_64/bin:$PATH # 代替 QT5_DIR 作用,編譯用;可省略 EOF $ . ~/.bashrc # 更新使修改后的配置文件立刻生效;重啟生效太 low 了$ cd picshot-0.1.2 # *** 后續(xù)所有命令均在此下操作【提示】 *** $ dh_make -f ../picshot-0.1.2.tar.gz -s -c mit -y # 源碼根目錄下,生成 debian 模板目錄$ vim debian/changelog # 修改日志文件 $ vim debian/control # 修改文件 $ vim debian/copyright # 修改版權(quán)信息$ dpkg-buildpackage -us -uc # 制作 deb 包,通過源碼編譯 $ ls -al ../ # 確認(rèn) deb 包生成$ lintian ../picshot_0.1.2-1_amd64.deb # lintian 檢查規(guī)范;若想進(jìn)官方 apt 必須全部通過;可省略 $ dpkg-deb -c ../picshot_0.1.2-1_amd64.deb # 查看 deb 文件的安裝目錄;可省略# PS 補(bǔ)充:------------------------------- sudo apt install devscripts # 使用 dch -i 或用 dch -v version-revision 來指定版本Linux 對應(yīng): /opt/Qt/5.15.2/gcc_64/bin 或 ~/Qt5.12.11/5.12.11/gcc_64/bin MacOS 對應(yīng): /Users/xmuli/Qt/5.15.2/clang_64/bin

詳細(xì)說明

源碼包名有個(gè)格式規(guī)定

$ cp -r PicShot/ picshot-0.1.2

下載 PicShot 源碼包后,若想用 dh_make 打包為 deb ,則需將 『文件夾』 重命名為指定格式 <package>-<version> ,這是官方強(qiáng)制的要求的 DESCRIPTION;例中我就直接 cp 一份改名。

dh_make is a tool that adds necessary files for making Debian source package from upstream source according to the requirements of the Debian Policy. dh_make must be invoked within a directory containing the source code, which must be named -. The must be all lowercase, The and must be all lowercase, digits and dashes. The can also contain digits, and the symbols plus, dot, tilde. The must start with a digit. If the directory name does not conform to this scheme, you must rename it before using dh_make. Alternatively, you may be able to use the –packagename option to force the package name.


配置環(huán)境變量

$ cat >> ~/.bashrc <<EOF # 配置環(huán)境變量,用于模板填充作者名和郵箱 DEBEMAIL="xmulitech@gmail.com" # 維護(hù)者的郵箱 DEBFULLNAME="XMuli" # 維護(hù)者的姓名 export DEBEMAIL DEBFULLNAME export PATH=~/Qt5.12.11/5.12.11/gcc_64/bin:$PATH # 代替 QT5_DIR 作用,編譯用;可省略 EOF $ . ~/.bashrc # 更新使修改后的配置文件立刻生效;

命令含義為,直接將 『DEBEMAIL=“xmulitech@gmail.com” …省略… :$PATH』 這段文本,追加在 ~/.bashrc 文件的尾部,然后更新使此新加的環(huán)境變量 立刻 生效。DEBEMAIL 和 DEBFULLNAME 兩個(gè)變量,是填充自動(dòng)生成模板使用的。


dh_make 生成 debian 目錄

$ dh_make -f ../picshot-0.1.2.tar.gz -s -c mit -y

dh_make 命令用來在源碼根目錄下 debian 的;問了下 debian 的官方某維護(hù)者,他也是教我用這個(gè)命令。我這兒直接指定了幾個(gè)參數(shù): 壓縮包 路徑和 packageclass 為 single,和 copyright 為 mit 許可證。

默認(rèn)生成的 debian 文件夾下又如此文件,以 .ex 結(jié)尾代表模板的含義,除了標(biāo)記出來的幾個(gè)必須 章 4. debian 目錄中的必須內(nèi)容 ,其余都是可刪除的,放心大膽的刪,屢試不爽。

xmuli@xmuli-virtual-machine:~/Desktop/DebExample/picshot-0.1.2$ tree debian debian ├── changelog # 必須 ├── control # 必須 ├── copyright # 必須 ├── manpage.1.ex ├── manpage.sgml.ex ├── manpage.xml.ex ├── picshot.cron.d.ex ├── picshot.doc-base.EX ├── picshot-docs.docs ├── postinst.ex ├── postrm.ex ├── preinst.ex ├── prerm.ex ├── README.Debian ├── README.source ├── rules # 必須 ├── salsa-ci.yml.ex ├── source # 必須 │ └── format └── watch.ex

我們只需要簡單修改 changelog 、control、copyright 這三個(gè)文件即可;rules 為構(gòu)建腳本,通常采用默認(rèn)即可。下面將我修改的提供大家參考。


修改 debian/changelog
xmuli@xmuli-virtual-machine:~/Desktop/DebExample/picshot-0.1.2$ cat debian/changelog # 修改后的參考 picshot (0.1.2-1) unstable; urgency=medium* try build .deb on Linux(ubuntu 20.04) #『改寫』隨便寫一句替換默認(rèn)的-- XMuli <xmulitech@gmail.com> Sun, 27 Mar 2022 16:16:38 +0800
修改 debian/control
xmuli@xmuli-virtual-machine:~/Desktop/DebExample/picshot-0.1.2$ cat debian/control # 修改后的參考 Source: picshot Section: unknown Priority: optional Maintainer: XMuli <xmulitech@gmail.com> #『已修改』維護(hù)者姓名和聯(lián)系方式 Build-Depends: debhelper-compat (= 12) #『未修改』構(gòu)建依賴 Standards-Version: 4.4.1 Homepage: https://github.com/XMuli #『已修改』首頁網(wǎng)站 #Vcs-Browser: https://salsa.debian.org/debian/picshot #Vcs-Git: https://salsa.debian.org/debian/picshot.gitPackage: picshot #『未修改』包名稱 Architecture: any #『未修改』平臺(tái) Depends: ${shlibs:Depends}, ${misc:Depends} #『未修改』依賴 Description: Open source cross-platform screenshots #『已修改』簡短的一句描述Qt5-based open source cross-platform screenshot tool #『已修改』可以書寫詳細(xì)的描述

注意: 關(guān)鍵詞后緊貼著冒號,填寫的內(nèi)容需要先填一個(gè)空格,格式正確,否則后面會(huì)失敗。


修改 debian/copyright
xmuli@xmuli-virtual-machine:~/Desktop/DebExample/picshot-0.1.2$ cat debian/copyright # 修改后的參考 Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: picshot Upstream-Contact: https://github.com/XMuli/PicShot #『已修改』 Source: https://github.com/XMuli/PicShot #『已修改』Files: * Copyright: 2022 XMuli <xmulitech@gmail.com> License: MITFiles: debian/* Copyright: 2022 XMuli <xmulitech@gmail.com> License: MITLicense: MITPermission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationthe rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the following conditions:.The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software..THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.# Please also look if there are files or directories which have a # different copyright/license attached and list them here. # Please avoid picking licenses with terms that are more restrictive than the # packaged work, as it may make Debian's contributions unacceptable upstream. # # If you need, there are some extra license texts available in two places: # /usr/share/debhelper/dh_make/licenses/ # /usr/share/common-licenses/

注意開源軟件的許可證,對于想要進(jìn)入 debian 官方上游 apt 倉庫,對于這些都管控很嚴(yán)格,提交不正確或者錯(cuò)誤,是會(huì)發(fā)郵件告知不i通過原因,按要求修改即可。


dh_make 的參數(shù)含義

感覺有必要列舉出來,含義自己看;幾個(gè)關(guān)鍵的參數(shù):-c、-f 、s|i|l|p ,沒必要全部都熟記,二八原則。 -y 參數(shù)的最大優(yōu)點(diǎn)就是后面寫 yml 構(gòu)建 CI/CD 的時(shí)候優(yōu)勢就出來了,屆時(shí)在寫一篇教程;

xmuli@xmuli-virtual-machine:~/Desktop/DebExample/PicShot$ dh_make --help usage: dh_make [-h] [-a] [-c <type>] [--copyrightfile <file>] [-d] [--docs] [-e <address>] [-f <file>][-n] [-o <dir>] [-p <name>] [-t <dir>] [-y] [--createorig] [--with-emacs][-C <cls> | -s | -i | -l | --python] [-v]prepare Debian packaging from an original source archiveoptional arguments:-h, --help show this help message and exit-a, --addmissing reprocess package and add missing files-c <type>, --copyright <type>use <type> of license in copyright file (apache|artistic|bsd|gpl|gpl2|gpl3|isc|lgpl|lgpl2|lgpl3|mit|custom)--copyrightfile <file>Template to use for custom copyright-d, --defaultless skip the default Debian and package class templates--docs create a separate docs package-e <address>, --email <address>use <address> as the maintainer e-mail address-f <file>, --file <file>use <file> as the original source archive-n, --native the program is Debian native, don't generate .orig-o <dir>, --overlay <dir>reprocess package using templates in <dir>-p <name>, --packagename <name>force package name to be <name>-t <dir>, --templates <dir>apply customizing templates from <dir>-y, --yes automatic yes to prompts and run non-interactively--createorig create orig.tar.xz file--with-emacs add files for emacsen-C <cls>, --packageclass <cls>set package class (s|i|l|p)-s, --single set package class to single-i, --indep set package class to arch-independent-l, --library set package class to library--python set package class to python-v, --version show program's version number and exit

dpkg-buildpackage 生成 deb 包

$ dpkg-buildpackage -us -uc

會(huì)自動(dòng)生成如下中間過程和最后的 picshot_0.1.2-1_amd64.deb 包;已然成功,雙擊安裝即可。

雙擊即可安裝;


lintian 檢查包

$ lintian ../picshot_0.1.2-1_amd64.deb

此步驟通過 lintian 對 deb 進(jìn)行一個(gè)標(biāo)準(zhǔn)的格式檢查,如果想要進(jìn)入上游 apt 倉庫,就必須全部通過。標(biāo)記有 E 只要不 apt 都是無所謂的,就如同編譯的 警告一樣。

當(dāng)時(shí)倘若你有心走的更遠(yuǎn),那么怎么也不能耽誤了武學(xué)奇才,給出一個(gè)具體案例講解 Linux上面使用lintian檢測deb包報(bào)錯(cuò)的解決方案。


dpkg-deb 查看 deb 的安裝路徑

$ dpkg-deb -c ../picshot_0.1.2-1_amd64.deb

執(zhí)行一下會(huì)看到你想要的信息?。


其它有用命令

再補(bǔ)充兩個(gè)命令

  • ldd 可以查看依賴

  • locate 命令用于查找符合條件的文檔

    sudo apt install mlocate # 所在包 locate Qt5X11Extras.so.5 # 用 例

系列地址

QtExamples

歡迎 star ? 和 fork 🍴這個(gè)系列的 C++ / QT / DTK 學(xué)習(xí),附學(xué)習(xí)由淺入深的目錄。

總結(jié)

以上是生活随笔為你收集整理的Linux 中用 dh_make 将 Qt + CMake 项目打包为 deb 文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。