rules IncFile and BuildFileList moved to Jambase
[k8jam.git] / defaults / misc / fsys / Jambase.misc.fsys
blob143e7f80d049e75ae2830146d2687fcad721cef0
1 # /MkDir  dir ;
3 # Creates _dir_ and its parent directories
5 rule MkDir {
6   # Ignore timestamps on directories: we only care if they exist.
7   NoUpdate $(<) ;
9   # Don't create . or any directory already created.
10   if $(<:G=) != $(DOT) && ! $($(<)-mkdir) {
11     # Cheesy gate to prevent multiple invocations on same dir
12     # Arrange for jam dirs
13     # MkDir1 has the actions
14     $(<)-mkdir = true ;
15     Depends dirs : $(<) ;
16     MkDir1 $(<) ;
18     # Recursively make parent directories.
19     # $(<:P) = $(<)'s parent, & we recurse until root
20     local s = $(<:P) ;
22     # Don't try to create A: or A:\ on windows
23     if $(NT) {
24       switch $(s) {
25         case "*:"   : s = ;
26         case "*:\\" : s = ;
27       }
28     }
29     # handle "C:", "C:/", "/cygdrive" and "/cygdrive/" in Cygwin
30     if $(UNIX) && $(OS) = CYGWIN {
31       switch $(s) {
32         case "?:"   : s = ;
33         case "?:/"  : s = ;
34         case "<dir>/cygdrive"   : s = ;
35         case "<dir>/cygdrive/"  : s = ;
36       }
37     }
39     if $(s) = $(<) {
40       # The parent is the same as the dir.
41       # We're at the root, which some OS's can't stat, so we mark
42       # it as NotFile.
43       NotFile $(s) ;
44     } else if $(s:G=) {
45       # There's a parent; recurse.
46       Depends $(<) : $(s) ;
47       MkDir $(s) ;
48     }
49   }
52 actions MkDir1 {
53   $(MKDIR) $(<)
57 actions Chgrp {
58   $(CHGRP) $(GROUP) $(<)
62 # /Chmod target ;
64 # (Unix and VMS only). Change file permissions on _target_ to target-specific
65 # $(MODE) value set by @Link, @File, @Install* and @Shell rules
67 rule Chmod {
68   if $(CHMOD) { Chmod1 $(<) ; }
71 actions Chmod1 {
72   $(CHMOD) $(MODE) $(<)
76 actions Chown {
77   $(CHOWN) $(OWNER) $(<)
81 # /HardLink target : source ;
83 # Makes _target_ a hard link to _source_, if it isn't one already
84 # (Unix only)
86 rule HardLink {
87   Depends files : $(<) ;
88   Depends $(<) : $(>) ;
89   SEARCH on $(>) = $(SEARCH_SOURCE) ;
93 actions HardLink {
94   $(RM) $(<) && $(LN) $(>) $(<)
98 rule SoftLink {
99   Depends files : $(<) ;
100   Depends $(<) : $(>) ;
101   SEARCH on $(>) = $(SEARCH_SOURCE) ;
102   Clean clean : $(<) ;
105 actions SoftLink {
106   $(RM) $(<) && $(LN) -s $(>) $(<)
110 rule Shell {
111   Depends shell : $(<) ;
112   Depends $(<) : $(>) ;
113   SEARCH on $(>) = $(SEARCH_SOURCE) ;
114   MODE on $(<) = $(SHELLMODE) ;
115   Clean clean : $(<) ;
116   Chmod $(<) ;
119 #DONT_TOUCH
120 actions Shell {
121   $(AWK) '
122     NR == 1 { print "$(SHELLHEADER)" }
123     NR == 1 && /^[#:]/ { next }
124     /^##/ { next }
125     { print }
126   ' < $(>) > $(<)
128 #DONT_TOUCH
131 rule Setuid {
132   MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;
136 # /File target : source ;
138 # Copies _source_ into _target_
140 rule File {
141   Depends files : $(<) ;
142   Depends $(<) : $(>) ;
143   SEARCH on $(>) = $(SEARCH_SOURCE) ;
144   MODE on $(<) = $(FILEMODE) ;
145   Chmod $(<) ;
148 actions File {
149   $(CP) $(>) $(<)
153 # /Bulk  directory : sources ;
155 # Copies _sources_ into _directory_
157 rule Bulk {
158   local i ;
160   for i in $(>) {
161     File $(i:D=$(<)) : $(i) ;
162   }
166 rule FileExists names {
167   local _fn _lst _dir _name ;
169   for _fn in $(names) {
170     _dir = [ Match "^(.*?)/[^/]+$" : $(_fn) ] ;
171     _name = [ Match "^.*?/([^/]+)$" : $(_fn) ] ;
172     if ! $(_dir) { _dir = . ; }
173     #Echo "_dir:" $(_dir) ;
174     #Echo "_name:" $(_name) ;
175     _lst = [ Glob $(_dir) : $(_name) : plain ] ;
176     #Echo "_lst:" $(_lst) ;
177     if ! $(_lst) { return "" ; }
178   }
179   return "tan" ;
183 rule BuildFileList dir : mask {
184   local _lst = [ Glob $(dir) : $(mask) : files-only ] ;
185   local _dirs = [ Glob $(dir) : "[^_.]*" : dirs-only ] ;
186   local _dn _l ;
188   for _dn in $(_dirs) {
189     #Echo "dir:" $(_dn) ;
190     _l = [ BuildFileList $(_dn) : $(mask) ] ;
191     _lst += $(_l) ;
192   }
194   return $(_lst) ;