summaryrefslogtreecommitdiff
path: root/doc/html/bbv2/extending/rules.html
blob: 95f8459899a65970ff45de4e25a94a55c0713733 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Main target rules</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
<style type="text/css">
body { background-image: url('http://docbook.sourceforge.net/release/images/draft.png');
       background-repeat: no-repeat;
       background-position: top left;
       /* The following properties make the watermark "fixed" on the page. */
       /* I think that's just a bit too distracting for the reader... */
       /* background-attachment: fixed; */
       /* background-position: center center; */
     }</style>
<link rel="start" href="../../index.html" title="The Boost C++ Libraries">
<link rel="up" href="../extender.html" title="Chapter 25. Extender Manual">
<link rel="prev" href="features.html" title="Features">
<link rel="next" href="toolset_modules.html" title="Toolset modules">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../people/people.htm">People</a></td>
<td align="center"><a href="../../../../more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="features.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="toolset_modules.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="bbv2.extending.rules"></a>Main target rules</h2></div></div></div>
<p>
      A main target rule (e.g &#8220;<code class="computeroutput">exe</code>&#8221;
      Or &#8220;<code class="computeroutput">lib</code>&#8221;) creates a top-level target. It's quite likely that you'll want to declare your own and
      there are two ways to do that.
      </p>
<p><a name="bbv2.extending.rules.main-type"></a>The first way applies when

      your target rule should just produce a target of specific type. In that case, a
      rule is already defined for you! When you define a new type, Boost.Build
      automatically defines a corresponding rule. The name of the rule is
      obtained from the name of the type, by downcasing all letters and
      replacing underscores with dashes. 
      
      For example, if you create a module
      <code class="filename">obfuscate.jam</code> containing:

</p>
<pre class="programlisting">
import type ;
type.register OBFUSCATED_CPP  : ocpp ;

import generators ;
generators.register-standard obfuscate.file : CPP : OBFUSCATED_CPP ;
</pre>
<p>
      and import that module, you'll be able to use the rule "obfuscated-cpp"
      in Jamfiles, which will convert source to the OBFUSCATED_CPP type.
    </p>
<p>The second way is to write a wrapper rule that calls
      any of the existing rules. For example, suppose you have only one library per
      directory and want all cpp files in the directory to be compiled into that library. You
      can achieve this effect with:
</p>
<pre class="programlisting">
lib codegen : [ glob *.cpp ] ;
</pre>
<p>
      but if you want to make it even simpler, you could add the following
      definition to the <code class="filename">project-root.jam</code> file:
</p>
<pre class="programlisting">
rule glib ( name : extra-sources * : requirements * )
{
    lib $(name) : [ glob *.cpp ] $(extra-sources) : $(requirements) ;
}
</pre>
<p>
which would allow you to reduce the Jamfile to
</p>
<pre class="programlisting">
glib codegen ;
</pre>
<p>
      Note that because you can associate a custom generator with a target
      type, the logic of building can be rather compiler. 
      
      For example, the
      <code class="computeroutput">boostbook</code> module declares a target type
      <code class="computeroutput">BOOSTBOOK_MAIN</code> and a custom generator for that
      type. You can use that as example if your main target rule is
      non-trivial.
    </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><small></small></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="features.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="toolset_modules.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>