4 # handle "C:", "C:/", "/cygdrive" and "/cygdrive/" in Cygwin
7 case "*:" : res = "1" ;
8 case '*:\' : res = "1" ;
10 } else if $(UNIX) && $(OS) = CYGWIN {
12 case "?:" : res = "1" ;
13 case "?:/" : res = "1" ;
14 case "/cygdrive" : res = "1" ;
15 case "/cygdrive/" : res = "1" ;
17 } else if $(<) = "/" || $(<) = $(<:P) {
25 rule RemoveTrailingSlashes {
26 if ! [ IsRootDir $(<[1]) ] {
27 local mt = [ Match '^(.*?)/+$' : $(<[1]) ] ;
28 if $(mt) { return $(mt[1]) ; }
34 rule AddTrailingSlash {
35 local _ttt = $(<[1]) ;
37 if ! ( $(_ttt) ~= '[/]$' ) { _ttt = "$(_ttt)/" ; }
45 # $(2): return empty as "."
46 rule FDirNormalizeDots {
47 local _d = [ RemoveTrailingSlashes $(<) ] ;
50 if $(2) { _d = "." ; } else { _d = ; }
51 } else if ! [ IsRootDir $(_d) ] {
53 local _p = [ RemoveTrailingSlashes $(_d:P) ] ;
56 _d = [ FDirNormalizeDots $(_p) ] ;
58 _d = [ FDirNormalizeDots $(_p) ] ;
60 if $(_d[1]) = "/" && $(_d[1]) = "/" { _d = "" $(_d[2-]) ; }
63 _d = $(_d:J=$(PATH_SEPARATOR)) ;
68 # $(2): return empty as "."
70 local _d = [ RemoveTrailingSlashes $(<) ] ;
72 #Echo "FDirNormalizeI:" "$(_d)" ;
75 if $(2) { _d = "." ; } else { _d = ; }
76 } else if ! [ IsRootDir $(_d) ] {
78 local _p = [ RemoveTrailingSlashes $(_d:P) ] ;
80 # check if we have only 'dotdots' here (fuck windoze and cygwin for now)
81 if $(_p) ~= '^(\.\.?/+)*\.\.?$' {
82 #Echo "DOTDOTS:" "$(_p)" ;
85 if $(_t) = $(DOTDOT) {
87 #Echo "XDOTDOT-I:" "$(_t)" ;
89 if [ IsRootDir $(_p) ] {
90 #Echo "XDOTDOT-R:" "$(_t)" "_p:" "$(_p)" ;
91 if ! $(_p) { _p = $(_t) ; }
92 #Echo "XDOTDOT-X:" "$(_p)" ;
97 _p = [ RemoveTrailingSlashes $(_p:P) ];
98 if $(_t) != $(DOT) { break ; }
100 #Echo "XDOTDOT-O:" "$(_t)" ;
101 _d = [ FDirNormalizeI $(_p) : $(2) ] ;
102 } else if $(_t) = $(DOT) {
104 _d = [ FDirNormalizeI $(_p) : $(2) ] ;
106 _d = [ FDirNormalizeI $(_p) : $(2) ] ;
108 if $(_d[1]) = "/" && $(_d[1]) = "/" { _d = "" $(_d[2-]) ; }
112 # Echo "ROOTDIR:" "$(_d)" ;
114 _d = $(_d:J=$(PATH_SEPARATOR)) ;
119 # $2: return empty dir as "./"?
121 #Echo "FDirNormalize-i:" "$(<)" ;
122 local res = [ FDirNormalizeDots $(<) : $(2) ] ;
123 res = [ FDirNormalizeI $(res) : $(2) ] ;
124 if ! $(res) && $(2) { res = "./" ; }
125 #Echo "FDirNormalize-o:" "$(res)" ;
130 # $2: return empty path as "./"?
131 rule FPathNormalize {
132 #Echo "FPathNormalize-i:" "$(<)" ;
133 local res = [ FDirNormalizeDots $(<) : $(2) ] ;
134 res = [ FDirNormalizeI $(res) : $(2) ] ;
137 res += $(PATH_SEPARATOR) ;
143 #Echo "FPathNormalize-o:" "$(res)" ;
150 # Creates _dir_ and its parent directories
153 # Ignore timestamps on directories: we only care if they exist.
156 # Don't create . or any directory already created.
157 if $(<:G=) != $(DOT) && ! $($(<)-mkdir) {
158 # Cheesy gate to prevent multiple invocations on same dir
159 # Arrange for jam dirs
160 # MkDir1 has the actions
162 Depends dirs : $(<) ;
165 # Recursively make parent directories.
166 # $(<:P) = $(<)'s parent, & we recurse until root
169 if [ IsRootDir $(s) ] { s = ; }
172 # The parent is the same as the dir.
173 # We're at the root, which some OS's can't stat, so we mark
177 # There's a parent; recurse.
178 Depends $(<) : $(s) ;
187 if $(d) && $(d) != $(DOT) && $(d) != $(DOTDOT) && ! $($(<)-mkdir) {
189 #Echo "MkDir0: $(d)" ;
190 d = [ FPathNormalize $(d) : tan ] ;
191 #Echo "MkDir1: $(d)" ;
194 #Echo "MkDir2: $(d)" ;
207 # (Unix and VMS only). Change file permissions on _target_ to target-specific
208 # $(MODE) value set by @Link, @File, @Install* and @Shell rules
211 if $(CHMOD) { Chmod1 $(<) ; }
215 $(CHMOD) $(MODE) $(<)
220 $(CHOWN) $(OWNER) $(<)
224 # /HardLink target : source ;
226 # Makes _target_ a hard link to _source_, if it isn't one already
230 Depends files : $(<) ;
231 Depends $(<) : $(>) ;
232 SEARCH on $(>) = $(SEARCH_SOURCE) ;
237 $(RM) $(<) && $(LN) $(>) $(<)
242 Depends files : $(<) ;
243 Depends $(<) : $(>) ;
244 SEARCH on $(>) = $(SEARCH_SOURCE) ;
249 $(RM) $(<) && $(LN) -s $(>) $(<)
254 Depends shell : $(<) ;
255 Depends $(<) : $(>) ;
256 SEARCH on $(>) = $(SEARCH_SOURCE) ;
257 MODE on $(<) = $(SHELLMODE) ;
265 NR == 1 { print "$(SHELLHEADER)" }
266 NR == 1 && /^[#:]/ { next }
275 MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;
279 # /File target : source ;
281 # Copies _source_ into _target_
284 Depends files : $(<) ;
285 Depends $(<) : $(>) ;
286 SEARCH on $(>) = $(SEARCH_SOURCE) ;
287 MODE on $(<) = $(FILEMODE) ;
296 # /Bulk directory : sources ;
298 # Copies _sources_ into _directory_
304 File $(i:D=$(<)) : $(i) ;
309 rule FileExists names {
310 local _fn _lst _dir _name ;
312 for _fn in $(names) {
313 _dir = [ Match '^(.*?)/[^/]+$' : $(_fn) ] ;
314 _name = [ Match '^.*?/([^/]+)$' : $(_fn) ] ;
315 if ! $(_dir) { _dir = . ; }
316 #Echo "_dir:" $(_dir) ;
317 #Echo "_name:" $(_name) ;
318 _lst = [ Glob $(_dir) : $(_name) : plain files-only ] ;
319 #Echo "_lst:" $(_lst) ;
320 if ! $(_lst) { return ; }
326 rule DirExists names {
327 local _fn _lst _dir _name ;
329 for _fn in $(names) {
330 _dir = [ Match '^(.*?)/[^/]+$' : $(_fn) ] ;
331 _name = [ Match '^.*?/([^/]+)$' : $(_fn) ] ;
332 if ! $(_dir) { _dir = . ; }
333 #Echo "_dir:" $(_dir) ;
334 #Echo "_name:" $(_name) ;
335 _lst = [ Glob $(_dir) : $(_name) : plain dirs-only ] ;
336 #Echo "_lst:" $(_lst) ;
337 if ! $(_lst) { return ; }
343 # build list of files in directory and all subdirs
344 # prepends add file names with $(dir)
345 rule BuildFileList dir : mask {
346 local _lst = [ Glob $(dir) : $(mask) : files-only ] ;
347 local _dirs = [ Glob $(dir) : '[^_.]*' : dirs-only ] ;
350 for _dn in $(_dirs) {
351 #Echo "dir:" $(_dn) ;
352 _l = [ BuildFileList $(_dn) : $(mask) ] ;