Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > a6d417e36f6bb1154f4c003e6717e298 > files > 165

a-a-p-1.090-2mdv2009.0.noarch.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 14. Variants</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="A-A-P Recipe Executive"><link rel="up" href="user.html" title="Part II. User Manual"><link rel="prev" href="user-depend.html" title="Chapter 13. Dependencies, Rules and Actions"><link rel="next" href="user-publish.html" title="Chapter 15. Publishing"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table width="100%" id="navtable"><tbody><tr><td align="left" class="left" width="33%"><b><a href="http://www.a-a-p.org">A-A-P home page</a></b></td><td align="center" class="center" width="34%"><b><a href="index.html">A-A-P Recipe Executive</a></b></td><td align="right" class="right" width="33%"></td></tr><tr><td align="left" class="left"><a accesskey="p" href="user-depend.html">Prev</a></td><td align="center" class="center">User Manual</td><td align="right" class="right"><a accesskey="n" href="user-publish.html">Next</a></td></tr></tbody></table><hr><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="user-variant"></a>Chapter 14. Variants</h2></div></div></div><p>
You might first want to read the <a href="tutor-variant.html" title="Chapter 5. Building Variants">tutorial</a>
for a few examples of using variants.
</p><p>
Here is an example how build variants can be specified.  This will be used to
explain how it works.
</p><pre class="programlisting">
     :variant Opt
         some
             OPTIMIZE = 2
         much
             OPTIMIZE = 6        
         *
             OPTIMIZE = 1
</pre><p>
"Opt" is the name of a variable.  It is used to select one of the variants.
Each possible value is listed in the following line and further lines with the
same indent.  In the example these are "some" and "much".  "*" is used to
accept any value, it must be the last one.  The first value mentioned is the
default when the variable isn't set.  
</p><p>
You can now start <span class="application">Aap</span> with various arguments to specify the kind of
optimizing you want to use:
</p><div class="literallayout"><p>        <strong class="userinput"><code>aap Opt=some</code></strong>      will set <code class="literal">OPTIMIZE</code> to 2<br>
        <strong class="userinput"><code>aap Opt=much</code></strong>      will set <code class="literal">OPTIMIZE</code> to 6<br>
        <strong class="userinput"><code>aap Opt=other</code></strong>    will set <code class="literal">OPTIMIZE</code> to 1<br>
        <strong class="userinput"><code>aap</code></strong>                      will set <code class="literal">OPTIMIZE</code> to 2<br>
</p></div><p>
Note that when "Opt" is not given a value the first entry is used, resulting
in <code class="literal">OPTIMIZE</code> being set to 2.  But when it is set to a value that
isn't mentioned the last entry "*" is used.
</p><h2><a name="id2640833"></a>The <code class="literal">BDIR</code> Variable</h2><p>
The <code class="literal">$BDIR</code> variable will be adjusted for the variant used. CAREFUL:
this means that using <code class="literal">$BDIR</code> before
<a href="ref-commands.html#cmd-variant">:variant</a> commands will use a
different value, that might not always be what you want.
</p><p>
  Inside the
  <a href="ref-commands.html#cmd-variant">:variant</a> command the value of <code class="literal">$BDIR</code> has already been
adjusted.
</p><p>
When a target that is being build starts with <code class="literal">$BDIR</code> and
<code class="literal">$BDIR</code> doesn't exist, it is created. (Actually, this happens when
an item in the path is "build" or starts with "build-".
</p><p>
<code class="literal">$BDIR</code> is relative to the recipe.  When using ":child dir/main.aap"
the child recipe will use a different build directory <code class="literal">dir/$BDIR</code>.
Note that when building the same source file twice from recipes that are in
different directories, you will get two results.  Best is to always build a
target from the same recipe (that makes it easier to understand the
recipe anyway).
</p><h2><a name="id2640903"></a>Compile only when needed</h2><p>
This continues the last example of the
<a href="tutor-variant.html" title="Chapter 5. Building Variants">tutorial</a>.
</p><p>
We happen to know that the main.c file does not depend on the GUI used.  With
the recipe above it will nevertheless be compiled again for every GUI version.
Although this is a small thing in this example, in a bigger project it becomes
more important to skip compilation when it is not needed.  Here is the
modified recipe:
</p><pre class="programlisting">
1    Source = main.c version.c gui.c
2
3    :variant Build
4        release
5            OPTIMIZE = 4
6            Target = myprog
7        debug
8            DEBUG = yes
9            Target = myprogd
10
11   :attr {var_DEFINE = $DEFINE} {var_BDIR = $BDIR} main.c
12    
13   Gui ?= motif
14   :variant Gui
15       console
16       motif
17            Source += motif.c
18       gtk
19            Source += gtk.c
20
21   DEFINE += -DGUI=$Gui
22
23   :program $Target : $Source
</pre><p>
The only new line is line 11.  The "main.c" file is given two extra
attributes: <code class="literal">var_DEFINE</code> and <code class="literal">var_BDIR</code>.  What happens is
that when "main.c" is being build, <span class="application">Aap</span> will check for attributes of this
source file that start with "var_".  The values will be used to set variables
with the following name to the value of the attribute.  Thus
<code class="literal">DEFINE</code> gets the value of <code class="literal">var_DEFINE</code>.  This means that
the variable is overruled by the attribute while building "main.c".
</p><p>
The <code class="literal">var_BDIR</code> attribute is set to "$BDIR" before the second
<code class="computeroutput">:variant</code> command.  It does not yet have the selected GUI
appended there.  The list of directories used is now:

</p><div class="informaltable"><table border="0"><colgroup><col width="250"><col></colgroup><thead><tr><th>directory</th><th>contains files</th></tr></thead><tbody><tr><td>build-SYS-release</td><td>main</td></tr><tr><td>build-SYS-debug</td><td>main</td></tr><tr><td>build-SYS-release-console</td><td>version, gui</td></tr><tr><td>build-SYS-debug-console</td><td>version, gui</td></tr><tr><td>build-SYS-release-motif</td><td>version, gui, motif</td></tr><tr><td>build-SYS-debug-motif</td><td>version, gui, motif</td></tr><tr><td>build-SYS-release-gtk</td><td>version, gui, gtk</td></tr><tr><td>build-SYS-debug-gtk</td><td>version, gui, gtk</td></tr></tbody></table></div><p>
</p><h2><a name="id2641127"></a>Building multiple variants at once</h2><p>
If you want to build all the variants that are possible, use a few lines of
Python code.  Here is an example:
</p><pre class="programlisting">
 1   :variant license
 2       trial
 3           DEFINE += -DTRIAL
 4       demo
 5           DEFINE += -DDEMO
 6       full
 7           DEFINE += -DFULL
 8   
 9   :variant language
10       chinese
11           DEFINE += -DCHINESE
12       bulgarian
13           DEFINE += -DBULGARIAN
14       *
15           DEFINE += -DENGLISH
16    
17   build:
18       :print Building with $license license for language $language.
19       :print DEFINE=$DEFINE
10    
21   all:
22       @for a in ['trial', 'demo', 'full']:                    #license
23       @   for c in ['chinese', 'bulgarian', 'english']:       #language
24               :execute main.aap build license=$a language=$c
</pre><p>
Invoking <span class="application">Aap</span> without arguments builds the "all" target, which loops over
all possible variants and invokes the
<a href="ref-commands.html#cmd-execute">:execute</a> command with the "build"
target.  The reason to use the "build" target is that without it the "all"
target would be built again and result in an endless loop.
</p><p>
This is the resulting output:
</p><div class="literallayout"><p>     Building with trial license for language chinese.<br>
     DEFINE=-DTRIAL -DCHINESE<br>
     Building with trial license for language bulgarian.<br>
     DEFINE=-DTRIAL -DBULGARIAN<br>
     Building with trial license for language english.<br>
     DEFINE=-DTRIAL -DENGLISH<br>
     Building with demo license for language chinese.<br>
     DEFINE=-DDEMO -DCHINESE<br>
     Building with demo license for language bulgarian.<br>
     DEFINE=-DDEMO -DBULGARIAN<br>
     Building with demo license for language english.<br>
     DEFINE=-DDEMO -DENGLISH<br>
     Building with full license for language chinese.<br>
     DEFINE=-DFULL -DCHINESE<br>
     Building with full license for language bulgarian.<br>
     DEFINE=-DFULL -DBULGARIAN<br>
     Building with full license for language english.<br>
     DEFINE=-DFULL -DENGLISH<br>
</p></div><p>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="user-depend.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="user-publish.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 13. Dependencies, Rules and Actions </td><td width="20%" align="center"><a accesskey="h" href="index.html">
		    Contents</a></td><td width="40%" align="right" valign="top"> Chapter 15. Publishing</td></tr></table></div></body></html>