added "C++FLAGS.all" (and "OBJCFLAGS.all"); "CFLAGS.all" is still in effect
[k8jam.git] / defaults / misc / Jambase.misc.fsys
blob8824879593fde2899b9344cd620340922a48cbd2
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 rule IsRootDir {
14   # handle 'C:', 'C:/', '/cygdrive' and '/cygdrive/' in Cygwin
15   if $(NT) {
16     switch $(<:G=:R=) {
17       case '*:'  : return 1 ;
18       case '*:\' : return 1 ;
19     }
20   } else if $(UNIX) && $(OS) = CYGWIN {
21     switch $(<:G=:R=) {
22       case '?:'  : return 1 ;
23       case '?:/' : return 1 ;
24       case '/cygdrive'  : return 1 ;
25       case '/cygdrive/' : return 1 ;
26     }
27   } else if $(<:G=:R=) = '/' || $(<) = $(<:D) {
28     return 1 ;
29   }
30   return ; # empty list
34 rule RemoveTrailingSlashes {
35   if ! [ IsRootDir $(<[1]) ] {
36     local mt = [ Match '^(.*?)/+$' : $(<[1]) ] ;
37     if $(mt) { return $(mt[1]) ; }
38   }
39   return $(<[1]) ;
43 rule AddTrailingSlash {
44   local _ttt = $(<[1]) ;
45   if $(_ttt) {
46     if ! ( $(_ttt) ~= '[/]$' ) { _ttt = "$(_ttt)/" ; }
47   } else {
48     _ttt = "" ;
49   }
50   return $(_ttt) ;
54 # $2: return empty path as './'?
55 rule FPathNormalize {
56   #Echo 'FPathNormalize-i:' $(<) '$2:' $(2) ;
57   local res = [ NormalizePath $(<[1]) : "" ] ;
58   #Echo ' FPathNormalize-x:' $(res) ;
59   if $(2) && ! $(res) { return './' ; }
60   if $(res) {
61     res = [ AddTrailingSlash $(res) ] ;
62     #if $(res) ~= '^[^/]' && ! ( $(res) ~= '^\.\.?/' ) { res = "./$(res)" ; }
63   }
64   #Echo 'FPathNormalize-o:' $(res) ;
65   return $(res) ;
69 # /MkDir  dir ;
71 # Creates _dir_ and its parent directories
73 rule MkDirI {
74   #Echo 'MkDirI:' $(<) ;
75   # Ignore timestamps on directories: we only care if they exist.
76   NoUpdate $(<) ;
77   # Don't create . or any directory already created.
78   if $(<:G=) != '.' && ! $($(<)-mkdir) {
79     # Cheesy gate to prevent multiple invocations on same dir
80     # Arrange for jam dirs
81     # MkDir1 has the actions
82     $(<)-mkdir = true ;
83     Depends dirs : $(<) ;
84     MkDir1 $(<) ;
85     # Recursively make parent directories.
86     # $(<:P) = $(<)'s parent, & we recurse until root
87     local s = $(<:GRD) ;
88     #Echo 's:' $(s) ;
89     if [ IsRootDir $(s) ] { s = ; }
90     if $(s) = $(<) {
91       # The parent is the same as the dir.
92       # We're at the root, which some OS's can't stat, so we mark it as NotFile.
93       NotFile $(s) ;
94     } else if $(s:G=) {
95       # There's a parent; recurse.
96       Depends $(<) : $(s) ;
97       MkDirI $(s) ;
98     }
99   }
102 rule MkDir {
103   #Echo 'MkDir:' $(<) ;
104   local d = [RemoveTrailingSlashes $(<:G=) ] ;
105   NoUpdate $(<) ;
106   if $(d) && $(d) != '.' && $(d) != '..' && ! $($(<)-mkdir) {
107     d = [ FPathNormalize $(d) : tan ] ;
108     if $(d) ~= '^[^/]' && ! ( $(d) ~= '^\.\.?/' ) { d = "./$(d)" ; }
109     #Echo 'MkDirX:' $(d) ;
110     #Echo 'MkDirY:' $(d:G=$(<:G)) ;
111     MkDirI $(d:G=$(<:G)) ;
112   }
115 actions MkDir1 {
116   $(MKDIR) $(<)
120 # /Chmod target ;
122 # (Unix and VMS only). Change file permissions on _target_ to target-specific
123 # $(MODE) value set by @Link, @File, @Install* and @Shell rules
125 rule Chmod {
126   if $(CHMOD) { Chmod1 $(<) ; }
129 actions Chmod1 {
130   $(CHMOD) $(MODE) $(<)
134 actions Chown {
135   $(CHOWN) $(OWNER) $(<)
139 # /HardLink target : source ;
141 # Makes _target_ a hard link to _source_, if it isn't one already
142 # (Unix only)
144 rule HardLink {
145   Depends files : $(<) ;
146   Depends $(<) : $(>) ;
147   SEARCH on $(>) = $(SEARCH_SOURCE) ;
151 actions HardLink {
152   $(RM) $(<) && $(LN) $(>) $(<)
156 rule SoftLink {
157   Depends files : $(<) ;
158   Depends $(<) : $(>) ;
159   SEARCH on $(>) = $(SEARCH_SOURCE) ;
160   Clean clean : $(<) ;
163 actions SoftLink {
164   $(RM) $(<) && $(LN) -s $(>) $(<)
168 rule Shell {
169   Depends shell : $(<) ;
170   Depends $(<) : $(>) ;
171   SEARCH on $(>) = $(SEARCH_SOURCE) ;
172   MODE on $(<) = $(SHELLMODE) ;
173   Clean clean : $(<) ;
174   Chmod $(<) ;
177 # 'dont-touch' thingy is THE comment for mkjambase
178 #DONT_TOUCH
179 actions Shell {
180   $(AWK) '
181     NR == 1 { print "$(SHELLHEADER)" }
182     NR == 1 && /^[#:]/ { next }
183     /^##/ { next }
184     { print }
185   ' < $(>) > $(<)
187 #DONT_TOUCH
190 rule Setuid {
191   MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;
195 # /File target : source ;
197 # Copies _source_ into _target_
199 rule File {
200   Depends files : $(<) ;
201   Depends $(<) : $(>) ;
202   SEARCH on $(>) = $(SEARCH_SOURCE) ;
203   MODE on $(<) = $(FILEMODE) ;
204   Chmod $(<) ;
207 actions File {
208   $(CP) $(>) $(<)
212 # /Bulk  directory : sources ;
214 # Copies _sources_ into _directory_
216 rule Bulk {
217   for local i in $(>) {
218     File $(i:D=$(<)) : $(i) ;
219   }
223 rule FileExists names {
224   for local _fn in $(names) {
225     local _dir = [ Match '^(.*?)/[^/]+$' : $(_fn) ] ;
226     local _name = [ Match '^.*?/([^/]+)$' : $(_fn) ] ;
227     if ! $(_dir) { _dir = '.' ; }
228     if ! ( [ Glob $(_dir) : $(_name) : plain files-only ] ) { return ; }
229   }
230   return 'tan' ;
234 rule DirExists names {
235   for local _fn in $(names) {
236     local _dir = [ Match '^(.*?)/[^/]+$' : $(_fn) ] ;
237     local _name = [ Match '^.*?/([^/]+)$' : $(_fn) ] ;
238     if ! $(_dir) { _dir = '.' ; }
239     if ! ( [ Glob $(_dir) : $(_name) : plain dirs-only ] ) { return ; }
240   }
241   return 'tan' ;
245 # build list of files in directory and all subdirs
246 # prepends all file names with $(dir)
247 rule BuildFileList dir : mask {
248   local _lst = [ Glob $(dir) : $(mask) : files-only ] ;
249   local _dirs = [ Glob $(dir) : '[^_.]*' : dirs-only ] ;
250   for local _dn in $(_dirs) {
251     local _l = [ BuildFileList $(_dn) : $(mask) ] ;
252     _lst += $(_l) ;
253   }
254   return $(_lst) ;