Sophie

Sophie

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

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 5. Building 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="tutorial.html" title="Part I. Tutorial"><link rel="prev" href="tutor-distribute.html" title="Chapter 4. Distributing a Program"><link rel="next" href="tutor-python.html" title="Chapter 6. Using Python"></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="tutor-distribute.html">Prev</a></td><td align="center" class="center">Tutorial</td><td align="right" class="right"><a accesskey="n" href="tutor-python.html">Next</a></td></tr></tbody></table><hr><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="tutor-variant"></a>Chapter 5. Building Variants</h2></div></div></div><p>
A-A-P provides a way to build two variants of the same application.  You
just need to specify what is different about them.  A-A-P will then take care
of putting the resulting files in a different directory, so that you don't
have to recompile everything when you toggle between two variants.
</p><p>
  For the details see
  <a href="ref-commands.html#cmd-variant">:variant</a> in the reference manual.
</p><h2><a name="build-variant"></a>One Choice</h2><p>
Quite often you want to compile an application for release with maximal
optimizing.  But the optimizer confuses the debugger, thus when stepping
through the program to locate a problem, you want to recompile without
optimizing.  Here is an example:
</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   :program $Target : $Source
</pre><p>
Write this recipe as "main.aap" and run <span class="application">Aap</span> without arguments.  This will
build "myprog" and use a directory for the object files that ends in
"-release".  The release variant is the first one mentioned, that makes it the
default choice.
</p><p>
The first argument for the <code class="computeroutput">:variant</code> command is
<code class="literal">Build</code>.  This is
the name of the variable that specifies what variant will be selected.  The
names of the alternatives
are specified with a bit more indent in lines 4 and 7.  For each alternative
two commands are given, again with more indent.  Note that the indent not only
makes it easy for you to see the parts of the <code class="computeroutput">:variant</code> command, they are
essential for <span class="application">Aap</span> to recognize them.
</p><p>
To select the "debug" variant the <code class="literal">Build</code> variable must be set to "debug".  A
convenient way to do this is by specifying this on the command line:
</p><div class="literallayout"><p>    % <strong class="userinput"><code>aap Build=debug</code></strong><br>
</p></div><p>
This will build the "myprogd" program for debugging instead of for release.
The <code class="literal">DEBUG</code> variable is recognized by <span class="application">Aap</span>.
The object files are stored in a directory ending in
"-debug".  Once you finished debugging and fixed the problem in, for example,
"gui.c", running <span class="application">Aap</span> to build the release variant will only compile the
modified file.  There is no need to compile all the C files, because the object
files for the "release" variant are still in the "-release" directory.
</p><h2><a name="id2627957"></a>Two Choices</h2><p>
You can extend the <code class="literal">Build</code> variant with more items, for example
"profile".  This is useful for alternatives that exclude each other.  Another
possibility is to add a second <code class="computeroutput">:variant</code> command.  Let us
extend the example with a selection of the user interface type.
</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   Gui ?= motif
12   :variant Gui
13       console
14       motif
15            Source += motif.c
16       gtk
17            Source += gtk.c
18
19   DEFINE += -DGUI=$Gui
20
21   :program $Target : $Source
</pre><p>
The <code class="computeroutput">:variant</code> command in line 12 uses the <code class="literal">Gui</code>
variable to select one of "console", "motif" or "gtk".  Together with the
earlier <code class="computeroutput">:variant</code> command this offers six alternatives:
"release" with "console", "debug" with "console", "release" with "motif", etc.
To build "debug" with "gtk" use this command:
</p><div class="literallayout"><p>    % <strong class="userinput"><code>aap Build=debug Gui=gtk</code></strong><br>
</p></div><p>
In line 11 an optional assignment "?=" is used.  This assignment is skipped if
the <code class="literal">Gui</code> variable already has a value.  Thus if <code class="literal">Gui</code> was
given a value on the command line, as in the example above, it will keep this
value.  Otherwise it will get the value "motif".
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note: Environment variables"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Environment variables</th></tr><tr><td align="left" valign="top"><p>
Environment variables are not used for variables in the recipe, like
<code class="literal">make</code> does.  When you happen to have a <code class="literal">Gui</code> environment
variable, this will not influence the variant in the recipe.  This is
especially useful if you are not aware of what environment variables are set
and/or which variables are used in the recipe.  If you intentionally want to
use an environment variable this can be specified with a Python expression (see the next chapter).
</p></td></tr></table></div><p>
In line 15, 17 and 19 the append assignment "+=" is used.  This appends the argument
to an existing variable.  A space is inserted if the value was not empty.  For
the variant "motif" the result of line 15 is that
<code class="literal">Source</code> becomes "main.c version.c gui.c motif.c".
</p><p>
The "motif" and "gtk" variants each add a source file in line 15 and 17.  For
the console version no extra file is needed.  The object files for each
combination of variants end up in a different directory.  Ultimately you get
object files in each of the six directories ("SYS" stands for the platform
being used):

</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-console</td><td>main, version, gui</td></tr><tr><td>build-SYS-debug-console</td><td>main, version, gui</td></tr><tr><td>build-SYS-release-motif</td><td>main, version, gui, motif</td></tr><tr><td>build-SYS-debug-motif</td><td>main, version, gui, motif</td></tr><tr><td>build-SYS-release-gtk</td><td>main, version, gui, gtk</td></tr><tr><td>build-SYS-debug-gtk</td><td>main, version, gui, gtk</td></tr></tbody></table></div><p>
</p><p>
See the <a href="user-variant.html" title="Chapter 14. Variants">user manual</a>
for more examples of using variants.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tutor-distribute.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tutor-python.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. Distributing a Program </td><td width="20%" align="center"><a accesskey="h" href="index.html">
		    Contents</a></td><td width="40%" align="right" valign="top"> Chapter 6. Using Python</td></tr></table></div></body></html>