Merged revisions 3057-3059,3061-3264 via svnmerge from
[scons.git] / doc / user / parseconfig.xml
1 <!--
2
3   __COPYRIGHT__
4
5   Permission is hereby granted, free of charge, to any person obtaining
6   a copy of this software and associated documentation files (the
7   "Software"), to deal in the Software without restriction, including
8   without limitation the rights to use, copy, modify, merge, publish,
9   distribute, sublicense, and/or sell copies of the Software, and to
10   permit persons to whom the Software is furnished to do so, subject to
11   the following conditions:
12
13   The above copyright notice and this permission notice shall be included
14   in all copies or substantial portions of the Software.
15
16   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17   KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18   WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 -->
25
26  <para>
27
28  Configuring the right options to build programs to work with
29  libraries--especially shared libraries--that are available
30  on POSIX systems can be very complicated.
31  To help this situation,
32  various utilies with names that end in <filename>config</filename>
33  return the command-line options for the GNU Compiler Collection (GCC)
34  that are needed to use these libraries;
35  for example, the command-line options
36  to use a library named <filename>lib</filename>
37  would be found by calling a utility named <filename>lib-config</filename>.
38
39  </para>
40
41  <para>
42
43  A more recent convention is that these options
44  are available from the generic <filename>pkg-config</filename> program,
45  which has common framework, error handling, and the like,
46  so that all the package creator has to do is provide the set of strings
47  for his particular package.
48
49  </para>
50
51  <para>
52
53  &SCons; construction environments have a &ParseConfig; method
54  that executes a <filename>*config</filename> utility
55  (either <filename>pkg-config</filename> or a
56  more specific utility)
57  and configures the appropriate construction variables
58  in the environment
59  based on the command-line options
60  returned by the specified command.
61
62  </para>
63
64  <programlisting>
65     env = Environment()
66     env['CPPPATH'] = ['/lib/compat']
67     env.ParseConfig("pkg-config x11 --cflags --libs")
68     print env['CPPPATH']
69  </programlisting>
70
71  <para>
72
73  &SCons; will execute the specified command string,
74  parse the resultant flags,
75  and add the flags to the appropriate environment variables.
76
77  </para>
78
79  <screen>
80     % <userinput>scons -Q</userinput>
81     ['/lib/compat', '/usr/X11/include']
82     scons: `.' is up to date.
83  </screen>
84
85  <para>
86
87  In the example above, &SCons; has added the include directory to
88  <varname>CPPPATH</varname>.
89  (Depending upon what other flags are emitted by the
90  <filename>pkg-config</filename> command,
91  other variables may have been extended as well.)
92
93  </para>
94
95  <para>
96
97  Note that the options are merged with existing options using
98  the &MergeFlags; method,
99  so that each option only occurs once in the construction variable:
100
101  </para>
102
103  <programlisting>
104     env = Environment()
105     env.ParseConfig("pkg-config x11 --cflags --libs")
106     env.ParseConfig("pkg-config x11 --cflags --libs")
107     print env['CPPPATH']
108  </programlisting>
109
110  <screen>
111     % <userinput>scons -Q</userinput>
112     ['/usr/X11/include']
113     scons: `.' is up to date.
114  </screen>