1 ## The XBPS source packages collection
3 This repository contains the XBPS source packages collection to build binary packages
4 for the Void Linux distribution.
6 The included `xbps-src` script will fetch and compile the sources, and install its
7 files into a `fake destdir` to generate XBPS binary packages that can be installed
8 or queried through the `xbps-install(1)` and `xbps-query(1)` utilities, respectively.
15 `xbps-src` requires an utility to chroot and bind mount existing directories
16 into a `masterdir` that is used as its main `chroot` directory. `xbps-src` supports
17 multiple utilities to accomplish this task:
19 - `xbps-uunshare(1)` - XBPS utility that uses `user_namespaces(7)` (part of xbps, default).
20 - `xbps-uchroot(1)` - XBPS utility that uses `namespaces` and must be `setgid` (part of xbps).
21 - `proot(1)` - utility that implements chroot/bind mounts in user space, see https://proot-me.github.io/.
23 > NOTE: you don't need to be `root` to use `xbps-src`, use your preferred chroot style as explained
28 This utility requires these Linux kernel options:
35 This is the default method, and if your system does not support any of the required kernel
36 options it will fail with `EINVAL (Invalid argument)`.
40 This utility requires these Linux kernel options:
47 Your user must be added to a special group to be able to use `xbps-uchroot(1)` and the
48 executable must be `setgid`:
50 # chown root:<group> xbps-uchroot
51 # chmod 4750 xbps-uchroot
52 # usermod -a -G <group> <user>
54 > NOTE: by default in void you shouldn't do this manually, your user must be a member of
60 $ echo XBPS_CHROOT_CMD=uchroot >> etc/conf
62 If for some reason it's erroring out as `ERROR clone (Operation not permitted)`, check that
63 your user is a member of the required `group` and that `xbps-uchroot(1)` utility has the
64 proper permissions and owner/group as explained above.
68 The `proot(1)` utility implements chroot and bind mounts support completely in user space,
69 and can be used if your Linux kernel does not have support for namespaces. See https://proot-me.github.io/.
75 $ echo XBPS_CHROOT_CMD=proot >> etc/conf
77 ### Quick setup in Void
79 Clone the `void-packages` git repository, install the bootstrap packages:
82 $ git clone git://github.com/void-linux/void-packages.git
84 $ ./xbps-src binary-bootstrap
91 to see all available targets/options and start building any available package
92 in the `srcpkgs` directory.
94 ### Install the bootstrap packages
96 The `bootstrap` packages are a set of packages required to build any available source package in a container. There are two methods to install the `bootstrap`:
98 - `bootstrap`: all bootstrap packages will be built from scratch; additional utilities are required in the
99 host system to allow building the `base-chroot` package: binutils, gcc, perl, texinfo, etc.
101 - `binary-bootstrap`: the bootstrap binary packages are downloaded via XBPS repositories.
103 If you don't want to waste your time building everything from scratch probably it's better to use `binary-bootstrap`.
107 The `etc/defaults.conf` file contains the possible settings that can be overridden
108 through the `etc/conf` configuration file for the `xbps-src` utility; if that file
109 does not exist, will try to read configuration settings from `~/.xbps-src.conf`.
111 If you want to customize default `CFLAGS`, `CXXFLAGS` and `LDFLAGS`, don't override
112 those defined in `etc/defaults.conf`, set them on `etc/conf` instead i.e:
114 $ echo 'XBPS_CFLAGS="your flags here"' >> etc/conf
115 $ echo 'XBPS_LDFLAGS="your flags here"' >> etc/conf
117 Native and cross compiler/linker flags are set per architecture in `common/build-profiles`
118 and `common/cross-profiles` respectively. Ideally those settings are good enough by default,
119 and there's no need to set your own unless you know what you are doing.
121 #### Virtual packages
123 The `etc/defaults.virtual` file contains the default replacements for virtual packages,
124 used as dependencies in the source packages tree.
126 If you want to customize those replacements, copy `etc/defaults.virtual` to `etc/virtual`
127 and edit it accordingly to your needs.
129 ### Directory hierarchy
131 The following directory hierarchy is used with a default configuration file:
142 | |- ccache-<arch> ...
143 | |- distcc-<arch> ...
150 | |- host -> bind mounted from <hostdir>
151 | |- void-packages -> bind mounted from <void-packages>
154 The description of these directories is as follows:
156 - `masterdir`: master directory to be used as rootfs to build/install packages.
157 - `builddir`: to unpack package source tarballs and where packages are built.
158 - `destdir`: to install packages, aka **fake destdir**.
159 - `hostdir/ccache`: to store ccache data if the `XBPS_CCACHE` option is enabled.
160 - `hostdir/distcc-<arch>`: to store distcc data if the `XBPS_DISTCC` option is enabled.
161 - `hostdir/repocache`: to store binary packages from remote repositories.
162 - `hostdir/sources`: to store package sources.
163 - `hostdir/binpkgs`: local repository to store generated binary packages.
165 ### Building packages
167 The simplest form of building package is accomplished by running the `pkg` target in `xbps-src`:
171 $ ./xbps-src pkg <pkgname>
174 When the package and its required dependencies are built, the binary packages will be created
175 and registered in the default local repository at `hostdir/binpkgs`; the path to this local repository can be added to
176 any xbps configuration file (see xbps.d(5)) or by explicitly appending them via cmdline, i.e:
178 $ xbps-install --repository=hostdir/binpkgs ...
179 $ xbps-query --repository=hostdir/binpkgs ...
181 By default **xbps-src** will try to resolve package dependencies in this order:
183 - If dependency exists in the local repository, use it (`hostdir/binpkgs`).
184 - If dependency exists in a remote repository, use it.
185 - If dependency exists in a source package, use it.
187 It is possible to avoid using remote repositories completely by using the `-N` flag.
189 > The default local repository may contain multiple *sub-repositories*: `debug`, `multilib`, etc.
191 ### Package build options
193 The supported build options for a source package can be shown with `xbps-src show-options`:
195 $ ./xbps-src show-options foo
197 Build options can be enabled with the `-o` flag of `xbps-src`:
199 $ ./xbps-src -o option,option1 pkg foo
201 Build options can be disabled by prefixing them with `~`:
203 $ ./xbps-src -o ~option,~option1 pkg foo
205 Both ways can be used together to enable and/or disable multiple options
206 at the same time with `xbps-src`:
208 $ ./xbps-src -o option,~option1,~option2 pkg foo
210 The build options can also be shown for binary packages via `xbps-query(1)`:
212 $ xbps-query -R --property=build-options foo
214 > NOTE: if you build a package with a custom option, and that package is available
215 in an official void repository, an update will ignore those options. Put that package
216 on `hold` mode via `xbps-pkgdb(1)`, i.e `xbps-pkgdb -m hold foo` to ignore updates
217 with `xbps-install -u`. Once the package is on `hold`, the only way to update it
218 is by declaring it explicitly: `xbps-install -u foo`.
220 Permanent global package build options can be set via `XBPS_PKG_OPTIONS` variable in the
221 `etc/conf` configuration file. Per package build options can be set via
222 `XBPS_PKG_OPTIONS_<pkgname>`.
224 > NOTE: if `pkgname` contains `dashes`, those should be replaced by `underscores`
225 i.e `XBPS_PKG_OPTIONS_xorg_server=opt`.
227 The list of supported package build options and its description is defined in the
228 `common/options.description` file or in the `template` file.
230 ### Sharing and signing your local repositories
232 To share a local repository remotely it's mandatory to sign it and the binary packages
233 stored on it. This is accomplished with the `xbps-rindex(1)` utility.
235 First a RSA key must be created with `openssl(1)` or `ssh-keygen(1)`:
237 $ openssl genrsa -des3 -out privkey.pem 4096
241 $ ssh-keygen -t rsa -b 4096 -f privkey.pem
243 > Only RSA keys in PEM format are currently accepted by xbps.
245 Once the RSA private key is ready you can use it to initialize the repository metadata:
247 $ xbps-rindex --sign --signedby "I'm Groot" --privkey privkey.pem $PWD/hostdir/binpkgs
249 And then make a signature per package:
251 $ xbps-rindex --sign-pkg --privkey privkey.pem $PWD/hostdir/binpkgs/*.xbps
253 > If --privkey is unset, it defaults to `~/.ssh/id_rsa`.
255 If the RSA key was protected with a passphrase you'll have to type it, or alternatively set
256 it via the `XBPS_PASSPHRASE` environment variable.
258 Once the binary packages have been signed, check the repository contains the appropriate `hex fingerprint`:
260 $ xbps-query --repository=hostdir/binpkgs -vL
263 Each time a binary package is created, a package signature must be created with `--sign-pkg`.
265 > It is not possible to sign a repository with multiple RSA keys.
267 ### Rebuilding and overwriting existing local packages
269 If for whatever reason a package has been built and it is available in your local repository
270 and you have to rebuild it without bumping its `version` or `revision` fields, it is possible
271 to accomplish this task easily with `xbps-src`:
273 $ ./xbps-src -f pkg xbps
275 Reinstalling this package in your target `rootdir` can be easily done too:
277 $ xbps-install --repository=/path/to/local/repo -yff xbps-0.25_1
279 > Please note that the `package expression` must be properly defined to explicitly pick up
280 the package from the desired repository.
282 ### Enabling distcc for distributed compilation
284 Setup the slaves (machines that will compile the code):
286 # xbps-install -Sy distcc
288 Modify the configuration to allow your local network machines to use distcc (e.g. `192.168.2.0/24`):
290 # echo "192.168.2.0/24" >> /etc/distcc/clients.allow
292 Enable and start the `distccd` service:
294 # ln -s /etc/sv/distccd /var/service
296 Install distcc on the host (machine that executes xbps-src) as well.
297 Unless you want to use the host as slave from other machines, there is no need
298 to modify the configuration.
300 On the host you can now enable distcc in the `void-packages/etc/conf` file:
303 XBPS_DISTCC_HOSTS="localhost/2 --localslots_cpp=24 192.168.2.101/9 192.168.2.102/2"
306 The example values assume a localhost CPU with 4 cores of which at most 2 are used for compiler jobs.
307 The number of slots for preprocessor jobs is set to 24 in order to have enough preprocessed data for other CPUs to compile.
308 The slave 192.168.2.101 has a CPU with 8 cores and the /9 for the number of jobs is a saturating choice.
309 The slave 192.168.2.102 is set to run at most 2 compile jobs to keep its load low, even if its CPU has 4 cores.
310 The XBPS_MAKEJOBS setting is increased to 16 to account for the possible parallelism (2 + 9 + 2 + some slack).
312 ### Distfiles mirror(s)
314 In etc/conf you may optionally define a mirror or a list of mirrors to search for distfiles.
316 $ echo 'XBPS_DISTFILES_MIRROR="ftp://192.168.100.5/gentoo/distfiles"' >> etc/conf
318 If more than one mirror is to be searched, you can either specify multiple URLs separated
319 with blanks, or add to the variable like this
321 $ echo 'XBPS_DISTFILES_MIRROR+=" http://repo.voidlinux.de/distfiles"' >> etc/conf
323 Make sure to put the blank after the first double quote in this case.
325 The mirrors are searched in order for the distfiles to build a package until the
326 checksum of the downloaded file matches the one specified in the template.
328 Ultimately, if no mirror carries the distfile, or in case all downloads failed the
329 checksum verification, the original download location is used.
331 If you use `proot` or `uchroot` for your XBPS_CHROOT_CMD, you may also specify a local path
332 using the `file://` prefix or simply an absolute path on your build host (e.g. /mnt/distfiles).
333 Mirror locations specified this way are bind mounted inside the chroot environment
334 under $XBPS_MASTERDIR and searched for distfiles just the same as remote locations.
336 ### Cross compiling packages for a target architecture
338 Currently `xbps-src` can cross build packages for some target architectures with a cross compiler.
339 The supported target is shown with `./xbps-src -h`.
341 If a source package has been adapted to be **cross buildable** `xbps-src` will automatically build the binary package(s) with a simple command:
343 $ ./xbps-src -a <target> pkg <pkgname>
345 If the build for whatever reason fails, might be a new build issue or simply because it hasn't been adapted to be **cross compiled**.
347 ### Using xbps-src in a foreign Linux distribution
349 xbps-src can be used in any recent Linux distribution matching the CPU architecture.
351 To use xbps-src in your Linux distribution use the following instructions. Let's start downloading the xbps static binaries:
353 $ wget http://repo.voidlinux.eu/static/xbps-static-latest.<arch>-musl.tar.xz
355 $ tar xvf xbps-static-latest.<arch>.tar.xz -C ~/XBPS
356 $ export PATH=~/XBPS/usr/bin:$PATH
358 If your system does not support `user namespaces`, a privileged group is required to be able to use
359 `xbps-uchroot(1)` with xbps-src, by default it's set to the `xbuilder` group, change this to your desired group:
361 # chown root:<group> ~/XBPS/usr/bin/xbps-uchroot.static
362 # chmod 4750 ~/XBPS/usr/bin/xbps-uchroot.static
364 Clone the `void-packages` git repository:
366 $ git clone git://github.com/void-linux/void-packages
368 and `xbps-src` should be fully functional; just start the `bootstrap` process, i.e:
370 $ ./xbps-src binary-bootstrap
372 The default masterdir is created in the current working directory, i.e `void-packages/masterdir`.
375 ### Remaking the masterdir
377 If for some reason you must update xbps-src and the `bootstrap-update` target is not enough, it's possible to recreate a masterdir with two simple commands (please note that `zap` keeps your `ccache/distcc/host` directories intact):
380 $ ./xbps-src binary-bootstrap
382 ### Keeping your masterdir uptodate
384 Sometimes the bootstrap packages must be updated to the latest available version in repositories, this is accomplished with the `bootstrap-update` target:
386 $ ./xbps-src bootstrap-update
388 ### Building 32bit packages on x86_64
390 Two ways are available to build 32bit packages on x86\_64:
392 - cross compilation mode
393 - native mode with a 32bit masterdir
395 The first mode (cross compilation) is as easy as:
397 $ ./xbps-src -a i686 pkg ...
399 The second mode (native) needs a new x86 `masterdir`:
401 $ ./xbps-src -m masterdir-x86 binary-bootstrap i686
402 $ ./xbps-src -m masterdir-x86 ...
404 ### Building packages natively for the musl C library
406 A native build environment is required to be able to cross compile the bootstrap packages for the musl C library; this is accomplished by installing them via `binary-bootstrap`:
408 $ ./xbps-src binary-bootstrap
410 Now cross compile `base-chroot-musl` for your native architecture:
412 $ ./xbps-src -a x86_64-musl pkg base-chroot-musl
414 Wait until all packages are built and when ready, prepare a new masterdir with the musl packages:
416 $ ./xbps-src -m masterdir-x86_64-musl binary-bootstrap x86_64-musl
418 Your new masterdir is now ready to build natively packages for the musl C library. Try:
420 $ ./xbps-src -m masterdir-x86_64-musl chroot
423 To see if the musl C dynamic linker is working as expected.
425 ### Building void base-system from scratch
427 To rebuild all packages in `base-system` for your native architecture:
429 $ ./xbps-src -N pkg base-system
431 It's also possible to cross compile everything from scratch:
433 $ ./xbps-src -a <target> -N pkg base-system
435 Once the build has finished, you can specify the path to the local repository to `void-mklive`, i.e:
439 # ./mklive.sh ... -r /path/to/hostdir/binpkgs
443 See [Contributing](https://github.com/void-linux/void-packages/blob/master/CONTRIBUTING.md)
444 for a general overview of how to contribute and the
445 [Manual](https://github.com/void-linux/void-packages/blob/master/Manual.md)
446 for details of how to create source packages.