XBPS is an independent package format created by Void Linux. xbps-src is an utility to create XBPS packages. Those packages can be used for installing and uninstalling programs later on. Similar to PKGBUILDs on Arch Linux, xbps-src takes a script-like file with variables and instructions to grab the source and build it to generate package files. It is like building from source, but automatically.
The instruction file is called “template”. We can use it to build the package again and again and it would produce the same result. That’s why development becomes so much easier. The xbps package templates can be found at the void-packages GitHub repository.
Previous I had this post on how to push your package to the void-packages repo to be reviewed and accepted into the Void Linux packages. But this one speaks what to do before you want to submit a package — the writing of the template file itself.
First of all, run these commands to prepare your environment to let you create a package:
sudo xbps-install xtools
git clone --depth=1 https://github.com/void-linux/void-packages.git
cd void-packages
./xbps-src binary-bootstrap
Now to create a package template file:
xnew my-cool-new-package
A new template file with the package name specified will be created and the template file will be opened in vi editor. You can edit here, or press q:<enter> to quit vi and edit with another editor of your choice.
A typical template file will look like this:
# Template file for 'my-cool-new-package'
pkgname=my-cool-new-package
version=
revision=1
#wrksrc=
#create_wrksrc=yes
#archs="i686 x86_64"
build_style=gnu-configure
#configure_args=""
#make_build_args=""
#make_install_args=""
#conf_files=""
#make_dirs="/var/log/dir 0755 root root"
hostmakedepends=""
makedepends=""
depends=""
short_desc=""
maintainer=" <>"
license="GPL-3.0-or-later"
homepage=""
distfiles=""
checksum=badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb
Enter distfiles and everything else. Get the license name from here. Then run:
xgensum -f srcpkgs/my-cool-new-package/template
This will download and store the file on hostdir/sources/<package name>-<version>/ and generate a checksum.
This will show an error message with the SHA256 checksum. It should show you the checksum in a checksum=xyz... line. Use this on your template file. If it fails for some reason, you can manually download the file and run sha256sum /path/to/file.ext. Use the checksum of the output in the template file, then run again to confirm it is correct. This time it should not show the error message.
List the -devel packages under makedepends, and list the other build dependencies under hostmakedepends. (glib-devel is an exception. To make it able to pass the ARM builds, put it in hostmakedepends even though it is a -devel package.) List the packages that are needed when running under depends.
If you want to use the variables for any case, remember that there are 3 directories to note:
1: Source directory – where your template file is
2: Build directory – where the downloaded source archives will be extracted to
3: Destination directory – where the binary output of the source (and other installable files, such as documentation, license etc.) are saved to. This will resemble a linux “/” directory having the files exactly how it will be once the package is installed.
Set the build_style appropriately. If it is something custom, then comment or delete the line.
You can browse the common/build-style/ directory of the repo to find out what the build_style templates do. If any one suits you, great, use it. If it doesn’t, comment the line and write your own do_build, do_install etc. functions.
If you are unsure what is causing the issue, it is a great idea to build from the source manually and see if it builds properly. Document how you made the build, then convert your steps into the template file. It worked wonders for me.
If it is ready, run:
./xbps-src pkg my-cool-new-package
If any error is occurred and need to rebuild, use this:
./xbps-src -I build my-cool-new-package
But if you change any dependencies, you will have to run ./xbps-src pkg my-cool-new-package again and the -I build command will not work. As a note, on some packages the -I build may not work at all. The first xbps-src template I made, it fails with the build command for some reason. So I go with the full ./xbps-src pkg command every time.
If the build was successful, run this to install it:
xi my-cool-new-package
If it works the way it should, then proceed to submitting it to void repo.
If you want to look at some xbps-src packages I wrote as an example, see here. If you are in a problem and can’t solve, you can try the IRC #voidlinux channel or Void Linux reddit.
Resources:
https://wiki.voidlinux.org/Xbps-src
https://github.com/void-linux/void-packages/blob/master/Manual.md
https://github.com/void-linux/void-packages/blob/master/Manual.md#package-naming-conventions