Prototype disk space checking functionality
[pacman-ng.git] / doc / PKGBUILD.5.txt
blobc85220b8d5703d4d1465d94ec1fc241e3408dd72
1 /////
2 vim:set ts=4 sw=4 syntax=asciidoc noet:
3 /////
4 PKGBUILD(5)
5 ===========
7 Name
8 ----
9 PKGBUILD - Arch Linux package build description file
12 Synopsis
13 --------
14 PKGBUILD
17 Description
18 -----------
19 This manual page is meant to describe general rules about PKGBUILDs. Once a
20 PKGBUILD is written, the actual package is built using makepkg and installed
21 with pacman.
23 NOTE: An example PKGBUILD, useful for reference, is located in '{pkgdatadir}'.
24 Also located there are other example files such as a ChangeLog and an install
25 script. You can copy the provided PKGBUILD.proto file to a new package build
26 directory and make customizations to suit your needs.
29 Options and Directives
30 ----------------------
31 The following is a list of standard options and directives available for use
32 in a PKGBUILD. These are all understood and interpreted by makepkg, and most
33 will be directly transferred to the built package.
35 If you need to create any custom variables for use in your build process, it is
36 recommended to name your custom variables with an '_' (underscore) prefix.
37 This will prevent any possible name clashes with internal makepkg variables.
38 For example, to store the base kernel version in a variable, use something
39 similar to `$_basekernver`.
41 *pkgname (array)*::
42         The name of the package. This has be a unix-friendly name as it will be
43         used in the package filename. Members of the array are not allowed to start
44         with hyphens.
46 *pkgver*::
47         The version of the software as released from the author (e.g. '2.7.1').
48         The variable is not allowed to contain hyphens.
50 *pkgrel*::
51         This is the release number specific to the Arch Linux release. This
52         allows package maintainers to make updates to the package's configure
53         flags, for example. A pkgrel of '1' is typically used for each upstream
54         software release and is incremented for intermediate PKGBUILD updates. The
55         variable is not allowed to contain hyphens.
57 *pkgdesc*::
58         This should be a brief description of the package and its functionality.
59         Try to keep the description to one line of text.
61 *epoch*::
62         Used to force the package to be seen as newer than any previous versions
63         with a lower epoch, even if the version number would normally not trigger
64         such an upgrade. This value is required to be a positive integer; the
65         default value if left unspecified is '0'. This is useful when the version
66         numbering scheme of a package changes (or is alphanumeric), breaking normal
67         version comparison logic. See linkman:pacman[8] for more information on
68         version comparisons.
70 *url*::
71         This field contains a URL that is associated with the software being
72         packaged. This is typically the project's website.
74 *license (array)*::
75         This field specifies the license(s) that apply to the package.
76         Commonly-used licenses are found in '/usr/share/licenses/common'. If you
77         see the package's license there, simply reference it in the license
78         field (e.g. `license=('GPL')`). If the package provides a license not
79         found in '/usr/share/licenses/common', then you should include the license
80         in the package itself and set `license=('custom')` or
81         `license=('custom:LicenseName')`. The license should be placed in
82         '$pkgdir/usr/share/licenses/$pkgname' when building the package. If
83         multiple licenses are applicable for a package, list all of them:
84         `license=('GPL' 'FDL')`.
86 *install*::
87         Specifies a special install script that is to be included in the package.
88         This file should reside in the same directory as the PKGBUILD, and will
89         be copied into the package by makepkg. It does not need to be included
90         in the source array (e.g. `install=pkgname.install`).
92 *changelog*::
93         Specifies a changelog file that is to be included in the package.
94         This file should reside in the same directory as the PKGBUILD, and will
95         be copied into the package by makepkg. It does not need to be included
96         in the source array (e.g. `changelog=$pkgname.changelog`).
98 *source (array)*::
99         An array of source files required to build the package. Source files
100         must either reside in the same directory as the PKGBUILD file, or be a
101         fully-qualified URL that makepkg will use to download the file. In order
102         to make the PKGBUILD as useful as possible, use the $pkgname and $pkgver
103         variables if possible when specifying the download location. Any files
104         that are compressed will automatically be extracted, unless found in
105         the noextract array listed below.
107 It is also possible to specify an optional filename, which is helpful
108 with weird URLs and for handling multiple source files with the same
109 name. The syntax is: `source=('filename::url')`.
111 *noextract (array)*::
112         An array of filenames corresponding to those from the source array. Files
113         listed here will not be extracted with the rest of the source files. This
114         is useful for packages which use compressed data which is downloaded but
115         not necessary to uncompress.
117 *md5sums (array)*::
118         This array contains an MD5 hash for every source file specified in the
119         source array (in the same order). makepkg will use this to verify source
120         file integrity during subsequent builds. To easily generate md5sums, run
121         ``makepkg -g >> PKGBUILD''. If desired, move the md5sums line to an
122         appropriate location.
124 *sha1sums, sha256sums, sha384sums, sha512sums (arrays)*::
125         Alternative integrity checks that makepkg supports; these all behave
126         similar to the md5sums option described above. To enable use and generation
127         of these checksums, be sure to set up the `INTEGRITY_CHECK` option in
128         linkman:makepkg.conf[5].
130 *groups (array)*::
131         An array of symbolic names that represent groups of packages, allowing
132         you to install multiple packages by requesting a single target. For
133         example, one could install all KDE packages by installing the 'kde' group.
135 *arch (array)*::
136         Defines on which architectures the given package is available (e.g.
137         `arch=('i686' 'x86_64')`). Packages that contain no architecture specific
138         files may use arch=('any').
140 *backup (array)*::
141         A space-delimited array of filenames, without preceding slashes, that
142         should be backed up if the package is removed or upgraded. This is
143         commonly used for packages placing configuration files in /etc. See
144         Handling Config Files in linkman:pacman[8] for more information.
146 *depends (array)*::
147         An array of packages that this package depends on to run. Packages in
148         this list should be surrounded with single quotes and contain at least
149         the package name. Entries can also include a version requirement of the
150         form 'name<>version', where <> is one of five comparisons: >= (greater
151         than or equal to), <= (less than or equal to), = (equal to), > (greater
152         than), or < (less than).
154 *makedepends (array)*::
155         An array of packages that this package depends on to build, but are not
156         needed at runtime. Packages in this list follow the same format as
157         depends.
159 *optdepends (array)*::
160         An array of packages (and accompanying reasons) that are not essential for
161         base functionality, but may be necessary to make full use of the contents
162         of this package. optdepends are currently for informational purposes only
163         and are not utilized by pacman during dependency resolution. The format
164         for specifying optdepends is:
166         optdepends=('fakeroot: for makepkg usage as normal user')
168 *conflicts (array)*::
169         An array of packages that will conflict with this package (i.e. they
170         cannot both be installed at the same time). This directive follows the
171         same format as depends. Versioned conflicts are also supported.
173 *provides (array)*::
174         An array of ``virtual provisions'' that this package provides. This allows
175         a package to provide dependencies other than its own package name. For
176         example, the dcron package can provide 'cron', which allows packages to
177         depend on 'cron' rather than 'dcron OR fcron'.
178         Versioned provisions are also possible, in the 'name=version' format.
179         For example, dcron can provide 'cron=2.0' to satisfy the 'cron>=2.0'
180         dependency of other packages. Provisions involving the '>' and '<'
181         operators are invalid as only specific versions of a package may be
182         provided.
184 *replaces (array)*::
185         An array of packages that this package should replace, and can be used
186         to handle renamed/combined packages. For example, if the 'j2re' package
187         is renamed to 'jre', this directive allows future upgrades to continue
188         as expected even though the package has moved. Sysupgrade is currently
189         the only pacman operation that utilizes this field, a normal sync will
190         not use its value.
192 *options (array)*::
193         This array allows you to override some of makepkg's default behavior
194         when building packages. To set an option, just include the option name
195         in the options array. To reverse the default behavior, place an ``!'' at
196         the front of the option. Only specify the options you specifically want
197         to override, the rest will be taken from linkman:makepkg.conf[5].
198         *NOTE:* 'force' is a now-removed option in favor of the top level 'epoch'
199         variable.
201         *strip*;;
202                 Strip symbols from binaries and libraries. If you frequently
203                 use a debugger on programs or libraries, it may be helpful to
204                 disable this option.
206         *docs*;;
207                 Save doc directories. If you wish to delete doc directories,
208                 specify `!docs` in the array.
210         *libtool*;;
211                 Leave libtool (.la) files in packages. Specify `!libtool` to
212                 remove them.
214         *emptydirs*;;
215                 Leave empty directories in packages.
217         *zipman*;;
218                 Compress man and info pages with gzip.
220         *ccache*;;
221                 Allow the use of ccache during build. More useful in its negative
222                 form `!ccache` with select packages that have problems building
223                 with ccache.
225         *distcc*;;
226                 Allow the use of distcc during build. More useful in its negative
227                 form `!distcc` with select packages that have problems building
228                 with distcc.
230         *makeflags*;;
231                 Allow the use of user-specific makeflags during build as specified
232                 in linkman:makepkg.conf[5]. More useful in its negative form
233                 `!makeflags` with select packages that have problems building with
234                 custom makeflags such as `-j2` (or higher).
237 build() Function
238 ----------------
239 In addition to the above directives, the optional build() bash function usually
240 comprises the remainder of the PKGBUILD. This is directly sourced and executed by
241 makepkg, so anything that bash or the system has available is available for use
242 here. Be sure any exotic commands used are covered by `makedepends`.
244 All of the above variables such as `pkgname` and `pkgver` are available for use
245 in the build function. In addition, makepkg defines three variables for your
246 use during the build and install process. These three variables are as follows:
248 *startdir*::
249         This contains the absolute path to the directory where the PKGBUILD was
250         located, which is usually the output of `$(pwd)` when makepkg is started.
252 *srcdir*::
253         This points to the directory where makepkg extracts or copies all source
254         files.
256 *pkgdir*::
257         This points to the directory where makepkg bundles the installed package
258         (this directory will become the root directory of your built package).
260 If you create any variables of your own in the build function, it is
261 recommended to use the bash `local` keyword to scope the variable to inside
262 the build function.
264 package() Function
265 ------------------
266 An optional package() function can be specified in addition to the build() function.
267 This function is run immediately after the build() function. When specified in
268 combination with the fakeroot BUILDENV option in linkman:makepkg.conf[5], fakeroot
269 usage will be limited to running the packaging stage. An existing build() function
270 will be run as the user calling makepkg.
272 Package Splitting
273 -----------------
274 makepkg supports building multiple packages from a single PKGBUILD. This is achieved
275 by assigning an array of package names to the `pkgname` directive. Each split package
276 uses a corresponding packaging function with name `package_foo()`, where `foo` is the
277 name of the split package.
279 All options and directives for the split packages default to the global values given
280 within the PKGBUILD. However, some of these can be overridden within each split
281 package's packaging function. The following variables can be overridden: `pkgver`,
282 `pkgrel`, `pkgdesc`, `arch`, `license`, `groups`, `depends`, `optdepends`,
283 `provides`, `conflicts`, `replaces`, `backup`, `options`, `install` and `changelog`.
285 An optional global directive is available when building a split package:
287 *pkgbase*::
288         The name used to refer to the group of packages in the output of makepkg
289         and in the naming of source-only tarballs.  If not specified, the first
290         element in the `pkgname` array is used.  The variable is not allowed to
291         begin with a hyphen.
293 Install/Upgrade/Remove Scripting
294 --------------------------------
295 Pacman has the ability to store and execute a package-specific script when it
296 installs, removes, or upgrades a package. This allows a package to configure
297 itself after installation and perform an opposite action upon removal.
299 The exact time the script is run varies with each operation:
301 *pre_install*::
302         script is run right before files are extracted. One argument is passed:
303         new package version.
305 *post_install*::
306         script is run right after files are extracted. One argument is passed:
307         new package version.
309 *pre_upgrade*::
310         script is run right before files are extracted. Two arguments are passed
311         in the following order: new package version, old package version.
313 *post_upgrade*::
314         script is run after files are extracted. Two arguments are passed
315         in the following order: new package version, old package version.
317 *pre_remove*::
318         script is run right before files are removed. One argument is passed:
319         old package version.
321 *post_remove*::
322         script is run right after files are removed. One argument is passed:
323         old package version.
325 To use this feature, create a file such as 'pkgname.install' and put it in the
326 same directory as the PKGBUILD script. Then use the install directive:
328         install=pkgname.install
330 The install script does not need to be specified in the source array. A
331 template install file is available in '{pkgdatadir}' as 'proto.install' for
332 reference with all of the available functions defined.
335 Development Directives
336 ----------------------
337 makepkg supports building development versions of packages without having to
338 manually update the pkgver in the PKGBUILD. This was formerly done using the
339 separate utility 'versionpkg'. In order to utilize this functionality, your
340 PKGBUILD must use correct variable names depending on the SCM being fetched
341 from.
343 *CVS*::
344         The generated pkgver will be the date the package is built.
346         *_cvsroot*;;
347                 The root of the CVS repository.
349         *_cvsmod*;;
350                 The CVS module to fetch.
352 *SVN*::
353         The generated pkgver will be the latest SVN revision number.
355         *_svntrunk*;;
356                 The trunk of the SVN repository.
358         *_svnmod*;;
359                 The SVN module to fetch.
361 *Git*::
362         The generated pkgver will be one formatted by the 'git-describe'
363         command, with '-' characters converted to '_' characters.
365         *_gitroot*;;
366                 The URL (all protocols supported) to the GIT repository.
368         *_gitname*;;
369                 GIT tag or branch to use.
371 *Mercurial*::
372         The generated pkgver will be the hg tip revision number.
374         *_hgroot*;;
375                 The URL of the mercurial repository.
377         *_hgrepo*;;
378                 The repository to follow.
380 *Darcs*::
381         The generated pkgver will be the date the package is built.
383         *_darcstrunk*;;
384                 URL to the repository trunk.
386         *_darcsmod*;;
387                 Darcs module to use.
389 *Bazaar*::
390         The generated pkgver will be the latest Bazaar revision number (revno).
392         *_bzrtrunk*;;
393                 URL to the bazaar repository.
395         *_bzrmod*;;
396                 Bazaar module to use.
399 Example
400 -------
401 The following is an example PKGBUILD for the 'patch' package. For more
402 examples, look through the build files of your distribution's packages. For
403 those using Arch Linux, consult the ABS tree.
405 [source,sh]
406 -------------------------------
407 include::PKGBUILD-example.txt[]
408 -------------------------------
410 See Also
411 --------
412 linkman:makepkg[8], linkman:pacman[8], linkman:makepkg.conf[5]
414 include::footer.txt[]