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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

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

文章目錄

      • 步驟流程
      • 詳細說明
        • 源碼包名有個格式規(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 的個人項目 PicShot ,通過 dh_make 制作一個.deb 安裝包。


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


步驟流程

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

$ sudo apt install wget tar dh-make debmake lintian # 下載工具包 $ cd ~/Desktop $ mkdir DebExample && cd DebExample # 創(chuàng)建一個空文件夾并且進入 $ git clone --recursive https://github.com/xmuli/PicShot.git # 下載倉庫和子模塊倉庫$ cp -r PicShot/ picshot-0.1.2 # 復制重命名格式<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" # 維護者的郵箱 DEBFULLNAME="XMuli" # 維護者的姓名 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 ../ # 確認 deb 包生成$ lintian ../picshot_0.1.2-1_amd64.deb # lintian 檢查規(guī)范;若想進官方 apt 必須全部通過;可省略 $ dpkg-deb -c ../picshot_0.1.2-1_amd64.deb # 查看 deb 文件的安裝目錄;可省略# PS 補充:------------------------------- sudo apt install devscripts # 使用 dch -i 或用 dch -v version-revision 來指定版本Linux 對應: /opt/Qt/5.15.2/gcc_64/bin 或 ~/Qt5.12.11/5.12.11/gcc_64/bin MacOS 對應: /Users/xmuli/Qt/5.15.2/clang_64/bin

詳細說明

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

$ cp -r PicShot/ picshot-0.1.2

下載 PicShot 源碼包后,若想用 dh_make 打包為 deb ,則需將 『文件夾』 重命名為指定格式 <package>-<version> ,這是官方強制的要求的 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" # 維護者的郵箱 DEBFULLNAME="XMuli" # 維護者的姓名 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 兩個變量,是填充自動生成模板使用的。


dh_make 生成 debian 目錄

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

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

默認生成的 debian 文件夾下又如此文件,以 .ex 結(jié)尾代表模板的含義,除了標記出來的幾個必須 章 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 這三個文件即可;rules 為構(gòu)建腳本,通常采用默認即可。下面將我修改的提供大家參考。


修改 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) #『改寫』隨便寫一句替換默認的-- 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> #『已修改』維護者姓名和聯(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 #『未修改』平臺 Depends: ${shlibs:Depends}, ${misc:Depends} #『未修改』依賴 Description: Open source cross-platform screenshots #『已修改』簡短的一句描述Qt5-based open source cross-platform screenshot tool #『已修改』可以書寫詳細的描述

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


修改 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/

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


dh_make 的參數(shù)含義

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

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

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

雙擊即可安裝;


lintian 檢查包

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

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

當時倘若你有心走的更遠,那么怎么也不能耽誤了武學奇才,給出一個具體案例講解 Linux上面使用lintian檢測deb包報錯的解決方案。


dpkg-deb 查看 deb 的安裝路徑

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

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


其它有用命令

再補充兩個命令

  • ldd 可以查看依賴

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

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

系列地址

QtExamples

歡迎 star ? 和 fork 🍴這個系列的 C++ / QT / DTK 學習,附學習由淺入深的目錄。

總結(jié)

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

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