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. Finally, if jam must deal with
79 # header files of the same name in different directories,
80 # they can be distinguished with HDRGRIST.
82 # $(SEARCH_SOURCE:E) is where cc first looks for #include
83 # "foo.h" files. If the source file is in a distant directory,
84 # look there. Else, look in "" (the current directory).
87 HDRS on $(<) = [ ConcatDirs $(SUBDIR) $(<:D) ]
88 $(SEARCH_SOURCE:E) $(HDRS) $(STDHDRS) ;
89 HDRGRIST on $(<) = $(HDRGRIST) ;
90 HDRRULE on $(<) = $(HDRRULE_$(<:S)) ;
91 HDRSCAN on $(<) = $(HDRPATTERN_$(<:S)) ;
95 # Invoke filetype specific rule
98 targets = [ $(FILETYPE_$(<:S)) $(<) : $(2) ] ;
102 echo "Warning: no rules for filetype $(>:S) defined (at file $(>))." ;
107 # construct clean target
108 Clean clean : $(targets) ;
114 ## HeaderRule source : headers
115 ## This rule is the default header rule used by the objects rules. You
116 ## might register custom rules with the RegisterHeaderRule rule.
119 # N.B. This rule is called during binding, potentially after
120 # the fate of many targets has been determined, and must be
121 # used with caution: don't add dependencies to unrelated
122 # targets, and don't set variables on $(<).
124 # Tell Jam that anything depending on $(<) also depends on $(>),
125 # set SEARCH so Jam can find the headers, but then say we don't
126 # care if we can't actually find the headers (they may have been
128 local s = $(>:G=$(HDRGRIST:E)) ;
130 Includes $(<) : $(s) ;
131 SEARCH on $(s) = $(HDRS) ;
137 HDRGRIST on $(s) = $(HDRGRIST) ;
138 HDRS on $(s) = $(HDRS) ;
139 HDRRULE on $(s) = [ on $(<) GetVar HDRRULE ] ;
140 HDRSCAN on $(s) = [ on $(<) GetVar HDRPATTERN ] ;
144 if $(JAMVERSION) < 2.5
146 ## XXX XXX XXX a bug in jam 2.4 let's the version above fail. I'll let this
147 ## non-optimal version in here until jam 2.5 is out.
151 local s = $(>:G=$(HDRGRIST:E)) ;
153 Includes $(<) : $(s) ;
154 SEARCH on $(s) = $(HDRS) ;
162 HDRGRIST on $(s) = $(HDRGRIST) ;
163 HDRS on $(s) = $(HDRS) ;
164 HDRRULE on $(s) = $(HDRRULE_$(i:S)) ;
165 HDRSCAN on $(s) = $(HDRPATTERN_$(i:S)) ;
169 #echo "No Header rule for $(i:S) file $(i) " ;
174 } # end of if $(JAMVERSION) < 1.5
176 # Dummy rule: .o files are used as is.
181 RegisterFileType UseObjectFile : .o ;
183 # Ignore header files.
188 RegisterFileType UseHeaderFile : .h .hpp ;
189 RegisterHeaderRule HeaderRule : $(HDRPATTERN) : .h .hpp .inc ;
191 # Generates a grist suitable for output objects based on
192 # SUBVARIANT and SUBDIR variable.
195 return $(<:G=$(SOURCE_GRIST:E)!$(SUBVARIANT)) ;
198 # Generates a grist suitable for source files based on SUBDIR variable.
201 return $(<:G=$(SOURCE_GRIST:E)) ;