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; provides the ability to build a lot of different
29 types of files right "out of the box."
30 So far, we've been using &SCons;' ability to build
31 programs, objects and libraries to
32 illustrate much of the underlying functionality of &SCons;
33 This section will describe all of the different
34 types of files that you can build with &SCons;,
35 and the built-in &Builder; objects used to build them.
36 By default, all of the &Builder; objects in this section
37 can be built either with or without an explicit
38 construction environment.
43 <title>Programs: the &Program; Builder</title>
47 As we've seen, the &b-link-Program; Builder
48 is used to build an executable program.
49 The &source; argument is one or more
50 source-code files or object files,
51 and the ⌖ argument is the
52 name of the executable program name to be created.
58 Program('prog', 'file1.o')
63 Will create the &prog;
64 executable on a POSIX system,
65 the &prog_exe; executable on a Windows system.
71 The target file's prefix and suffix may be omitted,
72 and the values from the
76 construction variables
77 will be appended appropriately.
83 env = Environment(PROGPREFIX='my', PROGSUFFIX='.xxx')
84 env.Program('prog', ['file1.o', 'file2.o'])
89 Will create a program named
90 <filename>myprog.xxx</filename>
91 regardless of the system on which it is run.
97 If you omit the ⌖,
98 the base of the first input
100 becomes the base of the target
107 Program(['hello.c', 'goodbye.c'])
112 Will create the &hello;
113 executable on a POSIX system,
114 the &hello_exe; executable on a Windows system.
120 Two construction variables control what libraries
121 will be linked with the resulting program.
122 The &cv-link-LIBS; variable is a list of the names of
123 libraries that will be linked into any programs,
124 and the &cv-link-LIBPATH; variables is a list of
125 directories that will be searched for
126 the specified libraries.
127 &SCons; will construct the right command-line
128 options for the running system.
134 env = Environment(LIBS = ['foo1', 'foo2'],
135 LIBPATH = ['/usr/dir1', 'dir2'])
136 env.Program(['hello.c', 'goodbye.c'])
141 Will execute as follows on a POSIX system:
146 % <userinput>scons -Q</userinput>
147 cc -o goodbye.o -c goodbye.c
148 cc -o hello.o -c hello.c
149 cc -o hello hello.o goodbye.o -L/usr/dir1 -Ldir2 -lfoo1 -lfoo2
154 And execute as follows on a Windows system:
159 C:\><userinput>scons -Q</userinput>
160 cl /Fogoodbye.obj /c goodbye.c /nologo
161 cl /Fohello.obj /c hello.c /nologo
162 link /nologo /OUT:hello.exe /LIBPATH:\usr\dir1 /LIBPATH:dir2 foo1.lib foo2.lib hello.obj goodbye.obj
167 The &cv-LIBS; construction variable
168 is turned into command line options
169 by appending the &cv-link-LIBLINKPREFIX; and &cv-link-LIBLINKSUFFIX;
170 construction variables to the beginning and end,
171 respectively, of each specified library.
177 The &cv-LIBPATH; construction variable
178 is turned into command line options
179 by appending the &cv-link-LIBDIRPREFIX; and &cv-link-LIBDIRSUFFIX;
180 construction variables to the beginning and end,
181 respectively, of each specified library.
187 Other relevant construction variables
188 include those used by the &b-link-Object;
189 builders to affect how the
190 source files specified as input to the &t-Program;
191 builders are turned into object files;
192 see the next section.
198 The command line used to control how a program is linked
199 is specified by the &cv-link-LINKCOM; construction variable.
200 By default, it uses the
201 &cv-link-LINK; construction variable
202 and the &cv-link-LINKFLAGS; construction variable.
209 <title>Object-File Builders</title>
213 &SCons; provides separate Builder objects
214 to create static and shared object files.
215 The distinction becomes especially important when
216 archiving object files into different types of libraries.
221 <title>The &StaticObject; Builder</title>
225 The &b-link-StaticObject; Builder
226 is used to build an object file
227 suitable for static linking into a program,
228 or for inclusion in a static library.
229 The &source; argument is a single source-code file,
230 and the ⌖ argument is the
231 name of the static object file to be created.
237 StaticObject('file', 'file.c')
242 Will create the &file_o;
243 object file on a POSIX system,
244 the &file_obj; executable on a Windows system.
250 The target file's prefix and suffix may be omitted,
251 and the values from the
255 construction variables
256 will be appended appropriately.
262 env = Environment(OBJPREFIX='my', OBJSUFFIX='.xxx')
263 env.StaticObject('file', 'file.c')
268 Will create an object file named
269 <filename>myfile.xxx</filename>
270 regardless of the system on which it is run.
276 If you omit the ⌖,
277 the base of the first input
279 beomces the base of the name
280 of the static object file to be created.
286 StaticObject('file.c')
291 Will create the &file_o;
292 executable on a POSIX system,
293 the &file_obj; executable on a Windows system.
300 <title>The &SharedObject; Builder</title>
304 The &b-link-SharedObject; Builder
305 is used to build an object file
306 suitable for shared linking into a program,
307 or for inclusion in a shared library.
308 The &source; argument is a single source-code file,
309 and the ⌖ argument is the
310 name of the shared object file to be created.
316 SharedObject('file', 'file.c')
321 Will create the &file_o;
322 object file on a POSIX system,
323 the &file_obj; executable on a Windows system.
329 The target file's prefix and suffix may be omitted,
330 and the values from the
331 &cv-link-SHOBJPREFIX;
333 &cv-link-SHOBJSUFFIX;
334 construction variables
335 will be appended appropriately.
341 env = Environment(SHOBJPREFIX='my', SHOBJSUFFIX='.xxx')
342 env.SharedObject('file', 'file.c')
347 Will create an object file named
348 <filename>myfile.xxx</filename>
349 regardless of the system on which it is run.
355 If you omit the ⌖,
356 the base of the first input
358 becomes the base of the name
359 of the shared object file to be created.
365 SharedObject('file.c')
370 Will create the &file_o;
371 executable on a POSIX system,
372 the &file_obj; executable on a Windows system.
379 <title>The &Object; Builder</title>
383 The &b-link-Object; Builder is a synonym for &b-link-StaticObject;
384 and is completely equivalent.
393 <title>Library Builders</title>
397 &SCons; provides separate Builder objects
398 to create static and shared libraries.
403 <title>The &StaticLibrary; Builder</title>
407 The &b-link-StaticLibrary; Builder
408 is used to create a library
409 suitable for static linking into a program.
410 The &source; argument is one or more
411 source-code files or object files,
412 and the ⌖ argument is the
413 name of the static library to be created.
419 StaticLibrary('foo', ['file1.c', 'file2.c'])
424 The target file's prefix and suffix may be omitted,
425 and the values from the
429 construction variables
430 will be appended appropriately.
436 env = Environment(LIBPREFIX='my', LIBSUFFIX='.xxx')
437 env.StaticLibrary('lib', ['file1.o', 'file2.o'])
442 Will create an object file named
443 <filename>mylib.xxx</filename>
444 regardless of the system on which it is run.
449 StaticLibrary('foo', ['file1.c', 'file2.c'])
454 If you omit the ⌖,
455 the base of the first input
457 becomes the base of the name of the static object file to be created.
463 StaticLibrary(['file.c', 'another.c'])
468 Will create the &libfile_a;
469 library on a POSIX system,
470 the &file_lib; library on a Windows system.
477 <title>The &SharedLibrary; Builder</title>
481 The &b-link-SharedLibrary; Builder
482 is used to create a shared library
483 suitable for linking with a program.
484 The &source; argument is one or more
485 source-code files or object files,
486 and the ⌖ argument is the
487 name of the shared library to be created.
493 SharedLibrary('foo', ['file1.c', 'file2.c'])
498 The target file's prefix and suffix may be omitted,
499 and the values from the
500 &cv-link-SHLIBPREFIX;
502 &cv-link-SHLIBSUFFIX;
503 construction variables
504 will be appended appropriately.
510 env = Environment(SHLIBPREFIX='my', SHLIBSUFFIX='.xxx')
511 env.SharedLibrary('shared', ['file1.o', 'file2.o'])
516 Will create an object file named
517 <filename>myshared.xxx</filename>
518 regardless of the system on which it is run.
523 SharedLibrary('foo', ['file1.c', 'file2.c'])
528 If you omit the ⌖,
529 the base of the first input
531 becomes the base of the name of the shared library to be created.
537 SharedLibrary(['file.c', 'another.c'])
542 Will create the &libfile_so;
543 library on a POSIX system,
544 the &file_dll; library on a Windows system.
551 <title>The &Library; Builder</title>
555 The &b-link-Library; Builder is a synonym for &b-link-StaticLibrary;
556 and is completely equivalent.
565 <title>Pre-Compiled Headers: the &PCH; Builder</title>
576 <title>Microsoft Visual C++ Resource Files: the &RES; Builder</title>
587 <title>Source Files</title>
592 &SCons; supports two Builder objects
593 that know how to build source files
594 from other input files.
595 These are typically invoked "internally"
596 to turn files that need preprocessing into other source files.
601 <title>The &CFile; Builder</title>
610 XXX CFile() programlisting
620 <title>The &CXXFile; Builder</title>
629 XXX CXXFILE() programlisting
641 <title>Documents</title>
645 &SCons; provides a number of Builder objects
646 for creating different types of documents.
651 <title>The &DVI; Builder</title>
660 XXX DVI() programlisting
670 <title>The &PDF; Builder</title>
681 <title>The &PostScript; Builder</title>
685 XXX PostScript() para
690 XXX PostScript() programlisting
694 XXX PostScript() screen
702 <title>Archives</title>
706 &SCons; provides Builder objects
707 for creating two different types of archive files.
712 <title>The &Tar; Builder</title>
716 The &b-link-Tar; Builder object uses the &tar;
717 utility to create archives of files
718 and/or directory trees:
724 env.Tar('out1.tar', ['file1', 'file2'])
725 env.Tar('out2', 'directory')
729 % <userinput>scons -Q .</userinput>
730 tar -c -f out1.tar file1 file2
731 tar -c -f out2.tar directory
736 One common requirement when creating a &tar; archive
737 is to create a compressed archive using the
738 <option>-z</option> option.
739 This is easily handled by specifying
740 the value of the &cv-link-TARFLAGS; variable
741 when you create the construction environment.
742 Note, however, that the <option>-c</option> used to
743 to instruct &tar; to create the archive
744 is part of the default value of &cv-TARFLAGS;,
745 so you need to set it both options:
750 env = Environment(TARFLAGS = '-c -z')
751 env.Tar('out.tar.gz', 'directory')
755 % <userinput>scons -Q .</userinput>
756 tar -c -z -f out.tar.gz directory
761 you may also wish to set the value of the
762 &cv-link-TARSUFFIX; construction variable
763 to your desired suffix for compress &tar; archives,
764 so that &SCons; can append it to the target file name
765 without your having to specify it explicitly:
770 env = Environment(TARFLAGS = '-c -z',
772 env.Tar('out', 'directory')
776 % <userinput>scons -Q .</userinput>
777 tar -c -z -f out.tgz directory
783 <title>The &Zip; Builder</title>
787 The &b-link-Zip; Builder object creates archives of files
788 and/or directory trees in the ZIP file format.
789 Python versions 1.6 or later
790 contain an internal &zipfile; module
791 that &SCons; will use.
792 In this case, given the following
799 env.Zip('out', ['file1', 'file2'])
804 Your output will reflect the fact
805 that an internal Python function
806 is being used to create the output ZIP archive:
811 % <userinput>scons -Q .</userinput>
812 zip(["out.zip"], ["file1", "file2"])
817 If you're using Python version 1.5.2 to run &SCons;,
818 then &SCons; will try to use an external
819 &zip; program as follows:
824 % <userinput>scons -Q .</userinput>
825 zip /home/my/project/zip.out file1 file2
837 &SCons; provides Builder objects
838 for creating various types of Java output files.
843 <title>Building Class Files: the &Java; Builder</title>
847 The &b-link-Java; builder takes one or more input
848 <filename>.java</filename> files
849 and turns them into one or more
850 <filename>.class</filename> files
851 Unlike most builders, however,
852 the &Java; builder takes
853 target and source <emphasis>directories</emphasis>,
860 env.Java(target = 'classes', source = 'src')
865 The &Java; builder will then
866 search the specified source directory
867 tree for all <filename>.java</filename> files,
868 and pass any out-of-date
879 <title>The &Jar; Builder</title>
883 XXX The &Jar; builder object
889 env.Java(target = 'classes', source = 'src')
890 env.Jar(target = '', source = 'classes')
900 <title>Building C header and stub files: the &JavaH; Builder</title>
909 XXX JavaH() programlisting
919 <title>Building RMI stub and skeleton class files: the &RMIC; Builder</title>
928 XXX RMIC() programlisting