Making slackware packages from source without slackbuild

Originally posted on linuxquestions.org by me.

This article describes how to build software packages for slackware linux from source code.
It is not easiest method, but it is useful for quick package creation.
If you simply want to install software, and do not want to compile it, then either download precompiled packages from www.linuxpackages.net, or get slackbuild from www.slackbuilds.org. Another option is to use src2pkg utility or checkinstall (but checkinstall is mostly broken since Slackware 11.0).

I'm posting this because some people have problems with making packages from source code, and howto where I learned how to do it isn't available anymore.

  1. howto is pretty short and doesn't dive into details too much (although I initially thought about overview of commonly used build systems).
  2. This doesn't work for all packages, only for most of them. Method is not universal
  3. This stuff is written for people that don't like Slackbuilds, or want to compile software without slackbuild. If you simply want to install program as fast as possible, search for compiled package on www.linuxpackages.net, or search for slackbuild on www.slackbuilds.org.
This method will work only if following conditions are met:
  1. program package contains ./configure script.
  2. Makefile produced by ./configure contains word DESTDIR (case-sensitive).
Seems pretty restrictive, but, fortunately, this covers 95% of all available linux software.

If there is no ./configure, or makefile doesn't have "DESTDIR" inside, this will not work. (there are exceptions from that rule, of course, but explaing them will take too much space)

Short explanation
In this example I assume that we have extracted our package, and right now are within source code directory, where ./configure script is located. In example our program has name "programname" and version "programversion". When compiling your own package, replace "programname" and "programversion" with values you need.

Most software can be turned into slackware package using this sequence:
  1. ./configure
  2. make
  3. mkdir pkg
  4. make DESTDIR=`pwd`/pkg install
  5. cd pkg
  6. su
  7. makepkg programname-programversion-1xyz.tgz
  8. chown me.users ./programname-programversion-1xyz.tgz (instead of "me" use your user name)
  9. mv ./programname-programversion-1xyz.tgz ..
  10. cd ..
  11. rm -r pkg
  12. Ctrl+D (exits "su")

If package meets requirements mentioned before, this sequence will create slackware package for you.

How it works
  1. "./configure" - configures package according to our system.
  2. "make" - compiles package.
  3. "mkdir pkg" - creates directory called "pkg" within same directory where ./configure is located. This "pkg" directory will be used to
    store files that will be put into package.
  4. "make DESTDIR=`pwd`/pkg install":
    This tells to the "make" command to install package as if "pkg" subdirectory (that we created in current directory) were root "/" folder.
    "`pwd`" inserts output of "pwd" command into current command line. DESTDIR is a variable used inside makefile. DESTDIR specify the root of installations, and because GNU make allows to override some variables during compilation, we can change it, and say that "pkg" subdirectory is a root of installation.
  5. "cd pkg" we are going into "pkg" subdirectory.
  6. "su" (enter password here) - changing privilegies to root, because makepkg (which is used to create packages) won't work with other privilegies.
  7. "makepkg programname-programversion-1xyz.tgz" This creates slackware package without description. Answer "yes" to all questions (well, unless it doesn't suit your needs). Also, notice "1xyz" part of the filename instead of numbers. When you build custom packages, you need to be able to distinguish them from stock packages. To do that, instead of standard numbers numbers, use custom signature, something like "1abc", "2abc", etc. Use whatever combination you want (I use number + my nickname), as long as you can distinguish your package from packages made by other people.
  8. "chown me.users ./programname-programversion-1xyz.tgz" Created package has "root.root" owner. If we want to be able later to move it somewhere, we need to change owner to our user ID.
  9. "mv ./programname-programversion-1xyz.tgz .." We are moving our package into the source directory - i.e. one level up.
  10. "cd .." Going one level up. (back into directory with "configure")
  11. "rm -r pkg" we are cleaning up and removing our pkg subdirectory.
  12. "Ctrl+D" - this equivalent to "exit" command which ends "su" session.

Now you have your slackware package.
If something doesn't work, or you don't understand something, ask it on slackware forums.

Few Notes
Package created this way normally will end in "/usr/local" instead of "/usr". This is because "/usr/local" is default location for user-built packages. "/usr/local/" is fine if you are creating packages for yourself, but, for example, linuxpackages.net rejects packages that are not in "/usr". So if you want to distribute your packages, or submit them to linucpackages.net, then change installation location from "/usr/local" to "/usr" using --prefix configure option.

No comments:

Post a Comment