<programlisting>
env = Environment()
- env.Command('foo.out', 'foo.in', "sed 's/x/y/' < $SOURCE > $TARGET")
+ env.Command('foo.out', 'foo.in', "sed 's/x/y/' < $SOURCE > $TARGET")
</programlisting>
<literallayout>
<scons_example name="ex2">
<file name="SConstruct" printme="1">
- bld = Builder(action = 'foobuild < $SOURCE > $TARGET')
+ bld = Builder(action = 'foobuild < $SOURCE > $TARGET')
env = Environment(BUILDERS = {'Foo' : bld})
env.Foo('file.foo', 'file.input')
env.Program('hello.c')
the target or targets to be
built by this builder function.
The file names of these target(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
the sources to be
used by this builder function to build the targets.
The file names of these source(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
by the command or other action
generated by this function.
The file names of these source(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
by the command or other action
generated by this function.
The file names of these target(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
</para>
<programlisting>
- bld = Builder(action = 'foobuild < $SOURCE > $TARGET')
+ bld = Builder(action = 'foobuild < $SOURCE > $TARGET')
env = Environment(BUILDERS = {'Foo' : bld})
env.Foo('file.foo', 'file.input')
env.Program('hello.c')
the target or targets to be
built by this builder function.
The file names of these target(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
the sources to be
used by this builder function to build the targets.
The file names of these source(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
by the command or other action
generated by this function.
The file names of these source(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
by the command or other action
generated by this function.
The file names of these target(s)
- may be extracted using the Python &str; funcion.
+ may be extracted using the Python &str; function.
</para>
</listitem>
def b(target, source, env):
pass
def s(target, source, env):
- return " ..."
+ return " ... [build output] ..."
a = Action(b, strfunction = s)
- env = Environment(BUILDERS = {'A' : a})
+ env = Environment(BUILDERS = {'A' : Builder(action=a)})
env.A('foo.out', 'foo.in')
</file>
<file name="foo.in">
<scons_output example="SCONSFLAGS">
<command>scons</command>
<command>export SCONSFLAGS="-Q"</command>
- <command>scons</command>
+ <command environment="SCONSFLAGS=-Q">scons</command>
</scons_output>
<para>
<literallayout>
% <userinput>scons</userinput>
scons: Reading SConscript files ...
- ...
scons: done reading SConscript files.
scons: Building targets ...
- scons: `.' is up to date.
+ ... [build output] ...
scons: done building targets.
% <userinput>export SCONSFLAGS="-Q"</userinput>
% <userinput>scons</userinput>
- scons: Reading SConscript files ...
- ...
- scons: done reading SConscript files.
- scons: Building targets ...
- scons: `.' is up to date.
- scons: done building targets.
+ ... [build output] ...
</literallayout>
<para>
Program('hello.c', CPPPATH = '.')
</file>
<file name="hello.c" printme="1">
- #include "hello.h"
+ #include <hello.h>
int
main()
{
</para>
<programlisting>
- env = Environment()
- hello = env.Program('hello.c')
- env.Ignore(hello, '/usr/include/stdio.h')
+ hello = Program('hello.c')
+ Ignore(hello, '/usr/include/stdio.h')
</programlisting>
</section>
</para>
<programlisting>
- env = Environment()
- hello = env.Program('hello.c')
- env.Depends(hello, 'other_file')
+ hello = Program('hello.c')
+ Depends(hello, 'other_file')
</programlisting>
<!-- XXX mention that you can use arrays for target and source? -->
</para>
<programlisting>
- #include "hello.h"
+ #include <hello.h>
int
main()
{
</para>
<programlisting>
- env = Environment()
- hello = env.Program('hello.c')
- env.Ignore(hello, '/usr/include/stdio.h')
+ hello = Program('hello.c')
+ Ignore(hello, '/usr/include/stdio.h')
</programlisting>
</section>
</para>
<programlisting>
- env = Environment()
- hello = env.Program('hello.c')
- env.Depends(hello, 'other_file')
+ hello = Program('hello.c')
+ Depends(hello, 'other_file')
</programlisting>
<!-- XXX mention that you can use arrays for target and source? -->
<literallayout>
% <userinput>scons -Q</userinput>
- scons: *** Two different environments were specified for the same target: foo.o
+ scons: *** Two environments with different actions were specified for the same target: foo.o
File "SConstruct", line 6, in ?
</literallayout>
<file name="SConstruct" printme="1">
Library('foo', ['f1.c', 'f2.c', 'f3.c'])
</file>
- <file name="hello.c">
- int main() { printf("Hello, world!\n"); }
- </file>
<file name="f1.c">
void f1() { printf("f1.c\n"); }
</file>
</para>
+ <section>
+ <title>Building Static Libraries Explicitly</title>
+
+ <para>
+
+ The &Library; function builds a traditional static library.
+ If you want to be explicit about the type of library being built,
+ you can use the synonym &StaticLibrary; function
+ instead of &Library:
+
+ </para>
+
+ <scons_example name="StaticLibrary" printme="1">
+ <file name="SConstruct" printme="1">
+ StaticLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])
+ </file>
+ </scons_example>
+
+ <para>
+
+ There is no functional difference between the
+ &StaticLibrary; and &Library; functions.
+
+ </para>
+
+ </section>
+
+ <section>
+ <title>Building Shared (DLL) Libraries</title>
+
+ <para>
+
+ If you want to build a shared library (on POSIX systems)
+ or a DLL file (on Windows systems),
+ you use the &SharedLibrary; function:
+
+ </para>
+
+ <scons_example name="SharedLibrary" printme="1">
+ <file name="SConstruct" printme="1">
+ SharedLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])
+ </file>
+ <file name="f1.c">
+ void f1() { printf("f1.c\n"); }
+ </file>
+ <file name="f2.c">
+ void f2() { printf("f2.c\n"); }
+ </file>
+ <file name="f3.c">
+ void f3() { printf("f3.c\n"); }
+ </file>
+ </scons_example>
+
+ <para>
+
+ The output on POSIX:
+
+ </para>
+
+ <scons_output example="SharedLibrary" os="posix">
+ <command>scons -Q</command>
+ </scons_output>
+
+ <para>
+
+ And the output on Windows:
+
+ </para>
+
+ <scons_output example="SharedLibrary" os="win32">
+ <command>scons -Q</command>
+ </scons_output>
+
+ <para>
+
+ Notice again that &SCons; takes care of
+ building the output file correctly,
+ adding the <literal>-shared</literal> option
+ for a POSIX compilation,
+ and the <literal>/dll</literal> option on Windows.
+
+ </para>
+
+ </section>
+
</section>
<section>
</para>
+ <section>
+ <title>Building Static Libraries Explicitly</title>
+
+ <para>
+
+ The &Library; function builds a traditional static library.
+ If you want to be explicit about the type of library being built,
+ you can use the synonym &StaticLibrary; function
+ instead of &Library;:
+
+ </para>
+
+ <programlisting>
+ StaticLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])
+ </programlisting>
+
+ <para>
+
+ There is no functional difference between the
+ &StaticLibrary; and &Library; functions.
+
+ </para>
+
+ </section>
+
+ <section>
+ <title>Building Shared (DLL) Libraries</title>
+
+ <para>
+
+ If you want to build a shared library (on POSIX systems)
+ or a DLL file (on Windows systems),
+ you use the &SharedLibrary; function:
+
+ </para>
+
+ <programlisting>
+ SharedLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])
+ </programlisting>
+
+ <para>
+
+ The output on POSIX:
+
+ </para>
+
+ <literallayout>
+ % <userinput>scons -Q</userinput>
+ cc -c -o f1.os f1.c
+ cc -c -o f2.os f2.c
+ cc -c -o f3.os f3.c
+ cc -shared -o libfoo.so f1.os f2.os f3.os
+ </literallayout>
+
+ <para>
+
+ And the output on Windows:
+
+ </para>
+
+ <literallayout>
+ C:\><userinput>scons -Q</userinput>
+ cl /nologo /c f1.c /Fof1.obj
+ cl /nologo /c f2.c /Fof2.obj
+ cl /nologo /c f3.c /Fof3.obj
+ link /nologo /dll /out:foo.dll /implib:foo.lib f1.obj f2.obj f3.obj
+ </literallayout>
+
+ <para>
+
+ Notice again that &SCons; takes care of
+ building the output file correctly,
+ adding the <literal>-shared</literal> option
+ for a POSIX compilation,
+ and the <literal>/dll</literal> option on Windows.
+
+ </para>
+
+ </section>
+
</section>
<section>
env = Environment(ENV = {'PATH' : '__ROOT__/usr/local/bin'})
env.Append(SCANNERS = kscan)
- env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
+ env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
</file>
<file name="foo.k">
include other_file
env = Environment(ENV = {'PATH' : '/usr/local/bin'})
env.Append(SCANNERS = kscan)
- env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
+ env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
</programlisting>
<!--
</para>
+ <section>
+ <title>Cleaning Up After a Build</title>
+
+ <para>
+
+ When using &SCons;, it is unnecessary to add special
+ commands or target names to clean up after a build.
+ Instead, you simply use the
+ <literal>-c</literal> or <literal>--clean</literal>
+ option when you invoke &SCons;,
+ and &SCons; removes the appropriate built files.
+ So if we build our example above
+ and then invoke <literal>scons -c</literal>
+ afterwards, the output on POSIX looks like:
+
+ </para>
+
+ <scons_example name="clean">
+ <file name="SConstruct">
+ Program('hello.c')
+ </file>
+ <file name="hello.c">
+ int main() { printf("Hello, world!\n"); }
+ </file>
+ </scons_example>
+
+ <scons_output example="clean" os="posix">
+ <command>scons</command>
+ <command>scons -c</command>
+ </scons_output>
+
+ <para>
+
+ And the output on Windows looks like:
+
+ </para>
+
+ <scons_output example="clean" os="win32">
+ <command>scons</command>
+ <command>scons -c</command>
+ </scons_output>
+
+ <para>
+
+ Notice that &SCons; changes its output to tell you that it
+ is <literal>Cleaning targets ...</literal> and
+ <literal>done cleaning targets.</literal>
+
+ </para>
+
+ </section>
+
<section>
<title>The &SConstruct; File</title>
</para>
<programlisting>
- Program('program', Split('main.c file1.c file2.'))
+ Program('program', Split('main.c file1.c file2.c'))
</programlisting>
<para>
</para>
<programlisting>
- list = Split('main.c file1.c file2.')
+ list = Split('main.c file1.c file2.c')
Program('program', list)
</programlisting>
</para>
<programlisting>
- list = Split('main.c file1.c file2.')
+ list = Split('main.c file1.c file2.c')
Program(target = 'program', source = list)
</programlisting>
</para>
<programlisting>
- list = Split('main.c file1.c file2.')
+ list = Split('main.c file1.c file2.c')
Program(source = list, target = 'program')
</programlisting>
</para>
+ <section>
+ <title>Cleaning Up After a Build</title>
+
+ <para>
+
+ When using &SCons;, it is unnecessary to add special
+ commands or target names to clean up after a build.
+ Instead, you simply use the
+ <literal>-c</literal> or <literal>--clean</literal>
+ option when you invoke &SCons;,
+ and &SCons; removes the appropriate built files.
+ So if we build our example above
+ and then invoke <literal>scons -c</literal>
+ afterwards, the output on POSIX looks like:
+
+ </para>
+
+
+
+ <literallayout>
+ % <userinput>scons</userinput>
+ scons: Reading SConscript files ...
+ scons: done reading SConscript files.
+ scons: Building targets ...
+ cc -c -o hello.o hello.c
+ cc -o hello hello.o
+ scons: done building targets.
+ % <userinput>scons -c</userinput>
+ scons: Reading SConscript files ...
+ scons: done reading SConscript files.
+ scons: Cleaning targets ...
+ Removed hello.o
+ Removed hello
+ scons: done cleaning targets.
+ </literallayout>
+
+ <para>
+
+ And the output on Windows looks like:
+
+ </para>
+
+ <literallayout>
+ C:\><userinput>scons</userinput>
+ scons: Reading SConscript files ...
+ scons: done reading SConscript files.
+ scons: Building targets ...
+ cl /nologo /c hello.c /Fohello.obj
+ link /nologo /OUT:hello.exe hello.obj
+ scons: done building targets.
+ C:\><userinput>scons -c</userinput>
+ scons: Reading SConscript files ...
+ scons: done reading SConscript files.
+ scons: Cleaning targets ...
+ Removed hello.obj
+ Removed hello.exe
+ scons: done cleaning targets.
+ </literallayout>
+
+ <para>
+
+ Notice that &SCons; changes its output to tell you that it
+ is <literal>Cleaning targets ...</literal> and
+ <literal>done cleaning targets.</literal>
+
+ </para>
+
+ </section>
+
<section>
<title>The &SConstruct; File</title>
</para>
<programlisting>
- Program('program', Split('main.c file1.c file2.'))
+ Program('program', Split('main.c file1.c file2.c'))
</programlisting>
<para>
</para>
<programlisting>
- list = Split('main.c file1.c file2.')
+ list = Split('main.c file1.c file2.c')
Program('program', list)
</programlisting>
</para>
<programlisting>
- list = Split('main.c file1.c file2.')
+ list = Split('main.c file1.c file2.c')
Program(target = 'program', source = list)
</programlisting>
</para>
<programlisting>
- list = Split('main.c file1.c file2.')
+ list = Split('main.c file1.c file2.c')
Program(source = list, target = 'program')
</programlisting>