1 Source packages (from old Packaging Manual)
2 ===========================================
4 The Debian binary packages in the distribution are generated from Debian
5 sources, which are in a special format to assist the easy and automatic
10 Tools for processing source packages
11 ------------------------------------
13 Various tools are provided for manipulating source packages; they pack
14 and unpack sources and help build of binary packages and help manage the
15 distribution of new versions.
17 They are introduced and typical uses described here; see dpkg-source(1)
18 for full documentation about their arguments and operation.
20 For examples of how to construct a Debian source package, and how to use
21 those utilities that are used by Debian source packages, please see the
22 ``hello`` example package.
24 .. _s-pkg-dpkg-source:
26 ``dpkg-source`` - packs and unpacks Debian source packages
27 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 This program is frequently used by hand, and is also called from
30 package-independent automated building scripts such as
31 ``dpkg-buildpackage``.
33 To unpack a package it is typically invoked with
37 dpkg-source -x .../path/to/filename.dsc
39 with the ``filename.tar.gz`` and ``filename.diff.gz`` (if applicable) in
40 the same directory. It unpacks into ``package-version``, and if
41 applicable ``package-version.orig``, in the current directory.
43 To create a packed source archive it is typically invoked:
47 dpkg-source -b package-version
49 This will create the ``.dsc``, ``.tar.gz`` and ``.diff.gz`` (if
50 appropriate) in the current directory. ``dpkg-source`` does not clean
51 the source tree first - this must be done separately if it is required.
53 See also :ref:`s-pkg-sourcearchives`.
55 .. _s-pkg-dpkg-buildpackage:
57 ``dpkg-buildpackage`` - overall package-building control script
58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 See ``dpkg-buildpackage(1)``.
62 .. _s-pkg-dpkg-gencontrol:
64 ``dpkg-gencontrol`` - generates binary package control files
65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 This program is usually called from ``debian/rules`` (see
68 `section\_title <#s-pkg-sourcetree>`__) in the top level of the source
71 This is usually done just before the files and directories in the
72 temporary directory tree where the package is being built have their
73 permissions and ownerships set and the package is constructed using
76 ``dpkg-gencontrol`` must be called after all the files which are to go
77 into the package have been placed in the temporary build directory, so
78 that its calculation of the installed size of a package is correct.
80 It is also necessary for ``dpkg-gencontrol`` to be run after
81 ``dpkg-shlibdeps`` so that the variable substitutions created by
82 ``dpkg-shlibdeps`` in ``debian/substvars`` are available.
84 For a package which generates only one binary package, and which builds
85 it in ``debian/tmp`` relative to the top of the source package, it is
86 usually sufficient to call ``dpkg-gencontrol``.
88 Sources which build several binaries will typically need something like:
92 dpkg-gencontrol -Pdebian/pkg -ppackage
94 The ``-P`` tells ``dpkg-gencontrol`` that the package is being built in
95 a non-default directory, and the ``-p`` tells it which package's control
96 file should be generated.
98 ``dpkg-gencontrol`` also adds information to the list of files in
99 ``debian/files``, for the benefit of (for example) a future invocation
100 of ``dpkg-genchanges``.
102 .. _s-pkg-dpkg-shlibdeps:
104 ``dpkg-shlibdeps`` - calculates shared library dependencies
105 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 See ``dpkg-shlibdeps(1)``.
109 .. _s-pkg-dpkg-distaddfile:
111 ``dpkg-distaddfile`` - adds a file to ``debian/files``
112 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114 Some packages' uploads need to include files other than the source and
115 binary package files.
117 ``dpkg-distaddfile`` adds a file to the ``debian/files`` file so that it
118 will be included in the ``.changes`` file when ``dpkg-genchanges`` is
121 It is usually invoked from the ``binary`` target of ``debian/rules``:
125 dpkg-distaddfile filename section priority
127 The filename is relative to the directory where ``dpkg-genchanges`` will
128 expect to find it - this is usually the directory above the top level of
129 the source tree. The ``debian/rules`` target should put the file there
130 just before or just after calling ``dpkg-distaddfile``.
132 The section and priority are passed unchanged into the resulting
135 .. _s-pkg-dpkg-genchanges:
137 ``dpkg-genchanges`` - generates a ``.changes`` upload control file
138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140 See ``dpkg-genchanges(1)``.
142 .. _s-pkg-dpkg-parsechangelog:
144 ``dpkg-parsechangelog`` - produces parsed representation of a changelog
145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147 See ``dpkg-parsechangelog(1)``.
149 .. _s-pkg-dpkg-architecture:
151 ``dpkg-architecture`` - information about the build and host system
152 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154 See ``dpkg-architecture(1)``.
156 .. _s-pkg-sourcetree:
158 The Debian package source tree
159 ------------------------------
161 The source archive scheme described later is intended to allow a Debian
162 package source tree with some associated control information to be
163 reproduced and transported easily. The Debian package source tree is a
164 version of the original program with certain files added for the benefit
165 of the packaging process, and with any other changes required made to
166 the rest of the source code and installation scripts.
168 The extra files created for Debian are in the subdirectory ``debian`` of
169 the top level of the Debian package source tree. They are described
172 .. _s-pkg-debianrules:
174 ``debian/rules`` - the main building script
175 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177 See :ref:`s-debianrules`.
179 .. _s-pkg-srcsubstvars:
181 ``debian/substvars`` and variable substitutions
182 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184 See :ref:`s-substvars`.
191 See :ref:`s-debianfiles`.
198 This is the default temporary location for the construction of binary
199 packages by the ``binary`` target. The directory ``tmp`` serves as the
200 root of the file system tree as it is being constructed (for example, by
201 using the package's upstream makefiles install targets and redirecting
202 the output there), and it also contains the ``DEBIAN`` subdirectory. See
203 :ref:`s-pkg-bincreating`.
205 This is only a default and can be easily overridden. Most packaging
206 tools no longer use ``debian/tmp``, instead preferring ``debian/pkg``
207 for the common case of a source package building only one binary
208 package. Such tools usually only use ``debian/tmp`` as a temporary
209 staging area for built files and do not construct packages from it.
211 If several binary packages are generated from the same source tree, it
212 is usual to use a separate ``debian/pkg`` directory for each binary
213 package as the temporary construction locations.
215 Whatever temporary directories are created and used by the ``binary``
216 target must of course be removed by the ``clean`` target.
218 .. _s-pkg-sourcearchives:
220 Source packages as archives
221 ---------------------------
223 As it exists on the FTP site, a Debian source package consists of three
224 related files. You must have the right versions of all three to be able
227 Debian source control file - ``.dsc``
228 This file is a control file used by ``dpkg-source`` to extract a
230 :ref:`s-debiansourcecontrolfiles`.
232 Original source archive - ``package_upstream-version.orig.tar.gz``
233 This is a compressed (with ``gzip -9``) ``tar`` file containing the
234 source code from the upstream authors of the program.
236 Debian package diff - ``package_upstream_version-revision.diff.gz``
237 This is a unified context diff (``diff -u``) giving the changes
238 which are required to turn the original source into the Debian
239 source. These changes may only include editing and creating plain
240 files. The permissions of files, the targets of symbolic links and
241 the characteristics of special files or pipes may not be changed and
242 no files may be removed or renamed.
244 All the directories in the diff must exist, except the ``debian``
245 subdirectory of the top of the source tree, which will be created by
246 ``dpkg-source`` if necessary when unpacking.
248 The ``dpkg-source`` program will automatically make the
249 ``debian/rules`` file executable (see below).
251 If there is no original source code - for example, if the package is
252 specially prepared for Debian or the Debian maintainer is the same as
253 the upstream maintainer - the format is slightly different: then there
254 is no diff, and the tarfile is named ``package_version.tar.gz``, and
255 preferably contains a directory named ``package-version``.
259 Unpacking a Debian source package without ``dpkg-source``
260 ---------------------------------------------------------
262 ``dpkg-source -x`` is the recommended way to unpack a Debian source
263 package. However, if it is not available it is possible to unpack a
264 Debian source archive as follows:
266 1. Untar the tarfile, which will create a ``.orig`` directory.
268 2. Rename the ``.orig`` directory to ``package-version``.
270 3. Create the subdirectory ``debian`` at the top of the source tree.
272 4. Apply the diff using ``patch -p0``.
274 5. Untar the tarfile again if you want a copy of the original source
275 code alongside the Debian version.
277 It is not possible to generate a valid Debian source archive without
278 using ``dpkg-source``. In particular, attempting to use ``diff``
279 directly to generate the ``.diff.gz`` file will not work.
283 Restrictions on objects in source packages
284 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
286 The source package may not contain any hard links, [#]_ [#]_ device
287 special files, sockets or setuid or setgid files. [#]_
289 The source packaging tools manage the changes between the original and
290 Debian source using ``diff`` and ``patch``. Turning the original source
291 tree as included in the ``.orig.tar.gz`` into the Debian package source
292 must not involve any changes which cannot be handled by these tools.
293 Problematic changes which cause ``dpkg-source`` to halt with an error
294 when building the source package are:
296 - Adding or removing symbolic links, sockets or pipes.
298 - Changing the targets of symbolic links.
300 - Creating directories, other than ``debian``.
302 - Changes to the contents of binary files.
304 Changes which cause ``dpkg-source`` to print a warning but continue
307 - Removing files, directories or symlinks. [#]_
309 - Changed text files which are missing the usual final newline (either
310 in the original or the modified source tree).
312 Changes which are not represented, but which are not detected by
313 ``dpkg-source``, are:
315 - Changing the permissions of files (other than ``debian/rules``) and
318 The ``debian`` directory and ``debian/rules`` are handled specially by
319 ``dpkg-source`` - before applying the changes it will create the
320 ``debian`` directory, and afterwards it will make ``debian/rules``
324 This is so that the control file which is produced has the right
328 This is not currently detected when building source packages, but
329 only when extracting them.
332 Hard links may be permitted at some point in the future, but would
333 require a fair amount of work.
336 Setgid directories are allowed.
339 Renaming a file is not treated specially - it is seen as the removal
340 of the old file (which generates a warning, but is otherwise
341 ignored), and the creation of the new one.