[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Supporting include in Makefiles

From: Dean Povey
Subject: Supporting include in Makefiles
Date: Thu, 28 Jun 2001 07:37:59 +1000

Firstly, apologies for the cross-posting, particularly giving the fact that 
I am including code, but this message contains issues relevant to both 
automake and autoconf.

For a while I have been thinking that it would be nice to be able to 
support "include" in autoconf/automake Makefiles.   This would be particularly 
nice with automake which generates very large repetitious Makefiles.  
Currently there are three ways to do inclusion that I can think of 
(AC_SUBST_FILE, the hack and automake's include) but 
all these result in full expansion of the included file in the final 
Makefile.  I am talking about a real include that is done by Make and 
not by auto{conf|make}.

A big motivation for me, is to use this with automake.  I have at least one
project which has a large number of Makefiles and uses a single include
file to add extra rules.  The big problem with the current setup is a
single change to the include file means rerunning automake/config.status on
_every_ Makefile.  Using an include mechanism it should be possible to just
regenerate the include file and have everything worked out.

The problem is of course, that not all makes do include the same way.  
There are basically two flavours.

#SYSV and GNU make
include file

#BSD make (although most of the later BSD makes seem to support include)
.include "file"

And while I cannot actually find a version of make that doesn't support 
include in some form, for safety we probably want to support some sort of 
hack that does an inline expansion of the include file if there is no Make 

To this end I have hacked up some autoconf macro's that do a check to see 
if include is supported and emulate it if it isn't.  You use it this way:

In your Makefile do:

#Lots of lovely make rules ...
@INCLUDE@ @INCLUDE_QUOT@@top_srcdir@/address@hidden@

(Yes I know the syntax is ugly and hard to read, but it is the easiest way 
to do it without having to dig through autoconf internals).

Then in your do:


Which automatically calls AC_PROG_MAKE_INCLUDE to check for include support
(if it hasn't already been called).

I have a reasonable amount of comments in the code, so it should be easy
enough to follow, and it seems to work on all the systems I have access to.
I have tried to avoid using autoconf internals wherever possible.  It is a 
hack and a bit fragile in places, but as a proof of concept it is probably 
a good start.  

Better support would probably require some access to automake internals.
For example, you would tend to want to have a single with all
the address@hidden@ stuff and include this from all the other Makefiles so it
makes sense to have the @INCLUDE@ subsitution very close to the top of the
sed commands list to avoid having to run through all the other
substitutions.  This would speed up config.status for a lot of files.

This might also make it easier to address the problem of recursive 
Makefiles in automake by doing the following:

Generate top level include with all the common stuff.
Generate directory specific stuff in a per-directory include file
Generate directory specific Makefile including top-level and per-directory 
Generate top-level Makefile with directory specific and all the 
per-directory files included.

This allows you to still do "cd foo; make" when that make sense.  Of course
resolving the namespace issues here would be non-trivial.

Any comments, suggestions?

Attachment: acmakeinclude.m4
Description: acmakeinclude.m4

reply via email to

[Prev in Thread] Current Thread [Next in Thread]