Create Ubuntu DEB package from a Qt application

摘要:
打包指南/QtApplication-UbuntuWikiQtApplication从QtApplication创建UbuntuDEB包以下说明描述了如何从Qtaapplication创建一个Ubuntu.deb包。编写介绍程序

PackagingGuide/QtApplication - Ubuntu Wiki

QtApplication



Create Ubuntu DEB package from a Qt application

The following instructions describe how to create an Ubuntu .deb package from a Qt application.

Introduction

Programs written using the Qt framework are not configured by a configure-script, but by the qmake (qmake-qt4) program which is part of the Qt development tools. This program will (also) generate the Makefile.

This guide assumes there is no similar package in an Ubuntu repository available and you intend to build a new package from scratch using dpkg-buildpackage / pbuilder.

A detailed guide on .deb packaging can be found at the PackagingGuide. This guide will describe the packaging process just in a short summary.

Setting up the environment

1. Download the necessary tools via apt-get

sudo apt-get install build-essential devscripts ubuntu-dev-tools debhelper dh-make diff patch gnupg fakeroot lintian pbuilder

2. Pbuilder lets you build in a clean, chroot environment, ensuring all dependencies are present. Create a file .pbuilderrc

nano .pbuilderrc

and fill it with

COMPONENTS="main restricted universe multiverse"

Then construct the base environment (note: it can take a long time)

sudo pbuilder create

3. Get the sources of the desired application and untar them into a specific directory

tar -xvf helloworld-1.0.tar.gz

4. Preserve an .orig-archive ('-' between name and version becomes '_'!)

cp helloworld-1.0.tar.gz helloworld_1.0.orig.tar.gz

5. Descend into the created directory and execute dh_make. Answer to the questions dh_make will ask

cd helloworld-1.0
dh_make -e your@email.address

6. Descend into the 'debian'-directory and delete unneeded templates (unless you need them)

cd debian
rm *.ex *.EX

7. Edit the 'changelog', 'copyright' and 'control' files. For information how to do it, go to https://wiki.ubuntu.com/PackagingGuide/PackagingOverview Make sure that libqt4-dev and qt4-qmake is added to the Build-Depends list (assuming you're using Qt 4.x).

8. In the next step, you can use either plain Debhelper or CDBS to write your rules file.

8a. If you want Debhelper, replace the 'rules'-file with the one from /usr/share/doc/debhelper/examples/rules.arch and edit it according to your needs

#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
#
# This version is for packages that are architecture dependent.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

build: build-stamp
build-stamp:
        dh_testdir

        # Add here commands to compile the package.
        qmake-qt4 -config release
        make

        touch build-stamp

clean:
        dh_testdir
        dh_testroot
        rm -f build-stamp

        # Add here commands to clean up after the build process.
        #$(MAKE) clean
        #$(MAKE) distclean

        dh_clean

install: build
        dh_testdir
        dh_testroot
        dh_prep
        dh_installdirs

        # Add here commands to install the package into debian/<packagename>
        make INSTALL_ROOT=`pwd`/debian/package_name install

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
        dh_testdir
        dh_testroot
        dh_installchangelogs
        dh_installdocs
        dh_installexamples
        dh_installman
        dh_link
        dh_strip
        dh_compress
        dh_fixperms
        dh_installdeb
        dh_shlibdeps
        dh_gencontrol
        dh_md5sums
        dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

Important: In line 38, change "package_name" into actual name of your package. If you have some custom commands, add it to line 16.

8b. CDBS (Common Debian Building System) provides a simpler method for writing the rules to build the package.

The use of this system requires that cdbs be added to the Build-Depends list in the control file (see step 7).

To use it, first install it with

sudo apt-get install cdbs

Then save the rules file with these contents

#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/qmake.mk

9. Add the following Lines to your .pro-file in the parent directory

TARGET = <application>
target.path = /usr/bin
INSTALLS += target

optional: add supplementary files to the installation

data.path = /usr/share/<application>/data
data.files = data/*
INSTALLS += data

A comprehensive guide that shows the possibilities of QMake, e.g. whether a certain file already exists on the target system, can be found at http://doc.qt.nokia.com/latest/qmake-manual.html

Building the package

10. Now you can either build the package locally or - if you prepared the pbuilder earlier - in a base environment.

10a. Building locally can be achieved with

debuild

It produces the DEB package in the directory above.

Note: If you don't have GPG key to sign the package, add parameters

debuild -uc -us

10b. To build with pbuilder, prepare .dsc file

debuild -S

Run pbuilder itself

sudo pbuilder build ../*.dsc

The DEB package goes to /var/cache/pbuilder/result/.

Note: Using pbuilder takes more time than building locally, but guarantees your package and its dependencies will be installed properly on any machine using Ubuntu. If you don't know if your prepared the sources properly, a common practice is to firstly build the package locally with debuild. If something goes wrong, you can speed up recompilation with parameters -nc. In the end, build the package again in pbuilder to make sure everything works.

免责声明:文章转载自《Create Ubuntu DEB package from a Qt application》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇导入pfx证书windows 下 note 版本管理-nvm下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

03-cmake语法-变量,字符串

CMake的基本数据类型是字符串(不区分大小写),一组字符串在一起称为列表(list)。 条件判断中的取值情况如下表: 真 1, ON, YES, TRUE, Y, 非0的数 假 0, OFF, NO, FALSE, N, IGNORE, 空字符串,以“-NOTFOUND”结尾的字符串 变量显式定义 set(VAR a b c) # 输出 V...

Android : apk签名的多种方法以及key的配置

  方法一:使用Android SDK中的签名工具给apk签名:   (1)Android源码的 build/target/product/security/ 目录下有 media.pk8、media.x509.pem、platform.pk8、platform.x509.pem、shared.pk8、shared.x509.pem、testkey.pk8...

openwrt固件支持3G和4G上网卡

http://wiki.openwrt.org/doc/howtobuild/wireless-router-with-a-3g-dongle Building image with support for 3g/4g and usb tethering Preparing build environment First of all, you nee...

Jenkins+Jdk+Git+Maven持续集成部署Weblogic实例项目

通过Jenkins部署Weblogic项目前,服务器需要提前安装好Weblogic服务,Weblogic服务搭建请百度或者在博客园搜索我的帖子“Weblogic服务搭建” 登录Jenkins http://IP或域名:8080 先构建一个“Build项目” 左侧导航栏,选择“新建任务”,然后输入一个任务名称,自定义,选择第二项“构建一个maven项目”,点...

QUARTZ系列之一-基础概念(Scheduler/Job/JobDetail/Trigger)

摘抄自quartz官方文档: The key interfaces of the Quartz API are: Scheduler - the main API for interacting with the scheduler.  (quartz提供的用来和调度器交互的API) Job - an interface to be implemen...

自定义yarn运行vue项目命令

  在项目中的package.json文件的scripts块中可以看到新项目的yarn命令集合 "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" },...