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:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
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.
28 &SCons; has a bewildering array of construction variables
29 for different types of options when building programs.
30 Sometimes you may not know exactly which variable
31 should be used for a particular option.
37 &SCons; construction environments have a &ParseFlags; method
38 that takes a set of typical command-line options
39 and distrbutes them into the appropriate construction variables.
40 Historically, it was created to support the &ParseConfig; method,
41 so it focuses on options used by the GNU Compiler Collection (GCC)
42 for the C and C++ toolchains.
48 &ParseFlags; returns a dictionary containing the options
49 distributed into their respective construction variables.
50 Normally, this dictionary would be passed to &MergeFlags;
51 to merge the options into a &consenv;,
52 but the dictionary can be edited if desired to provide
53 additional functionality.
54 (Note that if the flags are not going to be edited,
55 calling &MergeFlags; with the options directly
56 will avoid an additional step.)
62 d = env.ParseFlags("-I/opt/include -L/opt/lib -lfoo")
63 for k,v in sorted(d.items()):
71 % <userinput>scons -Q</userinput>
72 CPPPATH ['/opt/include']
75 cc -o f1.o -c -I/opt/include f1.c
76 cc -o f1 f1.o -L/opt/lib -lfoo
81 Note that if the options are limited to generic types
83 they will be correctly translated for other platform types:
88 C:\><userinput>scons -Q</userinput>
89 CPPPATH ['/opt/include']
92 cl /Fof1.obj /c f1.c /nologo /I\opt\include
93 link /nologo /OUT:f1.exe /LIBPATH:\opt\lib foo.lib f1.obj
98 Since the assumption is that the flags are used for the GCC toolchain,
99 unrecognized flags are placed in &cv-link-CCFLAGS;
100 so they will be used for both C and C++ compiles:
106 d = env.ParseFlags("-whatever")
107 for k,v in sorted(d.items()):
115 % <userinput>scons -Q</userinput>
117 cc -o f1.o -c -whatever f1.c
123 &ParseFlags; will also accept a (recursive) list of strings as input;
124 the list is flattened before the strings are processed:
130 d = env.ParseFlags(["-I/opt/include", ["-L/opt/lib", "-lfoo"]])
131 for k,v in sorted(d.items()):
139 % <userinput>scons -Q</userinput>
140 CPPPATH ['/opt/include']
143 cc -o f1.o -c -I/opt/include f1.c
144 cc -o f1 f1.o -L/opt/lib -lfoo
149 If a string begins with a "!" (an exclamation mark, often called a bang),
150 the string is passed to the shell for execution.
151 The output of the command is then parsed:
157 d = env.ParseFlags(["!echo -I/opt/include", "!echo -L/opt/lib", "-lfoo"])
166 % <userinput>scons -Q</userinput>
167 CPPPATH ['/opt/include']
170 cc -o f1.o -c -I/opt/include f1.c
171 cc -o f1 f1.o -L/opt/lib -lfoo
176 &ParseFlags; is regularly updated for new options;
177 consult the man page for details about those currently recognized.