浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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.

posted on 2012-04-22 10:26  lexus  阅读(469)  评论(0编辑  收藏  举报