Adventures with autotools

I’ve used and otherwise benefited from autotools a number of times in the past – being able to just ./configure && make && make install a large number of open source projects is hugely beneficial – but I’ve never actually ./configured (heh) one of my own projects to use them. Well…I decided to go down that path today.

The project – svgcal (link coming soon!) – is a little tool I’m throwing together to parse an input file and generate a (hopefully) pretty SVG file that displays my weekly agenda. I’m not too far along, so right now it’s just a couple of files – sources for the lexer and parser and a couple of header files – so I thought it would be good to go ahead and get autotools set up before it got much more complex than that. So, what did I have to do? Just a handful of steps:

  1. Create a couple of files for autoreconf to use (Makefile.am, configure.ac, and src/Makefile.am – listings below)
  2. Run autoreconf --install
  3. Tweak my lexer (autotools muck about with how the parser header file gets created; was an easy fix: s/y.tab.h/parser.h/)
  4. Add the generated files to source control
  5. …and that’s it!
My project is now all set up to be built using ./configure and make without me doing any additional work. Awesome!

Makefile.am:

SUBDIRS = src
dist_doc_DATA = README

configure.ac:

AC_INIT([svgcal], [0.1], [cliff@cliftonsnyder.net])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
# programs needed
AC_PROG_CC
AC_PROG_LEX
AC_PROG_YACC
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT

src/Makefile.am:

bin_PROGRAMS = parser
parser_SOURCES = svgcal.c parser.y lexer.l
AM_YFLAGS = -d

Advertisements


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