NOTE! THIS GUIDE IS WORK IN PROGRESS.
How to build packages for Wolvix (Slackware) Version: 0.1Introduction:This guide assumes you have basic knowledge about Linux, such as using the command line; that you are somewhat familiar with the Linux filesystem hierarchy; that you know what a tarball is; that you know what a dependency is; and that you know how to 'su' to root . It also assumes that you have basic knowledge about Slackware package management.
Other sources of information relevant to this topic are:
http://www.linuxpackages.net/howto.php?page=package&title=Package+Howtohttp://www.linuxpackages.net/howto.php?page=perfect-package&title=Perfect+Packagehttp://slackwiki.org/Building_A_Packagehttp://slackwiki.org/Writing_A_SlackBuild_ScriptI'll try to cover things in detail here, so if you're familiar with the basics of compiling from source you might want to skip parts of this guide.
If you're new to compiling and package building it might be best to read through the guide before doing any of the steps.
Naming rules for packages:Let's start off with examine the naming of a Slackware package. This is important as there are strict rules on how to name packages. Here's a typical example:
foobar-1.0.2-i486-1.tgz. The first word (foobar) before the dash ("-") is the name of the package, the numbers after the dash (1.0.2) is the version. After the version is the arch that the package was compiled for, in this case it's '
i486' which is the standard arch for Slackware, but this can also be '
i686', or even '
noarch'. After the arch comes the build number which indicates how many times the package of the same version has been compiled and released. In our example it's the first build (1).
On Wolvix packages you'll notice that the build number is accompanied with a 'wlv' tag. (
foobar-1.0.2-i486-1wlv.tgz) The tag indicates who built the package. For example if your name is Joe, you might use the tag 'joe' on the package like this:
foobar-1.0.2-i486-1joe.tgz, or if your nick name is Fox you might use the tag 'fox' like this:
foobar-1.0.2-i486-1fox.tgz. The last part of the package (tgz) is the file extension.
tgz is just a short name for
tar.gz. Packages use the
tgz extension to indicate that it is in fact a package and not a
tar.gz archive. (More on this later.)
As you can see a Slackware package will and should look like this:
name-version-arch-build.extension. Note that all the different strings are separated by a dash ("-")
It is not allowed to use dashes in the version string. It is however allowed to use dashes in the name. Example:
foo-bar-1.0.2-i486-1.tgz. This is allowed, but this:
foobar-1.0.2-1-i486-1.tgz is
not allowed. Sometimes you'll encounter source archives that use dashes and/or words like 'beta' or 'rc' in the version string. If this is the case then use an underscore ("_") instead of a dash. The use of words in the version string is allowed, example:
foobar-1.0.4beta1-i486-1.tgz,
foobar-1.0.2_beta1-i486-1.tgz or foobar-1.0.2_1-i486-1.tgz. All of those examples are allowed. Also note that it's customary to only use lowercase letters for the package name, but it's not a strict rule. (We'll look closer at the insides of a package later in this guide)
Compiling from source code:Now that we know how a package should be named, let's move on to compiling source code. Compiling a program or library from source can be pretty simple if the source has few or no dependencies. It can also be frustratingly difficult to compile some source code if the application in question has many and obscure dependencies. And if the dependencies has it's own dependencies you're in for a bumpy ride... It's also worth mentioning that not all sources are the same, some sources are coded in C/C++ while others are coded in Perl or Python and the compile process differs for each language. But don't be discouraged by this, we'll start off easy.
A note for Wolvix 1.1.0:
In order to save space Wolvix 1.1.0 does not come with a "build environment" (compiler, etc) and all headers has been stripped out of the various packages. So in order to compile on Wolvix 1.1.0 you need to install a few packages first:slapt-get --install glibc glibc-i18n kernel-headers
slapt-get --install meta-development hunter-headers
Alright. Let's get down to business. We'll start by compiling the sources for a program called
Geany. The Geany sources comes in two different archive types,
tar.gz and
tar.bz2. it doesn't matter which you choose, the difference is that
tar.bz2 archives has a higher compression rate than
tar.gz. I'll go with the
tar.gz archive in this example. Before we download the sources, let's create a nice set of directories to work in. In my home I'll create a
work directory and inside it three sub directories:
source,
packages and
temp. The 'source' dir will be used to hold the source archives and we'll also use it to compile in. The other two sub directories will be used a bit later in this guide.
mkdir -p work/{source,packages,temp}
Now
download the source archive for Geany from Sourceforge . At the time of writing this the latest version for Geany is 0.14, so I'll download the
geany-0.14.tar.gz archive to my
work/source/ directory.
Launch a terminal inside the
work/source/ directory and extract the source archive with the command:
tar -zxvf geany-0.14.tar.gz
Once the files are extracted you should have a
geany-0.14 directory inside
work/source/Change into the
geany-0.14 dir in the terminal with:
cd geany-0.14/
Once inside
work/source/geany-0.14/ you can use the 'ls' command to list all the files, or use the file manager browse the directory to have a look at the content.
Inside the
geany-0.14/ directory you'll see that there's a file called '
configure', this is great because this means Geany is most likely coded in C/C++ and that it follows the "standard" for sources, which makes it easier for us to compile and later on build a package for Geany. (Some C/C++ sources does not contain a
'configure' file, they only come with a pre generated '
Makefile') One can argue that it's just as easy, or even easier to compile Perl or Python sources, this might be true, but I personally prefer to compile and build packages from C code.
As I promised we'll start off easy, so we'll just concentrate on compiling the source for now, without any tweaking, so in your terminal do the following:
./configure
After the configure step you're presented with a nice summary, like this:
Install Geany in : /usr/local
Using GTK version : 2.12.9
Build with GTK printing support : yes
Build with plugin support : yes
Use virtual terminal support : yes
Use (UNIX domain) socket support : yes
Configuration is done OK.
After the configure step is done we will start the compile process, which might take a while depending on your hardware and how much source there is to compile. To start compiling use the command:
make
Hopefully the compile process went fine. I did this on a custom Slackware 12.1 install (Which will be Wolvix 2.0.0) Once the process is done you'll see something like this as the two last lines:
make[2]: Leaving directory `/home/wolven/work/source/geany-0.14'
make[1]: Leaving directory `/home/wolven/work/source/geany-0.14'
And you'll be back in the normal prompt.
Now that the source has been compiled we can install the program to our system. This needs to be done as the root user, so 'su' to root and use this command to install the program:
make install
Once the install process is finished you'll once again see:
make[2]: Leaving directory `/home/wolven/work/source/geany-0.14'
make[1]: Leaving directory `/home/wolven/work/source/geany-0.14'
As the two last lines before you're returned to the prompt.
If all went well you should now have a Geany entry with a nice icon in the program menu under 'Development'
To remove the Geany install from your system use the command:
make uninstall
This also needs to be done as root.
OK. That was rather easy don't you think? Installing software like that works just fine, but it's not as practical as installing, upgrading or removing packages. Plus it's near impossible to distribute a compiled program like this.
Next I'll show you how to make a package from the compiled source, but first we need to examine how a Slackware package looks inside.
Anatomy of a package:If you look inside a Slackware package you'll see the following directory structure and files:
./
./install
./install/doinst.sh
./install/slack-desc
./etc
./usr
./usr/bin
./usr/doc
./usr/lib
./usr/share
./var
Not all package have the
./etc or the
./var directory, but most packages will have the
./install and
./usr directories. All packages should also contain a
./install/slack-desc file and most of them will also have a
./install/doinst.shThe slack-desc file:First let's have a look at the
slack-desc file, as this is a very important file. It contains the description for the package, if you've ever installed a Slackware package you've probably noticed the output in the terminal looking something like this when you installed it:
foobar: foobar (A superb foobar program)
foobar:
foobar: Foobar is program for bla bla bla bla bla bla
foobar: bla bla bla bla bla bla bla bla bla bla bla
foobar: bla bla bla bla bla bla bla bla bla bla bla
foobar: bla bla bla bla bla bla bla bla bla bla bla
foobar:
foobar: bla bla bla bla bla bla bla bla bla bla bla
foobar: bla bla bla bla bla bla bla bla bla bla bla
foobar:
foobar: http://foobar.example.com Here's a nice example
slack-desc taken from:
http://slackwiki.org/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------------------------------------------------------|
appname: Summary of application name and function (one line only)
appname: <this line is generally left blank>
appname: Description of application - this description should be fairly
appname: in-depth; in other words, make it clear what the package does (and
appname: maybe include relevant links and/or instructions if there's room),
appname: but don't get too verbose.
appname: This file can have a maximum of eleven (11) lines of text preceded by
appname: the "appname: " designation.
appname:
appname: It's a good idea to include a link to the application's homepage too.
appname:
The "appname" string must *exactly* match the application name portion of the Slackware package (for example, a package titled "gaim-1.5-i486-1.tgz" must have a slack-desc file with the <appname> string of "gaim: " rather than "Gaim: " or "GAIM: " or something else.
The "handy ruler" is meant to stop you at 79 characters, because the standard console is 80x25 and if you go beyond this the words will wrap.
You can find a nice tool for creating
slack-desc files here:
http://www.linuxpackages.net/slackcreator.phpThe doinst.sh file:The
doinst.sh file contains commands that will run on package install, some of the commands are generated automatically when you create a package, such as scripts for re creating symbolic links. You can also place your own custom commands in the
doinst.sh, but I won't cover that now. For more details about
doinst.sh look here:
http://slackwiki.org/Doinst.shConfiguring the source:You might have noticed that when we compiled and installed Geany in the example above it placed the files in the
/usr/local/ directory. Example the 'geany' binary was placed in
/usr/local/bin/. The Slackware standard is to place files in
/usr/somedir and not in
/usr/local/somedir. For personal packages you can go with
/usr/local, but if you plan to distribute the package(s) you must use the
/usr directory, which is the
Filesystem Hierarchy Standard.
By default most sources will use the
/usr/local directory, so when we configure the sources before compiling we need to tell it that we want to use the
/usr directory. This is done with the
--prefix=DIR option. So let's go back to the Geany example and do a new
./configure, but this time with the
--prefix=DIR option:
./configure --prefix=/usr
The above command will tell the source that we want to install the files in
/usr instead of
/usr/local. There are a few other options that we'll also use to make sure other files end up in the right directories, so let's do it like this: (Note! It's also customary on Slackware to place documents in
/usr/doc/name-version/ instead of the default
/usr/share/doc/name/ directory, but this is easier to control in a build script, so we'll get back to that later.)
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --mandir=/usr/man
In most cases these are all the configure options you'll need to use, but in some cases you'd want to control other options. What those are depends on the source, but you can get the details with the command:
./configure --help
This should display all the configure options for the source in question.
Before you continue with the new configure step uninstall Geany with the '
make uninstall' command first, if you haven't already done so:
make uninstall
Right, let's prepare Geany for package building, so configure it with the options mentioned above:
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --mandir=/usr/man
Now compile the source again:
make
Installing the source to temporary directory:Since we want to build a package we will not install Geany to our root file system ("/") as we did above. Instead we will specify a temporary directory which we will install it to, so we can easily make a package for it. This is done with the '
DESTDIR=/path/to/dir' option. We'll use the '
work/temp/' directory which we created earlier for this. Note that you need to specify the full path to the directory. In my case this is '
/home/wolven/work/temp' Also note that this has to be done as the root user.
make install DESTDIR=/home/wolven/work/temp
If you take a look in your
work/temp/ directory now you'll see that it's now populated with a
usr/ directory containing some sub directories with files in them. Here's a quick overview of the directories:
./usr/bin
./usr/include
./usr/lib
./usr/man
./usr/share
Creating the slack-desc:We're soon ready to build a package for Geany, but first we need to create a
slack-desc file for it, so in the
work/temp/ directory create a new dir called
install.
In the terminal you should now be in the
work/source/geany-0.14/ directory, so let's move to the
work/temp/ dir like this:
cd ../../temp
Then create the install directory:
mkdir install
You should now have an
install/ and a
usr/ directory inside
work/temp/. Next let's create the
slack-desc file. There are a number of ways to do this, but I will do it with a combination of using
nano and the
slack-desc tool at LinuxPackages.net.
nano install/slack-desc
My finished
slack-desc for Geany looks like this:
# 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------------------------------------------------------|
geany: geany (A small and lightweight IDE)
geany:
geany: Geany is a small and lightweight integrated development environment.
geany: It was developed to provide a small and fast IDE, which has only a
geany: few dependencies from other packages.
geany:
geany: http://geany.uvena.de/
geany:
geany:
geany:
geany: Package Created By: Wolven To make sure the description text is not too long so it will wrap, you can view the
slack-desc file in the terminal for control like this:
cat install/slack-desc
Creating the package:Now we are finally ready to build the package, (Huzza!) so let's get on with it. Make sure your in the
work/temp/ directory with the terminal. And note that you need to do the following step as root:
makepkg geany-0.14-i486-1tag.tgz
Replace the '
tag' with your tag. In my case it would be '
wlv' so the command will look like this:
makepkg geany-0.14-i486-1wlv.tgz
You'll be asked the following question:
Would you like to reset all directory permissions to 755 (drwxr-xr-x) and
directory ownerships to root.root ([y]es, [n]o)?
Answer yes to this. (Note that this might break permissions on some packages, but in this case it's safe to do this.)
If the install had contained symbolic links you'd also be asked if you'd wanted to remove the links and create a
doinst.sh file to re create them at install time. If that had been the case you should have answered yes.
Congratulations!! You've just created your first Slackware package. You should now copy it to the
work/packages/ directory for safe keeping. After that you can install it with the '
installpkg' command (as root).
cd ../
installpkg packages/geany-0.14-i486-1tag.tgz
NOTE! If you want to compile and install a new program to
work/temp/ in order to make a package for it, you need clean out the directory first. Also note that if you're going to re create the package from the install in
work/temp/ you need to remove the old package from the
work/temp/ directory first. If you don't do this the old package will end up inside the new package.