Autoconf/Automake installer for a Perl program

If you create a Perl application and want it to be installed in some standard part like /usr/local  or /opt/yourapp, it’s quite easy to do with a the standard GNU Autoconf, Automake and a couple of helper scripts.

This tutorial is based on the Gerty project code at Github.

Hint #1: do not apply AC_CONFIG_FILES to your Perl files directly. Use a helper script (setup_tools/substvars.sh.in in Gerty sources) that does the variable substitution. The reason is that for variables which depend on other variable values, AC_CONFIG_FILES expands them as references. For example, @datadir@ is expanded into ${datarootdir}. A little shell script like substvars.sh expands these recursive references into string values which you finally use in your Perl program.

Hint #2: you may list all your .pm files in a Makefile.am, but then you’d have to update it every time you add a new module. It’s quite easy to miss one, especially if your project is actively developing. Instead, you can embed a small shell script into your makefile, and it would copy all .pm files from your lib directory. See lib/Makefile.am in Gerty sources as a working example.

You may start with writing your configure.ac file as usual. Also it’s faster if you copy it from an existing project 🙂

You will definitely need AC_PATH_PROG for Perl, as your installer should be able to work with any perl instance on the target system. Also configure.ac in Gerty sources offers a simple checkup for pre-requisite modules. Also it enables to skip those check-ups if you only intend to package, and not to run the software.

Makefile.am is quite standard so far. The one in Gerty inserts a small file called DIST_REVISION: it contains the date and the Git branch information at the moment of “make dist” execution.

The bin/Makefile.am in Gerty illustrates how the executable scripts need to be handled.

Once all configure.ac and Makefile.am files are ready for testing, proceed as follows:

touch AUTHORS ChangeLog INSTALL NEWS README
aclocal
autoconf
automake -a -c

Later you can run “autoreconf” instead of “aclocal && autoconf && automake“. Autoreconf is part of Libtool package.

Now your package is generally ready. You can proceed with “./configure” and “make install” as you usually do with other packages.

Do not forget the .gitignore (or svn:ignore if you like). Autotools would keep some temporary garbage in your project directory, so it’s important to set up a proper .gitignore before making any commits.

Advertisements

, , , , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: