oops, i accidentally "-Wall" in profile setup
[k8jam.git] / defaults / misc / Jambase.misc
blob5322c7966d1fd8560e962638bd70c0e737ebce12
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, version 3 of the License ONLY.
5 # This program is distributed in the hope that it will be useful,
6 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8 # GNU General Public License for more details.
10 # You should have received a copy of the GNU General Public License
11 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
13 # miscelaneous helper rules
16 # Utility rules; no side effects on these
19 # /FGrist path to file ;
21 # Returns a single string that is used as grist
23 rule FGrist {
24   return $(<:J=!) ;
28 rule FGristFiles {
29   return $(<:G=$(SOURCE_GRIST:E)) ;
33 ## LOCAL CHANGE: OPT_HEADER_CACHE_EXT
34 # With header caching, there is no performance penalty to gristing
35 # header files. It is also not correct to assume that header
36 # files have global visibility.
38 # So FGristSourceFiles is the same as FGristFiles
39 #rule FGristSourceFiles
42 rule FSubDir {
43   # If $(<) is the path to the current directory, compute the
44   # path (using ../../ etc) back to that root directory.
45   if ! $(<[1]) {
46     return '.' ;
47   } else {
48     local _d = '..' ;
49     for local _i in $(<[2-]) { _d = $(_d:R='..') ; }
50     return $(_d) ;
51   }
54 # /FStripCommon v1 : v2 ;
56 # Strip common initial elements of variables v1 and v2.
57 # Modifies the variable values themselves.
58 rule FStripCommon {
59   if $($(<)[1]) && $($(<)[1]) = $($(>)[1]) {
60     $(<) = $($(<)[2-]) ;
61     $(>) = $($(>)[2-]) ;
62     FStripCommon $(<) : $(>) ;
63   }
67 rule FRelPath {
68   local _l _r ;
69   # first strip off common parts
70   _l = $(<) ;
71   _r = $(>) ;
72   FStripCommon _l : _r ;
73   # now make path to root and path down
74   _l = [ FSubDir $(_l) ] ;
75   _r = [ FDirName $(_r) ] ;
76   # Concatenate and save
77   # XXX This should be better
78   if $(_r) = '.' { return $(_l) ; } else { return $(_r:R=$(_l)) ; }
82 rule FAppendSuffix {
83   # E.g., "FAppendSuffix yacc lex foo.bat : $(SUFEXE) ;"
84   # returns (yacc,lex,foo.bat) on Unix and
85   # (yacc.exe,lex.exe,foo.bat) on NT.
86   if $(>) {
87     local _o = ;
88     for local _i in $(<) {
89       if $(_i:S) { _o += $(_i) ; } else { _o += $(_i:S=$(>)) ; }
90     }
91     return $(_o) ;
92   } else {
93     return $(<) ;
94   }
99 # Operating system specific utility rules
100 # First, the (generic) UNIX versions
103 rule FDefines { return -D$(<) ; }
104 rule FIncludes { return -I$(<) ; }
105 rule FDIncludes { return -J$(<) ; }
107 rule FDirName {
108   # Turn individual elements in $(<) into a usable path.
109   local _s = '.' ;
110   for local _i in $(<) { _s = $(_i:R=$(_s)) ; }
111   return $(_s) ;
115 if $(NT) && $(JAM_TOOLSET) != MINGW && $(JAM_TOOLSET) != LCC {
116   rule FDefines { return /D$(<) ; }
117   rule FIncludes { return /I$(<) ; }
121 rule sys-has-command {
122   if [ Command "which $(1:Q) 2>/dev/null 1>&2" ] {
123     return ;
124   } else {
125     return 'tan' ;
126   }
130 rule Undefines {
131   UNDEFS on [ FAppendSuffix $(<) : $(SUFEXE) ] += $(UNDEFFLAG)$(>) ;
135 rule IsGCC {
136   #if ( 'gcc' in $(CC) ) || ( $(JAM_TOOLSET) = MINGW ) { return 'tan'; }
137   if ( ( $(CC) ~= '\bgcc$' ) || ( $(JAM_TOOLSET) = MINGW ) ) { return 'tan'; }
138   return ;
142 rule IsG++ {
143   #if ( 'g++' in $(C++) ) || ( $(JAM_TOOLSET) = MINGW ) { return 'tan'; }
144   if ( ( $(CC) ~= '\bg\+\+$' ) || ( $(JAM_TOOLSET) = MINGW ) ) { return 'tan'; }
145   return ;
149 rule JoinAndRemoveSpaces str {
150   str = $(str:J) ;
151   while tan {
152     local pn = [ Match '^(.*)\s+(.*)$' : $(str) ] ;
153     if $(pn) {
154       str = $(pn[1]) $(pn[2]) ;
155       str = $(str:J) ;
156     } else {
157       return $(str) ;
158     }
159   }
163 # adds "all" if JAM_TARGETS becomes empty
164 # $(1): target name
165 rule RemoveJamTarget {
166   local newtgt _t ;
167   newtgt = ;
168   for _t in $(JAM_TARGETS) {
169     if $(_t) = $(1) {
170       # nothing to do
171     } else {
172       newtgt += $(_t) ;
173     }
174   }
175   if $(newtgt) = "" { newtgt = "all" ; }
176   JAM_TARGETS = $(newtgt) ;
180 rule CompareVersions a : b {
181   local spa = [ Split $(a) : "." ] ;
182   local spb = [ Split $(b) : "." ] ;
183   local alen = [ ListLength $(spa) ] ;
184   local blen = [ ListLength $(spb) ] ;
185   local cnt = 1 ;
186   local v0 = '' ;
187   local v1 = '' ;
189   while tan {
190     if [ ExprI1 $(cnt) ">" $(alen) ] {
191       if [ ExprI1 $(cnt) ">" $(blen) ] {
192         # equal
193         return '0' ;
194       }
195       # b is longer, so a is lesser
196       return '-1' ;
197     } else if [ ExprI1 $(cnt) ">" $(blen) ] {
198       # b is shorter, so a is greater
199       return '1' ;
200     }
203     v0 = $(spa[$(cnt)]) ;
204     v1 = $(spb[$(cnt)]) ;
206     if [ ExprI1 $(v0) "<" $(v1) ] {
207       return '-1' ;
208     }
209     if [ ExprI1 $(v0) ">" $(v1) ] {
210       return '1' ;
211     }
212     # equal
214     cnt = [ ExprI1 $(cnt) + 1 ] ;
215   }
219 . Jambase.misc.fsys
220 . Jambase.misc.opts