Smart gnumakefiles are smart

I've never set up GNU automake on an open source project, but on the surface the input files (Makefile.am) look nice: they simply list the targets and the things that go in the targets without getting bogged down in rules.

On the other hand, it's apparently difficult or impossible to use both automake and the "nonrecursive GNU make" style that I like so very much. Apparently this is at least in part because the authors of automake decline to use GNU extensions to make, which is a bit surprising to me since GNU make is ubiquitous on GNU/Linux systems anyway.

I think a modest amount of work on GNU make rules and infrastructure can create Makefiles that are similarly nice looking to Makefile.am files. Here's an example:

PROGRAMS := wako pnminfo pnmbinary

CFLAGS := -O2 -g -std=gnu99
LFLAGS := -lnetpbm

SRCS_wako := bit.c channel.c coding.c io.c main.c reorder.c transform.c utility.c
CFLAGS_wako := -O3 -std=gnu99
LFLAGS_wako := $(LFLAGS) -lm

SRCS_pnminfo := pnminfo.c

SRCS_pnmbinary := pnmbinary.c

include program.inc

Now wasn't that pleasant? Paths are permitted for items in SRCS_, so you can build a whole directory structure from a single Makefile, or include Submakefiles on your own. A simple variation on program.inc could build libraries; another set of variations would add support for C++ source files.

Files currently attached to this page:

program.inc2.1kB

Of course, the real question is why I haven't jumped on scons, since it's written in Python and all.... hmmm



Entry first conceived on 5 January 2009, 23:26 UTC, last modified on 15 January 2012, 3:46 UTC
Website Copyright © 2004-2024 Jeff Epler