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/>.
15 # handle "C:", "C:/", "/cygdrive" and "/cygdrive/" in Cygwin
18 case "*:" : return 1 ;
19 case '*:\' : return 1 ;
21 } else if $(UNIX) && $(OS) = CYGWIN {
23 case "?:" : return 1 ;
24 case "?:/" : return 1 ;
25 case "/cygdrive" : return 1 ;
26 case "/cygdrive/" : return 1 ;
28 } else if $(<:G=:R=) = "/" || $(<) = $(<:D) {
35 rule RemoveTrailingSlashes {
36 if ! [ IsRootDir $(<[1]) ] {
37 local mt = [ Match '^(.*?)/+$' : $(<[1]) ] ;
38 if $(mt) { return $(mt[1]) ; }
44 rule AddTrailingSlash {
45 local _ttt = $(<[1]) ;
47 if ! ( $(_ttt) ~= '[/]$' ) { _ttt = "$(_ttt)/" ; }
55 # $2: return empty path as "./"?
57 #Echo "FPathNormalize-i:" $(<) "$2:" $(2) ;
58 local res = [ NormalizePath $(<[1]) : "" ] ;
59 if $(2) && ! $(res) { return "./" ; }
61 res = [ AddTrailingSlash $(res) ] ;
62 if $(res) ~= '^[^/]' { res = "./$(res)" ; }
64 #Echo "FPathNormalize-o:" $(res) ;
71 # Creates _dir_ and its parent directories
74 # Ignore timestamps on directories: we only care if they exist.
76 # Don't create . or any directory already created.
77 if $(<:G=) != $(DOT) && ! $($(<)-mkdir) {
78 # Cheesy gate to prevent multiple invocations on same dir
79 # Arrange for jam dirs
80 # MkDir1 has the actions
84 # Recursively make parent directories.
85 # $(<:P) = $(<)'s parent, & we recurse until root
87 if [ IsRootDir $(s) ] { s = ; }
89 # The parent is the same as the dir.
90 # We're at the root, which some OS's can't stat, so we mark it as NotFile.
93 # There's a parent; recurse.
103 if $(d) && $(d) != $(DOT) && $(d) != $(DOTDOT) && ! $($(<)-mkdir) {
105 #Echo "MkDir0: $(d)" ;
106 d = [ FPathNormalize $(d) : tan ] ;
107 #Echo "MkDir1: $(d)" ;
110 #Echo "MkDir2: $(d)" ;
122 # (Unix and VMS only). Change file permissions on _target_ to target-specific
123 # $(MODE) value set by @Link, @File, @Install* and @Shell rules
126 if $(CHMOD) { Chmod1 $(<) ; }
130 $(CHMOD) $(MODE) $(<)
135 $(CHOWN) $(OWNER) $(<)
139 # /HardLink target : source ;
141 # Makes _target_ a hard link to _source_, if it isn't one already
145 Depends files : $(<) ;
146 Depends $(<) : $(>) ;
147 SEARCH on $(>) = $(SEARCH_SOURCE) ;
152 $(RM) $(<) && $(LN) $(>) $(<)
157 Depends files : $(<) ;
158 Depends $(<) : $(>) ;
159 SEARCH on $(>) = $(SEARCH_SOURCE) ;
164 $(RM) $(<) && $(LN) -s $(>) $(<)
169 Depends shell : $(<) ;
170 Depends $(<) : $(>) ;
171 SEARCH on $(>) = $(SEARCH_SOURCE) ;
172 MODE on $(<) = $(SHELLMODE) ;
177 # "dont-touch" thingy is THE comment for mkjambase
181 NR == 1 { print "$(SHELLHEADER)" }
182 NR == 1 && /^[#:]/ { next }
191 MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;
195 # /File target : source ;
197 # Copies _source_ into _target_
200 Depends files : $(<) ;
201 Depends $(<) : $(>) ;
202 SEARCH on $(>) = $(SEARCH_SOURCE) ;
203 MODE on $(<) = $(FILEMODE) ;
212 # /Bulk directory : sources ;
214 # Copies _sources_ into _directory_
217 for local i in $(>) {
218 File $(i:D=$(<)) : $(i) ;
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 ; }
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 ; }
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) ] ;