7 <A HREF=http://www.perforce.com/jam/jam.html
>
12 Using Jamfiles and Jambase
17 This document describes how to write Jamfiles using the Jam Jambase
18 rules to build software products.
19 Related documents of interest are:
22 <a href=
"Jam.html">The Jam Executable Program
</A>,
23 which describes using the
<b>jam
</b> command and the
24 langauge used in Jambase
26 <A href=
"Jambase.html">Jambase Reference
</A>,
27 which summarizes the Jambase rules and variables
34 <P><B>jam,
</B> the Jam executable program,
35 recursively builds target files from source files
36 using dependency and build specifications defined
38 <B>jam
</B> parses the rules files to identify targets
40 examines the filesystem to determine which
41 targets need updating, and issues OS commands to update
43 <P>A base rules file called
"Jambase" is provided with the
45 The Jambase file defines rules and variables which support
46 standard software build operations, like compiling, linking,
49 When the Jambase rules are used,
50 <B>jam
</B> reads Jambase, then reads a file called
51 "Jamfile" in the current directory.
52 The Jamfile describes what to do with the source files in
53 its directory. It may also cause
54 Jamfiles in other directories to be read.
56 Under certain circumstances, the first Jamfile read
57 also causes a site-specific
"Jamrules" file to be read.
58 The Jamrules file is an optional set of rule and variable
59 definitions used to define site-specific processing.
65 Jamfiles contain rule invocations, which usually look like:
67 <I>RuleName
</I> <I>targets
</I> :
<I>targets
</I> ;
69 The target(s) to the left of the colon usually indicate
70 what gets built, and the target(s) to the right of the
71 colon usually indicate what it is built from.
74 A Jamfile can be as simple as this:
76 Main myprog : main.c util.c ;
78 This specifies that there is a main.c and util.c file in the same
79 directory as the Jamfile, and that those source files should be
80 compiled and linked into an executable called myprog.
81 If you cd to the directory where this Jamfile lives,
82 you can see the exactly how
<b>jam
</b> would
87 Or, you can actually build myprog with the command:
96 Jamfile elements are delimited by whitespace (blanks, tabs, or
97 newlines). Elements to be delimited include rule names, targets,
98 colons, and semicolons. A common mistake users make is to forget the
101 Main myprog: main.c util.c ; #
<I>WRONG!
</I>
103 Jam doesn't distinguish between a typo and a target called
"myprog:",
104 so if you get strange results, the first thing
105 you should check for in your Jamfile is missing whitespace.
108 Filenames, Target Identifiers, and Buildable Targets
111 Consider this Jamfile:
113 Main myprog : main.c util.c ;
114 LinkLibraries myprog : libtree ;
115 Library libtree : treemake.c treetrav.c ;
118 The Main rule specifies that an executable called myprog will be built.
119 The compiled main.c and util.c objects will be linked to produce
121 The LinkLibraries rule specifies that libtree will
122 be linked into myprog as well.
123 The Library rule specifies which source files will be compiled and
124 archived into the libtree library.
126 The Jamfile above refers to targets like
"myprog" and
"libtree".
127 However, depending on the platform you're building on, the actual
128 filenames of those targets could be
"myprog.exe" and
"libtree.lib".
129 Most Jambase rules supply the actual filenames of targets,
130 so that Jamfiles themselves need not make any
131 platform-specific filename references.
133 The
<b>jam
</b> program builds up a list of unique target identifiers.
134 Unless you are using the SubDir rules (described later),
135 the default identifier for a file target is its filename. In the above
136 example, the target identifiers are the filenames: myprog.exe,
137 libtree.lib, main.obj, etc.
139 While all Jambase rules refer to
"targets",
140 not all targets are buildable.
141 There are two kinds of buildable targets:
142 file targets and pseudotargets.
143 File targets are objects that can be found in the filesystem.
144 Pseudotargets are symbolic, and represent other targets.
146 You can use any buildable target on the
<b>jam
</b> command line to
147 build a subset of defined targets. For example:
151 on Unix builds the libtree library and all the compiled objects
158 Most Jambase rules that define file targets also define pseudotargets
159 which are dependent on types of file targets.
160 For example, Jambase defines a pseudotarget called
"lib", which
161 is dependent on file targets created by the Library rule. So
166 used with the above example would cause the libtree library to be built.
167 Also, there is one pseudotarget built into
<b>jam
</b> itself, called
168 "all". Jambase sets
"all" dependent on (almost) all other targets.
170 In the unfortunate case where you have a buildable target whose name
171 is the same as one of the Jambase pseudotargets, you'll have problems
172 with the conflicting target name.
173 Your workaround choices are:
176 <lI>Change the name of your buildable file or directory that conflicts.
178 <li>Modify your Jambase and change the name of the conflicting pseudotarget.
179 (Pseudotargets are defined in Jambase using the NOTFILE rule.)
181 <li>Use grist on the conflicting target name in your Jamfile. E.g., instead
184 File lib : libfoo.a ;
188 File
<dir
>lib : libfoo.a ;
197 Jambase rules set dependencies on targets, so that if you update a
198 source file, all the file targets that depend on that source
199 file, and only the ones that depend on that source file,
200 will be updated (rebuilt) the next time you run
<b>jam
</b>.
202 Here are some of the dependencies
203 that get set when
<b>jam
</b> runs on NT using the example Jamfile above:
206 <TR><TD><B>Target
</B><TD> <TD><B>Depends on
</B></TD>
207 <TR><TD>myprog.exe
<TD><TD>main.obj, util.obj, libtree.lib
208 <TR><TD>libtree.lib
<TD><TD>treemake.obj, treetrav.obj
209 <TR><TD>treetrav.obj
<TD><TD>treetrav.c
213 Furthermore, the Main and Library rules set up recursive
214 header scanning on their source targets.
215 So after
<b>jam
</b> has finished parsing the Jamfile and
216 setting the rule-driven dependencies, it scans the source
217 files for
"#include" lines. All #include files found during
218 this scan become dependencies of the compiled object.
219 E.g., all header files used to compile treetrav.c would
220 be made dependencies of treetrav.obj.
222 As a result, when you run
<b>jam
</b>, it will rebuild targets
223 if either the source files change or the
224 header files change. You can't tell by looking at a Jamfile
225 which header files are dependencies, but you can easily
226 display those dependencies with:
234 Rules which specify dependencies, like the Main, Library, and
235 LinkLibrary rules, can be invoked in any order.
<b>jam
</b>
236 figures out the order in which targets are built from
239 Some rules, however, set variables which are used by subsequent
240 rule invocations, and their ordering is important.
241 For example, the SubDir* rules (discussed
242 later) must be invoked in a particular order.
246 Detailed Jambase Specifications
249 This document describes how to use various Jambase rules
250 from a functional point of view.
251 You can see the summary of available Jambase rules in the
252 <a href=
"Jambase.html">Jambase Reference
</A>.
253 The detailed specifications for any Jambase rule
254 can be found by reading the rule definition itself
260 Handling Directory Trees
262 The SubDir* rules are used to
263 define source code directory hierarchies.
264 With SubDir and SubInclude, you can use
<b>jam
</b>
265 to build software from source files and Jamfiles spread
266 across many directories, as is typical for large projects.
267 The SubDir* rules unify an entire
268 source code tree so that
<b>jam
</b> can read in
269 all the Jamfiles in one pass and
270 compute dependencies across the entire project.
272 To use the SubDir* rules, you must:
275 <LI> Preface the Jamfile in each directory with an invocation
278 <LI> Place at the root of the tree a file named Jamrules.
279 This file could be empty, but in
280 practice it contains user-provided rules and variable
281 definitions that are shared throughout the
282 tree. Examples of such definitions are library
283 names, header directories, install directories,
284 compiler flags, etc. This file is good candidate
285 for automatic customizing with autoconf(GNU).
287 <LI> Optionally, set an environment variable pointing
288 to the root directory of the srouce tree. The
289 variable's name is left up to you, but in these
290 examples, we use TOP.
297 The SubDir rule must be invoked before any rules that
298 refer to the contents of the directory - it is best to put
299 it at the top of each Jamfile. For example:
301 # Jamfile in $(TOP)/src/util directory.
303 SubDir TOP src util ;
305 Main myprog : main.c util.c ;
306 LinkLibraries myprog : libtree ;
307 Library libtree : treemake.c treetrav.c ;
309 This compiles four files in $(TOP)/src/util, archives
310 two of the objects into libtree, and links the whole
312 Outputs are placed in the $(TOP)/src/util
315 This doesn't appear to be any different from
316 the previous example that didn't have a SubDir rule,
317 but two things are happening behind the scenes:
319 <LI>The SubDir rule causes
<b>jam
</b> to read
320 in the $(TOP)/Jamrules file.
321 (The Jamrules file can alternately be named by the
322 variable $(xxxRULES), where xxx is the name of the
323 root variable, e.g., $(TOPRULES)).
325 The Jamrules file can contain variable definitions
326 and rule definitions specific to your codeline.
327 It allows you to completely customize your build
328 environment without having to rewrite Jambase.
329 Jamrules is only read
330 in once, at the first SubDir invocation.
333 The SubDir rule initializes a set of variables
334 that are used by Main and other rules to
335 uniquely identify the source files in this
336 directory and assign locations to the targets
337 built from files in this directory.
339 When you have set a root variable, e.g., $(TOP),
340 SubDir constructs path names rooted with $(TOP),
341 e.g., $(TOP)/src/util.
342 Otherwise, SubDir constructs relative pathnames
343 to the root directory, computed from the number
344 of arguments to the first SubDir rule, e.g.,
345 ../../src/util. In either case, the SubDir
346 rule constructs the path names that locate source
348 You'll see how this is useful later.
353 The SubDir rule takes as its first argument the root
354 variable's name and takes as subsequent arguments the
355 directory names leading from the root to the directory of
356 the current Jamfile. Note that the name of the subdirectory
357 is given as individual elements: the SubDir rule
358 does not use system-specific directory name syntax.
364 The SubInclude rule is used in a Jamfile to cause another
365 Jamfile to be read in.
366 Its arguments are in the same format as
369 The recommended practice is only to include one level of
370 subdirectories at a time, and let the Jamfile in each subdirectory
371 include its own subdirectories. This allows a
372 user to sit in any arbitrary directory of the source tree
373 and build that subtree. For example:
375 # This is $(TOP)/Jamfile, top level Jamfile for mondo project.
379 SubInclude TOP misc ;
380 SubInclude TOP util ;
382 If a directory has both subdirectories of its own as well
383 as files that need building, the SubIncludes should be
384 either before the SubDir rule or be at the end of the Jamfile
385 - not between the SubDir and other rule invocations.
388 # This is $(TOP)/src/Jamfile:
392 Main mondo : mondo.c ;
393 LinkLibraries mondo : libmisc libutil ;
395 SubInclude TOP src misc ;
396 SubInclude TOP src util ;
399 (
<b>jam
</b> processes all the Jamfiles it reads as if
400 it were reading one single, large Jamfile.
401 Build rules like Main and LinkLibraries rely on the
402 preceding SubDir rule to set up source file and
403 output file locations, and SubIncludes rules read in
404 Jamfiles that contain SubDir rules. So if you put
405 a SubIncludes rule between a SubDir and a Main
406 rule,
<b>jam
</b> will try to find the source files
407 for the Main rule in the wrong directory.)
410 Variables Used to Handle Directory Trees
412 The following variables are set by the SubDir rule
413 and used by the Jambase rules that define file targets:
419 <TD><TD>The SubDir targets (e.g.,
"TOP src util")
420 are used to construct a pathname (e.g., $(TOP)/src/util),
421 and that pathname is assigned to $(SEARCH_SOURCE).
422 Rules like Main and Library use $(SEARCH_SOURCE)
423 to set search paths on source files.
426 <TD><TD>Initialized by the SubDir rule to the same
427 value as $(SEARCH_SOURCE), unless ALL_LOCATE_TARGET
429 $(LOCATE_SOURCE) is used by rules that build
430 generated source files (e.g., Yacc and Lex) to
431 set location of output files.
432 Thus the default location of built source files
433 is the directory of the Jamfile that defines them.
436 <TD><TD>Initalized by the SubDir rule to the same
437 value as $(SEARCH_SOURCE), unless ALL_LOCATE_TARGET
439 $(LOCATE_TARGET) is used by rules that build
440 binary objects (e.g., Main and Library) to
441 set location of output files.
442 Thus the default location of built binaray files
443 is the directory of the Jamfile that defines them.
447 If $(ALL_LOCATE_TARGET) is set, LOCATE_SOURCE
448 and and LOCATE_TARGET are set to $(ALL_LOCATE_TARGET)
449 instead of to $(SEARCH_SOURCE). This can be used to
450 direct built files to be written to a location outside
451 of the source tree, and enables building from read-only
455 <TD><TD>The SubDir targets are formed into a string
456 like
"src!util" and that string is assigned to
457 SOURCE_GRIST. Rules that define file targets
458 use $(SOURCE_GRIST) to set the
"grist" attribute
459 on targets. This is used to assure uniqueness
460 of target identifiers where filenames themselves
462 For example, the target identifiers of
463 $(TOP)/src/client/main.c and $(TOP)/src/server/main.c
464 would be
<src!client
>main.c and
<src!server
>main.c.
468 The $(LOCATE_TARGET) and $(SEARCH_SOURCE) variables are used
469 extensively by rules in Jambase: most rules that generate
470 targets (like Main, Object, etc.) set $(LOCATE) to
471 $(LOCATE_TARGET) for the targets they generate, and rules
472 that use sources (most all of them) set $(SEARCH) to be
473 $(SEARCH_SOURCE) for the sources they use.
475 $(LOCATE) and $(SEARCH) are better explained in
476 <A HREF=
"Jam.html">The Jam Executable Program
</A>
477 but in brief they tell
<B>jam
</B> where to create new targets and
478 where to find existing ones, respectively.
480 Note that you can reset these variables
481 after SubDir sets them. For example, this Jamfile builds
482 a program called gensrc, then runs it to create a source file
485 SubDir TOP src util ;
486 Main gensrc : gensrc.c ;
487 LOCATE_SOURCE = $(NEWSRC) ;
488 GenFile new.c : gensrc ;
490 By default, new.c would be written into the
491 $(TOP)/src/util directory, but resetting LOCATE_SOURCE causes
492 it to be written to the $(NEWSRC) directory. ($(NEWSRC) is assumed
493 to have been set elsewhere, e.g., in Jamrules.)
498 On VMS, the logical name table is not imported as is the
499 environment on UNIX. To use the SubDir and related rules,
500 you must set the value of the variable that names the root
501 directory. For example:
503 TOP = USR_DISK:[JONES.SRC] ;
505 SubInclude TOP util ;
507 The variable must have a value that looks like a directory
508 or device. If you choose, you can use a concealed logical.
513 SubInclude TOP util ;
515 The : at the end of TOP makes the value of $(TOP) look
516 like a device name, which jam respects as a directory name
517 and will use when trying to access files. TOP must then
520 $ define/job/translation=concealed TOP DK100:[USERS.JONES.SRC.]
522 Note three things: the concealed translation allows the
523 logical to be used as a device name; the device name in
524 the logical (here DK100) cannot itself be concealed logical
525 (VMS rules, man); and the directory component of the
526 definition must end in a period (more VMS rules).
529 Building Executables and Libraries
532 The rules that build executables and libraries are: Main, Library,
537 The Main rule compiles source files and links the resulting
538 objects into an executable. For example:
540 Main myprog : main.c util.c ;
542 This compiles main.c and util.c and links main.o and
543 util.o into myprog. The object files and resulting
544 executable are named appropriately for the platform.
546 Main can also be used to build shared libraries and/or
547 dynamic link libraries, since those are also linked
550 Main driver$(SUFSHR) : driver.c ;
552 Normally, Main uses $(SUFEXE) to determine the suffix on
553 the filename of the built target. To override it,
554 you can supply a suffix explicity.
556 $(SUFSHR) is assumed to be the OS-specific shared library
557 suffix, defined in Jamrules with something
560 if $(UNIX) { SUFSHR = .so ; }
561 else if $(NT) { SUFSHR = .dll ; }
564 Main uses the Objects rule to compile source targets.
569 The Library rule compiles source files, archives the
570 resulting object files into a library, and then deletes
571 the object files. For example:
573 Library libstring : strcmp.c strcpy.c strlen.c ;
574 Library libtree : treemake.c treetrav.c ;
576 This compiles five source files, archives three of the
577 object files into libstring and the other two into libtree.
578 Actual library filenames are formed with the $(SUFLIB) suffix.
579 Once the objects are safely in the libraries, the
582 Library uses the Objects rule to compile source files.
587 To link executables with built libraries, use
588 the LinkLibraries rule. For example:
590 Main myprog : main.c util.c ;
591 LinkLibraries myprog : libstring libtree ;
593 The LinkLibraries rule does two things: it makes the
594 libraries dependencies of the executable, so that they get
595 built first; and it makes the libraries show up on the
596 command line that links the executable. The ordering of
597 the lines above is not important, because
<b>jam
</b> builds targets
598 in the order that they are needed.
600 You can put multiple libraries on a single invocation of
601 the LinkLibraries rule, or you can provide them in multiple
602 invocations. In both cases, the libraries appear on
603 the link command line in the order in which they were
604 encountered. You can also provide multiple executables to
605 the LinkLibraries rule, if they need the same libraries,
608 LinkLibraries prog1 prog2 prog3 : libstring libtree ;
612 Variables Used in Building Executables and Libraries
618 <TD><TD>Archive command, used for Library targets.
621 <TD>*
<TD>Suffix on filenames of executables referenced
622 by Main and LinkLibraries.
625 <TD><TD>Link command, used for Main targets.
628 <TD><TD>Linker flags.
631 <TD><TD>Link libraries that aren't dependencies. (See note
635 <TD>*
<TD>File permissions on Main targets.
638 <TD><TD>Target-specific file permissions on Main targets
639 (set from $(EXEMODE))
642 <TD><TD>Name of ranlib program, if any.
647 Variables above marked with
"*" are used by the Main,
648 Library, and LinkLibraries rules. Their values at the
649 time the rules are invoked are used to set target-specific
652 All other variables listed above are globally defined,
653 and are used in actions that update Main and Library
654 targets. This means that the global values of those
655 variables are used, uness target-specific values have
657 (For instance, a target-specific MODE value is set by
659 The target-specific values always override
662 Note that there are two ways to specify link libraries for
665 <LI>Use the LinkLibraries rule
666 to specify built libraries; i.e., libraries
667 that are built by Library rules. This assures that
668 these libraries are built first, and that Main targets are
669 rebuilt when the libraries are updated.
671 <LI>Use the LINKLIBS variable to specify external
672 libraries; e.g., system libraries or third-party libraries.
673 The LINKLIBS variable must be set to the the actual
674 link command flag that specifies the libraries.
681 if $(UNIX) { X11LINKLIBS = -lXext -lX11 ; }
682 if $(NT) { X11LINKLIBS = libext.lib libX11.lib ; }
685 Main xprog : xprog.c ;
686 LINKLIBS on xprog$(SUFEXE) = $(X11LINKLIBS) ;
687 LinkLibraries xprog : libxutil ;
688 Library libxutil : xtop.c xbottom.c xutil.c ;
690 This example uses the Jam syntax
"variable on target" to
691 set a target-specific variable. In this way, only xprog
692 will be linked with this special $(X11LINKLIBS),
693 even if other executables were going to be built
694 by the same Jamfile. Note that when you set a variable
695 on a target, you have to specify the target identifer
696 exactly, which in this case is the suffixed filename of
698 The actual link command line on Unix, for example, would
699 look something like this:
701 cc -o xprog xprog.o libxutil.a -lXext -lX11
706 Compiling of source files occurs normally as a byproduct
707 of the Main or Library rules, which call the rules
708 described here. These rules may also be called explicitly
709 if the Main and Library behavior doesn't satisfy your
715 The Main and Library rules call the Objects rule on source files.
716 Compiled object files built by
717 the Objects rule are a dependency of the
<I>obj
</i>
718 pseudotarget, so
"jam obj" will build object files used in
719 Main and Library rules.
721 Target identifiers created by the Objects rule have grist
722 set to $(SOURCE_GRIST). So given this Jamfile:
724 SubDir TOP src lock ;
725 Main locker : lock.c ;
727 the object file created is lock.o (or lock.obj) and
728 its target identifier is
<src!lock
>lock.o
729 (or
<src!lock
>lock.obj).
732 You can also call Objects directly. For example:
734 Objects a.c b.c c.c ;
736 This compiles a.c into a.o, b.c into b.o, etc. The object
737 file suffix is supplied by the Objects rule.
742 Objects gets its work done by calling the Object rule on
743 each of the source files.
744 You could use the Object rule directly.
745 For example, on Unix, you could use:
747 Object foo.o : foo.c ;
749 However, the Object rule does not provide suffixes, and
750 it does not provide the grist needed to construct target
751 identifiers if you are using the SubDir* rules.
752 A portable and robust Jamfile would need to invoke Object thus:
754 Object
<src!util
>foo$(SUFOBJ) :
<src!util
>foo.c ;
756 which is inelegant and clearly shows why using Objects
757 is better than using Object.
759 If there's any advantage to the Object rule, it's
760 that it doesn't require that the object name bear
761 any relationship to the source. It is thus possible to
762 compile the same file into different objects. For example:
769 This compiles foo.c (three times) into a.o, b.o, and c.o.
770 Later examples show how this is useful.
772 The Object rule looks at the suffix of the source file and
773 calls the appropriate rules to do the actual preprocessing
774 (if any) and compiling needed to produce the output object file.
776 capable of the generating of an object file from any
777 type of source. For example:
779 Object grammar$(SUFOBJ) : grammar.y ;
780 Object scanner$(SUFOBJ) : scanner.l ;
781 Object fastf$(SUFOBJ) : fastf.f ;
782 Object util$(SUFOBJ) : util.c ;
784 An even more elegant way to get the same result is to let the
785 Objects rule call Object:
787 Objects grammar.y scanner.l fastf.f util.c ;
790 In addition to calling the compile rules, Object sets up
791 a bunch of variables specific to the source and target
792 files. (See Variables Used in Compiling, below.)
795 Cc, C++, Yacc, Lex, Fortran, As, etc. Rules
798 The Object rule calls compile rules specific to the suffix of
799 the source file. (You can see which suffixes are supported
800 by looking at the Object rule definition in Jambase.)
801 Because the extra work done by the
802 Object rule, it is not always useful to call the compile
803 rules directly. But the adventurous user might attempt
806 Yacc grammar.c : grammar.y ;
807 Lex scan.c : scan.l ;
810 These examples individually run yacc(
1), lex(
1), and the C
811 compiler on their sources.
816 Any files with suffixes not understood by the Object rule
817 are passed to the UserObject rule. The default definition
818 of UserObject simply emits a warning that the suffix is
819 not understood. This Jambase rule definition is intended to be
820 overridden in Jamrules with one that recognizes the project-specific
821 source file suffixes. For example:
830 case *.rc : ResourceCompiler $(
<) : $(
>) ;
831 case * : ECHO
"unknown suffix on" $(
>) ;
835 rule ResourceCompiler
837 DEPENDS $(
<) : $(
>) ;
841 actions ResourceCompiler
843 rc /fo $(
<) $(RCFLAGS) $(
>)
849 Library liblock : lockmgr.c ;
850 if $(NT) { Library liblock : lock.rc ; }
853 In this example, the UserObject definition in Jamrules
854 allows *.rc files to be handle as regular Main and Library
855 sources. The lock.rc file is compiled into lock.obj
856 by the
"rc" command, and lock.obj is archived into a library
857 with other compiled objects.
859 LibraryFromObjects Rule
861 Sometimes the Library rule's straightforward compiling of
862 source into object modules to be archived isn't flexible
863 enough. The LibraryFromObjects rule does the archiving
864 (and deleting) job of the Library rule, but not the compiling.
865 The user can make use of the Objects or Object
866 rule for that. For example:
868 LibraryFromObjects libfoo.a : max.o min.o ;
869 Object max.o : maxmin.c ;
870 Object min.o : maxmin.c ;
871 ObjectCcFlags max.o : -DUSEMAX ;
872 ObjectCcFlags min.o : -DUSEMIN ;
874 This Unix-specific example compiles the same source file into
876 objects, with different compile flags, and archives them.
877 (The ObjectCcFlags rule is described shortly.)
878 Unfortunately, the portable and robust implementation of the
879 above example is not as pleasant to read:
882 LibraryFromObjects libfoo$(SUFLIB) :
<foo!bar
>max$(SUFOBJ)
883 <foo!bar
>min$(SUFOBJ) ;
884 Object
<foo!bar
>min$(SUFOBJ) :
<foo!bar
>maxmin.c ;
885 Object
<foo!bar
>max$(SUFOBJ) :
<foo!bar
>maxmin.c ;
886 ObjectCcFlags
<foo!bar
>min$(SUFOBJ) : -DUSEMIN ;
887 ObjectCcFlags
<foo!bar
>max$(SUFOBJ) : -DUSEMAX ;
889 Note that, among other things, you must supply the library
890 file suffix when using the LibraryFromObjects rule.
895 Similar to LibraryFromObjects, MainFromObjects does the
896 linking part of the Main rule, but not the compiling.
897 MainFromObjects can be used when there are no
898 objects at all, and everything is to be loaded from
899 libraries. For example:
901 MainFromObjects testprog ;
902 LinkLibraries testprog : libprog ;
903 Library libprog : main.c util.c ;
905 On Unix, say, this generates a link command that looks like:
907 cc -o testprog libprog.a
909 Linking purely from libraries is something that doesn't
910 work everywhere: it depends on the symbol
"main" being
911 undefined when the linker encounters the library that contains
912 the definition of
"main".
915 Variables Used in Compiling
917 The following variables control the compiling of source
924 <TD><TD>The C++ compiler command
927 <TD><TD>The C compiler command
932 <TD VALIGN=TOP
><TD VALIGN=TOP
>Compile flags, used to
933 create or update compiled objects
938 <TD VALIGN=TOP
><TD VALIGN=TOP
>Additonal compile flags
939 for source files in this directory.
942 <TD><TD>Compiler optimization flag. The Cc and C++
943 actions use this as well as C++FLAGS or CCFLAGS.
946 <TD VALIGN=TOP
><TD>Non-standard header directories; i.e.,
947 the directories the compiler will not look in
948 by default and which therefore must be supplied
949 to the compile command. These directories are
950 also used by
<b>jam
</b> to scan for include files.
953 <TD VALIGN=TOP
><TD>Standard header directories, i.e., the
954 directories the compiler searches automatically.
955 These are not passed to the compiler, but they
956 are used by
<b>jam
</b> to scan for include files.
959 <TD><TD>Additional paths to add to HDRS for source files
963 <TD><TD>The lex(
1) command
966 <TD><TD>The yacc(
1) command
970 The Cc rule sets a target-specific $(CCFLAGS) to the current
971 value of $(CCFLAGS) and $(SUBDIRCCFLAGS). Similarly
972 for the C++ rule. The Object rule sets a target-specific
973 $(HDRS) to the current value of $(HDRS) and $(SUBDDIRHDRS).
976 $(CC), $(C++), $(CCFLAGS), $(C++FLAGS), $(OPTIM), and
977 $(HDRS) all affect the compiling of C and C++ files.
978 $(OPTIM) is separate from $(CCFLAGS) and $(C++FLAGS) so
979 they can be set independently.
981 $(HDRS) lists the directories to search for header files,
982 and it is used in two ways: first, it is passed to the C
983 compiler (with the flag -I prepended); second, it is used
984 by HdrRule to locate the header files whose names were
985 found when scanning source files. $(STDHDRS) lists the
986 header directories that the C compiler already knows
987 about. It does not need passing to the C compiler, but is
990 Note that these variables, if set as target-specific variables,
991 must be set on the target, not the source file.
992 The target file in this case is the object file to be generated.
995 Library libximage : xtiff.c xjpeg.c xgif.c ;
997 HDRS on xjpeg$(SUFOBJ) = /usr/local/src/jpeg ;
998 CCFLAGS on xtiff$(SUFOBJ) = -DHAVE_TIFF ;
1000 This can be done more easily with the rules that follow.
1003 ObjectCcFlags, ObjectC++Flags, ObjectHdrs Rules
1005 $(CCFLAGS), $(C++FLAGS) and $(HDRS) can be set on object file
1007 directly, but there are rules that allow these variables
1008 to be set by referring to the original source file name,
1009 rather than to the derived object file name. ObjectCcFlags
1010 adds object-specific flags to the $(CCFLAGS) variable,
1011 ObjectC++Flags adds object-specific flags to the
1012 $(C++FLAGS) variable, and ObjectHdrs add object-specific
1013 directories to the $(HDRS) variable. For example:
1016 if $(NT) { CCFLAGS_X = /DXVERSION ;
1017 HDRS_X = \\\\SPARKY\\X11\\INCLUDE\\X11 ;
1021 Main xviewer : viewer.c ;
1022 ObjectCcFlags viewer.c : $(CCFLAGS_X) ;
1023 ObjectHdrs viewer.c : $(HDRS_X) ;
1025 The ObjectCcFlags and ObjectHdrs rules take .c files
1026 as targets, but actually set $(CCFLAGS) and $(HDRS) values
1027 on the .obj (or .o) files. As a result, the action
1028 that updates the target .obj file uses the target-specific
1029 values of $(CCFLAGS) and $(HDRS).
1032 SubDirCcFlags, SubDirC++Flags, SubDirHdrs Rules
1034 These rules set the values of $(SUBDIRCCFLAGS), $(SUBDIRC++FLAGS)
1035 and $(SUBDIRHDRS), which are used by the Cc,
1036 C++, and Object rules when setting the target-specific
1037 values for $(CCFLAGS), $(C++FLAGS) and $(HDRS). The SubDir
1038 rule clears these variables out, and thus they provide
1039 directory-specific values of $(CCFLAGS), $(C++FLAGS) and
1040 $(HDRS). For example:
1043 GZHDRS = $(TOP)/src/gz/include ;
1047 SubDir TOP src gz utils ;
1049 SubDirHdrs $(GZHDRS) ;
1050 SubDirCcFlags $(GZFLAG) ;
1052 Library libgz : gizmo.c ;
1053 Main gizmo : main.c ;
1054 LinkLibraries gizmo : libgz ;
1056 All .c files in this directory files will be compiled with
1057 $(GZFLAG) as well as the default $(CCFLAG), and the include
1058 paths used on the compile command will be $(GZHDRS) as well
1059 as the default $(HDRS).
1061 Header File Processing
1063 One of the functions of the Object rule is set up
1065 files for (C style) header file inclusions. To do so, it
1066 sets the special variables $(HDRSCAN) and $(HDRRULE)
1067 as target-specific variables on the source file. The
1068 presence of these variables triggers a special mechanism
1069 in
<B>jam
</B> for scanning a file for header file inclusions and
1070 invoking a rule with the results of the scan. The
1071 $(HDRSCAN) variable is set to an egrep(
1) pattern that
1072 matches
"#include" statements in C source files, and the
1073 $(HDRRULE) variable is set to the name of the rule that
1074 gets invoked as such:
1076 $(HDRRULE) source-file : included-files ;
1078 This rule is supposed to set up the dependencies between
1079 the source file and the included files. The Object rule
1080 uses HdrRule to do the job. HdrRule itself expects
1081 another variable, $(HDRSEARCH), to be set to the list of
1082 directories where the included files can be found. Object
1083 does this as well, setting $(HDRSEARCH) to $(HDRS) and
1086 The header file scanning occurs during the
"file binding"
1087 phase of
<b>jam
</b>, which means that the target-specific
1088 variables (for the source file) are in effect. To accomodate
1089 nested includes, one of the HdrRule's jobs is to pass
1090 the target-specific values of $(HDRRULE), $(HDRSCAN), and
1091 $(HDRSEARCH) onto the included files, so that they will be
1097 Normally, HdrRule is not invoked directly; the Object rule
1098 (called by Main and Library) invokes it.
1100 If there are special dependencies that need to be set,
1101 and which are not set by HdrRule itself, you can define
1102 another rule and let it invoke HdrRule. For example:
1108 DEPENDS $(
>) : mkhdr$(SUFEXE) ;
1109 HdrRule $(
<) : $(
>) ;
1113 Main mkhdr : mkhdr.c ;
1114 Main ugly : ugly.c ;
1116 HDRRULE on ugly.c = BuiltHeaders ;
1119 This example just says that the files included by
"ugly.c"
1120 are generated by the program
"mkhdr", which can be built
1121 from
"mkhdr.c". During the binding phase,
<b>jam
</b> will
1122 scan ugly.c, and if it finds an include file, ughdr.h,
1123 for example, it will automatically invoke the rule:
1125 BuiltHeaders ugly.c : ughdr.h ;
1127 By calling HdrRule at the end of BuiltHeaders,
1128 all the gadgetry of HdrRule takes effect and it
1129 doesn't need to be duplicated.
1132 Variables Used for Header Scanning
1138 <TD><TD>Default scan pattern for
"include" lines.
1141 <TD><TD>Scan pattern to use.
1142 This is a special variable: during binding, if
1143 both HDRSCAN and HDRRULE are set, scanning is activated
1144 on the target being bound.
1145 The HdrRule and Object rules sets this
1146 to $(HDRPATTERN) on their source targets.
1149 <TD><TD>Name of rule to invoked on files found in header
1150 scan. The HdrRule and Object rules set this to
"HdrRule"
1151 on their source targets. This is also a special variable;
1152 it's the only
<b>jam
</b> variable that can hold the
1153 name of a rule to be invoked.
1156 <TD><TD>Search paths for files found during header scanning.
1157 This is set from $(HDRS) and $(STDHDRS), which are
1158 described in the Compiling section.
1159 <b>jam
</b> will search $(HDRSEARCH) directories for
1160 the files found by header scans.
1164 The Object rule sets HDRRULE and HDRSCAN specifically for
1165 the source files to be scanned, rather than globally. If
1166 they were set globally, jam would attempt to scan all
1167 files, even library archives and executables, for header
1168 file inclusions. That would be slow and probably not
1169 yield desirable results.
1177 The File rule copies one file to another. The target name
1178 needn't be the same as the source name. For
1183 case NT* : File config.h : confignt.h ;
1184 case * : File config.h : configunix.h ;
1186 LOCATE on config.h = $(LOCATE_SOURCE) ;
1188 This creates a config.h file from either confignt.h or
1189 configunix.h, depending on the current build platform.
1191 The File rule does not
1192 use the LOCATE_SOURCE variable set by the
1193 SubDir rule (although it does use SEARCH_SOURCE), which
1194 means you have to set the copied file's output directory
1195 yourself. That's done by setting the special
1196 LOCATE variable on the target, as shown above,
1197 or with the MakeLocate rule described below.
1201 The Bulk rule is a shorthand for many invocations of the
1202 File rule when all files are going to the same directory.
1206 DISTRIB_GROB = d:\\distrib\\grob ;
1209 Bulk $(DISTRIB_GROB) : grobvals.txt grobvars.txt ;
1211 This causes gobvals.txt and grobvars.txt to be copied
1212 into the $(DISTRIB_GROB) directory.
1216 The Unix-only HardLink rule makes a hard link (using ln(
1)) from the
1217 source to the target, if there isn't one already. For
1220 HardLink config.h : configunix.h ;
1225 The Shell rule is like the File rule, except that on Unix it makes
1226 sure the first line of the target is
"#!/bin/sh" and sets
1227 the permission to make the file executable. For example:
1229 Shell /usr/local/bin/add : add.sh ;
1232 You can also use $(SHELLHEADER) to dictate
1233 what the first line of the copied file will be.
1237 Shell /usr/local/bin/add : add.awk ;
1238 SHELLHEADER on /usr/local/bin/add =
"#!/bin/awk -f" ;
1240 This installs an awk(
1) script.
1243 Variables Used When Copying Files
1249 <TD><TD>Default file permissions for copied files
1252 <TD><TD>Default file permissions for Shell rule targets
1255 <TD><TD>File permissions set on files copied by
1256 File, Bulk, and Shell rules.
1257 File and Shell sets a target-specific MODE to the current
1258 value of $(FILEMODE) or $(SHELLMODE), respectively.
1261 <TD><TD>String to write in first line of Shell targets
1262 (default is #!/bin/sh).
1271 Jambase provides a set of Install* rules to copy files
1272 into an destination directory and set permissions on them.
1273 On Unix, the install(
1) program is used.
1274 If the destination directory does not exist,
<b>jam
</b>
1277 All files copied with the Install* rules are dependencies
1278 of the
<i>install
</i> pseudotarget, which means that the
1279 command
"jam install" will cause the installed copies to
1280 be updated. Also,
"jam uninstall" will cause the installed
1281 copies to be removed.
1283 The Install* rules are:
1286 <TR><TD VALIGN=TOP
><B>InstallBin
</B>
1287 <TD VALIGN=TOP
>Copies file and sets its permission to $(EXEMODE).
1288 You must specify the suffixed executable name. E.g.:
1289 <PRE>InstallBin $(BINDIR) : thing$(SUFEXE) ;
1292 <TR><TD VALIGN=TOP
><B>InstallFile
</B>
1293 <TD VALIGN=TOP
>Copies file and sets its permission to $(FILEMODE). E.g.:
1294 <PRE>InstallFile $(DESTDIR) : readme.txt ;
1297 <TR><TD VALIGN=TOP
><B>InstallLib
</B>
1298 <TD VALIGN=TOP
>Copies file and sets its permission to $(FILEMODE).
1299 You must specify the suffixed library name. E.g.:
1300 <PRE>InstallLib $(LIBDIR) : libzoo$(SUFLIB) ;
1303 <TR><TD VALIGN=TOP
><B>InstallMan
</B>
1304 <TD VALIGN=TOP
>Copies file into the man
<i>n
</i>
1305 subdirectory of the target directory
1306 and sets its permission to $(FILEMODE). E.g.,
1307 this copies foo
.5 into the $(DESTDIR)/man5 directory:
1308 <PRE>InstallMan $(DESTDIR) : foo
.5 ;
1311 <TR><TD VALIGN=TOP
><B>InstallShell
</B>
1312 <TD VALIGN=TOP
>Copies file and sets its permission to $(SHELLMODE). E.g.:
1313 <PRE>InstallShell $(DESTDIR) : startup ;
1323 The following variables control the installation rules:
1329 <TD><TD>The install program (Unix only)
1332 <TD><TD>Default file permissions on readable files.
1335 <TD><TD>Default file permission executable files.
1338 <TD><TD>Default file permission on shell script files.
1341 <TD><TD>Target-specific file permissions
1346 The Install rules set a target-specific MODE to the current
1347 value of $(FILEMODE), $(EXEMODE), or $(SHELLMODE),
1348 depending on which Install rule was invoked.
1350 The directory variables are just defined for convenience:
1351 they must be passed as the target to the appropriate
1352 Install rule. The $(INSTALL) and mode variables must be
1353 set (globally) before calling the Install rules in order
1363 The Clean rule defines files to be removed when you run
"jam clean".
1364 Any site-specific build rules defined in your Jamrules should invoke
1365 Clean so that outputs can be removed. E.g.,
1367 rule ResourceCompiler
1369 DEPENDS $(<) : $(
>) ;
1370 Clean clean : $(<) ;
1375 Most Jambase rules invoke the Clean rule on their built targets,
1376 so
"jam clean" will remove all compiled objects, libraries,
1382 MakeLocate is a single convenient rule that creates a directory,
1383 sets LOCATE on a target to that directory, and makes the directory
1384 a dependency of the target. It is used by many Jambase rules,
1385 and can be invoked directly, e.g.:
1387 GenFile data.tbl : hxtract data.h ;
1388 MakeLocate data.tbl : $(TABLEDIR) ;
1390 In this example, the File rule creates data.tbl from data.h.
1391 The MakeLocate causes data.tbl to be written into the $(TABLEDIR)
1392 directory; and if the directory doesn't exist, it is created first.
1394 The MakeLocate rule invokes another Jambase rule, MkDir,
1395 to (recursively) create
1396 directories. MkDir uses the $(MKDIR) variable to determine the
1397 platform-specific command that creates directories.
1402 Some intermediate files are meant to be temporary.
1403 The RmTemps rule can be used to cause
1404 <b>jam
</b> to delete them after they are used.
1410 invoked on the permanent file that uses
1411 the temporary file(s)
1413 invoked with the permanent file as the output
1414 target and the temporary file(s) as the input target
1416 invoked with the exact target identifiers of
1417 the permanent file and the temporary file(s)
1422 SubDir TOP src big ;
1423 GenFile big.y : joinfiles part1.y part2.y part3.y ;
1424 Main bigworld : main.c big.y ;
1425 RmTemps bigworld$(SUFEXE) :
<src!big
>big.y ;
1427 This causes big.y to be deleted after it has been used to create
1428 the bigworld executable.
1429 The exact target identifier of big.y is
<src!big
>big.y
1430 (the GenFile and Main rules tack on the grist automatically);
1431 the exact target identifier of the bigworld executable
1432 is bigworld$(SUFEXE).
1435 <A HREF=
"#TOP">Back to top.
</A>
1437 Copyright
1997,
2000 Perforce Software, Inc.
1439 Changes and additions by Ketmar // Vampire Avalon