1 #============================================================================
2 # Rules for compiling a set of sources to object files
3 #============================================================================
4 # These are slightly modified versions of the Object and Objects rules from
5 # jam. The problem with the original rules in Jambase is the handling of
6 # custom file types. The solution with the UserObject rule is monolithic, you
7 # can only have 1 such rule. Thus we construct a more flexible toolkit here
8 # which let's you register rules for certain filetypes.
10 ## RegisterFileType Rulename : extensions
11 ## Register a rule which is used to compile a filetype into object
12 ## files. The registered rule is called with the name of the
13 ## sourcefile as argument and should return a list of objectfiles which are
14 ## created. You should set the grist of the object files by using the
15 ## DoObjectGrist function.
21 FILETYPE_$(suffix) = $(<) ;
25 ## RegisterHeaderRule rulename : regexpattern : extensions
26 ## Registers a rule and a regular expression which will be used for header
27 ## file scanning of the specified extensions.
28 rule RegisterHeaderRule
33 HDRRULE_$(suffix) = $(<) ;
34 HDRPATTERN_$(suffix) = $(>) ;
38 ## CompileObjects sources [ : options ]
39 ## Compile a set of sourcefiles into objectfiles (extension: SUFOBJ,
40 ## usually .o). This rule takes care of setting LOCATE and SEARCH
41 ## variables to the $(SEARCH_SOURCE) and $(LOCATE_SOURCE) variables.
42 ## The Application, Plugin and Library rules already use this rule
43 ## internally. You should only use this rule if you have to avoid the
44 ## Application, Plugin or Library rules.
51 SEARCH on $(<) = $(SEARCH_SOURCE) ;
55 # compile the sourcefile to targetfile
56 targets += [ CompileObject $(source) : $(2) ] ;
60 MakeLocate $(targets) : $(LOCATE_TARGET) ;
65 #----------------------------------------------------------------------------
68 # CompileObject sourcefile [ : options ]
69 # helper rule: Compiles a source file to an object file. Does header file
70 # scanning, sets LOCATE and SEARCH for source and target, grists the files
71 # with the current subdir and searches for the correct registered rule.
74 # handle #includes for source: Jam scans for headers with
75 # the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE)
76 # with the scanned file as the target and the found headers
77 # as the sources. HDRSEARCH is the value of SEARCH used for
78 # the found header files.
80 # $(SEARCH_SOURCE:E) is where cc first looks for #include
81 # "foo.h" files. If the source file is in a distant directory,
82 # look there. Else, look in "" (the current directory).
85 HDRSEARCH on $(<) = $(SEARCH_SOURCE:E) $(HDRSEARCH) $(STDHDRSEARCH) ;
86 SEARCH_SOURCE on $(<) = $(SEARCH_SOURCE) ;
87 HDRRULE on $(<) = $(HDRRULE_$(<:S)) ;
88 HDRSCAN on $(<) = $(HDRPATTERN_$(<:S)) ;
92 # Invoke filetype specific rule
95 targets = [ $(FILETYPE_$(<:S)) $(<) : $(2) ] ;
99 echo "Warning: no rules for filetype $(>:S) defined (at file $(>))." ;
104 # construct clean target
105 Clean clean : $(targets) ;
111 ## HeaderRule source : headers
112 ## This rule is the default header rule used by the objects rules. You
113 ## might register custom rules with the RegisterHeaderRule rule.
116 # N.B. This rule is called during binding, potentially after
117 # the fate of many targets has been determined, and must be
118 # used with caution: don't add dependencies to unrelated
119 # targets, and don't set variables on $(<).
121 # Tell Jam that anything depending on $(<) also depends on $(>),
122 # set SEARCH so Jam can find the headers, but then say we don't
123 # care if we can't actually find the headers (they may have been
125 local HDRSEARCH = [ on $(<) GetVar HDRSEARCH ] ;
126 local SEARCH_SOURCE = [ on $(<) GetVar SEARCH_SOURCE ] ;
128 Includes $(<) : $(>) ;
129 SEARCH on $(>) = $(HDRSEARCH) $(SEARCH_SOURCE)/$(<:D) ;
136 SEARCH on $(>) = $(HDRSEARCH) $(SEARCH_SOURCE)/$(<:D) ;
138 SEARCH_SOURCE on $(i) = $(SEARCH_SOURCE)/$(<:D) ;
140 SEARCH_SOURCE on $(i) = $(SEARCH_SOURCE) ;
142 HDRSEARCH on $(>) = $(HDRSEARCH) ;
143 HDRRULE on $(>) = [ on $(<) GetVar HDRRULE ] ;
144 HDRSCAN on $(>) = [ on $(<) GetVar HDRPATTERN ] ;
148 if $(JAMVERSION) < 2.5
150 ## XXX XXX XXX a bug in jam 2.4 let's the version above fail. I'll let this
151 ## non-optimal version in here until jam 2.5 is out.
155 local s = $(>:G=$(HDRGRIST)) ;
157 Includes $(<) : $(s) ;
158 SEARCH on $(s) = $(HDRSEARCH) ;
166 HDRGRIST on $(s) = $(HDRGRIST) ;
167 HDRSEARCH on $(s) = $(HDRSEARCH) ;
168 HDRRULE on $(s) = $(HDRRULE_$(i:S)) ;
169 HDRSCAN on $(s) = $(HDRPATTERN_$(i:S)) ;
173 #echo "No Header rule for $(i:S) file $(i) " ;
178 } # end of if $(JAMVERSION) < 1.5
180 # Dummy rule: .o files are used as is.
185 RegisterFileType UseObjectFile : .o ;
187 # Ignore header files.
192 RegisterFileType UseHeaderFile : .h .hpp ;
193 RegisterHeaderRule HeaderRule : $(HDRPATTERN) : .h .hpp .inc ;
195 # Generates a grist suitable for output objects based on
196 # SUBVARIANT and SUBDIR variable.
199 return $(<:G=$(SOURCE_GRIST:E)!$(SUBVARIANT)) ;
202 # Generates a grist suitable for source files based on SUBDIR variable.
205 return $(<:G=$(SOURCE_GRIST:E)) ;