Exploring a Slackware SlackBuild

Published: 2022-01-14 | Last Updated: 2022-01-14 | ~16 Minute Read

Table of Contents

Introduction

We’ve previously discussed general package management and Slackware package management so I thought I’d build on that by going over the anatomy of a Slackware SlackBuild script that you can use to install software on your system. SlackBuilds are usually associated with the third party slackbuilds.org repository, however they clarify that this was not something they originated.

Prerequisites

You should have a full Slackware installation but the general minimum requirements are:

  1. The sources for your application
  2. A build toolchain installed on your system
  3. The native Slackware pkgtools.

This should be enough to create most packages from a SlackBuild, and more than enough for the package we will inspect today, Slackware’s own pkgtools!

Downloading the source code

We can get the pkgtools sources from an available Slackware mirror, in my case I’ll use the Slackware UK mirror:

Create the directory where we will be working:

bash-5.1$ mkdir build-package

Change directory into the newly created working directory:

bash-5.1$ cd build-package

Download the sources from the Slackware mirror via wget:

bash-5.1$ wget --recursive --no-host-directories --cut-dirs=4 --execute robots=off --no-parent --reject "index.html" https://slackware.uk/slackware/slackware64-14.2/source/a/pkgtools/

A brief explanation of the wget options used:

Let’s confirm that we have downloaded the sources into our build-package directory:

bash-5.1$ pwd
/tmp/build-package
bash-5.1$ ls
pkgtools
bash-5.1$ tree
.
└── pkgtools
    ├── manpages
    │   ├── explodepkg.8
    │   ├── installpkg.8
    │   ├── makepkg.8
    │   ├── pkgtool.8
    │   ├── removepkg.8
    │   └── upgradepkg.8
    ├── manpages-l10n.tar.xz
    ├── obsolete-scripts
    │   ├── README
    │   └── setup.90.modem-device
    ├── pkgtools.SlackBuild
    ├── scripts
    │   ├── explodepkg
    │   ├── installpkg
    │   ├── makebootdisk
    │   ├── makepkg
    │   ├── pkgtool
    │   ├── removepkg
    │   ├── setup.70.install-kernel
    │   ├── setup.80.make-bootdisk
    │   ├── setup.htmlview
    │   ├── setup.services
    │   └── upgradepkg
    └── slack-desc

4 directories, 22 files
bash-5.1$

Great, we have what we’ll need.

Checking for a toolchain

This is a very in depth subject that warrants its own post, hence I chose a package that will not require compiling and I will do a deep dive into the topic on a later post. The software toolchain is necessary to install most software that would be needed by a Slackware system user and so it is included as part of the “Full” installation.

The detailed list of packages that Slackware includes for building other software is in the /d series of packages and can be found on any mirror or installation media, for brevity I will only showcase how to check for gcc and make on your local system:

Checking for gcc:

Using traditional commands as any user:

bash-5.1$ ls /var/log/packages | grep -i "gcc"
gcc-10.2.0-x86_64-2
gcc-brig-10.2.0-x86_64-2
gcc-g++-10.2.0-x86_64-2
gcc-gdc-10.2.0-x86_64-2
gcc-gfortran-10.2.0-x86_64-2
gcc-gnat-10.2.0-x86_64-2
gcc-go-10.2.0-x86_64-2
gcc-objc-10.2.0-x86_64-2
gccmakedep-1.0.3-noarch-2

Using slackpkg as root:

root@host:~# slackpkg search gcc

Looking for gcc in package list. Please wait... DONE

The list below shows all packages with name matching "gcc".

[ Status           ] [ Repository               ] [ Package                                  ]
  upgrade                  slackware64                  gcc-10.2.0-x86_64-2 --> gcc-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-brig-10.2.0-x86_64-2 --> gcc-brig-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-g++-10.2.0-x86_64-2 --> gcc-g++-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-gdc-10.2.0-x86_64-2 --> gcc-gdc-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-gfortran-10.2.0-x86_64-2 --> gcc-gfortran-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-gnat-10.2.0-x86_64-2 --> gcc-gnat-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-go-10.2.0-x86_64-2 --> gcc-go-11.2.0-x86_64-2  
  upgrade                  slackware64                  gcc-objc-10.2.0-x86_64-2 --> gcc-objc-11.2.0-x86_64-2  
  upgrade                  slackware64                  gccmakedep-1.0.3-noarch-2 --> gccmakedep-1.0.3-noarch-4  

You can search specific files using "slackpkg file-search file".

gcc is installed along with several other packages that add functionality to compile different languages.

Note: Here we can see that I have some pending updates on my system, but I will wait until Slackware 15 is officially released to do a full installation :)

Checking for make:

Using traditional commands as any user:

bash-5.1$ ls /var/log/packages | grep -i "make"
automake-1.16.2-noarch-1
cmake-3.19.2-x86_64-1
gccmakedep-1.0.3-noarch-2
imake-1.0.8-x86_64-1
make-4.2.1-x86_64-7
makedepend-1.0.6-x86_64-1
pmake-1.111-x86_64-5
windowmaker-0.95.9-x86_64-1

Using slackpkg as root:

root@host:~# slackpkg search make

Looking for make in package list. Please wait... DONE

The list below shows all packages with name matching "make".

[ Status           ] [ Repository               ] [ Package                                  ]
  uninstalled              slackware64                  extra-cmake-modules-5.90.0-x86_64-1       
  upgrade                  slackware64                  automake-1.16.2-noarch-1 --> automake-1.16.2-noarch-4  
  upgrade                  slackware64                  cmake-3.19.2-x86_64-1 --> cmake-3.21.4-x86_64-1  
  upgrade                  slackware64                  gccmakedep-1.0.3-noarch-2 --> gccmakedep-1.0.3-noarch-4  
  upgrade                  slackware64                  imake-1.0.8-x86_64-1 --> imake-1.0.8-x86_64-3  
  upgrade                  slackware64                  make-4.2.1-x86_64-7 --> make-4.3-x86_64-3  
  upgrade                  slackware64                  makedepend-1.0.6-x86_64-1 --> makedepend-1.0.6-x86_64-3  
  upgrade                  slackware64                  pmake-1.111-x86_64-5 --> pmake-1.111-x86_64-7  
  upgrade                  slackware64                  windowmaker-0.95.9-x86_64-1 --> windowmaker-0.95.9-x86_64-3  

You can search specific files using "slackpkg file-search file".

make is also installed on the system along with additional make packages for compatibility.

In case these packages are missing in your system you can install them easily with slackpkg:

# slackpkg install d

This will indicate to slackpkg that you want to install the d package series. All packages inside that series will then be fetched and installed from the mirror you have specified in /etc/slackpkg/mirrors.

Slackware’s pkgtools is created using bash scripts so we won’t actually compile anything in this case (Again I will create a separate post where we go more in depth on compiling packages), but in most other cases you will need this software.

Checking for pkgtools

In the same way that we checked for gcc and make we will check the system for pkgtools:

Using traditional commands as any user:

bash-5.1$ ls /var/log/packages | grep -i pkgtools
pkgtools-15.0-noarch-34

Using slackpkg as root:

root@host:~# slackpkg search pkgtools

Looking for pkgtools in package list. Please wait... DONE

The list below shows all packages with name matching "pkgtools".

[ Status           ] [ Repository               ] [ Package                                  ]
  upgrade                  slackware64                  pkgtools-15.0-noarch-34 --> pkgtools-15.0-noarch-42  

You can search specific files using "slackpkg file-search file".

Now that we confirmed that all of our prerequisites are met, we can move to taking a look at the package name structure.

Package naming

A very important aspect of packages in Slackware are the package names. The name of every package contains details about that package, from the documentation:

These different pieces of information are obtained from the package name and the following SlackBuild section:

# *** UPDATE THESE WITH EACH BUILD:
VERSION=14.2
ARCH=${ARCH:-noarch}
BUILD=10

Let’s analyze a few package names:

brave-browser-1.21.73-x86_64-1_SBo.tgz
| ========= | | === | | == | | = | |=|
      |          |       |     |    |
program name  version    |   build  |
                         |   number |
                         |          |
                    architecture    |
                                    |
                                compression
                                   type


filezilla-3.51.0-x86_64-1_SBo.tgz
| ===== | | == | | == | | = | |=|
    |        |      |     |    |
program   version   |   build  |
 name               |   number |
                    |          |
               architecture    |
                               |
                          compression
                             type


pkgtools-14.2-noarch-10.txz
| ==== | |==| | == | || |=|
    |      |     |    |  |
program version  | build |
 name            | number|
                 |       |
            architecture |
                         |
                    compression
                       type

This naming convention makes it simple to look at the packages and immediately know important information for system maintenance.

Exploring the pkgtools sources

Now we will analyze the downloaded files to better understand what they provide for us.

There are three main components to every package:

  1. Program source
  2. slack-desc & program.info
  3. program.SlackBuild script

Additionally to these three components we can sometimes find other files:

Now we can take a closer look at the three main sections:

Program source

Again the source code for pkgtools are a set of bash scripts that we can easily check by using a text editor or command line utilities:

bash-5.1$ cd pkgtools/scripts/
bash-5.1$ pwd
/tmp/build-package/pkgtools/scripts
bash-5.1$ head installpkg 
#!/bin/sh
# Copyright 1994, 1998, 2000  Patrick Volkerding, Concord, CA, USA 
# Copyright 2001, 2003  Slackware Linux, Inc., Concord, CA, USA
# Copyright 2007, 2009, 2011  Patrick Volkerding, Sebeka, MN, USA 
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
bash-5.1$

slack-desc & program.info

Here we can see that pkgtools does not have a pkgtools.info (program.info) file, this seems to be because the source is provided by Patrick Volkerding himself and not a different upstream.

We do have a slack-desc file with the recommended standard formatting ( see here for more details on slack-desc files):

bash-5.1$ cat slack-desc 
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|' on
# the right side marks the last column you can put a character in.  You must make
# exactly 11 lines for the formatting to be correct.  It's also customary to
# leave one space after the ':'.

        | -----handy-ruler------------------------------------------------------ |
pkgtools: pkgtools (The Slackware package maintenance system)
pkgtools:
pkgtools: This package contains utilities for handling Slackware packages.
pkgtools: Included are the command line utilities 'installpkg', 'removepkg',
pkgtools: 'makepkg', 'explodepkg', and 'upgradepkg' that install, remove,
pkgtools: build, examine, and upgrade software packages.  Also included are 
pkgtools: 'pkgtool', a menu based program for installing packages, removing
pkgtools: packages, or viewing the packages that are installed on the system,
pkgtools: documentation (man pages), and a few other system admin scripts.
pkgtools:
pkgtools:

Program SlackBuild

This file contains instructions for the compilation/build steps of the installation process. Depending on the framework/language the package you’re trying to install uses you will most likely have a different SlackBuild script. The community maintained slackbuilds.com project provides some very handy templates that can get you started if you decide to create a SlackBuild of your own. In case you do opt to create your own package SlackBuild, make sure to check the submission guidelines over at the slackbuilds project.

In our example, since there are no binary files, the SlackBuild script only moves files into their appropriate locations, Let’s break down the script section by section and go over what is being automated.

The first section contains the SlackBuild license:

bash-5.1$ cat pkgtools.SlackBuild 
#!/bin/sh
# Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013  Patrick J. Volkerding, Sebeka, MN, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This section defines base variables that the SlackBuild will use:

# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-pkgtools

We took a look at these variables earlier, they are used to properly name the resulting package from the SlackBuild:

# *** UPDATE THESE WITH EACH BUILD:
VERSION=14.2
ARCH=${ARCH:-noarch}
BUILD=10

This section creates the $TMP path, /tmp by default, if not found and cleans up before starting work:

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

We then compress and move the man pages that came bundled with the program source files into the appropriate location, compression optimizes final package sizes and the man command can decompress these on demand:

# Install Slackware script manpages:
( cd $CWD/manpages
  mkdir -p $PKG/usr/man/man8
  for page in explodepkg.8 installpkg.8 makepkg.8 upgradepkg.8 pkgtool.8 \
    removepkg.8 ; do
    cat $page | gzip -9c > $PKG/usr/man/man8/$page.gz
  done
)

Additional internationalized man pages are then added as well:

# Install internationalized manpages from
# http://slint.fr/forSlackware/man_l10n/pkgtools/
( cd $PKG/usr/man
  tar xf $CWD/manpages-l10n.tar.xz
  for page in manpages-l10n/* ; do
    manpage=$(basename $page)
    mkdir -p ${manpage%%.*}/man8
    mv $page ${manpage%%.*}/man8/${page#*.}.8
  done
  gzip -9 */man8/*.8
  rmdir manpages-l10n
)

Now we move on to the actual utilities that come with pkgtools and begin placing them in their corresponding folders inside the $PKG variable, effectively /tmp/package-pkgtools at this point:

# Install Slackware scripts:
( cd $CWD/scripts
  # Install the core Slackware package tools:
  mkdir -p $PKG/sbin
  # Don't include makebootdisk...  it's useless since a kernel won't fit on a
  # floppy disk, and nobody uses floppies any more anyway.
  for file in explodepkg installpkg makepkg pkgtool removepkg upgradepkg ; do
    cp -a $CWD/scripts/$file $PKG/sbin
  done
  chown root:root $PKG/sbin/*
  chmod 755 $PKG/sbin/*

These sripts are also used during the initial system installation so they are placed accordingly:

  # These scripts are used during the installation:
  mkdir -p $PKG/var/log/setup/tmp
  chmod 700 $PKG/var/log/setup/tmp
  for file in setup.* ; do
    cp -a $file $PKG/var/log/setup
  done
  chown root:root $PKG/var/log/setup/setup.*
  chmod 755 $PKG/var/log/setup/setup.*
  # Add a link for makebootstick:
  ( cd $PKG/sbin ; ln -sf ../var/log/setup/setup.80.make-bootdisk makebootstick )
)

The slack-desc file is now placed into the $PKG/install directory:

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

Finally with all the files in place we call the makepkg command in order to create a package tarball from all the files we just prepared:

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/pkgtools-$VERSION-$ARCH-$BUILD.txz

This seems to be a note for Patrick from himself to make sure he updates the package information on every build since this is not part of the slackbuilds provided templates and he’s the person that most likely builds this package most often.

echo
echo "HEY -- did you remember to update the version numbers in the setup scripts?"
echo

Building the program and package

Once we have confirmed that the SlackBuild contains all the commands to properly build the software we can run the pkgtools.SlackBuild script to get our final package:

root@host:/tmp/build-package/pkgtools# ./pkgtools.SlackBuild 

Slackware package maker, version 3.14159265.

Searching for symbolic links:
sbin/makebootstick      ../var/log/setup/setup.80.make-bootdisk

Making symbolic link creation script:
( cd sbin ; rm -rf makebootstick )
( cd sbin ; ln -sf ../var/log/setup/setup.80.make-bootdisk makebootstick )

It is recommended that you make these lines your new installation script.

Would you like to make this stuff the install script for this package
and remove the symbolic links ([y]es, [n]o)? y


Removing symbolic links:
removed './sbin/makebootstick'

Creating your new ./install/doinst.sh...

This next step is optional - you can set the directories in your package
to some sane permissions. If any of the directories in your package have
special permissions, then DO NOT reset them here!

Would you like to reset all directory permissions to 755 (drwxr-xr-x) and
directory ownerships to root.root ([y]es, [n]o)? n

Creating Slackware package:  /tmp/pkgtools-14.2-noarch-10.txz

./
install/
install/doinst.sh
install/slack-desc
sbin/
sbin/explodepkg
sbin/installpkg
sbin/makepkg
sbin/pkgtool
sbin/removepkg
sbin/upgradepkg
usr/
usr/man/
usr/man/de/
usr/man/de/man8/
...
var/
var/log/
var/log/setup/
var/log/setup/setup.70.install-kernel
var/log/setup/setup.80.make-bootdisk
var/log/setup/setup.htmlview
var/log/setup/setup.services
var/log/setup/tmp/

Slackware package /tmp/pkgtools-14.2-noarch-10.txz created.


HEY -- did you remember to update the version numbers in the setup scripts?

Now we confirm that the package was created as the script mentions:

root@host:/tmp/build-package/pkgtools# ls /tmp/pkgtools-14.2-noarch-10.txz
/tmp/pkgtools-14.2-noarch-10.txz

It’s important to note that the SlackBuild scripts usually don’t install the package for you, they simply compile the software and create the package in an automated fashion.

Once confirmed you can install it by running the installpkg utility from pkgtools:

root@host:/tmp/build-package/pkgtools# installpkg /tmp/pkgtools-14.2-noarch-10.txz

It’s worth noting that installpkg will write the package files onto the filesystem following the same file hierarchy that was outlined in the SlackBuild script, so it’s important that this matches your system’s filesystem hierarchy. This is one of the reasons that SlackBuilds are the preferred method for installing packages on Slackware Linux, they greatly minimize room for error since they adhere to Slackware’s filesystem hierarchy.

Conclusion

That was a brief overview of what the contents of a Slackware package are and what they provide to a user, you can of course simply use the regular ./configure > make > make install process, however the additional structure around the Slackware way to create/install packages via SlackBuilds aids the user in ease of maintainability of their system.

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~grokkingnix/blog@lists.sr.ht [mailing list etiquette] [mailing list archive]


Posts from blogs I follow:

Introducing a Falkon extension RSS Finder

This weekend I decided to semi automate the process of searching for RSS feeds on websites while using Falkon web brosers. Many websites provide RSS feeds but do not provide any visible link or icon to access them (eg. many Wordpress based sites) and I ha…

via My land January 23, 2022
Help Chile write free software values, privacy, and digital sovereignty into their constitution

For those out of the loop, a group which included myself up until recently,1 Chile is in the midst of a revolution. They’re fighting against the increased cost of living, privatization of essential services, and worsening inequality — problems facing everyon…

via Drew DeVault's blog January 19, 2022
A warning to business owners and managers, you are a big part of the problem!

In my last couple of articles, mainly So-called modern web developers are the culprits and Is the madness ever going to end? I have written about some of the major problems with so-called modern web development and I have addressed the issues to the devel…

via unixsheikh.com January 13, 2022

Generated by openring