Autopackage provides some helpful shortcuts for creating packages of software built with autotools. If the software you wish to package doesn't use autotools, then you must manually set some things in the apspec file. This document aims to show how to use the SCons build system to create an autopackage.

Setting up the build system

There are some things the build system must be able to do in order to work well with autopackage.

Staging directory

First, it must be able to install to a custom destination. For instance, if program data is usually installed to /usr/share, you should set up a staging directory variable in the SConstruct that tells it to install instead to <staging directory>/usr/share. Then you can run something like scons install staging=/home/user/tmp/ and the program data will end up in /home/user/tmp/usr/share. This can be done with an option like this:

opts.Add('staging', 'Staging directory to install to.  Useful for packaging. ', '')

It is empty by default so that it will not affect the installation path when it is not set. Combined with a prefix option, you can construct the program data installation path as env['staging'] + env['prefix'] + "/share" .

For Autopackage, the staging directory should be set to the $build_root environment variable.

APBuild

Next, your SCons build setup must know how to use apbuild so the program will work on many platforms. You can add an option to the SConstruct like this:

opts.Add(BoolOption('use_apbuild', 'Set this to 1 if you want to compile with apgcc to create an autopackage', 0))

and some code to handle it like this:

if env['use_apbuild']:
    env['CXX'] = 'apg++'
    env['CC'] = 'apgcc'

Setting up the apspec file to use SCons

The apspec functions prepareBuild and unprepareBuild will not work properly with a SCons-based build system. You'll need to delete those and write your own. This is pretty simple as long as your build system is set up right. For the BuildPrepare section, this should work nicely:

[BuildPrepare]
scons install use_apbuild=1 staging=$build_root

If there are other commands that need to run before or after this to install the program properly, you may add them. Likewise, other options can be added to the build command.

For BuildUnprepare, something similar can be used to tell SCons to clean up:

[BuildUnprepare]
scons -c install staging=$build_root

In both examples, $build_root is filled in by makepackage, this is the directory from which it will build the autopackage.

Other sections of the apspec file can be set with the defaults that mkapspec generates, including the Imports section.

Calling the autopackage builder through SCons

You can add a build target to your project's SConstruct file that calls the autopackage builder. Here's an example:

if 'autopackage' in COMMAND_LINE_TARGETS:
    os.system("makepackage autopackage/default.apspec")

As long as the autopackage/default.apspec file is present, this will build the package for you. The end result is that SCons will build an autopackage when you run scons autopackage .

Customizing your autopackage

To avoid having to change your apspec file every time you do a release, you can use variables for things like SoftwareVersion:

[Meta]
ShortName: myprog
SoftwareVersion: $MY_VERSION
...

Now if you have a variable in your SConstruct called version you can pass it to the apspec by modifying your autopackage target:

if 'autopackage' in COMMAND_LINE_TARGETS:
    os.system("MY_VERSION=%s makepackage autopackage/default.apspec" % version)

Other variables can be added, of course.

Reference