1PKGBUILD(5) Pacman Manual PKGBUILD(5)
2
3
4
6 PKGBUILD - Arch Linux package build description file
7
9 PKGBUILD
10
12 This manual page describes general rules about PKGBUILDs. Once a
13 PKGBUILD is written, the actual package is built using makepkg and
14 installed with pacman.
15
16 Note
17 An example PKGBUILD, useful for reference, is located in
18 /usr/share/pacman along with other example files such as an install
19 script. You can copy the provided PKGBUILD.proto file to a new
20 package build directory and make customizations to suit your needs.
21
23 The following is a list of standard options and directives available
24 for use in a PKGBUILD. These are all understood and interpreted by
25 makepkg, and most of them will be directly transferred to the built
26 package. The mandatory fields for a minimally functional PKGBUILD are
27 pkgname, pkgver, pkgrel and arch.
28
29 If you need to create any custom variables for use in your build
30 process, it is recommended to prefix their name with an _ (underscore).
31 This will prevent any possible name clashes with internal makepkg
32 variables. For example, to store the base kernel version in a variable,
33 use something similar to $_basekernver.
34
35 pkgname (array)
36 Either the name of the package or an array of names for split
37 packages. Valid characters for members of this array are
38 alphanumerics, and any of the following characters: “@ . _ + -”.
39 Additionally, names are not allowed to start with hyphens or dots.
40
41 pkgver
42 The version of the software as released from the author (e.g.,
43 2.7.1). The variable is not allowed to contain colons, forward
44 slashes, hyphens or whitespace.
45
46 The pkgver variable can be automatically updated by providing a
47 pkgver() function in the PKGBUILD that outputs the new package
48 version. This is run after downloading and extracting the sources
49 and running the prepare() function (if present), so it can use
50 those files in determining the new pkgver. This is most useful when
51 used with sources from version control systems (see below).
52
53 pkgrel
54 This is the release number specific to the distribution. This
55 allows package maintainers to make updates to the package’s
56 configure flags, for example. This is typically set to 1 for each
57 new upstream software release and incremented for intermediate
58 PKGBUILD updates. The variable is a positive integer, with an
59 optional subrelease level specified by adding another positive
60 integer separated by a period (i.e. in the form x.y).
61
62 epoch
63 Used to force the package to be seen as newer than any previous
64 versions with a lower epoch, even if the version number would
65 normally not trigger such an upgrade. This value is required to be
66 a positive integer; the default value if left unspecified is 0.
67 This is useful when the version numbering scheme of a package
68 changes (or is alphanumeric), breaking normal version comparison
69 logic. See pacman(8) for more information on version comparisons.
70
71 pkgdesc
72 This should be a brief description of the package and its
73 functionality. Try to keep the description to one line of text and
74 to not use the package’s name.
75
76 url
77 This field contains a URL that is associated with the software
78 being packaged. This is typically the project’s web site.
79
80 license (array)
81 This field specifies the license(s) that apply to the package.
82 Commonly used licenses can be found in /usr/share/licenses/common.
83 If you see the package’s license there, simply reference it in the
84 license field (e.g., license=('GPL')). If the package provides a
85 license not available in /usr/share/licenses/common, then you
86 should include it in the package itself and set license=('custom')
87 or license=('custom:LicenseName'). The license should be placed in
88 $pkgdir/usr/share/licenses/$pkgname/ when building the package. If
89 multiple licenses are applicable, list all of them: license=('GPL'
90 'FDL').
91
92 install
93 Specifies a special install script that is to be included in the
94 package. This file should reside in the same directory as the
95 PKGBUILD and will be copied into the package by makepkg. It does
96 not need to be included in the source array (e.g.,
97 install=$pkgname.install).
98
99 changelog
100 Specifies a changelog file that is to be included in the package.
101 The changelog file should end in a single newline. This file should
102 reside in the same directory as the PKGBUILD and will be copied
103 into the package by makepkg. It does not need to be included in the
104 source array (e.g., changelog=$pkgname.changelog).
105
106 source (array)
107 An array of source files required to build the package. Source
108 files must either reside in the same directory as the PKGBUILD, or
109 be a fully-qualified URL that makepkg can use to download the file.
110 To simplify the maintenance of PKGBUILDs, use the $pkgname and
111 $pkgver variables when specifying the download location, if
112 possible. Compressed files will be extracted automatically unless
113 found in the noextract array described below.
114
115 Additional architecture-specific sources can be added by appending
116 an underscore and the architecture name e.g., source_x86_64=().
117 There must be a corresponding integrity array with checksums, e.g.
118 cksums_x86_64=().
119
120 It is also possible to change the name of the downloaded file,
121 which is helpful with weird URLs and for handling multiple source
122 files with the same name. The syntax is: source=('filename::url').
123
124 makepkg also supports building developmental versions of packages
125 using sources downloaded from version control systems (VCS). For
126 more information, see Using VCS Sources below.
127
128 Files in the source array with extensions .sig, .sign or, .asc are
129 recognized by makepkg as PGP signatures and will be automatically
130 used to verify the integrity of the corresponding source file.
131
132 validpgpkeys (array)
133 An array of PGP fingerprints. If this array is non-empty, makepkg
134 will only accept signatures from the keys listed here and will
135 ignore the trust values from the keyring. If the source file was
136 signed with a subkey, makepkg will still use the primary key for
137 comparison.
138
139 Only full fingerprints are accepted. They must be uppercase and
140 must not contain whitespace characters.
141
142 noextract (array)
143 An array of file names corresponding to those from the source
144 array. Files listed here will not be extracted with the rest of the
145 source files. This is useful for packages that use compressed data
146 directly.
147
148 cksums (array)
149 This array contains CRC checksums for every source file specified
150 in the source array (in the same order). makepkg will use this to
151 verify source file integrity during subsequent builds. If SKIP is
152 put in the array in place of a normal hash, the integrity check for
153 that source file will be skipped. To easily generate cksums, run
154 “makepkg -g >> PKGBUILD”. If desired, move the cksums line to an
155 appropriate location. Note that checksums generated by "makepkg -g"
156 should be verified using checksum values provided by the software
157 developer.
158
159 md5sums, sha1sums, sha224sums, sha256sums, sha384sums, sha512sums,
160 b2sums (arrays)
161 Alternative integrity checks that makepkg supports; these all
162 behave similar to the cksums option described above. To enable use
163 and generation of these checksums, be sure to set up the
164 INTEGRITY_CHECK option in makepkg.conf(5).
165
166 groups (array)
167 An array of symbolic names that represent groups of packages,
168 allowing you to install multiple packages by requesting a single
169 target. For example, one could install all KDE packages by
170 installing the kde group.
171
172 arch (array)
173 Defines on which architectures the given package is available
174 (e.g., arch=('i686' 'x86_64')). Packages that contain no
175 architecture specific files should use arch=('any'). Valid
176 characters for members of this array are alphanumerics and “_”.
177
178 backup (array)
179 An array of file names, without preceding slashes, that should be
180 backed up if the package is removed or upgraded. This is commonly
181 used for packages placing configuration files in /etc. See
182 "Handling Config Files" in pacman(8) for more information.
183
184 depends (array)
185 An array of packages this package depends on to run. Entries in
186 this list should be surrounded with single quotes and contain at
187 least the package name. Entries can also include a version
188 requirement of the form name<>version, where <> is one of five
189 comparisons: >= (greater than or equal to), <= (less than or equal
190 to), = (equal to), > (greater than), or < (less than).
191
192 If the dependency name appears to be a library (ends with .so),
193 makepkg will try to find a binary that depends on the library in
194 the built package and append the version needed by the binary.
195 Appending the version yourself disables automatic detection.
196
197 Additional architecture-specific depends can be added by appending
198 an underscore and the architecture name e.g., depends_x86_64=().
199
200 makedepends (array)
201 An array of packages this package depends on to build but are not
202 needed at runtime. Packages in this list follow the same format as
203 depends.
204
205 Additional architecture-specific makedepends can be added by
206 appending an underscore and the architecture name e.g.,
207 makedepends_x86_64=().
208
209 checkdepends (array)
210 An array of packages this package depends on to run its test suite
211 but are not needed at runtime. Packages in this list follow the
212 same format as depends. These dependencies are only considered when
213 the check() function is present and is to be run by makepkg.
214
215 Additional architecture-specific checkdepends can be added by
216 appending an underscore and the architecture name e.g.,
217 checkdepends_x86_64=().
218
219 optdepends (array)
220 An array of packages (and accompanying reasons) that are not
221 essential for base functionality, but may be necessary to make full
222 use of the contents of this package. optdepends are currently for
223 informational purposes only and are not utilized by pacman during
224 dependency resolution. Packages in this list follow the same format
225 as depends, with an optional description appended. The format for
226 specifying optdepends descriptions is:
227
228 optdepends=('python: for library bindings')
229
230 Additional architecture-specific optdepends can be added by
231 appending an underscore and the architecture name e.g.,
232 optdepends_x86_64=().
233
234 conflicts (array)
235 An array of packages that will conflict with this package (i.e.
236 they cannot both be installed at the same time). This directive
237 follows the same format as depends. Versioned conflicts are
238 supported using the operators as described in depends.
239
240 Additional architecture-specific conflicts can be added by
241 appending an underscore and the architecture name e.g.,
242 conflicts_x86_64=().
243
244 provides (array)
245 An array of “virtual provisions” this package provides. This allows
246 a package to provide dependencies other than its own package name.
247 For example, the dcron package can provide cron, which allows
248 packages to depend on cron rather than dcron OR fcron.
249
250 Versioned provisions are also possible, in the name=version format.
251 For example, dcron can provide cron=2.0 to satisfy the cron>=2.0
252 dependency of other packages. Provisions involving the > and <
253 operators are invalid as only specific versions of a package may be
254 provided.
255
256 If the provision name appears to be a library (ends with .so),
257 makepkg will try to find the library in the built package and
258 append the correct version. Appending the version yourself disables
259 automatic detection.
260
261 Additional architecture-specific provides can be added by appending
262 an underscore and the architecture name e.g., provides_x86_64=().
263
264 replaces (array)
265 An array of packages this package should replace. This can be used
266 to handle renamed/combined packages. For example, if the j2re
267 package is renamed to jre, this directive allows future upgrades to
268 continue as expected even though the package has moved. Versioned
269 replaces are supported using the operators as described in depends.
270
271 Sysupgrade is currently the only pacman operation that utilizes
272 this field. A normal sync or upgrade will not use its value.
273
274 Additional architecture-specific replaces can be added by appending
275 an underscore and the architecture name e.g., replaces_x86_64=().
276
277 options (array)
278 This array allows you to override some of makepkg’s default
279 behavior when building packages. To set an option, just include the
280 option name in the options array. To reverse the default behavior,
281 place an “!” at the front of the option. Only specify the options
282 you specifically want to override, the rest will be taken from
283 makepkg.conf(5). NOTE: force is a now-removed option in favor of
284 the top level epoch variable.
285
286 strip
287 Strip symbols from binaries and libraries. If you frequently
288 use a debugger on programs or libraries, it may be helpful to
289 disable this option.
290
291 docs
292 Save doc directories. If you wish to delete doc directories,
293 specify !docs in the array.
294
295 libtool
296 Leave libtool (.la) files in packages. Specify !libtool to
297 remove them.
298
299 staticlibs
300 Leave static library (.a) files in packages. Specify
301 !staticlibs to remove them (if they have a shared counterpart).
302
303 emptydirs
304 Leave empty directories in packages.
305
306 zipman
307 Compress man and info pages with gzip.
308
309 ccache
310 Allow the use of ccache during build(). More useful in its
311 negative form !ccache with select packages that have problems
312 building with ccache.
313
314 distcc
315 Allow the use of distcc during build(). More useful in its
316 negative form !distcc with select packages that have problems
317 building with distcc.
318
319 buildflags
320 Allow the use of user-specific buildflags (CPPFLAGS, CFLAGS,
321 CXXFLAGS, LDFLAGS) during build() as specified in
322 makepkg.conf(5). More useful in its negative form !buildflags
323 with select packages that have problems building with custom
324 buildflags.
325
326 makeflags
327 Allow the use of user-specific makeflags during build() as
328 specified in makepkg.conf(5). More useful in its negative form
329 !makeflags with select packages that have problems building
330 with custom makeflags such as -j2 (or higher).
331
332 debug
333 Add the user-specified debug flags (DEBUG_CFLAGS,
334 DEBUG_CXXFLAGS) to their counterpart buildflags as specified in
335 makepkg.conf(5). When used in combination with the ‘strip’
336 option, a separate package containing the debug symbols is
337 created.
338
339 lto
340 Enable building packages using link time optimization. Adds
341 -flto to both CFLAGS and CXXFLAGS.
342
344 In addition to the above directives, PKGBUILDs require a set of
345 functions that provide instructions to build and install the package.
346 As a minimum, the PKGBUILD must contain a package() function which
347 installs all the package’s files into the packaging directory, with
348 optional prepare(), build(), and check() functions being used to create
349 those files from source.
350
351 This is directly sourced and executed by makepkg, so anything that Bash
352 or the system has available is available for use here. Be sure any
353 exotic commands used are covered by the makedepends array.
354
355 If you create any variables of your own in any of these functions, it
356 is recommended to use the Bash local keyword to scope the variable to
357 inside the function.
358
359 package() Function
360 The package() function is used to install files into the directory
361 that will become the root directory of the built package and is run
362 after all the optional functions listed below. The packaging stage
363 is run using fakeroot to ensure correct file permissions in the
364 resulting package. All other functions will be run as the user
365 calling makepkg.
366
367 prepare() Function
368 An optional prepare() function can be specified in which operations
369 to prepare the sources for building, such as patching, are
370 performed. This function is run after the source extraction and
371 before the build() function. The prepare() function is skipped when
372 source extraction is skipped.
373
374 build() Function
375 The optional build() function is used to compile and/or adjust the
376 source files in preparation to be installed by the package()
377 function.
378
379 check() Function
380 An optional check() function can be specified in which a package’s
381 test-suite may be run. This function is run between the build() and
382 package() functions. Be sure any exotic commands used are covered
383 by the checkdepends array.
384
385 All of the above variables such as $pkgname and $pkgver are available
386 for use in the packaging functions. In addition, makepkg defines the
387 following variables:
388
389 srcdir
390 This contains the directory where makepkg extracts, or copies, all
391 source files.
392
393 All of the packaging functions defined above are run starting
394 inside $srcdir
395
396 pkgdir
397 This contains the directory where makepkg bundles the installed
398 package. This directory will become the root directory of your
399 built package. This variable should only be used in the package()
400 function.
401
402 startdir
403 This contains the absolute path to the directory where the PKGBUILD
404 is located, which is usually the output of $(pwd) when makepkg is
405 started. Use of this variable is deprecated and strongly
406 discouraged.
407
409 makepkg supports building multiple packages from a single PKGBUILD.
410 This is achieved by assigning an array of package names to the pkgname
411 directive. Each split package uses a corresponding packaging function
412 with name package_foo(), where foo is the name of the split package.
413
414 All options and directives for the split packages default to the global
415 values given in the PKGBUILD. Nevertheless, the following ones can be
416 overridden within each split package’s packaging function: pkgdesc,
417 arch, url, license, groups, depends, optdepends, provides, conflicts,
418 replaces, backup, options, install, and changelog.
419
420 Note that makepkg does not consider split package depends when checking
421 if dependencies are installed before package building and with
422 --syncdeps. All packages required to make the package are required to
423 be specified in the global depends and makedepends arrays.
424
425 An optional global directive is available when building a split
426 package:
427
428 pkgbase
429 The name used to refer to the group of packages in the output of
430 makepkg and in the naming of source-only tarballs. If not
431 specified, the first element in the pkgname array is used. Valid
432 characters for this variable are alphanumerics, and any of the
433 following characters: “@ . _ + -”. Additionally, the variable is
434 not allowed to start with hyphens or dots.
435
437 Pacman has the ability to store and execute a package-specific script
438 when it installs, removes, or upgrades a package. This allows a package
439 to configure itself after installation and perform an opposite action
440 upon removal.
441
442 The exact time the script is run varies with each operation, and should
443 be self-explanatory. Note that during an upgrade operation, none of the
444 install or remove functions will be called.
445
446 Scripts are passed either one or two “full version strings”, where a
447 full version string is either pkgver-pkgrel or epoch:pkgver-pkgrel, if
448 epoch is non-zero.
449
450 pre_install
451 Run right before files are extracted. One argument is passed: new
452 package full version string.
453
454 post_install
455 Run right after files are extracted. One argument is passed: new
456 package full version string.
457
458 pre_upgrade
459 Run right before files are extracted. Two arguments are passed in
460 this order: new package full version string, old package full
461 version string.
462
463 post_upgrade
464 Run after files are extracted. Two arguments are passed in this
465 order: new package full version string, old package full version
466 string.
467
468 pre_remove
469 Run right before files are removed. One argument is passed: old
470 package full version string.
471
472 post_remove
473 Run right after files are removed. One argument is passed: old
474 package full version string.
475
476 To use this feature, create a file such as pkgname.install and put it
477 in the same directory as the PKGBUILD script. Then use the install
478 directive:
479
480 install=pkgname.install
481
482 The install script does not need to be specified in the source array. A
483 template install file is available in /usr/share/pacman as
484 proto.install for reference with all of the available functions
485 defined.
486
488 Building a developmental version of a package using sources from a
489 version control system (VCS) is enabled by specifying the source in the
490 form:
491
492 source=('directory::url#fragment?query')
493
494 Currently makepkg supports the Bazaar, Git, Subversion, Fossil and
495 Mercurial version control systems. For other version control systems,
496 manual cloning of upstream repositories must be done in the prepare()
497 function.
498
499 The source URL is divided into four components:
500
501 directory
502 (optional) Specifies an alternate directory name for makepkg to
503 download the VCS source into.
504
505 url
506 The URL to the VCS repository. This must include the VCS in the URL
507 protocol for makepkg to recognize this as a VCS source. If the
508 protocol does not include the VCS name, it can be added by
509 prefixing the URL with vcs+. For example, using a Git repository
510 over HTTPS would have a source URL in the form: git+https://....
511
512 fragment
513 (optional) Allows specifying a revision number or branch for
514 makepkg to checkout from the VCS. A fragment has the form
515 type=value, for example to checkout a given revision the source
516 line would be source=(url#revision=123). The available types
517 depends on the VCS being used:
518
519 bzr
520 revision (see 'bzr help revisionspec' for details)
521
522 fossil
523 branch, commit, tag
524
525 git
526 branch, commit, tag
527
528 hg
529 branch, revision, tag
530
531 svn
532 revision
533
534 query
535 (optional) Allows specifying whether a VCS checkout should be
536 checked for PGP-signed revisions. The source line should have the
537 format source=(url#fragment?signed) or
538 source=(url?signed#fragment). Currently only supported by Git.
539
541 The following is an example PKGBUILD for the patch package. For more
542 examples, look through the build files of your distribution’s packages.
543 For those using Arch Linux, consult the Arch Build System (ABS) tree.
544
545 # Maintainer: Joe User <joe.user@example.com>
546
547 pkgname=patch
548 pkgver=2.7.1
549 pkgrel=1
550 pkgdesc="A utility to apply patch files to original sources"
551 arch=('i686' 'x86_64')
552 url="https://www.gnu.org/software/patch/patch.html"
553 license=('GPL')
554 groups=('base-devel')
555 depends=('glibc')
556 makedepends=('ed')
557 optdepends=('ed: for "patch -e" functionality')
558 source=("ftp://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.xz"{,.sig})
559 md5sums=('e9ae5393426d3ad783a300a338c09b72'
560 'SKIP')
561
562 build() {
563 cd "$srcdir/$pkgname-$pkgver"
564 ./configure --prefix=/usr
565 make
566 }
567
568 package() {
569 cd "$srcdir/$pkgname-$pkgver"
570 make DESTDIR="$pkgdir/" install
571 }
572
574 makepkg(8), pacman(8), makepkg.conf(5)
575
576 See the pacman website at https://archlinux.org/pacman/ for current
577 information on pacman and its related tools.
578
580 Bugs? You must be kidding; there are no bugs in this software. But if
581 we happen to be wrong, submit a bug report with as much detail as
582 possible at the Arch Linux Bug Tracker in the Pacman section.
583
585 Current maintainers:
586
587 • Allan McRae <allan@archlinux.org>
588
589 • Andrew Gregory <andrew.gregory.8@gmail.com>
590
591 • Eli Schwartz <eschwartz@archlinux.org>
592
593 • Morgan Adamiec <morganamilo@archlinux.org>
594
595 Past major contributors:
596
597 • Judd Vinet <jvinet@zeroflux.org>
598
599 • Aurelien Foret <aurelien@archlinux.org>
600
601 • Aaron Griffin <aaron@archlinux.org>
602
603 • Dan McGee <dan@archlinux.org>
604
605 • Xavier Chantry <shiningxc@gmail.com>
606
607 • Nagy Gabor <ngaba@bibl.u-szeged.hu>
608
609 • Dave Reisner <dreisner@archlinux.org>
610
611 For additional contributors, use git shortlog -s on the pacman.git
612 repository.
613
614
615
616Pacman 6.0.2 2023-05-19 PKGBUILD(5)