diff options
author | Luca Falavigna <dktrkranz@debian.org> | 2014-04-26 15:11:58 +0200 |
---|---|---|
committer | Luca Falavigna <dktrkranz@debian.org> | 2014-04-26 15:11:58 +0200 |
commit | a3a0ab66f0da855e75e3a0e2acfb8aa106b46510 (patch) | |
tree | 5352edff1387c3d7e5a8b49ec56524f085c22782 /doc/user/add-method.xml | |
parent | 51fa4e4acb6fc8fc7a2af0fbdc21fd1e8feddb3a (diff) | |
parent | 140d836e9cd54fb67b969fd82ef7ed19ba574d40 (diff) |
Merge tag 'upstream/2.3.1'
Upstream version 2.3.1
Diffstat (limited to 'doc/user/add-method.xml')
-rw-r--r-- | doc/user/add-method.xml | 123 |
1 files changed, 75 insertions, 48 deletions
diff --git a/doc/user/add-method.xml b/doc/user/add-method.xml index 717f24c..50a2d01 100644 --- a/doc/user/add-method.xml +++ b/doc/user/add-method.xml @@ -1,6 +1,28 @@ +<?xml version='1.0'?> +<!DOCTYPE sconsdoc [ + <!ENTITY % scons SYSTEM "../scons.mod"> + %scons; + + <!ENTITY % builders-mod SYSTEM "../generated/builders.mod"> + %builders-mod; + <!ENTITY % functions-mod SYSTEM "../generated/functions.mod"> + %functions-mod; + <!ENTITY % tools-mod SYSTEM "../generated/tools.mod"> + %tools-mod; + <!ENTITY % variables-mod SYSTEM "../generated/variables.mod"> + %variables-mod; + +]> + +<chapter id="chap-add-method" + xmlns="http://www.scons.org/dbxsd/v1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0/scons.xsd scons.xsd"> +<title>Pseudo-Builders: the AddMethod function</title> + <!-- - Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons Foundation + Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 The SCons Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -39,28 +61,29 @@ </para> - <programlisting> - def install_in_bin_dirs(env, source): - """Install source in both bin dirs""" - i1 = env.Install("$BIN", source) - i2 = env.Install("$LOCALBIN", source) - return [i1[0], i2[0]] # Return a list, like a normal builder - env = Environment(BIN='/usr/bin', LOCALBIN='#install/bin') - env.AddMethod(install_in_bin_dirs, "InstallInBinDirs") - env.InstallInBinDirs(Program('hello.c')) # installs hello in both bin dirs - </programlisting> + <scons_example name="addmethod_ex1"> + <file name="SConstruct" printme="1"> +def install_in_bin_dirs(env, source): + """Install source in both bin dirs""" + i1 = env.Install("$BIN", source) + i2 = env.Install("$LOCALBIN", source) + return [i1[0], i2[0]] # Return a list, like a normal builder +env = Environment(BIN='__ROOT__/usr/bin', LOCALBIN='#install/bin') +env.AddMethod(install_in_bin_dirs, "InstallInBinDirs") +env.InstallInBinDirs(Program('hello.c')) # installs hello in both bin dirs + </file> + <file name="hello.c"> +int main() { printf("Hello, world!\n"); } + </file> + </scons_example> <para> This produces the following: </para> - <screen> - % <userinput>scons -Q /</userinput> - cc -o hello.o -c hello.c - cc -o hello hello.o - Install file: "hello" as "/usr/bin/hello" - Install file: "hello" as "install/bin/hello" - </screen> + <scons_output example="addmethod_ex1" suffix="1"> + <scons_output_command>scons -Q /</scons_output_command> + </scons_output> <para> @@ -75,46 +98,48 @@ </para> - <programlisting> - def BuildTestProg(env, testfile, resourcefile, testdir="tests"): - """Build the test program; - prepends "test_" to src and target, - and puts target into testdir.""" - srcfile = "test_%s.c" % testfile - target = "%s/test_%s" % (testdir, testfile) - if env['PLATFORM'] == 'win32': - resfile = env.RES(resourcefile) - p = env.Program(target, [srcfile, resfile]) - else: - p = env.Program(target, srcfile) - return p - AddMethod(Environment, BuildTestProg) - - env = Environment() - env.BuildTestProg('stuff', resourcefile='res.rc') - </programlisting> + <scons_example name="addmethod_ex2"> + <file name="SConstruct" printme="1"> +def BuildTestProg(env, testfile, resourcefile, testdir="tests"): + """Build the test program; + prepends "test_" to src and target, + and puts target into testdir.""" + srcfile = "test_%s.c" % testfile + target = "%s/test_%s" % (testdir, testfile) + if env['PLATFORM'] == 'win32': + resfile = env.RES(resourcefile) + p = env.Program(target, [srcfile, resfile]) + else: + p = env.Program(target, srcfile) + return p +AddMethod(Environment, BuildTestProg) + +env = Environment() +env.BuildTestProg('stuff', resourcefile='res.rc') + </file> + <file name="test_stuff.c"> +int main() { printf("Hello, world!\n"); } + </file> + <file name="res.rc"> +res.rc + </file> + </scons_example> <para> This produces the following on Linux: </para> - <screen> - % <userinput>scons -Q</userinput> - cc -o test_stuff.o -c test_stuff.c - cc -o tests/test_stuff test_stuff.o - </screen> + <scons_output example="addmethod_ex2" suffix="1"> + <scons_output_command>scons -Q</scons_output_command> + </scons_output> <para> And the following on Windows: </para> - <screen> - C:\><userinput>scons -Q</userinput> - rc /fores.res res.rc - cl /Fotest_stuff.obj /c test_stuff.c /nologo - link /nologo /OUT:tests\test_stuff.exe test_stuff.obj res.res - embedManifestExeCheck(target, source, env) - </screen> + <scons_output example="addmethod_ex2" os="win32" suffix="2"> + <scons_output_command>scons -Q</scons_output_command> + </scons_output> <para> Using &AddMethod; is better than just adding an instance method @@ -122,3 +147,5 @@ and because &AddMethod; provides for copying the method to any clones of the &consenv; instance. </para> + +</chapter> |