Creating PKGBUILD for iris


Creating a PKGBUILD for iris

Iris is the default wallpaper manager in CalinixOS. Know more about it in the Github repo

Iris is cross platform and highly configurable. But this article isn't about iris, its about making a PKGBUILD for iris

A PKGBUILD is a shell script containing the build information required by Arch Linux packages.

Packages in Arch Linux are built using the makepkg utility. When makepkg is run, it searches for a PKGBUILD file in the current directory and follows the instructions therein to either compile or otherwise acquire the files to build a package archive (pkgname.pkg.tar.zst). The resulting package contains binary files and installation instructions, readily installable with pacman.

For iris, we already have a binary in its releases The binaries come from my own fork of iris where I continue the release cycle.

So I don't have to give build instructions.

Getting Started

The PKGBUILD for iris is in the GitHub repo of calinix repo PKGBUILDs

The work folder contains of 2 files, PKGBUILD and iris-bin.install.

You can upload iris (or any other package) in the AUR

https://wiki.archlinux.org/index.php/AUR_submission_guidelines

Contents of the PKGBUILD:

# Maintainer: Arghya Sarkar <arghyasarkar.nolan@gmail.com>
pkgname=iris-bin
_pkgname=iris-bin
_destname="/usr/bin/"
_licensedir="/usr/share/licenses/${_pkgname}/"
_readmedir="/usr/share/doc/${_pkgname}/"
pkgver=2.1.0
pkgrel=1
epoch=
pkgdesc="Iris is an easy to use, cross platform and customizable wallpaper manager."
arch=('x86_64')
url="https://www.github.com/Shravan-1908/iris.git"
license=('MIT')
groups=()
depends=(feh)
makedepends=(git)
checkdepends=()
optdepends=()
provides=(iris-bin)
conflicts=()
replaces=()
backup=()
options=()
install=${pkgname}.install
changelog=
source_x86_64=("iris::https://github.com/arghyagod-coder/iris/releases/download/v0.2.1/iris-linux-amd64"
               "https://raw.githubusercontent.com/Shravan-1908/iris/main/LICENSE.txt"
               "https://raw.githubusercontent.com/Shravan-1908/iris/main/README.md"
              )
noextract=("iris")
sha256sums_x86_64=('c13d2ab201972ef65630c4d240972b0333f5cb140d117db11427aa889f1fc483'
                   'efbe6d24b7d99e06ba60cfd385f5e9e8fe0dccfb6ccb483edeb70af2ec1dd1cc'
                   'b8913a9b96a7cbf37fb3d11facbee7bdb25b8368ecf612bc3dd1b7bfe4ba56e4')
validpgpkeys=()

# pkgver() {
#     # cd "${_pkgname}"
#     # printf "1.r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
# }

package() {
    install -dm755 ${pkgdir}${_destname}
    install -Dm755 "${srcdir}/iris" "${pkgdir}${_destname}iris"

    install -dm755 ${pkgdir}${_licensedir}${_pkgname}
    install -dm755 ${pkgdir}${_readmedir}${_pkgname}
    install -m644  ${srcdir}/LICENSE.txt ${pkgdir}${_licensedir}${_pkgname}
    install -Dm644 ${srcdir}/README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
}

Understanding the PKGBUILD

Let's move line by line

First line consists of the maintainer, which is a comment. You can add your name and email there.

# Maintainer: Arghya Sarkar <arghyasarkar.nolan@gmail.com>

After that, everything is bash syntax.

Mandatory variables are pkgname, pkgver, pkgrel, and arch. license is not strictly necessary to build a package, but is recommended for any PKGBUILD shared with others, as makepkg will produce a warning if not present.

Here the pkgname and _pkgname is iris-bin which is the name of your package.

Package names generally have some rules.

-bin stands at the end of packages which provide a binary

-git stands for building the latest repository from source (basically unstable)

Just "packagename" stands for building from source but stably.

_destname="/usr/bin/"
_licensedir="/usr/share/licenses/${_pkgname}/"
_readmedir="/usr/share/doc/${_pkgname}/"

These are few optional variables I created. Destname consists of /usr/bin which is the standard path for program binaries.

It is where the binary will be placed. Licensedir will be the place where the license will be placed and readmedir is where the readme will be placed.

${_pkgname} everywhere refers to the _pkgname variable.

pkgver refers to the version of the package. This should be the same as the version published by the author of the upstream software. It can contain letters, numbers, periods and underscores, but not a hyphen (-). If the author of the software uses one, replace it with an underscore (_). If the pkgver variable is used later in the PKGBUILD, then the underscore can easily be substituted for a hyphen, e.g.

pkgrel is The release number. This is usually a positive integer number that allows to differentiate between consecutive builds of the same version of a package. As fixes and additional features are added to the PKGBUILD that influence the resulting package, the pkgrel should be incremented by 1.

pkgdesc is the description of a package.

arch refers to the architecture your software is made for. For example if your software supports 64 bit x86, use arch=('x86_64'). If your software is cross platform and if doesn't matter, just use arch=('any')

url="https://www.github.com/Shravan-1908/iris.git"

url variable stores the url to our github repo. This can be changed to the project url / website url of your product.

license variable should mention the license of your package. Whether its under a proprietary license or something else. Iris is under the MIT license.

depends=(feh)
makedepends=(git)

Dependencies state the packages you need pre-installed/installed in your computer to be able to run the package. For example iris uses feh as its wallpaper setting tool, so pacman will install feh before installing iris

Makedepends states the packages you will need to build the package. Here we have git for example.

provides refers to the package name that is provided.

install=${pkgname}.install

The install parameter refers to a shell script to execute after packaging and building the package. The iris-bin.install file in the work directory refers to the shell script

source_x86_64=("iris::https://github.com/arghyagod-coder/iris/releases/download/v0.2.1/iris-linux-amd64"
               "https://raw.githubusercontent.com/Shravan-1908/iris/main/LICENSE.txt"
               "https://raw.githubusercontent.com/Shravan-1908/iris/main/README.md"
              )

Source is an array of files which are fetched through HTTP or FTP, and are required for building the package. This is where we fetch the binary, the license and the README. The binary in github is named iris-linux-amd64 but the iris:: option tells to save the source as iris

sha256sums_x86_64=('c13d2ab201972ef65630c4d240972b0333f5cb140d117db11427aa889f1fc483'
                   'efbe6d24b7d99e06ba60cfd385f5e9e8fe0dccfb6ccb483edeb70af2ec1dd1cc'
                   'b8913a9b96a7cbf37fb3d11facbee7bdb25b8368ecf612bc3dd1b7bfe4ba56e4')

The above parameter sha256sums refer to the sha256sum codes of each of the sources. The codes should be provided in the exact order like the source. For example, the hash for iris executable comes first. Then license and then readme. To find out the hash of a file, run sha256sum filename.

package() {
    install -dm755 ${pkgdir}${_destname}
    install -Dm755 "${srcdir}/iris" "${pkgdir}${_destname}iris"

    install -dm755 ${pkgdir}${_licensedir}${_pkgname}
    install -dm755 ${pkgdir}${_readmedir}${_pkgname}
    install -m644  ${srcdir}/LICENSE.txt ${pkgdir}${_licensedir}${_pkgname}
    install -Dm644 ${srcdir}/README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
}

This is the packaging part stored in package() {}. pkgdir refers to our file system.

install -dm755 ${pkgdir}${_destname}

-dm755 creates the following directory in your file system (if doesn't exist already). Pkgdir is your root filesystem (/) and destname is our variable for /usr/bin/

install -Dm755 "${srcdir}/iris" "${pkgdir}${_destname}iris"

-Dm755 is used to install a file as an executable in a specific destination. The variable srcdir refers to the directory where all files from source are present.

Learn more about the install command here: https://www.google.com/amp/s/www.geeksforgeeks.org/install-command-in-linux-with-examples/amp/

Similar articles:

https://wiki.archlinux.org/title/creating_packages https://itsfoss.com/create-pkgbuild/

Comments

Popular Posts