Main renamed to C-Main; new Main now will try to detect language
[k8jam.git] / defaults / main / Jambase.main
blob88669db8392414ead316c1633880d83d4eaf56c5
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/>.
14 # $(1): image
15 # $(2): target list
16 # returns '_' for 'selftarget'
17 rule --MainNormalizeTargets-- {
18   local _ctt = $(2) ;
19   if ! $(_ctt) { _ctt = exe ; }
20   else if $(_ctt) = $(1) { _ctt = '_' ; }
21   return $(_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 ;
32   local _ctt = $(3) ;
34   # check if we have attributes
35   have_attrs = [ --main-preprocess-attrs-- $(>) ] ;
36   objlist = $(have_attrs[2-]) ;
37   have_attrs = $(have_attrs[1]) ;
39   # Add suffix to exe
40   tgts = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
41   # so 'jam foo' works when it's really foo.exe
42   if $(tgts) != $(<) {
43     Depends $(<) : $(tgts) ;
44     NotFile $(<) ;
45   }
47   #Echo 'MainFromObjects: tgts:' "$(tgts)" '_ctt:' "$(_ctt)" ;
49   # make compiled sources a dependency of target
50   if $(_ctt) != '_' {
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 ;
56     }
57   } else {
58     #Echo 'separate target:' "$(tgts)" ;
59     Clean $(tgts)_clean : $(tgts) ;
60     Depends $(tgts)_clean : clean ;
61   }
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
70   #
71   #if $(JAM_TOOLSET) = BORLANDC {
72   #  MakeLocate $(tgts:S=.tds) : $(LOCATE_TARGET) ;
73   #  Clean clean : $(tgts:S=.tds) ;
74   #}
76   $(4) $(tgts) : $(objlist) ;
78   if $(have_attrs) { return [ --main-postprocess-attrs-- $(5) ] ; }
79   return $(5) ;
83 # /Main image : sources [ : targets ] ;
85 # Compiles _sources_ and links them into _image_. Calls @Objects and
86 # @MainFromObjects.
88 # _image_ may be supplied without suffix.
90 rule Main {
91   local main_name = ;
92   local detected ;
93   # detect which main we want
94   for local fn in $(2) {
95     if ! ( $(fname) ~= '^![^!]' ) {
96       #Echo "ext:" $(fn:S) ;
97       local 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) ;
107       if $(detected) {
108         if ! $(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' ;
119           } else {
120             Exit "Main: can't detect language for $(1)" ;
121           }
122         }
123       }
124     }
125   }
126   #Echo "main_name:" $(main_name) ;
127   if ! $(main_name) { Exit "Main: can't detect language for $(1)" ; }
128   #Echo "Main detected:" $(main_name) ;
129   $(main_name) ;
133 . Jambase.main.attrs
134 . Jambase.main.c
135 . Jambase.main.cpp
136 . Jambase.main.objc
137 . Jambase.main.lib
138 . Jambase.main.libso
139 . Jambase.main.libboth
140 . Jambase.main.gdc