1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # returns '_' for 'selftarget'
17 rule --MainNormalizeTargets-- {
19 if ! $(_ctt) { _ctt = exe ; }
20 else if $(_ctt) = $(1) { _ctt = '_' ; }
25 # /--MainFromObjects-- image : objects : targets : linkrule : origlist ;
27 # Links _objects_ into _image_. Dependency of exe.
28 # @MainFromObjects provides a default suffix for _image_
30 rule --MainFromObjects-- {
31 local objlist tgts have_attrs ;
34 # check if we have attributes
35 have_attrs = [ --main-preprocess-attrs-- $(>) ] ;
36 objlist = $(have_attrs[2-]) ;
37 have_attrs = $(have_attrs[1]) ;
40 tgts = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
41 # so 'jam foo' works when it's really foo.exe
43 Depends $(<) : $(tgts) ;
47 #Echo 'MainFromObjects: tgts:' "$(tgts)" '_ctt:' "$(_ctt)" ;
49 # make compiled sources a dependency of target
51 for local tgtname in $(_ctt) {
52 #Echo 'separate target:' "$(tgtname)" ;
53 Depends $(tgtname) : $(tgts) ;
54 Clean $(tgtname)_clean : $(tgts) ;
55 Depends $(tgtname)_clean : clean ;
58 #Echo 'separate target:' "$(tgts)" ;
59 Clean $(tgts)_clean : $(tgts) ;
60 Depends $(tgts)_clean : clean ;
62 #Depends exe : $(tgts) ;
63 Depends $(tgts) : $(objlist) ;
64 #k8:MakeLocate $(tgts) : $(LOCATE_TARGET) ;
65 MakeLocate $(tgts) : $(LOCATE_BIN) ;
66 Clean clean : $(tgts) ;
68 # special case for stupid Borland C++, which always generates a
69 # .tds file for executables, even when no debug information is needed
71 #if $(JAM_TOOLSET) = BORLANDC {
72 # MakeLocate $(tgts:S=.tds) : $(LOCATE_TARGET) ;
73 # Clean clean : $(tgts:S=.tds) ;
76 $(4) $(tgts) : $(objlist) ;
78 if $(have_attrs) { return [ --main-postprocess-attrs-- $(5) ] ; }
83 # /Main image : sources [ : targets ] ;
85 # Compiles _sources_ and links them into _image_. Calls @Objects and
88 # _image_ may be supplied without suffix.
93 # detect which main we want
94 for local fn in $(2) {
95 if ! ( $(fname) ~= '^![^!]' ) {
96 #Echo "ext:" $(fn:S) ;
98 if $(ext) = '.d' { detected = Gdc-Main ; }
99 else if $(ext) = '.c' { detected = C-Main ; }
100 else if $(ext) = 'C' { detected = C++Main ; }
101 else if $(ext) ~= '/^\.c++/i' { detected = C++Main ; }
102 else if $(ext) ~= '/^\.cc/i' { detected = C++Main ; }
103 else if $(ext) ~= '/^\.cpp/i' { detected = C++Main ; }
104 else { detected = ; }
105 #Echo " detected:" $(detected) ;
106 #Echo " main_name:" $(main_name) ;
109 main_name = $(detected) ;
110 } else if $(detected) != $(main_name) {
111 # two languages detected
112 if $(detected) == 'C-Main' {
113 # it's ok to mix C and C++
114 if $(main_name) != 'C++Main' { Exit "Main: conflicting languages for $(1)" ; }
115 } else if $(detected) == 'C++Main' {
116 # it's ok to mix C and C++
117 if $(main_name) != 'C-Main' { Exit "Main: conflicting languages for $(1)" ; }
118 main_name = 'C++Main' ;
120 Exit "Main: can't detect language for $(1)" ;
126 #Echo "main_name:" $(main_name) ;
127 if ! $(main_name) { Exit "Main: can't detect language for $(1)" ; }
128 #Echo "Main detected:" $(main_name) ;
139 . Jambase.main.libboth