<para>
- You've seen that when you call the &Program; builder method,
+ You've seen that when you call the &b-link-Program; builder method,
it builds the resulting program with the same
base name as the source file.
That is, the following call to build an
</para>
<scons_output example="target" os="posix">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
<para>
</para>
<scons_output example="target" os="win32">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
</section>
<scons_example name="ex2">
<file name="SConstruct" printme="1">
- Program(['main.c', 'file1.c', 'file2.c'])
+ Program(['prog.c', 'file1.c', 'file2.c'])
</file>
- <file name="main.c">
- int main() { printf("main.c\n"); }
+ <file name="prog.c">
+ int main() { printf("prog.c\n"); }
</file>
<file name="file1.c">
void file1() { printf("file1.c\n"); }
</para>
<scons_output example="ex2">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
<para>
<scons_example name="ex3">
<file name="SConstruct" printme="1">
- Program('program', ['main.c', 'file1.c', 'file2.c'])
+ Program('program', ['prog.c', 'file1.c', 'file2.c'])
</file>
- <file name="main.c">
+ <file name="prog.c">
int main() { printf("prog.c\n"); }
</file>
<file name="file1.c">
</para>
<scons_output example="ex3" os="posix">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
<para>
</para>
<scons_output example="ex3" os="win32">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
</section>
+ <section>
+ <title>Making a list of files with &Glob;</title>
+
+ <para>
+
+ You can also use the &Glob; function to find all files matching a
+ certain template, using the standard shell pattern matching
+ characters <literal>*</literal>, <literal>?</literal>
+ and <literal>[abc]</literal> to match any of
+ <literal>a</literal>, <literal>b</literal> or <literal>c</literal>.
+ <literal>[!abc]</literal> is also supported,
+ to match any character <emphasis>except</emphasis>
+ <literal>a</literal>, <literal>b</literal> or <literal>c</literal>.
+ This makes many multi-source-file builds quite easy:
+
+ </para>
+
+ <sconstruct>
+ Program('program', Glob('*.c'))
+ </sconstruct>
+
+ <para>
+
+ The SCons man page has more details on using &Glob;
+ with variant directories
+ (see <xref linkend="chap-variants"></xref>, below)
+ and repositories
+ (see <xref linkend="chap-repositories"></xref>, below),
+ and returning strings rather than Nodes.
+
+ </para>
+
+ </section>
+
<section>
<title>Specifying Single Files Vs. Lists of Files</title>
</para>
<sconstruct>
- Program('hello', ['file1.c', 'file2'])
+ Program('hello', ['file1.c', 'file2.c'])
</sconstruct>
<para>
you'll have realized that this is similar to the
<function>split()</function> method
in the Python standard <function>string</function> module.
- Unlike the <function>string.split()</function> method,
+ Unlike the <function>split()</function> member function of strings,
however, the &Split; function
does not require a string as input
and will wrap up a single non-string object in a list,
<para>
Putting the call to the &Split; function
- inside the <function>Program</function> call
+ inside the &b-Program; call
can also be a little unwieldy.
A more readable alternative is to
assign the output from the &Split; call
to a variable name,
and then use the variable when calling the
- <function>Program</function> function:
+ &b-Program; function:
</para>
<programlisting>
- list = Split('main.c file1.c file2.c')
- Program('program', list)
+ src_files = Split('main.c file1.c file2.c')
+ Program('program', src_files)
</programlisting>
<para>
</para>
<programlisting>
- list = Split("""main.c
- file1.c
- file2.c""")
- Program('program', list)
+ src_files = Split("""main.c
+ file1.c
+ file2.c""")
+ Program('program', src_files)
</programlisting>
<para>
</para>
<programlisting>
- list = Split('main.c file1.c file2.c')
- Program(target = 'program', source = list)
+ src_files = Split('main.c file1.c file2.c')
+ Program(target = 'program', source = src_files)
</programlisting>
<para>
</para>
<programlisting>
- list = Split('main.c file1.c file2.c')
- Program(source = list, target = 'program')
+ src_files = Split('main.c file1.c file2.c')
+ Program(source = src_files, target = 'program')
</programlisting>
<para>
In order to compile multiple programs
within the same &SConstruct; file,
- simply call the <function>Program</function> method
+ simply call the &Program; method
multiple times,
once for each program you need to build:
</para>
<scons_output example="ex4">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
<para>
from the common source files,
which can then be linked into resulting programs.
(Creating libraries is discussed in
- <xref linkend="chap-libraries">, below.)
+ <xref linkend="chap-libraries"></xref>, below.)
</para>
&SCons; recognizes that the object files for
the &common1_c; and &common2_c; source files
- each only need to be built once,
+ each need to be built only once,
even though the resulting object files are
each linked in to both of the resulting executable programs:
</para>
<scons_output example="ex5">
- <command>scons -Q</command>
+ <scons_output_command>scons -Q</scons_output_command>
</scons_output>
<para>