This document describes how to use the various Jambase rules from a functional point of view. You can see the summary of available Jambase rules in the Jambase Reference. The detailed specifications for any Jambase rule can be found by reading the rule definition itself in the Jambase.
The build configuration rules can only be used in the Jamconfigure script and perform the necessary tests to determine whether all dependencies required for the build are present. When the Jamconfigure script is run in the build configuration step, the Jamrules file is generated. This file is loaded at the beginning of the build step.
Once the toolset has been configured with the ConfigureC or the ConfigureC++ rule, the rules CheckBuildC and CheckBuildC++ can be used to build small test programs to find out if headers and libraries are available.
WITH_DL = [ CheckBuildC++ "#include" "int main() { dlopen(0,0); return 0; }" : "" : -ldl ] ; if ! { Exit "dlopen not available" ; }
This uses the C++ toolset to compile a small program calling a function of the dl library. The program is linked with the linker flag -ldl. The third argument passed to CheckBuildC++ is empty, but additional compiler flags could be passed here. An optional fifth argument allows to pass linker paths to the build command. The rule will return nothing if the program can not be built and a boolean-like value on success. The command will be logged in the file Jamrules.log.
The Configure rule can be used to make the result of a test available to the following build steps.
WITH_FOO = ; if --with-foo in $(ARGS) { WITH_FOO = yes ; } Configure WITH_FOO ;
This tests if the command line option "--with-foo" was set and if so, the jam variable named WITH_FOO is stored in the build configuration result file. Note, that empty variables are not stored, so later in the Jamfiles it can simply be tested if WITH_FOO is set or not.
The ConfigureCc and ConfigureC++ rules can be used to configure the toolset, so that C or C++ programs can be built with the build rules like Main, Library and SharedLibrary. They do not require any arguments and have to be invoked before any other tests are done that require the toolsets to be functional.
ConfigureCc ; ConfigureC++ ;
Most, if not all Jamconfigure scripts call one or both rules at the beginning. All tests will be logged in the file Jamrules.log.
This rule formats and prints the value and description of a configured value. It has the purpose to indicate progress during the configuration step.
EchoOption --with-foo : "Enable foo module" : $(WITH_FOO:E="no") ;
The first argument is the option itself, the second one the description and the third one the value configured for the option. The third argument is optional and if left away, the first argument will be taken as the name of the jam variable that holds the value:
EchoOption MY_INSTALL_BINDIR : "Program installation directory" ;
If this form is used, it will be indicated that the MY_INSTALL_BINDIR variable can be overridden with the -s command line switch, in this case something like -sMY_INSTALL_BINDIR=/some/dir.
The TryCommand rule takes one argument and that is a shell command to execute. It can be used to check if a required tool is in the path:
if [ TryCommand "ls" ] { Echo The ls command is available ; } else { Echo The ls command is not available ; }The rule returns nothing if the return code of the shell command indicates failure. All output of the command will be written to the logfile config.log. This is the most basic form to perform tests, but usually one of the more high-level configuration rules will be used.
Building Executables and Libraries
The rules to build targets can only be used in the Jamfiles and the Jamrules script. All build options that were configured are available in the build step. Some rules like Main, Library and SharedLibray can only work if the toolset has been configured previously.
The SubDir* rules are used to define source code directory hierarchies. With SubDir and SubInclude, you can use jam to build software from source files and Jamfiles spread across many directories, as is typical for large projects. The SubDir* rules unify an entire source code tree so that jam can read in all the Jamfiles in one pass and compute dependencies across the entire project.
To use the SubDir* rules, you must:
The SubDir rule must be invoked before any rules that refer to the contents of the directory - it is best to put it at the top of each Jamfile. For example:
# Jamfile in $(TOP)/src/util directory. SubDir TOP src util ; Main myprog : main.c util.c ; LinkLibraries myprog : libtree ; Library libtree : treemake.c treetrav.c ;This compiles four files in $(TOP)/src/util, archives two of the objects into libtree, and links the whole thing into myprog. Outputs are placed in the $(TOP)/src/util directory. Two things are happening behind the scenes:
Jamrules is only read in once, at the first SubDir invocation.
When you have set a root variable, e.g., $(TOP), SubDir constructs path names rooted with $(TOP), e.g., $(TOP)/src/util. Otherwise, SubDir constructs relative pathnames to the root directory, computed from the number of arguments to the first SubDir rule, e.g., ../../src/util. In either case, the SubDir rule constructs the path names that locate source files. You'll see how this is useful later.
The SubDir rule takes as its first argument the root variable's name and takes as subsequent arguments the directory names leading from the root to the directory of the current Jamfile. Note that the name of the subdirectory is given as individual elements: the SubDir rule does not use system-specific directory name syntax.
The recommended practice is only to include one level of subdirectories at a time, and let the Jamfile in each subdirectory include its own subdirectories. This allows a user to sit in any arbitrary directory of the source tree and build that subtree. For example:
# This is $(TOP)/Jamfile, top level Jamfile for mondo project. SubInclude TOP src ; SubInclude TOP man ; SubInclude TOP misc ; SubInclude TOP util ;If a directory has both subdirectories of its own as well as files that need building, the SubIncludes should be either before the SubDir rule or be at the end of the Jamfile - not between the SubDir and other rule invocations. For example:
# This is $(TOP)/src/Jamfile: SubDir TOP src ; Main mondo : mondo.c ; LinkLibraries mondo : libmisc libutil ; SubInclude TOP src misc ; SubInclude TOP src util ;
(jam processes all the Jamfiles it reads as if it were reading one single, large Jamfile. Build rules like Main and LinkLibraries rely on the preceding SubDir rule to set up source file and output file locations, and SubIncludes rules read in Jamfiles that contain SubDir rules. So if you put a SubIncludes rule between a SubDir and a Main rule, jam will try to find the source files for the Main rule in the wrong directory.)
SEARCH_SOURCE | The SubDir targets (e.g., "TOP src util") are used to construct a pathname (e.g., $(TOP)/src/util), and that pathname is assigned to $(SEARCH_SOURCE). Rules like Main and Library use $(SEARCH_SOURCE) to set search paths on source files. | |
LOCATE_SOURCE | Initialized by the SubDir rule to the same value as $(SEARCH_SOURCE), unless ALL_LOCATE_TARGET is set. $(LOCATE_SOURCE) is used by rules that build generated source files (e.g., Yacc and Lex) to set location of output files. Thus the default location of built source files is the directory of the Jamfile that defines them. | |
LOCATE_TARGET | Initalized by the SubDir rule to the same value as $(SEARCH_SOURCE), unless ALL_LOCATE_TARGET is set. $(LOCATE_TARGET) is used by rules that build binary objects (e.g., Main and Library) to set location of output files. Thus the default location of built binaray files is the directory of the Jamfile that defines them. | |
ALL_LOCATE_TARGET | If $(ALL_LOCATE_TARGET) is set, LOCATE_SOURCE and and LOCATE_TARGET are set to $(ALL_LOCATE_TARGET) instead of to $(SEARCH_SOURCE). This can be used to direct built files to be written to a location outside of the source tree, and enables building from read-only source trees. | |
SOURCE_GRIST | The SubDir targets are formed into a string like "src!util" and that string is assigned to SOURCE_GRIST. Rules that define file targets use $(SOURCE_GRIST) to set the "grist" attribute on targets. This is used to assure uniqueness of target identifiers where filenames themselves are not unique. For example, the target identifiers of $(TOP)/src/client/main.c and $(TOP)/src/server/main.c would be <src!client>main.c and <src!server>main.c. |
The $(LOCATE_TARGET) and $(SEARCH_SOURCE) variables are used extensively by rules in Jambase: most rules that generate targets (like Main, Object, etc.) set $(LOCATE) to $(LOCATE_TARGET) for the targets they generate, and rules that use sources (most all of them) set $(SEARCH) to be $(SEARCH_SOURCE) for the sources they use.
$(LOCATE) and $(SEARCH) are better explained in Basic Usage but in brief they tell jam where to create new targets and where to find existing ones, respectively.
Note that you can reset these variables after SubDir sets them. For example, this Jamfile builds a program called gensrc, then runs it to create a source file called new.c:
SubDir TOP src util ; Main gensrc : gensrc.c ; LOCATE_SOURCE = $(NEWSRC) ; GenFile new.c : gensrc ;By default, new.c would be written into the $(TOP)/src/util directory, but resetting LOCATE_SOURCE causes it to be written to the $(NEWSRC) directory. ($(NEWSRC) is assumed to have been set elsewhere, e.g., in Jamrules.)
TOP = USR_DISK:[JONES.SRC] ; SubInclude TOP util ;The variable must have a value that looks like a directory or device. If you choose, you can use a concealed logical. For example:
TOP = TOP: ; SubInclude TOP util ;The : at the end of TOP makes the value of $(TOP) look like a device name, which jam respects as a directory name and will use when trying to access files. TOP must then be defined from DCL:
$ define/job/translation=concealed TOP DK100:[USERS.JONES.SRC.]Note three things: the concealed translation allows the logical to be used as a device name; the device name in the logical (here DK100) cannot itself be concealed logical (VMS rules, man); and the directory component of the definition must end in a period (more VMS rules).
Main myprog : main.c util.c ;This compiles main.c and util.c and links main.o and util.o into myprog. The object files and resulting executable are named appropriately for the platform.
Main uses the Objects rule to compile source targets.
Library libstring : strcmp.c strcpy.c strlen.c ; Library libtree : treemake.c treetrav.c ;This compiles five source files, archives three of the object files into libstring and the other two into libtree. Actual library filenames are formed with the $(SUFLIB) suffix. Once the objects are safely in the libraries, the objects are deleted.
Library uses the Objects rule to compile source files.
SharedLibrary example : example.c util.c ;This compiles example.c and util.c and links example.o and util.o into example. The object files and resulting executable are named appropriately for the platform. Main uses the Objects rule to compile source targets.
Normally, SharedLibrary uses $(SUFLIB) and $(SUFDLL) to determine the prefix/suffix on the filename of the built target. Under windows the resulting library will be called example.dll and a import library called example.lib will be created. Under unix, one shared library called libexample.so will be created. To override it, you can supply a prefix/suffix explicity.
Library tree : tree.c ; Library string : string.c ; Main myprog : main.c util.c ; LinkLibraries myprog : tree ; SharedLibrary mydll : dll.c stuff.c ; LinkLibraries mydll : string tree ;The LinkLibraries rule does two things: it makes the libraries dependencies of the executable, so that they get built first; and it makes the libraries show up on the command line that links the executable. The ordering of the lines above is important, because the preceeding Main or SharedLibrary Rule define its target.
You can put multiple libraries on a single invocation of the LinkLibraries rule, or you can provide them in multiple invocations. In both cases, the libraries appear on the link command line in the order in which they were encountered.
SharedLibrary mydll : dll.c stuff.c ; Main myprog : main.c util.c ; LinkSharedLibraries myprog : mydll ;The LinkSharedLibraries rule does two things: it makes the libraries dependencies of the executable, so that they get built first; and it makes the libraries show up on the command line that links the executable. The ordering of the lines above is important, because the preceeding Main or SharedLibrary Rules type its target.
You can put multiple libraries on a single invocation of the LinkSharedLibraries rule, or you can provide them in multiple invocations. In both cases, the libraries appear on the link command line in the order in which they were encountered. E. g.:
LinkSharedLibraries myprog : dll1 dll2 ;
Main myprog : main.c util.c ; LinkLibs myprog : ;
This rule is useful for linker flags that specify which libraries should be linked, like the -lxxx flags for most unix toolsets, because these flags must be placed at a special position in the linker command line. Use the LinkFlags rule for other linker flags.
Main myprog : main.c util.c ; LinkFlags myprog : $(FLAGS) ; SharedLibrary mydll : dll.c stuff.c ; LinkFlags mydll : $(FLAGS) ;This adds the linker flags contained in $(FLAGS) to the command line that links the targets myprog or mydll. Do not use this rule for linker flags that specify which libraries should be linked, like the -lxxx flags required by most unix toolsets. Use the LinkLibs rule for this, because these library linker flags have to be placed at a special position in the linker command line.
AR | Archive command, used for Library targets. | |
SUFEXE | * | Suffix on filenames of executables referenced by Main and LinkLibraries. |
SUFDLL | * | Suffix on filenames of shared libraries referenced by SharedLibrary and LinkSharedLibraries. |
LINK | Link command, used for Main targets. | |
LINKFLAGS | Linker flags. | |
LINKLIBS | Link libraries that aren't dependencies. (See note below.) | |
EXEMODE | * | File permissions on Main targets. |
MODE | Target-specific file permissions on Main targets (set from $(EXEMODE)) | |
RANLIB | Name of ranlib program, if any. |
Variables above marked with "*" are used by the build rules. Their values at the time the rules are invoked are used to set target-specific variables.
All other variables listed above are globally defined, and are used in actions that update build targets. This means that the global values of those variables are used, unless target-specific values have been set. (For instance, a target-specific MODE value is set by the Main rule.) The target-specific values always override global values.
Note that there are several ways to specify link libraries for executables:
For example:
#In Jamrules: X11LINKLIBS ?= -lXext -lX11 ; #In Jamfile: Library libxutil : xtop.c xbottom.c xutil.c ; Main xprog : xprog.c ; LinkLibraries xprog : libxutil ; LinkLibs xprog : $(X11LINKLIBS) ; # Or: LINKLIBS on xprog$(SUFEXE) = $(X11LINKLIBS) ;This example uses the Jam syntax "variable on target" to set a target-specific variable. In this way, only xprog will be linked with this special $(X11LINKLIBS), even if other executables were going to be built by the same Jamfile. Note that when you set a variable on a target, you have to specify the target identifer exactly, which in this case is the suffixed filename of the executable. Therefore you should always prefer to use the LinkLibs rule instead of setting the LINKLIBS variable directly. The actual link command line on Unix, for example, would look something like this:
cc -o xprog xprog.o libxutil.a -lXext -lX11
Target identifiers created by the Objects rule have grist set to $(SOURCE_GRIST). So given this Jamfile:
SubDir TOP src lock ; Main locker : lock.c ;the object file created is lock.o (or lock.obj) and its target identifier is <src!lock>lock.o (or <src!lock>lock.obj).
You can also call Objects directly. For example:
Objects a.c b.c c.c ;This compiles a.c into a.o, b.c into b.o, etc. The object file suffix is supplied by the Objects rule.
Object foo.o : foo.c ;However, the Object rule does not provide suffixes, and it does not provide the grist needed to construct target identifiers if you are using the SubDir* rules. A portable and robust Jamfile would need to invoke Object thus:
Object <src!util>foo$(SUFOBJ) : <src!util>foo.c ;which is inelegant and clearly shows why using Objects is better than using Object.
If there's any advantage to the Object rule, it's that it doesn't require that the object name bear any relationship to the source. It is thus possible to compile the same file into different objects. For example:
Object a.o : foo.c ; Object b.o : foo.c ; Object c.o : foo.c ;This compiles foo.c (three times) into a.o, b.o, and c.o. Later examples show how this is useful.
The Object rule looks at the suffix of the source file and calls the appropriate rules to do the actual preprocessing (if any) and compiling needed to produce the output object file. The Object rule is capable of the generating of an object file from any type of source. For example:
Object grammar$(SUFOBJ) : grammar.y ; Object scanner$(SUFOBJ) : scanner.l ; Object fastf$(SUFOBJ) : fastf.f ; Object util$(SUFOBJ) : util.c ;An even more elegant way to get the same result is to let the Objects rule call Object:
Objects grammar.y scanner.l fastf.f util.c ;
In addition to calling the compile rules, Object sets up a bunch of variables specific to the source and target files. (See Variables Used in Compiling, below.)
The Object rule calls compile rules specific to the suffix of the source file. (You can see which suffixes are supported by looking at the Object rule definition in Jambase.) Because the extra work done by the Object rule, it is not always useful to call the compile rules directly. But the adventurous user might attempt it. For example:
Yacc grammar.c : grammar.y ; Lex scan.c : scan.l ; Cc prog.o : prog.c ;These examples individually run yacc(1), lex(1), and the C compiler on their sources.
#In Jamrules: rule UserObject { switch $(>) { case *.rc : ResourceCompiler $(<) : $(>) ; case * : ECHO "unknown suffix on" $(>) ; } } rule ResourceCompiler { DEPENDS $(<) : $(>) ; Clean clean : $(<) ; } actions ResourceCompiler { rc /fo $(<) $(RCFLAGS) $(>) } #In Jamfile: Library liblock : lockmgr.c ; if $(NT) { Library liblock : lock.rc ; }
In this example, the UserObject definition in Jamrules allows *.rc files to be handle as regular Main and Library sources. The lock.rc file is compiled into lock.obj by the "rc" command, and lock.obj is archived into a library with other compiled objects.
LibraryFromObjects libfoo.a : max.o min.o ; Object max.o : maxmin.c ; Object min.o : maxmin.c ; ObjectCcFlags max.o : -DUSEMAX ; ObjectCcFlags min.o : -DUSEMIN ;This Unix-specific example compiles the same source file into two different objects, with different compile flags, and archives them. (The ObjectCcFlags rule is described shortly.) Unfortunately, the portable and robust implementation of the above example is not as pleasant to read:
SubDir TOP foo bar ; LibraryFromObjects libfoo$(SUFLIB) : <foo!bar>max$(SUFOBJ) <foo!bar>min$(SUFOBJ) ; Object <foo!bar>min$(SUFOBJ) : <foo!bar>maxmin.c ; Object <foo!bar>max$(SUFOBJ) : <foo!bar>maxmin.c ; ObjectCcFlags <foo!bar>min$(SUFOBJ) : -DUSEMIN ; ObjectCcFlags <foo!bar>max$(SUFOBJ) : -DUSEMAX ;Note that, among other things, you must supply the library file suffix when using the LibraryFromObjects rule.
MainFromObjects testprog ; LinkLibraries testprog : libprog ; Library libprog : main.c util.c ;On Unix, say, this generates a link command that looks like:
cc -o testprog libprog.aLinking purely from libraries is something that doesn't work everywhere: it depends on the symbol "main" being undefined when the linker encounters the library that contains the definition of "main".
C++ | The C++ compiler command | |
CC | The C compiler command | |
C++FLAGS
CCFLAGS | Compile flags, used to create or update compiled objects | |
SUBDIRC++FLAGS
SUBDIRCCFLAGS | Additonal compile flags for source files in this directory. | |
OPTIM | Compiler optimization flag. The Cc and C++ actions use this as well as C++FLAGS or CCFLAGS. | |
HDRS | Non-standard header directories; i.e., the directories the compiler will not look in by default and which therefore must be supplied to the compile command. These directories are also used by jam to scan for include files. | |
STDHDRS | Standard header directories, i.e., the directories the compiler searches automatically. These are not passed to the compiler, but they are used by jam to scan for include files. | |
SUBDIRHDRS | Additional paths to add to HDRS for source files in this directory. | |
LEX | The lex(1) command | |
YACC | The yacc(1) command |
The Cc rule sets a target-specific $(CCFLAGS) to the current value of $(CCFLAGS) and $(SUBDIRCCFLAGS). Similarly for the C++ rule. The Object rule sets a target-specific $(HDRS) to the current value of $(HDRS) and $(SUBDDIRHDRS).
$(CC), $(C++), $(CCFLAGS), $(C++FLAGS), $(OPTIM), and $(HDRS) all affect the compiling of C and C++ files. $(OPTIM) is separate from $(CCFLAGS) and $(C++FLAGS) so they can be set independently.
$(HDRS) lists the directories to search for header files, and it is used in two ways: first, it is passed to the C compiler (with the flag -I prepended); second, it is used by HdrRule to locate the header files whose names were found when scanning source files. $(STDHDRS) lists the header directories that the C compiler already knows about. It does not need passing to the C compiler, but is used by HdrRule.
Note that these variables, if set as target-specific variables, must be set on the target, not the source file. The target file in this case is the object file to be generated. For example:
Library libximage : xtiff.c xjpeg.c xgif.c ; HDRS on xjpeg$(SUFOBJ) = /usr/local/src/jpeg ; CCFLAGS on xtiff$(SUFOBJ) = -DHAVE_TIFF ;This can be done more easily with the rules that follow.
#In Jamrules: if $(NT) { CCFLAGS_X = /DXVERSION ; HDRS_X = \\\\SPARKY\\X11\\INCLUDE\\X11 ; } #In Jamfile: Main xviewer : viewer.c ; ObjectCcFlags viewer.c : $(CCFLAGS_X) ; ObjectHdrs viewer.c : $(HDRS_X) ;The ObjectCcFlags and ObjectHdrs rules take .c files as targets, but actually set $(CCFLAGS) and $(HDRS) values on the .obj (or .o) files. As a result, the action that updates the target .obj file uses the target-specific values of $(CCFLAGS) and $(HDRS).
#In Jamrules: GZHDRS = $(TOP)/src/gz/include ; GZFLAG = -DGZ ; OBJS = $(TOP)/objs #In Jamfile: SubDir TOP src gz utils ; SubDirHdrs $(GZHDRS) ; SubDirCcFlags $(GZFLAG) ; SubDirObjects $(OBJS) ; Library libgz : gizmo.c ; Main gizmo : main.c ; LinkLibraries gizmo : libgz ;All .c files in this directory will be compiled with $(GZFLAG) as well as the default $(CCFLAG), and the include paths used on the compile command will be $(GZHDRS) as well as the default $(HDRS). All objects will be generated in $(TOP)/objs.
$(HDRRULE) source-file : included-files ;This rule is supposed to set up the dependencies between the source file and the included files. The Object rule uses HdrRule to do the job. HdrRule itself expects another variable, $(HDRSEARCH), to be set to the list of directories where the included files can be found. Object does this as well, setting $(HDRSEARCH) to $(HDRS) and $(STDHDRS).
The header file scanning occurs during the "file binding" phase of jam, which means that the target-specific variables (for the source file) are in effect. To accomodate nested includes, one of the HdrRule's jobs is to pass the target-specific values of $(HDRRULE), $(HDRSCAN), and $(HDRSEARCH) onto the included files, so that they will be scanned as well.
If there are special dependencies that need to be set, and which are not set by HdrRule itself, you can define another rule and let it invoke HdrRule. For example:
#In Jamrules: rule BuiltHeaders { DEPENDS $(>) : mkhdr$(SUFEXE) ; HdrRule $(<) : $(>) ; } #In Jamfile: Main mkhdr : mkhdr.c ; Main ugly : ugly.c ; HDRRULE on ugly.c = BuiltHeaders ;This example just says that the files included by "ugly.c" are generated by the program "mkhdr", which can be built from "mkhdr.c". During the binding phase, jam will scan ugly.c, and if it finds an include file, ughdr.h, for example, it will automatically invoke the rule:
BuiltHeaders ugly.c : ughdr.h ;By calling HdrRule at the end of BuiltHeaders, all the gadgetry of HdrRule takes effect and it doesn't need to be duplicated.
HDRPATTERN | Default scan pattern for "include" lines. | |
HDRSCAN | Scan pattern to use. This is a special variable: during binding, if both HDRSCAN and HDRRULE are set, scanning is activated on the target being bound. The HdrRule and Object rules sets this to $(HDRPATTERN) on their source targets. | |
HDRRULE | Name of rule to invoked on files found in header scan. The HdrRule and Object rules set this to "HdrRule" on their source targets. This is also a special variable; it's the only jam variable that can hold the name of a rule to be invoked. | |
HDRSEARCH | Search paths for files found during header scanning. This is set from $(HDRS) and $(STDHDRS), which are described in the Compiling section. jam will search $(HDRSEARCH) directories for the files found by header scans. |
The Object rule sets HDRRULE and HDRSCAN specifically for the source files to be scanned, rather than globally. If they were set globally, jam would attempt to scan all files, even library archives and executables, for header file inclusions. That would be slow and probably not yield desirable results.
switch $(OS) { case NT* : File config.h : confignt.h ; case * : File config.h : configunix.h ; } LOCATE on config.h = $(LOCATE_SOURCE) ;This creates a config.h file from either confignt.h or configunix.h, depending on the current build platform.
The File rule does not use the LOCATE_SOURCE variable set by the SubDir rule (although it does use SEARCH_SOURCE), which means you have to set the copied file's output directory yourself. That's done by setting the special LOCATE variable on the target, as shown above, or with the MakeLocate rule described below.
#In Jamrules: DISTRIB_GROB = d:\\distrib\\grob ; #In Jamfile: Bulk $(DISTRIB_GROB) : grobvals.txt grobvars.txt ;This causes gobvals.txt and grobvars.txt to be copied into the $(DISTRIB_GROB) directory.
HardLink config.h : configunix.h ;
Shell /usr/local/bin/add : add.sh ;
You can also use $(SHELLHEADER) to dictate what the first line of the copied file will be. For example:
Shell /usr/local/bin/add : add.awk ; SHELLHEADER on /usr/local/bin/add = "#!/bin/awk -f" ;This installs an awk(1) script.
FILEMODE | Default file permissions for copied files | |
SHELLMODE | Default file permissions for Shell rule targets | |
MODE | File permissions set on files copied by File, Bulk, and Shell rules. File and Shell sets a target-specific MODE to the current value of $(FILEMODE) or $(SHELLMODE), respectively. | |
SHELLHEADER | String to write in first line of Shell targets (default is #!/bin/sh). |
The MakeInstall rule installs a target at a given location. It works for all targets defined by the Main, Library and SharedLibrary rules.
Main myprog : main.c ; MakeInstall myprog : ;This installs the program "myprog" to the path given by the variable MY_INSTALL_BINDIR. This rule calls one or more of the other Install* rules as appropriate.
All files copied with the Install* rules are dependencies of the install pseudotarget, which means that the command "jam install" will cause the installed copies to be updated. Also, "jam uninstall" will cause the installed copies to be removed.
The Install* rules are:
InstallBin | Copies file and sets its permission to $(EXEMODE).
You must specify the suffixed executable name. E.g.:
InstallBin $(BINDIR) : thing$(SUFEXE) ; |
InstallFile | Copies file and sets its permission to $(FILEMODE). E.g.:
InstallFile $(DESTDIR) : readme.txt ; |
InstallLib | Copies file and sets its permission to $(FILEMODE).
You must specify the suffixed library name. E.g.:
InstallLib $(LIBDIR) : libzoo$(SUFLIB) ; |
InstallMan | Copies file into the mann
subdirectory of the target directory
and sets its permission to $(FILEMODE). E.g.,
this copies foo.5 into the $(DESTDIR)/man5 directory:
InstallMan $(DESTDIR) : foo.5 ; |
InstallShell | Copies file and sets its permission to $(SHELLMODE). E.g.:
InstallShell $(DESTDIR) : startup ; |
INSTALL | The install program (Unix only) | |
FILEMODE | Default file permissions on readable files. | |
EXEMODE | Default file permission executable files. | |
SHELLMODE | Default file permission on shell script files. | |
MODE | Target-specific file permissions |
The Install rules set a target-specific MODE to the current value of $(FILEMODE), $(EXEMODE), or $(SHELLMODE), depending on which Install rule was invoked.
The directory variables are just defined for convenience: they must be passed as the target to the appropriate Install rule. The $(INSTALL) and mode variables must be set (globally) before calling the Install rules in order to take effect.
The Clean rule defines files to be removed when you run "jam clean". Any site-specific build rules defined in your Jamrules should invoke Clean so that outputs can be removed. E.g.,
rule ResourceCompiler { DEPENDS $(<) : $(>) ; Clean clean : $(<) ; }
Most Jambase rules invoke the Clean rule on their built targets, so "jam clean" will remove all compiled objects, libraries, executables, etc.
GenFile data.tbl : hxtract data.h ; MakeLocate data.tbl : $(TABLEDIR) ;In this example, the File rule creates data.tbl from data.h. The MakeLocate causes data.tbl to be written into the $(TABLEDIR) directory; and if the directory doesn't exist, it is created first.
The MakeLocate rule can be used to build targets introduced by Main, Library or SharedLibrary at a specific location.
Main myprog : main.c ; MakeLocate myprog : $(OUTPUT) ;In the example above the program 'myprog' is built at the location specified by the variable OUTPUT.
The MakeLocate rule invokes another Jambase rule, MkDir, to (recursively) create directories. MkDir uses the $(MKDIR) variable to determine the platform-specific command that creates directories.
RmTemps must be:
SubDir TOP src big ; GenFile big.y : joinfiles part1.y part2.y part3.y ; Main bigworld : main.c big.y ; RmTemps bigworld$(SUFEXE) : <src!big>big.y ;This causes big.y to be deleted after it has been used to create the bigworld executable. The exact target identifier of big.y is <src!big>big.y (the GenFile and Main rules tack on the grist automatically); the exact target identifier of the bigworld executable is bigworld$(SUFEXE).