Re: Scopes for rules

Bram Moolenaar <[email protected]> Mon, 05 Jan 2004 16:19:44 +0100
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
Richard Boulton wrote:

> The attached minimal example does not behave as I would expect.
> 
> The example consists of a main.aap, which includes (using :child) 
> sub.aap.  In sub.aap, the "INCLUDE" variable is set to a new value, 
> local to the child, and the default rule for compiling a C file into an 
> object is used.
> 
> In main.aap, INCLUDE is set to an invalid value.  I would expect this to 
> be overridden by the value used in the child.
> 
> The following is the output obtained when running AAP:
> 
> Aap: Creating directory 
> "/data/home/richard/stuff/aap_example/build-Linux2_4_20_k7"
> Aap:  cc   -Iinc1    -MM foo.c > build-Linux2_4_20_k7/foo.c.aap
> Aap: cc   invalid include -O2  -c -o build-Linux2_4_20_k7/foo.o foo.c
> gcc-3.2: cannot specify -o with -c or -S and multiple compilations
> Aap: Error in recipe "/data/home/richard/Working/aap/Exec/default.aap" 
> line 229: Error executing commands for compile c: Error in recipe 
> "/data/home/richard/Working/aap/Exec/default.aap" line 233: Shell 
> command returned 1
> 
> 
> As you can see, the top level definition of INCLUDE is used for the 
> compilation of foo.o from foo.c, rather than the definition in the 
> recipe which causes the rule to fire.
> 
> Interestingly, I note that the dependency calculation uses the value of 
> INCLUDE from the sub.aap recipe scope.  I believe this difference occurs 
> because the dependency calculation is not invoked by a rule.
> 
> I'm not familiar enough with the scope searching code to work out 
> exactly what is going on here.  I'd be grateful if anyone can suggest 
> where the problem lies.

The problem is not in Aap but in your recipe.

In your child recipe you only specify how to build "foo" from "foo.o".
There is no rule to build "foo.o" from "foo.c".  When Aap figures out
what to do, it sees that "foo.o" needs to be build and applies a default
rule to compile it from "foo.c".  But this rule works at the toplevel,
not in the child recipe.

I see two solutions:

1. Don't use the object file for ":program" but the source file.

	:program $BDIR/foo : foo.c

2. Specify a dependency for compiling foo.c in the child recipe:

	$foo_objects : foo.c
		:do compile $source

I verified that both these soluitons work and use the "-Iinc1" value of
$INCLUDE.

-- 
Birthdays are healthy.  The more you have them, the longer you live.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click