X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=mk%2Fjam%2Fobjects.jam;h=03b006b94c0121b7e9083c8a1d7f8a9ac83b81b0;hb=c62a9b627722f6371877c4dcbc218c60edb58559;hp=aeec2506ee41d932ece746747eb33998c9399c52;hpb=6fe1f3519eecbbb75eca97c45a6697eee36b2442;p=supertux.git diff --git a/mk/jam/objects.jam b/mk/jam/objects.jam index aeec2506e..03b006b94 100644 --- a/mk/jam/objects.jam +++ b/mk/jam/objects.jam @@ -10,9 +10,9 @@ ## RegisterFileType Rulename : extensions ## Register a rule which is used to compile a filetype into object ## files. The registered rule is called with the name of the -## sourcefile as argument and should return a list of objectfiles which are -## created. You should set the grist of the object files by using the -## DoObjectGrist function. +## sourcefile as argument (completely gristed and SEARCH is set already). +## The rule should return the object files created completely gristed and +## with LOCATE set (use the LocateTarget rule to do this). rule RegisterFileType { local suffix ; @@ -36,28 +36,23 @@ rule RegisterHeaderRule } ## CompileObjects sources [ : options ] -## Compile a set of sourcefiles into objectfiles (extension: SUFOBJ, -## usually .o). This rule takes care of setting LOCATE and SEARCH -## variables to the $(SEARCH_SOURCE) and $(LOCATE_SOURCE) variables. -## The Application, Plugin and Library rules already use this rule -## internally. You should only use this rule if you have to avoid the -## Application, Plugin or Library rules. +## Compile a set of sourcefiles into objectfiles (usually .o extension). +## For ungristed sourcefiles $(SEARCH) will be set to $(SEARCH_SOURCE). +## The function returns the names of the targets being built (gristed and +## with LOCATE set. +## Normally you don't have to use this rule. The Application or Library rules +## are taking care of calling it for you. rule CompileObjects { - local source ; + local s ; + local sources = [ SearchSource $(<) ] ; local targets ; - # Search the source - SEARCH on $(<) = $(SEARCH_SOURCE) ; - - for source in $(<) + for s in $(sources) { # compile the sourcefile to targetfile - targets += [ CompileObject $(source) : $(2) ] ; + targets += [ CompileObject $(s) : $(2) ] ; } - - # locate the targets - MakeLocate $(targets) : $(LOCATE_TARGET) ; return $(targets) ; } @@ -66,44 +61,37 @@ rule CompileObjects # private part # CompileObject sourcefile [ : options ] -# helper rule: Compiles a source file to an object file. Does header file -# scanning, sets LOCATE and SEARCH for source and target, grists the files -# with the current subdir and searches for the correct registered rule. +# helper rule: Compiles a source file to an object file. The source should be +# correctly gristed and SEARCH should be set. The function will return the +# target names gristed and with LOCATE set. rule CompileObject { # handle #includes for source: Jam scans for headers with # the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE) # with the scanned file as the target and the found headers # as the sources. HDRSEARCH is the value of SEARCH used for - # the found header files. Finally, if jam must deal with - # header files of the same name in different directories, - # they can be distinguished with HDRGRIST. + # the found header files. # $(SEARCH_SOURCE:E) is where cc first looks for #include # "foo.h" files. If the source file is in a distant directory, # look there. Else, look in "" (the current directory). if $(HDRRULE_$(<:S)) { - HDRS on $(<) = [ ConcatDirs $(SUBDIR) $(<:D) ] - $(SEARCH_SOURCE:E) $(HDRS) $(STDHDRS) ; - HDRGRIST on $(<) = $(HDRGRIST) ; + HDRSEARCH on $(<) = $(SEARCH_SOURCE:E) $(HDRSEARCH) $(STDHDRSEARCH) ; + SEARCH_SOURCE on $(<) = $(SEARCH_SOURCE) ; HDRRULE on $(<) = $(HDRRULE_$(<:S)) ; HDRSCAN on $(<) = $(HDRPATTERN_$(<:S)) ; } local targets ; # Invoke filetype specific rule - if $(FILETYPE_$(<:S)) - { + if $(FILETYPE_$(<:S)) { targets = [ $(FILETYPE_$(<:S)) $(<) : $(2) ] ; - } - else - { - echo "Warning: no rules for filetype $(>:S) defined (at file $(>))." ; + } else { + echo "Warning: no rules for filetype $(<:S) defined (at file $(<))." ; } - if $(targets) - { + if $(targets) { # construct clean target Clean clean : $(targets) ; } @@ -125,54 +113,29 @@ rule HeaderRule # set SEARCH so Jam can find the headers, but then say we don't # care if we can't actually find the headers (they may have been # within ifdefs), - local s = $(>:G=$(HDRGRIST:E)) ; - - Includes $(<) : $(s) ; - SEARCH on $(s) = $(HDRS) ; - NoCare $(s) ; - - local i ; - for i in $(s) - { - HDRGRIST on $(s) = $(HDRGRIST) ; - HDRS on $(s) = $(HDRS) ; - HDRRULE on $(s) = [ on $(<) GetVar HDRRULE ] ; - HDRSCAN on $(s) = [ on $(<) GetVar HDRPATTERN ] ; - } -} - -if $(JAMVERSION) < 2.5 -{ -## XXX XXX XXX a bug in jam 2.4 let's the version above fail. I'll let this -## non-optimal version in here until jam 2.5 is out. + local HDRSEARCH = [ on $(<) GetVar HDRSEARCH ] ; + local SEARCH_SOURCE = [ on $(<) GetVar SEARCH_SOURCE ] ; -rule HeaderRule -{ - local s = $(>:G=$(HDRGRIST:E)) ; + Includes $(<) : $(>) ; + SEARCH on $(>) = $(HDRSEARCH) $(SEARCH_SOURCE)/$(<:D) ; + NoCare $(>) ; - Includes $(<) : $(s) ; - SEARCH on $(s) = $(HDRS) ; - NoCare $(s) ; - local i ; - for i in $(s) + for i in $(>) { - if $(HDRRULE_$(i:S)) - { - HDRGRIST on $(s) = $(HDRGRIST) ; - HDRS on $(s) = $(HDRS) ; - HDRRULE on $(s) = $(HDRRULE_$(i:S)) ; - HDRSCAN on $(s) = $(HDRPATTERN_$(i:S)) ; - } - else if $(JAM_DEBUG) - { - #echo "No Header rule for $(i:S) file $(i) " ; + + SEARCH on $(>) = $(HDRSEARCH) $(SEARCH_SOURCE)/$(<:D) ; + if $(i:D) = "" { + SEARCH_SOURCE on $(i) = $(SEARCH_SOURCE)/$(<:D) ; + } else { + SEARCH_SOURCE on $(i) = $(SEARCH_SOURCE) ; } + HDRSEARCH on $(>) = $(HDRSEARCH) ; + HDRRULE on $(>) = [ on $(<) GetVar HDRRULE ] ; + HDRSCAN on $(>) = [ on $(<) GetVar HDRPATTERN ] ; } } -} # end of if $(JAMVERSION) < 1.5 - # Dummy rule: .o files are used as is. rule UseObjectFile { @@ -188,16 +151,42 @@ rule UseHeaderFile RegisterFileType UseHeaderFile : .h .hpp ; RegisterHeaderRule HeaderRule : $(HDRPATTERN) : .h .hpp .inc ; -# Generates a grist suitable for output objects based on -# SUBVARIANT and SUBDIR variable. -rule DoObjectGrist +## SearchSource +## Sets search path of the sourcefiles to the current SUBDIR and sets a +## suitable grist on the sources. Ignores source files that already have +## grist set. +rule SearchSource { - return $(<:G=$(SOURCE_GRIST:E)!$(SUBVARIANT)) ; + local sources ; + + for f in $(<) { + if $(f:G) { + sources += $(f) ; + } else { + local source = $(f:G=$(SOURCE_GRIST:E)) ; + sources += $(source) ; + SEARCH on $(source) = $(SEARCH_SOURCE) ; + } + } + return $(sources) ; } -# Generates a grist suitable for source files based on SUBDIR variable. -rule DoSourceGrist +## LocateTarget +## Sets LOCATE on the current output directory (depending on builddir, +## variant and current subdir), sets a suitable grist and makes sure the +## target directory is created if it doesn't exist. +rule LocateTarget { - return $(<:G=$(SOURCE_GRIST:E)) ; + local targetdir ; + if $(>) { + targetdir = $(>) ; + } else { + targetdir = $(LOCATE_TARGET) ; + } + + local targets = $(<:G=T!$(SOURCE_GRIST:E)!$(SUBVARIANT)) ; + MakeLocate $(targets) : $(targetdir) ; + + return $(targets) ; }