Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/bbv2/extending/targets.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 7.2 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Target types</title>
5<link rel="stylesheet" href="../../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<style type="text/css">
8body { background-image: url('http://docbook.sourceforge.net/release/images/draft.png');
9       background-repeat: no-repeat;
10       background-position: top left;
11       /* The following properties make the watermark "fixed" on the page. */
12       /* I think that's just a bit too distracting for the reader... */
13       /* background-attachment: fixed; */
14       /* background-position: center center; */
15     }</style>
16<link rel="start" href="../../index.html" title="The Boost C++ Libraries">
17<link rel="up" href="../extender.html" title="Chapter 25. Extender Manual">
18<link rel="prev" href="../extender.html" title="Chapter 25. Extender Manual">
19<link rel="next" href="tools.html" title="Tools and generators">
20</head>
21<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
22<table cellpadding="2" width="100%">
23<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../boost.png"></td>
24<td align="center"><a href="../../../../index.htm">Home</a></td>
25<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
26<td align="center"><a href="../../../../people/people.htm">People</a></td>
27<td align="center"><a href="../../../../more/faq.htm">FAQ</a></td>
28<td align="center"><a href="../../../../more/index.htm">More</a></td>
29</table>
30<hr>
31<div class="spirit-nav">
32<a accesskey="p" href="../extender.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../extender.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="tools.html"><img src="../../images/next.png" alt="Next"></a>
33</div>
34<div class="section" lang="en">
35<div class="titlepage"><div><div><h2 class="title" style="clear: both">
36<a name="bbv2.extending.targets"></a>Target types</h2></div></div></div>
37<div class="toc"><dl><dt><span class="section"><a href="targets.html#bbv2.extending.scanners">Scanners</a></span></dt></dl></div>
38<p>The first thing we did in the <a href="../extender.html#bbv2.extender.intro" title="Introduction">intruduction</a> was declaring a
39      new target type:
40</p>
41<pre class="programlisting">
42import type ;
43type.register VERBATIM : verbatim ;
44</pre>
45<p>
46        The type is the most important property of a target. Boost.Build can
47        automatically generate necessary build actions only because you
48        specify the desired type (using the different main target rules), and
49        because Boost.Build can guess the type of sources from their
50        extensions.       
51      </p>
52<p>The first two parameters for the <code class="computeroutput">type.register</code> rule
53        are the name of new type and the list of extensions associated with
54        it. A file with an extension from the list will have the given target
55        type. In the case where a target of the declared type is generated
56        from other sources, the first specified extension will be used.
57      </p>
58<p>Sometimes you want to change the suffix used for generated targets
59      depending on build properties, such as toolset. For example, some compiler
60      uses extension <code class="literal">elf</code> for executable files. You can use the
61      <code class="computeroutput">type.set-generated-target-suffix</code> rule:
62</p>
63<pre class="programlisting">
64type.set-generated-target-suffix EXE : &lt;toolset&gt;elf : elf ;
65</pre>
66<p>A new target type can be inherited from an existing one.
67</p>
68<pre class="programlisting">
69type.register PLUGIN : : SHARED_LIB ;
70</pre>
71<p>
72      The above code defines a new type derived from
73      <code class="computeroutput">SHARED_LIB</code>. Initially, the new type inherits all the
74      properties of the base type - in particular generators and suffix.
75      Typically, you'll change the new type in some way. For example, using
76      <code class="computeroutput">type.set-generated-target-suffix</code> you can set the suffix for
77      the new type. Or you can write special generator for the new type. For
78      example, it can generate additional metainformation for plugin.
79      In either way, the <code class="computeroutput">PLUGIN</code> type can be used whenever
80      <code class="computeroutput">SHARED_LIB</code> can. For example, you can directly link plugins
81      to an application.
82    </p>
83<p>A type can be defined as "main", in which case Boost.Build will
84      automatically declare a main target rule for building targets of that
85      type. More details can be found <a href="rules.html#bbv2.extending.rules.main-type">later</a>.
86    </p>
87<div class="section" lang="en">
88<div class="titlepage"><div><div><h3 class="title">
89<a name="bbv2.extending.scanners"></a>Scanners</h3></div></div></div>
90<p>
91          Sometimes, a file can refer to other files via some include
92          mechanism. To make Boost.Build track dependencies to the included
93          files, you need to provide a scanner. The primary limitation is that
94          only one scanner can be assigned to a target type.
95        </p>
96<p>First, we need to declare a new class for the scanner:
97</p>
98<pre class="programlisting">
99class verbatim-scanner : common-scanner
100{
101    rule pattern ( )
102    {
103        return "//###include[ ]*\"([^\"]*)\"" ;
104    }
105}
106</pre>
107<p>         
108          All the complex logic is in the <code class="computeroutput">common-scanner</code>
109          class, and you only need to override the method that returns
110          the regular expression to be used for scanning. The
111          paranthethis in the regular expression indicate which part
112          of the string is the name of the included file.  Only the
113          first parenthesized group in the regular expression will be
114          recognized; if you can't express everything you want that
115          way, you can return multiple regular expressions, each of
116          which contains a parenthesized group to be matched.
117        </p>
118<p>After that, we need to register our scanner class:
119</p>
120<pre class="programlisting">
121scanner.register verbatim-scanner : include ;
122</pre>
123<p>
124            The value of the second parameter, in this case
125            <code class="computeroutput">include</code>, specifies the properties that contain the list
126            of paths that should be searched for the included files.
127         </p>
128<p>Finally, we assign the new scaner to the <code class="computeroutput">VERBATIM</code>
129        target type:
130</p>
131<pre class="programlisting">
132type.set-scanner VERBATIM : verbatim-scanner ;
133</pre>
134<p>
135          That's enough for scanning include dependencies.
136        </p>
137</div>
138</div>
139<table width="100%"><tr>
140<td align="left"></td>
141<td align="right"><small></small></td>
142</tr></table>
143<hr>
144<div class="spirit-nav">
145<a accesskey="p" href="../extender.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../extender.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="tools.html"><img src="../../images/next.png" alt="Next"></a>
146</div>
147</body>
148</html>
Note: See TracBrowser for help on using the repository browser.