%scons; %builders-mod; %functions-mod; %tools-mod; %variables-mod; ]> Set &consvars; for the &b-Textfile; and &b-Substfile; builders. LINESEPARATOR SUBSTFILEPREFIX SUBSTFILESUFFIX TEXTFILEPREFIX TEXTFILESUFFIX FILE_ENCODING SUBST_DICT The &b-Textfile; builder generates a single text file from a template consisting of a list of strings, replacing text using the &cv-link-SUBST_DICT; &consvar; (if set) - see &b-link-Substfile; for a description of replacement. The strings will be separated in the target file using the value of the &cv-link-LINESEPARATOR; &consvar;; the line separator is not emitted after the last string. Nested lists of source strings are flattened. Source strings need not literally be Python strings: they can be Nodes or Python objects that convert cleanly to &f-link-Value; nodes. The prefix and suffix specified by the &cv-link-TEXTFILEPREFIX; and &cv-link-TEXTFILESUFFIX; &consvars; (by default an empty string and .txt, respectively) are automatically added to the target if they are not already present. By default the target file encoding is "utf-8" and can be changed by &cv-link-FILE_ENCODING; Examples: # builds/writes foo.txt env.Textfile(target='foo.txt', source=['Goethe', 42, 'Schiller']) # builds/writes bar.txt env.Textfile(target='bar', source=['lalala', 'tanteratei'], LINESEPARATOR='|*') # nested lists are flattened automatically env.Textfile(target='blob', source=['lalala', ['Goethe', 42, 'Schiller'], 'tanteratei']) # files may be used as input by wraping them in File() env.Textfile( target='concat', # concatenate files with a marker between source=[File('concat1'), File('concat2')], LINESEPARATOR='====================\n', ) Results: foo.txt Goethe 42 Schiller bar.txt lalala|*tanteratei blob.txt lalala Goethe 42 Schiller tanteratei The &b-Substfile; builder creates a single text file from a template consisting of a file or set of files (or nodes), replacing text using the &cv-link-SUBST_DICT; &consvar; (if set). If a set, they are concatenated into the target file using the value of the &cv-link-LINESEPARATOR; &consvar; as a separator between contents; the separator is not emitted after the contents of the last file. Nested lists of source files are flattened. See also &b-link-Textfile;. By default the target file encoding is "utf-8" and can be changed by &cv-link-FILE_ENCODING; Examples: If a single source file name is specified and has a .in suffix, the suffix is stripped and the remainder of the name is used as the default target name. The prefix and suffix specified by the &cv-link-SUBSTFILEPREFIX; and &cv-link-SUBSTFILESUFFIX; &consvars; (an empty string by default in both cases) are automatically added to the target if they are not already present. If a construction variable named &cv-link-SUBST_DICT; is present, it may be either a Python dictionary or a sequence of (key, value) tuples. If it is a dictionary it is converted into a list of tuples with unspecified order, so if one key is a prefix of another key or if one substitution could be further expanded by another subsitition, it is unpredictable whether the expansion will occur. Any occurrences of a key in the source are replaced by the corresponding value, which may be a Python callable function or a string. If the value is a callable, it is called with no arguments to get a string. Strings are subst-expanded and the result replaces the key. env = Environment(tools=['default']) env['prefix'] = '/usr/bin' script_dict = {'@prefix@': '/bin', '@exec_prefix@': '$prefix'} env.Substfile('script.in', SUBST_DICT=script_dict) conf_dict = {'%VERSION%': '1.2.3', '%BASE%': 'MyProg'} env.Substfile('config.h.in', conf_dict, SUBST_DICT=conf_dict) # UNPREDICTABLE - one key is a prefix of another bad_foo = {'$foo': '$foo', '$foobar': '$foobar'} env.Substfile('foo.in', SUBST_DICT=bad_foo) # PREDICTABLE - keys are applied longest first good_foo = [('$foobar', '$foobar'), ('$foo', '$foo')] env.Substfile('foo.in', SUBST_DICT=good_foo) # UNPREDICTABLE - one substitution could be futher expanded bad_bar = {'@bar@': '@soap@', '@soap@': 'lye'} env.Substfile('bar.in', SUBST_DICT=bad_bar) # PREDICTABLE - substitutions are expanded in order good_bar = (('@bar@', '@soap@'), ('@soap@', 'lye')) env.Substfile('bar.in', SUBST_DICT=good_bar) # the SUBST_DICT may be in common (and not an override) substutions = {} subst = Environment(tools=['textfile'], SUBST_DICT=substitutions) substitutions['@foo@'] = 'foo' subst['SUBST_DICT']['@bar@'] = 'bar' subst.Substfile( 'pgm1.c', [Value('#include "@foo@.h"'), Value('#include "@bar@.h"'), "common.in", "pgm1.in"], ) subst.Substfile( 'pgm2.c', [Value('#include "@foo@.h"'), Value('#include "@bar@.h"'), "common.in", "pgm2.in"], ) The separator used by the &b-link-Substfile; and &b-link-Textfile; builders. This value is used between sources when constructing the target. It defaults to the current system line separator. The dictionary used by the &b-link-Substfile; or &b-link-Textfile; builders for substitution values. It can be anything acceptable to the dict() constructor, so in addition to a dictionary, lists of tuples are also acceptable. The prefix used for &b-link-Substfile; file names, an empty string by default. The suffix used for &b-link-Substfile; file names, an empty string by default. The prefix used for &b-link-Textfile; file names, an empty string by default. The suffix used for &b-link-Textfile; file names; .txt by default. File encoding used for files written by &b-link-Textfile; and &b-link-Substfile;. Set to "utf-8" by default. Added in version 4.5.0.