2010-03-24

Dynamically building headers with automake / autotools

Say part of your build process is meant to generate a custom include file, eg. resource.h, built from embedded resources and you want to ensure that this header is always built before the rest.

The trick then is to add
BUILT_SOURCES = resource.h
in your Makefile/Makefile.am as all files mentioned as BUILT_SOURCES will be built before any of the normal compilation rules run.

This is what we do in WDI (Windows Driver Installer) for libusb 1.0 with a Makefile.am that looks like:
BUILT_SOURCES = resource.h
lib_LTLIBRARIES = libusb-wdi.la

LIB_SRC = resource.h infs.h usbi.h installer.h installer_library.h installer_library.c

libusb_wdi_la_CFLAGS = $(VISIBILITY_CFLAGS) $(AM_CFLAGS) -L../../libusb/libusb/.libs -lusb-1.0 
libusb_wdi_la_SOURCES = $(LIB_SRC)

resource.h:
    ../embedder/embedder.exe resource.h

clean-local:
    -rm -rf resource.h

No comments:

Post a comment