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/>.
14 # handle 'C:', 'C:/', '/cygdrive' and '/cygdrive/' in Cygwin
17 case '*:' : return 1 ;
18 case '*:\' : return 1 ;
20 } else if $(UNIX) && $(OS) = CYGWIN {
22 case '?:' : return 1 ;
23 case '?:/' : return 1 ;
24 case '/cygdrive' : return 1 ;
25 case '/cygdrive/' : return 1 ;
27 } else if $(<:G=:R=) = '/' || $(<) = $(<:D) {
34 rule RemoveTrailingSlashes {
35 if ! [ IsRootDir $(<[1]) ] {
36 local mt = [ Match '^(.*?)/+$' : $(<[1]) ] ;
37 if $(mt) { return $(mt[1]) ; }
43 rule AddTrailingSlash {
44 local _ttt = $(<[1]) ;
46 if ! ( $(_ttt) ~= '[/]$' ) { _ttt = "$(_ttt)/" ; }
54 # $2: return empty path as './'?
56 #Echo 'FPathNormalize-i:' $(<) '$2:' $(2) ;
57 local res = [ NormalizePath $(<[1]) : "" ] ;
58 #Echo ' FPathNormalize-x:' $(res) ;
59 if $(2) && ! $(res) { return './' ; }
61 res = [ AddTrailingSlash $(res) ] ;
62 #if $(res) ~= '^[^/]' && ! ( $(res) ~= '^\.\.?/' ) { res = "./$(res)" ; }
64 #Echo 'FPathNormalize-o:' $(res) ;
71 # Creates _dir_ and its parent directories
74 #Echo 'MkDirI:' $(<) ;
75 # Ignore timestamps on directories: we only care if they exist.
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
85 # Recursively make parent directories.
86 # $(<:P) = $(<)'s parent, & we recurse until root
89 if [ IsRootDir $(s) ] { 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.
95 # There's a parent; recurse.
103 #Echo 'MkDir:' $(<) ;
104 local d = [RemoveTrailingSlashes $(<:G=) ] ;
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)) ;
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) ] ;