Building Packages

Embed Size (px)

Citation preview

  • 8/8/2019 Building Packages

    1/16

    Tutorial to Re-Build a Debian Package

    https://wiki.debian.org/BuildingTutorial

    02/04/15

    Contents

    1 Debian Source Package   1

    2 How to Download a source package   2

    2.1 With apt-get source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.2 From debian.org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    3 Working with a source package   2

    3.1 How to build the Debian package   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2 How to extract the source files  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    4 Introduction to Re-Build a Package   3

    5 Requirements   3

    6 configure apt   36.1 create a working directory   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46.2 Choose the package  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    7 The packaging workflow   4

    7.1 Get the source package   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    8 Get the build dependencies   5

    9 Rebuild without changes   5

    10 Edit the source code   6

    11 Building the modified package   7

    12 Building the source package   8

    12.1 Sending your changes to the BTS   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    13 Conclusions   8

    13.1 That’s it, get ready for the next package   . . . . . . . . . . . . . . . . . . . . . . . . . 813.2 Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    14 Questions and Answers   9

    15 How to download, modify, build and install a Debian source package   10

    1

    https://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/BuildingTutorial

  • 8/8/2019 Building Packages

    2/16

    16 Advanced Building Tips   11

    16.1 Useful packages   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1116.2 Using the changelog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1116.3 Building the source package   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1216.4 Using interdiff   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1216.5 Using lintian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    17 Referências   13

    1 Debian Source Package

    This definition of a source package is due to Debian. The source packages provide you with all of thenecessary files to compile or otherwise, build the desired piece of software. It consists, in its simplestform, of three files:

    •  The upstream tarball with  .tar.gz ending

    •  A description file with .dsc ending. It contains the name of the package, both, in its filenameas well as content (after the Source: keyword).

    •  A tarball, with any changes made to upstream source, plus all the files created for the Debianpackage.

    –  This has a  .debian.tar.gz (source format: 3.0)

    –   or a  .diff.gz ending (source format: 1.0)

    Why looking at a source package?

    •  If you want to study packaging, or a specific package.

    •  If you want to know which compile-time options are enabled for a specific package DebianPack-ageConfiguration.

    Why bother with source package if there is a binary package?Some build systems (e.g. cmake) and ad-hoc scripts provide a convenient way to produce Binary

    packages (i.e. .deb files for Debian, .rpm for   RedHat,   etc) in a uniform fashion. Although suchapproach sounds appealing at first, it is not only insufficient for upload into Debian proper, wheresource package is required, but might be inferior, because binary-only distribution

    •  does not even provide a unified way to obtain the sources of a corresponding software (as it isnow with "apt-get source package")

    •  makes it difficult (if not impossible at all) for a user/contributor to rebuild .deb package dueto lack of standardization in build procedures and description of build-dependencies. It isoften mitigated by upstream authors with detailed descriptions in README, but instructionswould vary from package to package, are not guarantee to be complete; thus altogether makingrebuilding not straightforward and fragile. So it is of no surprise why Debian policy demandssource packages with standardized build procedures – Debian needs to rebuild architecture-agnostic software for all (>12) supported platforms.

    •  manually composes "Depends:" for a generated .deb and those quite often would not be cor-rect across Debian suites/releases, thus complicating installation procedures. Quick and dirtysolution is often to build statically thus loosing benefits of modularity in Debian, making thesoftware less robust and secure.

    2

    https://wiki.debian.org/SourcePackagehttps://wiki.debian.org/dschttps://wiki.debian.org/Packaginghttps://wiki.debian.org/Packagehttps://wiki.debian.org/DebianPackageConfigurationhttps://wiki.debian.org/DebianPackageConfigurationhttps://wiki.debian.org/RedHathttps://wiki.debian.org/RedHathttps://wiki.debian.org/RedHathttps://wiki.debian.org/DebianPackageConfigurationhttps://wiki.debian.org/DebianPackageConfigurationhttps://wiki.debian.org/Packagehttps://wiki.debian.org/Packaginghttps://wiki.debian.org/dschttps://wiki.debian.org/SourcePackage

  • 8/8/2019 Building Packages

    3/16

    2 How to Download a source package

    Sources are normally not installed. You can only install them if you know the package name.How to find the name of the source packageOn http://www.debian.org/distrib/packages, there is a search engine which will go to:  http:

    //packages.debian.org/src:.

    A source package could generate many .debs.  To know the source package name, see the Source:field in the output of 

    a pt - c a c he s h ow p a c k a ge _ n a me

    2.1 With apt-get source

    One way to obtain source packages is with

    a p t - g e t   source   < p a c ka g e n am e >

    You need a  deb-src  entry in your  /etc/apt/sources.list file, like:

    d eb - s r c h t tp : / / h t t p . u s . d e b ia n . o r g / d e b ia n u n s ta b l e m a in

    A source package is downloaded in the current directory and is not installed (it will not appearin the installed package list), so you need not be  root to use apt-get source.

    2.2 From debian.org

    You can do a manual download, from  http://www.debian.org/distrib/packages.When you are on the page of the package, choose a distribution, and you will have a link to the

    three files which make the source package.

    3 Working with a source package

    3.1 How to build the Debian package

    You need root privileges or fakeroot to build the .[50]deb. To automatically build the DebianPackageafter download, you can also use

    a pt - g e t - - b u il d   source   p a c k a g e _ n a m e

    If you want to make optimized packages from source to your machine in order to possibly getfaster operation, install and use apt-build (which in order uses apt-get source -b ...)

    3.2 How to extract the source files

    Assuming the files of the source package are present in the same directory, to unpack a source package,you can typically use:

    d p k g - source   - x . . ./ p a t h / t o / p a c k a g e_ n a m e . d s c

    3

    http://www.debian.org/distrib/packageshttp://www.debian.org/distrib/packageshttp://packages.debian.org/src:%3Cname%3Ehttp://packages.debian.org/src:%3Cname%3Ehttp://packages.debian.org/src:%3Cname%3Ehttps://wiki.debian.org/debhttps://wiki.debian.org/debhttps://wiki.debian.org/debhttps://wiki.debian.org/SourcePackage/ManualDownloadhttp://www.debian.org/distrib/packageshttp://www.debian.org/distrib/packageshttps://wiki.debian.org/DebianPackagehttps://wiki.debian.org/es/apt-buildhttps://wiki.debian.org/es/apt-buildhttps://wiki.debian.org/DebianPackagehttp://www.debian.org/distrib/packageshttps://wiki.debian.org/SourcePackage/ManualDownloadhttps://wiki.debian.org/debhttps://wiki.debian.org/debhttp://packages.debian.org/src:%3Cname%3Ehttp://packages.debian.org/src:%3Cname%3Ehttp://www.debian.org/distrib/packages

  • 8/8/2019 Building Packages

    4/16

    All the files will be unpacked into a directory: package-version.See also UsingQuilt

    4 Introduction to Re-Build a Package

    This tutorial is based on a   BuildingTutorial,   Debian Women,   Build it Event  held by MargaritaManterola (in collaboration with the OpenHatch project) on 07-May-2011

    This tutorial is about taking an existing package, re-building it, applying changes to it, andpreparing those changes so that you can send them to a bug as a patch.

    5 Requirements

    You need very little previous knowledge for this tutorial, just no fear of the command line :-)Technical requirements:

    •  You should have a working Debian distribution or a Debian based distribution.

    •   You should have administration rights in this computer (either root or sudo). Every time thatadmin rights are needed, we’ll include  sudo  in front. If you don’t use  sudo, just get the rightswhatever way you like.

    •   build-essential

    •   fakeroot

    •   devscripts

    Remember:

    s u do a pt - g e t i n s ta l l b ui l d - e s s e n t i al f a k er o o t d e v s cr i p t s

    6 configure apt

    Once you have installed the needed packages, the next thing that you need to do, is make sure thatyou have some source repositories configured in your computer.

    Open your  /etc/apt/sources.list file and check if you have one or more lines that start with

    deb-src.

    d eb - s r c h t tp : / / h t t p . u s . d e b ia n . o r g / d e b ia n u n s ta b l e m a in

    These lines are needed in order to work with source packages.If you don’t have any deb-src lines, you’ll need to add at least one . This is usually achieved by

    copying one of the existing deb lines and changing it to deb-src. You can do that by running aneditor with admin rights (sudo gedit,   sudo kate  or   sudo vim).

    Usually, it’s a good idea to use unstable as the repository, since you’ll be working with the latestversion of the package. But if you intend to modify a package as it is in stable or testing you could

    use those distributions as well.If you use stable/testing/whatever as your running distribution, getting source from unstablewon’t affect it.

    Once you’ve added the line, you’ll need to do

    4

    https://wiki.debian.org/UsingQuilthttps://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/BuildingTutorialhttp://women.debian.org/https://wiki.debian.org/DebianWomen/BuildItEventhttp://openhatch.org/https://packages.debian.org/sudohttps://packages.debian.org/build-essentialhttps://packages.debian.org/fakeroothttps://packages.debian.org/devscriptshttps://packages.debian.org/devscriptshttps://packages.debian.org/fakeroothttps://packages.debian.org/build-essentialhttps://packages.debian.org/sudohttp://openhatch.org/https://wiki.debian.org/DebianWomen/BuildItEventhttp://women.debian.org/https://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/UsingQuilt

  • 8/8/2019 Building Packages

    5/16

    s ud o a pt - g e t u p da t e

    in order to update the list of packages available for installation.

    6.1 create a working directory

    With the sources URL added to your apt repositories, you’ll now be able to get the source of anyDebian package that you like.

    For this particular tutorial, we are going to download the source of one package and make a smallmodification to it, so that it works better.

    It’s always a good idea to have a directory that you use to work with source software, separatedfrom other directories used for other stuff. In case you don’t already have one, I’d suggest that youcreate a directory src with another one called debian inside it:

     mk dir -p src / d eb ia n /;   cd   s r c / d e b i a n

    Inside this directory we will get the source of the package that we want to work with.

    6.2 Choose the package

    In this example, we’ll use a package called  fdupes, a tool to detect duplicate files, and we will befixing the Debian bug 585426.

    You should install the package (or check if you have it installed and up to the latest version)before proceeding, since you’ll need to have the dependencies sorted up when you want to install themodified one.

    If you don’t have fdupes installed, you can do this by doing:

    s ud o a pt - g e t i n st a ll f d up e s

    and check that the bug is still present. You can do that by running

    f d u pe s - - h e lp

    and checking that the second line of info for the  --debug  option still doesn’t make any sense.

    7 The packaging workflow

    7.1 Get the source package

    In order to get the source of  fdupes, what you need to do is go to your chosen directory (src/debianin this example) and do (as normal user):

    a p t - g e t   source   fdupes

    You have now downloaded the 3 files (.dsc,   .tar.gz,   .diff.gz), composing the Debian sourcepackage.

    It probably also informed you that fdupes is maintained with Git.

    Once the package is downloaded, you can check the directory where you are (typing   ls), andyou’ll find that apart from the 3 files that were downloaded you also have a directory, calledfdupes-1.50-PR2. This is the unpacked source of the Debian package.

    To enter that directory, type:

    5

    https://packages.debian.org/fdupeshttps://bugs.debian.org/585426https://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://bugs.debian.org/585426https://packages.debian.org/fdupes

  • 8/8/2019 Building Packages

    6/16

    cd   fdupes -1.50- PR2/

    When you check the contents of this directory (typing ls again), you’ll see quite a number of filesof different sorts, and a debian directory.

    Every Debian (or Debian derivative) package includes a debian directory, where all the informationrelated to the Debian package is stored. Anything that’s outside of that directory, is the upstream

    code, i.e. the original code released by whoever programmed the software.Go into the debian directory, by typing

    cd   debian

    This is the directory that the package maintainer has added to the source code to build thepackage.

    In this directory you’ll usually find lots of files related to Debian’s version of the program, Debianspecific patches, manpages, documentation, and so on. We won’t be going any deeper about thesefiles here. Look at its contents by typing ls.

    Just keep in mind that•  the rules file is the executable file that we will be running in order to build the package.

    •  in the patches directory, there are also a number of patches applied by the maintainer

    Let’s move one directory back, by doing

    cd   ..

    You should be again at  fdupes-1.50-PR2, the main directory of the source code.

    8 Get the build dependencies

    In order to build almost any program, you will need some dependencies installed.The dependencies are the programs or libraries needed to compile your program. Usually it’s a

    bunch of packages that end in -dev, but it might also be other things like automake or gcc, dependingon how many development tools you’ve ever installed in that machine.

    apt provides a way of easily installing all the needed dependencies:

    s ud o a pt - g e t b ui ld - d ep f d up e s

    Once you’ve downloaded these tools, you’ll be ready to build the package.

    9 Rebuild without changes

    Before making any changes to the code, let’s build the package as it is right now, just to make surethat it builds and it installs properly. Do:

    d eb ui ld - b - uc - us

    The extra parameters are to build a binary only package (.deb) and prevent it from signing the

    package, since we don’t need to sign it right now.This command will probably take a while to run, since usually it first has to run  ./configure,

    then it has to compile the source code and then build the packages. In fact, it will run the commandsthat are listed in the  debian/rules  file and will hopefully end with a message like:

    6

    https://packages.debian.org/automakehttps://packages.debian.org/gcchttps://packages.debian.org/apthttps://packages.debian.org/apthttps://packages.debian.org/gcchttps://packages.debian.org/automake

  • 8/8/2019 Building Packages

    7/16

    d pk g - d e b : b u i l di n g p a c ka g e   fdupes '   in   . ./ f d u p e s _ 1 . 50 - P R 2 - 3 _ < y o u r a rc h > . d e b'

    In your own language. can be   i386,  amd64, depending on which architecture you arerunning your machine on.

    Once the package has correctly built, the next step is to install this file with:

    s u do d p kg - i . . / f d u pe s _ 1 . 50 - P R 2 - 3 _ < y o u r a rc h > . d e b

    After that, check that the bug is still present, running

    f d u pe s - - h e lp

    10 Edit the source code

    Now, we want to actually fix this bug.Here comes the fun part. When you are trying to fix a package bug, sometimes it will be located

    in the upstream source, sometimes it will be related to how the program was packaged for Debian.So you’ll be editing different files depending on where the problem is.

    In this particular case, the package uses the dpatch tool, a tool to manage patches for the package,so we will make use of that tool. Other packages use a different tool, called  quilt, to manage patches,but we won’t be covering that one in this tutorial.

    To create a new patch, you’ll need to do the following. Type:

    d p at c h - e d it - p a t c h 8 0 _ b t s 5 8 5 42 6 _ f i x _h e l p 7 0 _ b t s 5 3 7 1 3 8_ d i s a m b ig u a t e _ r e cu r s e .←

    dpatch

    This will start a new shell inside a special environment, where you can edit your files and dpatchwill afterwards take care of getting the differences with the original.

    •  the first parameter is the name assigned to the new patch:  80_bts585426_fix_help

    •   the second parameter is the last patch that should be applied before applying the new one:70_bts537138_disambiguate_recurse.dpatch

    The name of the patch was chosen to match the pattern already established by the maintainer.Now we need to edit the fdupes.c file. Go to the line 1066 and delete it. The line says:

    printf ( " \ teach set of d u p li c a t e s wi t ho ut p r o mp t i ng the user \n " ) ;

    You can edit the file with your preferred editor (vi fdupes.c, gedit fdupes.c,  kate fdupes.c,etc).

    Once you are done, you should type into the console :

    exit

    It will end the special environment that dpatch created for us, and you’ll have a new patch in

    the  debian/patches/ directory. Check it out with:

    ca t   d e b i a n / p a t c h e s / 8 0 _ b t s 5 8 5 4 2 6 _ f i x _ h e l p . d p a t c h

    7

    https://packages.debian.org/dpatchhttps://packages.debian.org/quilthttps://packages.debian.org/quilthttps://packages.debian.org/dpatch

  • 8/8/2019 Building Packages

    8/16

    In order for this patch to get applied, you’ll need to edit the  debian/patches/00list file, andadd after the last line:

    8 0 _ b t s 5 8 5 4 2 6 _ f i x _ h e l p

    The  00list file is the dpatch file that lists all the patches that will be applied. They are applied

    in order, from the one appearing in the first line, till the one appearing in the last line.Before rebuilding the package with this patch, we want to make our package different from the

    original one, so that we can afterwards extract the changes in order to send them as a patch to thebug. In order to do this, type:

    d ch - n

    This will

    •  add a new entry in the changelog file, maybe with your name (depending on other configurationsthat we are not going to cover), with the current date,

    •  and open the changelog with the configured command-line editor.

    –   In case this is vi, and it’s your first time with vi, you can start editing by pressing theInsert key, and after you are finished, you can save an close by pressing:   ESC:wq 

    So, you are editing the changelog file now. What you have to enter in this file is some descriptionof the change that we’ve made. For example:

    A dd ed a p at ch to f ix t he - - he lp i ss ue w it h t he - - de bu g o pt io n . C lo se s :   #←

    5 8 5 4 2 6 " .

    Do this in the line with the empty *.

    11 Building the modified package

    Once this is done, just build the package again with the same command as before:

    d eb ui ld - b - uc - us

    Add -tc option if you want to clean build artifacts.In the case that you need to debug the compiled package, particularly if it’s a Segmentation Fault

    that you are trying to fix, you might want to compile it like this, so that the code is not optimizedand not stripped and it’s easier to debug:

    D E B _ B U I L D _ O P T I O N S = 'n o s tr i p n o o pt d e bu g '   d pk g - b u i l dp a ck a ge - b - uc - u s

    You’ll see a some compiling output on screen. This is usually not very interesting, unless you arelooking for a bug that is related to the compilation of the package itself. Normally, I just let this gowhile I do something else (grab some cookies for your coffee, for example).

    This time, the package created should be:   ../fdupes_1.50-PR2-3.1_.deb, the

    version changed because  dch changed it for us in the changelog (-3.1 instead of -3).Installing and testing the modified packageInstall it with:

    8

  • 8/8/2019 Building Packages

    9/16

    s u do d p kg - i . . / f d u pe s _ 1 . 50 - P R 2 - 3 . 1 _ < y o u r a r c h > . d e b

    and test that the help is now correct. :)If in any case what you’ve done has made things worst, you can always revert to Debian’s version

    by doing:

    a pt - g e t i n s ta l l - - r e i ns t a l l f d u pe s = < p r e v i o us _ v er s i o n >

    12 Building the source package

    Once a bug is fixed, you might want to also build the source package. This means not only the .debfile, but the other files that we downloaded at the beginning. This is done with:

    d e bu i ld - u s - u c

    If you’ve built the source package, go to the previous directory with   cd .. and check the filesthere with ls. You’ll see that you have more files there now, including 2 dsc files, one for the originalpackage and one for the one you just made.

    12.1 Sending your changes to the BTS

    Once you’ve built any source package, you can find out the difference between your package and theoriginal one, by using debdiff :

    d e b di f f f d u p es _ 1 . 5 0 - P R2 - 3 . d sc f d u p es _ 1 . 5 0 - P R2 - 3 .1 . d s c > m y _ f i r st _ d e b di f f . d i f f

    In this particular case, since we used the dpatch tool, what we would send to the BTS as a patchis the dpatch file that we created, because the change that we made is enclosed there.

    But if we hadn’t used dpatch, we could use the output of that debdiff and send that to the BTS.

    13 Conclusions

    13.1 That’s it, get ready for the next package

    You’re done with modifying the package, you can now keep fixing bugs in other Debian packages!

    These are the important commands you’ll need to remember:

    a p t - g e t   source   t h e - p a c k a g e

    a pt - g e t b ui l d - d e p t he - p a c ka g e

    (...)

    f a k er o o t d e b ia n / r u l e s b i n ar y

    d p kg - i t he - p a c ka g e - b l a b la . d e b

    d pk g - b u i l dp a c k a ge - u s - u c

    d e b di f f p a ck a ge - b l a b la . d s c p a ck a ge - b l a b la . 1 . d s c > a n o t h er _ d e b d if f . d i f f

    13.2 Feedback

    I hope you enjoyed the tutorial, please send me your feedback if you feel like it, or modify this wikiif you want to add some useful information I might have left out.

    9

    https://packages.debian.org/debdiffmailto:[email protected]:[email protected]://packages.debian.org/debdiff

  • 8/8/2019 Building Packages

    10/16

    14 Questions and Answers

    QUESTION:  Is the number 80_ in the name of the patch a cosmetic thing?ANSWER:   It’s so that you can get them in order when you list them with ls. The order of 

    application is the order in which they appear in the 00list file. Some maintainers choose to give themnumbers, some don’t. But when you are patching a package, you should try to follow whichever

    pattern the maintainer chose.QUESTION:  About dpatch-edit-patch params, where did you get your params? I mean thebts****

    ANSWER:  The first one is the name of the patch. I chose a name similar to the other ones."bts" stands for "bug tracking system", the number is the bug number that we are closing.

    QUESTION:  How does dch pick the number "3.1"?ANSWER:  We used dch -n, because we are not the maintainer of the package (n stands for

    non-maintainer). Then it’s 3.1. If you were the maintainer, you’d have done dch -i, and it wouldhave chosen -4

    QUESTION:  When sending a patch to the BTS, do we send anything about the changelog?ANSWER:  Not necessarily, but you can send that too, it depends on the bug that you are

    fixing. Sending the debdiff output is always acceptable.If you’re sending only a small and simple patch it’s normal to let the maintainer write the

    changelog; if it’s a big NMU update then yes you should send the changelog as part of your big patchto the BTS.

    QUESTION:  Sending a changelog with a NMU is considered not polite?ANSWER:  What some (not all) maintainers don’t like is if when someone actually uploads an

    NMU. Sending a patch to the BTS is always/immer/siempre/sempre well received!QUESTION:  What is the quickest/easiest way to find out which tool (if any) is used to manage

    patches?ANSWER:  If there’s a build dependency on quilt or dpatch in debian/control. Or if there’s a

    debian/README.source file.QUESTION:  Does this workflow work for all packages?ANSWER:   The workflow is quite general. The only thing that might change is the patch

    management system (dpatch/quilt/none). The rest is basically always the same.See also

    •   If you want to go on a little bit further in your package making, you can read some of theAdvancedBuildingTips

    •  You can find a tutorial about creating new packages for Debian at

    •   Introduction to Debian Packaging

    •   Packaging is the page that gather everything about packaging on this wiki

    15 How to download, modify, build and install a Debian source

    package

    This fast review is based on a following  question in ubuntu forum.QUESTION:   If I want to make minor changes to the source code of a Debian package, how

    do I go about downloading, incrementing the package version, building the (modified) source, andinstalling it on my computer?ANSWER:  There’s basically two ways to do it, the first one is the classic form, you’ll get the

    source with:

    10

    https://wiki.debian.org/AdvancedBuildingTipshttps://wiki.debian.org/IntroDebianPackaginghttps://wiki.debian.org/Packaginghttp://askubuntu.com/questions/81870/how-to-download-modify-build-and-install-a-debian-source-packagehttp://askubuntu.com/questions/81870/how-to-download-modify-build-and-install-a-debian-source-packagehttps://wiki.debian.org/Packaginghttps://wiki.debian.org/IntroDebianPackaginghttps://wiki.debian.org/AdvancedBuildingTips

  • 8/8/2019 Building Packages

    11/16

    Classic:  First get the source package with:

    a p t - g e t   source   p a c k a g e

    Then you’ll be able to modify it:

    cd   p a c k a g e

    v i m s o m e _f i l e

    Rebuild it:

    s ud o a pt - g e t b ui ld - d ep p a ck a ge

    d ch - i

    d eb ui ld - us - uc - b

    Note that the command dch -i will will open your editor to edit the  changefile, here’s where

    you can increment the package version.And now you can install it:

    s ud o d pk g - i . ./ p a c ka g e . de b

    New Ubuntu Approach:  The new way (the Ubuntu way) is by using  bzr branches, you’ll get thecode by using:

    b z r b r a nc h l p : u b u nt u / p a c k a g e   # w h ic h w il l d o wn l oa d t he l a te st u b un t u   ←

    p a c k a g eb z r b r a nc h l p : u b u nt u / t r u s t y / p a c k ag e   # t o g et t he p ac ka ge i n t ru st y

    You can also get the code using:

    lp - source   p a c k a g e   # lp - s o u rc e i s p ar t o f t he u bu nt u - d ev - t oo l s p kg

    Then you’ll be able to edit it:

    cd   p a c k a g e

    v i m s o m e _f i l e

    Rebuild it:

    d ch - i

    d e b c o m m i t

    b zr bd -- - b - us - uc

    And install it:

    s ud o d pk g - i . ./ p a c ka g e . de b

    I recommend that you check the  Ubuntu packaging guide out to know the details.

    Also you might encounter problems if the package depends of others

    11

    http://developer.ubuntu.com/packaging/html/http://developer.ubuntu.com/packaging/html/

  • 8/8/2019 Building Packages

    12/16

    16 Advanced Building Tips

    Once you’ve downloaded, modified and built a Debian package, you usually feel that you could keepdoing it, since it’s   so easy . Here we presents some advanced tips to do it.

    And it’s just like that, but even if the BuildingTutorial is a good introduction to modifying Debianpackages, there were some things that were left out on purpose, to keep it simple. So, here you’ll

    find some extra tips to take full advantage of some of the many Debian tools.

    16.1 Useful packages

    Although they might not be build dependencies, there’s a bunch of useful packages that anyoneinterested in helping Debian development should have installed:

    build-essential:  includes the essential packages for building your own ones, this is probably alreadyinstalled in your system, but it never hurts to check.

    devscripts:  lots of useful scripts for Debian Development (including:   dch, debuild, uscan, uupdate

    and many others).

    lintian:  package checker, that verify the built package is in good shape regarding Debian Policy.

    diff, patch and patchutils:  utilities for working with patches.

    And here’s a useful command line, to copy and paste:

    a pt - g e t i n st a ll b ui ld - e s s en t ia l d e vs c ri p ts l i nt i an d if f p at ch p a tc h ut i ls

    16.2 Using the changelogThe debian/changelog file is one of the important files in the debian directory. Let’s take onechangelog entry as an example:

    c o nt r ol - c e n t e r ( 1 : 2. 8 . 1 - 3 ) u n s t ab l e ; u r g en c y = l o w

    * d e b ia n / r u l e s :

    - C o rr e ct e d e r ro n eo u s l in e r e sp o ns i bl e   for   n o t i n cl u di n g t he . d e sk t op

    f i l es ( C l o s es :   # 2 7 4 4 0 1 )

    * d e b ia n / p a t c h es :

    - S u p p re s s e d   'T e xt E d it o r '   in t he " p r e fe r re d a p pl i ca t io n s " a s it 's u s el e ss

    w it h t he n ew m im e   type   s y s t e m .

    - - A rn a ud P a ta rd < a r na u d . p at ar d @r tp - n et . o rg > T hu , 2 5 N ov 2 00 4 2 1 :1 6 :0 4 + 01 0 0

    There are many things to notice in this entry: in the first line you have the name and versionof the source package, also the distribution to which it is initially uploaded to (unstable), and theurgency level (this is used by Debian bots to determine when the package is ready to enter testing).

    Then, we have a bulleted list with the files that were changed and a very brief summary of thereasons for the changes. Note the  274401,  this is used by Debian bugs bot to automatically closebugs.

    Finally, we can see the name and email of the last person to change the package and the date onwhich it was changed.

    Now, to edit the   changelog, if you have installed   devscripts   you’ll have a nifty commanddch that prefills a lot of this information and opens your preferred editor. Although you can editeverything manually if you want, I recommend using  dch.

    12

    https://wiki.debian.org/AdvancedBuildingTipshttps://wiki.debian.org/BuildingTutorialhttps://bugs.debian.org/274401https://bugs.debian.org/274401https://bugs.debian.org/274401https://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/AdvancedBuildingTips

  • 8/8/2019 Building Packages

    13/16

    Important: when you first start modifying a package, you’ll want to make a new version of it,so that you can differentiate it from the original one. So, the first time you are about to edit achangelog entry, you should do

    d ch - i

    This will add a whole new entry, incrementing the version number and letting you write whichfiles you modified. After that, you can always add more info about your changes by just using  dch.

    16.3 Building the source package

    When you do  debian/rules  binary you just build the binary package, the one that you want toinstall on your system. But in many cases you want to also build the source package (which isactually composed of three files:  package_version.orig.tar.gz,  package_version.diff.gz andpackage_version.dsc).

    To do this there are lots of tools. Here, we’ll be using  dpkg-buildpackage  that comes with the

    dpkg-dev package (part of  build-essential).Provided you already modified the package and the package’s changelog, you’ll build it by doing:

    d pk g - b u i l dp a c k a ge - r f a k e ro o t

    (There are many option to pass to  dpkg-buildpackage, -S  for example, will only build the sourcepackage, -tc will clean the compiled files after making the package, etc. See man dpkg-buildpackagefor more info)

    Once you’ve done this, you’ll find a new trio of files in your parent directory, that will have almostthe same name as the ones you downloaded but with a change in the version number.

    16.4 Using interdiff 

    If you’ve built a package, incremented the version number in the changelog file, and now you havetwo sets of three files (two source packages) you can gather what the changes between versions werevery easily by using interdiff:

    i n t e rd i f f - z p a c k a g e_ o l d v e rs i o n . d i f f . g z p a c k a g e_ n e w v er s i o n . d i f f . g z > y o ur . p a t c h

    After running this command you can inspect the contents of your.patch, it should contain every-thing that you changed to the package. If you are solving a bug in the Debian BTS, this is what you

    should send to the bug number.Note that  interdiff  only makes sense when you haven’t changed the upstream source (this is

    to say, the  package_version.orig.tar.gz has to be the same).

    16.5 Using lintian

    Not all Debian packages comply perfectly with Debian’s policy. Sometimes this is due to the policygetting quickly updated, sometimes this is because of lack of time from the maintainer, sometimesbecause it’s not easy for certain software to be totally compliant.

    In any case, these tools provide us with an easy way to find problems in Debian packages. Using

    them is easy: you just run them against the  .diff.gz and  .dsc files of your source package.Depending on the package, you could get no messages, some messages or a lot of messages. Thesemessages are usually brief and not always will you know what they mean, but many times they’llpoint you to the problematic part of the package.

    13

  • 8/8/2019 Building Packages

    14/16

    Of course, these tools are just an aid, not a replacement to actually reading Debian’s policy.

    17 Referências

    1. https://wiki.debian.org/BuildingTutorial?diffs=1&show_att=1&action=rss_rc&uniq ue=0&page=BuildingTutorial&ddiffs=1

    2.   https://wiki.debian.org/FrontPage

    3.   https://wiki.debian.org/BuildingTutorial?action=raw

    4.   https://wiki.debian.org/BuildingTutorial?action=print

    5.   https://wiki.debian.org/FindPage

    6.   https://wiki.debian.org/TitleIndex

    7.   https://wiki.debian.org/WordIndex

    8.   https://wiki.debian.org/HelpOnFormatting

    9.  http://www.debian.org/

    10.  https://wiki.debian.org/

    11.   https://wiki.debian.org/BuildingTutorial?action=login

    12.   https://wiki.debian.org/FrontPage

    13.   https://wiki.debian.org/RecentChanges

    14.   https://wiki.debian.org/FindPage

    15.   https://wiki.debian.org/HelpContents

    16.   https://wiki.debian.org/BuildingTutorial

    17.  http://www.debian.org/

    18.  https://wiki.debian.org/

    19.   https://wiki.debian.org/BuildingTutorial?action=login

    20.   https://wiki.debian.org/BuildingTutorial

    21.   https://wiki.debian.org/BuildingTutorial?action=info

    22.   https://wiki.debian.org/BuildingTutorial?action=AttachFile

    23. https://wiki.debian.org/BuildingTutorial?action=fullsearch&context=180&value=linkto:"BuildingTutorial"

    24.   https://wiki.debian.org/DebianWiki/EditorGuide#translation

    25.   https://wiki.debian.org/es/BuildingTutorial26.   https://wiki.debian.org/it/BuildingTutorial

    27.   https://wiki.debian.org/pt_BR/BuildingTutorial

    14

    https://wiki.debian.org/BuildingTutorial?diffs=1&show_att=1&action=rss_rc&unique=0&page=BuildingTutorial&ddiffs=1https://wiki.debian.org/BuildingTutorial?diffs=1&show_att=1&action=rss_rc&unique=0&page=BuildingTutorial&ddiffs=1https://wiki.debian.org/FrontPagehttps://wiki.debian.org/BuildingTutorial?action=rawhttps://wiki.debian.org/BuildingTutorial?action=printhttps://wiki.debian.org/FindPagehttps://wiki.debian.org/TitleIndexhttps://wiki.debian.org/WordIndexhttps://wiki.debian.org/HelpOnFormattinghttp://www.debian.org/https://wiki.debian.org/https://wiki.debian.org/BuildingTutorial?action=loginhttps://wiki.debian.org/FrontPagehttps://wiki.debian.org/RecentChangeshttps://wiki.debian.org/FindPagehttps://wiki.debian.org/HelpContentshttps://wiki.debian.org/BuildingTutorialhttp://www.debian.org/https://wiki.debian.org/https://wiki.debian.org/BuildingTutorial?action=loginhttps://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/BuildingTutorial?action=infohttps://wiki.debian.org/BuildingTutorial?action=AttachFilehttps://wiki.debian.org/BuildingTutorial?action=fullsearch&context=180&value=linkto:%22BuildingTutorial%22https://wiki.debian.org/BuildingTutorial?action=fullsearch&context=180&value=linkto:%22BuildingTutorial%22https://wiki.debian.org/DebianWiki/EditorGuide#translationhttps://wiki.debian.org/es/BuildingTutorialhttps://wiki.debian.org/it/BuildingTutorialhttps://wiki.debian.org/pt_BR/BuildingTutorialhttps://wiki.debian.org/pt_BR/BuildingTutorialhttps://wiki.debian.org/it/BuildingTutorialhttps://wiki.debian.org/es/BuildingTutorialhttps://wiki.debian.org/DebianWiki/EditorGuide#translationhttps://wiki.debian.org/BuildingTutorial?action=fullsearch&context=180&value=linkto:%22BuildingTutorial%22https://wiki.debian.org/BuildingTutorial?action=fullsearch&context=180&value=linkto:%22BuildingTutorial%22https://wiki.debian.org/BuildingTutorial?action=AttachFilehttps://wiki.debian.org/BuildingTutorial?action=infohttps://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/BuildingTutorial?action=loginhttps://wiki.debian.org/http://www.debian.org/https://wiki.debian.org/BuildingTutorialhttps://wiki.debian.org/HelpContentshttps://wiki.debian.org/FindPagehttps://wiki.debian.org/RecentChangeshttps://wiki.debian.org/FrontPagehttps://wiki.debian.org/BuildingTutorial?action=loginhttps://wiki.debian.org/http://www.debian.org/https://wiki.debian.org/HelpOnFormattinghttps://wiki.debian.org/WordIndexhttps://wiki.debian.org/TitleIndexhttps://wiki.debian.org/FindPagehttps://wiki.debian.org/BuildingTutorial?action=printhttps://wiki.debian.org/BuildingTutorial?action=rawhttps://wiki.debian.org/FrontPagehttps://wiki.debian.org/BuildingTutorial?diffs=1&show_att=1&action=rss_rc&unique=0&page=BuildingTutorial&ddiffs=1https://wiki.debian.org/BuildingTutorial?diffs=1&show_att=1&action=rss_rc&unique=0&page=BuildingTutorial&ddiffs=1

  • 8/8/2019 Building Packages

    15/16

    28.   https://wiki.debian.org/BuildingTutorial#Introduction

    29.   https://wiki.debian.org/BuildingTutorial#Requirements

    30.   https://wiki.debian.org/BuildingTutorial#configure_apt

    31.   https://wiki.debian.org/BuildingTutorial#create_a_working_directory

    32.   https://wiki.debian.org/BuildingTutorial#Choose_the_package

    33.   https://wiki.debian.org/BuildingTutorial#The_packaging_workflow

    34.   https://wiki.debian.org/BuildingTutorial#Get_the_source_package

    35.   https://wiki.debian.org/BuildingTutorial#Get_the_build_dependencies

    36.   https://wiki.debian.org/BuildingTutorial#Rebuild_without_changes

    37.   https://wiki.debian.org/BuildingTutorial#Edit_the_source_code

    38.   https://wiki.debian.org/BuildingTutorial#Building_the_modified_package

    39. https://wiki.debian.org/BuildingTutorial#Installing_and_testing_the_modified_package

    40.   https://wiki.debian.org/BuildingTutorial#Building_the_source_package

    41.   https://wiki.debian.org/BuildingTutorial#Sending_your_changes_to_the_BTS

    42.   https://wiki.debian.org/BuildingTutorial#Conclusions

    43. https://wiki.debian.org/BuildingTutorial#That.27s_it.2C_get_ready_for_the_next_

    package

    44.   https://wiki.debian.org/BuildingTutorial#Feedback

    45.   https://wiki.debian.org/BuildingTutorial#Questions]_and_Answers

    46.   https://wiki.debian.org/BuildingTutorial#See_also

    47.  http://women.debian.org/

    48.   https://wiki.debian.org/DebianWomen/BuildItEvent

    49.  http://openhatch.org/

    50.   https://packages.debian.org/sudo

    51.   https://packages.debian.org/build-essential

    52.   https://packages.debian.org/fakeroot

    53.   https://packages.debian.org/devscripts

    54.   https://packages.debian.org/fdupes

    55.   https://bugs.debian.org/585426

    56.   https://packages.debian.org/fdupes

    57.   https://packages.debian.org/fdupes

    15

    https://wiki.debian.org/BuildingTutorial#Introductionhttps://wiki.debian.org/BuildingTutorial#Requirementshttps://wiki.debian.org/BuildingTutorial#configure_apthttps://wiki.debian.org/BuildingTutorial#create_a_working_directoryhttps://wiki.debian.org/BuildingTutorial#Choose_the_packagehttps://wiki.debian.org/BuildingTutorial#The_packaging_workflowhttps://wiki.debian.org/BuildingTutorial#Get_the_source_packagehttps://wiki.debian.org/BuildingTutorial#Get_the_build_dependencieshttps://wiki.debian.org/BuildingTutorial#Rebuild_without_changeshttps://wiki.debian.org/BuildingTutorial#Edit_the_source_codehttps://wiki.debian.org/BuildingTutorial#Building_the_modified_packagehttps://wiki.debian.org/BuildingTutorial#Installing_and_testing_the_modified_packagehttps://wiki.debian.org/BuildingTutorial#Building_the_source_packagehttps://wiki.debian.org/BuildingTutorial#Sending_your_changes_to_the_BTShttps://wiki.debian.org/BuildingTutorial#Conclusionshttps://wiki.debian.org/BuildingTutorial#That.27s_it.2C_get_ready_for_the_next_packagehttps://wiki.debian.org/BuildingTutorial#That.27s_it.2C_get_ready_for_the_next_packagehttps://wiki.debian.org/BuildingTutorial#Feedbackhttps://wiki.debian.org/BuildingTutorial#Questions]_and_Answershttps://wiki.debian.org/BuildingTutorial#See_alsohttp://women.debian.org/https://wiki.debian.org/DebianWomen/BuildItEventhttp://openhatch.org/https://packages.debian.org/sudohttps://packages.debian.org/build-essentialhttps://packages.debian.org/fakeroothttps://packages.debian.org/devscriptshttps://packages.debian.org/fdupeshttps://bugs.debian.org/585426https://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://packages.debian.org/fdupeshttps://bugs.debian.org/585426https://packages.debian.org/fdupeshttps://packages.debian.org/devscriptshttps://packages.debian.org/fakeroothttps://packages.debian.org/build-essentialhttps://packages.debian.org/sudohttp://openhatch.org/https://wiki.debian.org/DebianWomen/BuildItEventhttp://women.debian.org/https://wiki.debian.org/BuildingTutorial#See_alsohttps://wiki.debian.org/BuildingTutorial#Questions]_and_Answershttps://wiki.debian.org/BuildingTutorial#Feedbackhttps://wiki.debian.org/BuildingTutorial#That.27s_it.2C_get_ready_for_the_next_packagehttps://wiki.debian.org/BuildingTutorial#That.27s_it.2C_get_ready_for_the_next_packagehttps://wiki.debian.org/BuildingTutorial#Conclusionshttps://wiki.debian.org/BuildingTutorial#Sending_your_changes_to_the_BTShttps://wiki.debian.org/BuildingTutorial#Building_the_source_packagehttps://wiki.debian.org/BuildingTutorial#Installing_and_testing_the_modified_packagehttps://wiki.debian.org/BuildingTutorial#Building_the_modified_packagehttps://wiki.debian.org/BuildingTutorial#Edit_the_source_codehttps://wiki.debian.org/BuildingTutorial#Rebuild_without_changeshttps://wiki.debian.org/BuildingTutorial#Get_the_build_dependencieshttps://wiki.debian.org/BuildingTutorial#Get_the_source_packagehttps://wiki.debian.org/BuildingTutorial#The_packaging_workflowhttps://wiki.debian.org/BuildingTutorial#Choose_the_packagehttps://wiki.debian.org/BuildingTutorial#create_a_working_directoryhttps://wiki.debian.org/BuildingTutorial#configure_apthttps://wiki.debian.org/BuildingTutorial#Requirementshttps://wiki.debian.org/BuildingTutorial#Introduction

  • 8/8/2019 Building Packages

    16/16

    58.   https://packages.debian.org/fdupes

    59.   https://packages.debian.org/automake

    60.   https://packages.debian.org/gcc

    61.   https://packages.debian.org/apt

    62.   https://packages.debian.org/dpatch

    63.   https://packages.debian.org/quilt

    64.   https://packages.debian.org/debdiff

    65.  mailto:[email protected]

    66.   https://wiki.debian.org/AdvancedBuildingTips

    67.   https://wiki.debian.org/IntroDebianPackaging

    68.   https://wiki.debian.org/Packaging

    69.   https://wiki.debian.org/eugene

    70.  http://moinmo.in/

    71.  http://moinmo.in/Python

    72.   http://validator.w3.org/check?uri=referer

    73.   https://wiki.debian.org/Teams/DebianWiki

    74.   http://bugs.debian.org/wiki.debian.org

    75.   http://git.debian.org/?p=collab-maint/wiki.debian.org.git;a=summary

    76.   http://www.dg-i.net/

    https://packages.debian.org/fdupeshttps://packages.debian.org/automakehttps://packages.debian.org/gcchttps://packages.debian.org/apthttps://packages.debian.org/dpatchhttps://packages.debian.org/quilthttps://packages.debian.org/debdiffmailto:[email protected]://wiki.debian.org/AdvancedBuildingTipshttps://wiki.debian.org/IntroDebianPackaginghttps://wiki.debian.org/Packaginghttps://wiki.debian.org/eugenehttp://moinmo.in/http://moinmo.in/Pythonhttp://validator.w3.org/check?uri=refererhttps://wiki.debian.org/Teams/DebianWikihttp://bugs.debian.org/wiki.debian.orghttp://git.debian.org/?p=collab-maint/wiki.debian.org.git;a=summaryhttp://www.dg-i.net/http://www.dg-i.net/http://git.debian.org/?p=collab-maint/wiki.debian.org.git;a=summaryhttp://bugs.debian.org/wiki.debian.orghttps://wiki.debian.org/Teams/DebianWikihttp://validator.w3.org/check?uri=refererhttp://moinmo.in/Pythonhttp://moinmo.in/https://wiki.debian.org/eugenehttps://wiki.debian.org/Packaginghttps://wiki.debian.org/IntroDebianPackaginghttps://wiki.debian.org/AdvancedBuildingTipsmailto:[email protected]://packages.debian.org/debdiffhttps://packages.debian.org/quilthttps://packages.debian.org/dpatchhttps://packages.debian.org/apthttps://packages.debian.org/gcchttps://packages.debian.org/automakehttps://packages.debian.org/fdupes