automake
[Top][All Lists]
Advanced

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

Re: Extending default suffix rules.


From: Ralf Wildenhues
Subject: Re: Extending default suffix rules.
Date: Sun, 2 Mar 2008 15:20:42 +0100
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

* Remco Bras wrote on Sun, Mar 02, 2008 at 03:10:58PM CET:
> Op Sunday 02 March 2008 10:42:04 schreef Ralf Wildenhues:
> > * Remco Bras wrote on Fri, Feb 29, 2008 at 11:37:01PM CET:
> > > as part of my work on GNU RPGE, I've had to 'extend' the automake suffix
> > > rule for compiling .c files to .o ones.
> >
> > Why, what limitation made this necessary, and how exactly do your
> > changed rules/macros look like?  Maybe it can be solved in a different
> > way without breakage.

> It's more of a convenience, being that the .c files are preprocessed using 
> sed 
> to generate some common function definitions without having to write them all 
> out by hand.  The changed rule is as follows:
> 
> .c.o:
>       $(top_srcdir)/convertors.sh $< && $(CC) $(CFLAGS) $(AM_CFLAGS) -o $@ -c 
> $< && 
> cp $<{.backup,} && rm $<.backup
> 
> convertors.sh copies the original .c file to a .c.backup equivalent and 
> invokes sed a few times on the original. Once done, the cp and rm commands 
> are meant to restore the original version of the original, so that the 
> abbreviation can remain in place.

Your rule is dangerous.  If the user interrupts make at the time the
convertors.sh script has run but the backup hasn't been restored yet,
the source will be wrong, and the next time you may have duplicate
function definitions (or whatnot else the sed script then does given
the wrong input file).

Much better if you organize things differently.  Put your original,
hand-written sources in
  EXTRA_DIST = src1.c src2.c ...

put the generated sources in
  foo_SOURCES = src1-gen.c src2-gen.c ...

and write a rule or rules using convertors.sh for them.

If you want to write only one such rule instead of several, consider
using a different suffix for the hand-written sources (ugly, I know),
or, in case you may assume that all your users use GNU make, use a
pattern rule.  

For example, with GNU make, this should work (completely untested!):

  bin_PROGRAMS = foo
  foo_SOURCES = src1-gen.c src2-gen.c
  EXTRA_DIST = $(foo_SOURCES:-gen.c=.c)
  %-gen.c: %.c
        $(top_srcdir)/convertors.sh $< 

HTH.  Cheers,
Ralf




reply via email to

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