[Cook] c_incl and -D

Jason Evans jasone at canonware.com
Wed Mar 19 10:20:43 EST 2003


On Wed, Mar 19, 2003 at 09:32:08AM +1100, Peter Miller wrote:
> On Mon, 2003-03-03 at 09:06, Jason Evans wrote:
> > c_incl doesn't ignore -D command line
> > flags, which requires extra complexity in build systems to keep -I and -D
> > cpp flags separate.  Does it seem reasonable to Peter and others to add
> > this pseudo feature to c_incl?
> 
> It's easy enough to get -D* options to be ignored.  It requires
> non-symmetric hacks in common/arglex.c to make -Dname=value parse
> nicely.
> 
> Also, where does it stop?  Will you want -W* and -f* and -m* next, and
> all those other gcc options?
> 
> However, if you can come up with an elegant (well, as elegant as it can
> be, I suppose) patch, I'll probably accept it.

You make a good argument for leaving out the ability to ignore cpp flags,
since -D is only the most commonly used of many such flags.  I no longer
think this is a good idea.

I've made a minor modification to my Cookfiles, so that all calls to c_incl
filter CPPFLAGS using the following function:

--------
/*
 * Given [CPPFLAGS], filter out everything but -I flags.  This is typically used
 * in preparation for calling c_incl, which doesn't recognize flags such as the
 * -D flag.
 */
function filter_cppdefs =
{
  local cppflags = [arg];

  cppflags = [unsplit " " [cppflags]];
  cppflags = [subst " -I " " -I" [cppflags]];
  cppflags = [split " " [cppflags]];
  cppflags = [filter -I%0% [cppflags]];

  return [cppflags];
}
--------

This solves the problem, without gross hacks to c_incl.  This should have
occurred to me earlier...

In any case, thanks for your consideration.

Jason



More information about the Cook-users mailing list