welcome GPLv3! yes, k8jam is GPL'ed now, along with Jambase. because i can.
[k8jam.git] / defaults / misc / Jambase.misc.fsys
blobd543d3e23913bbe0589cad91d10a219a008ce8d8
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/>.
14 rule IsRootDir {
15   # handle "C:", "C:/", "/cygdrive" and "/cygdrive/" in Cygwin
16   if $(NT) {
17     switch $(<:G=:R=) {
18       case "*:"  : return 1 ;
19       case '*:\' : return 1 ;
20     }
21   } else if $(UNIX) && $(OS) = CYGWIN {
22     switch $(<:G=:R=) {
23       case "?:"  : return 1 ;
24       case "?:/" : return 1 ;
25       case "/cygdrive"  : return 1 ;
26       case "/cygdrive/" : return 1 ;
27     }
28   } else if $(<:G=:R=) = "/" || $(<) = $(<:D) {
29     return 1 ;
30   }
31   return ; # empty list
35 rule RemoveTrailingSlashes {
36   if ! [ IsRootDir $(<[1]) ] {
37     local mt = [ Match '^(.*?)/+$' : $(<[1]) ] ;
38     if $(mt) { return $(mt[1]) ; }
39   }
40   return $(<[1]) ;
44 rule AddTrailingSlash {
45   local _ttt = $(<[1]) ;
46   if $(_ttt) {
47     if ! ( $(_ttt) ~= '[/]$' ) { _ttt = "$(_ttt)/" ; }
48   } else {
49     _ttt = "" ;
50   }
51   return $(_ttt) ;
55 # $2: return empty path as "./"?
56 rule FPathNormalize {
57   #Echo "FPathNormalize-i:" $(<) "$2:" $(2) ;
58   local res = [ NormalizePath $(<[1]) : "" ] ;
59   if $(2) && ! $(res) { return "./" ; }
60   if $(res) {
61     res = [ AddTrailingSlash $(res) ] ;
62     if $(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   # Ignore timestamps on directories: we only care if they exist.
75   NoUpdate $(<) ;
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
81     $(<)-mkdir = true ;
82     Depends dirs : $(<) ;
83     MkDir1 $(<) ;
84     # Recursively make parent directories.
85     # $(<:P) = $(<)'s parent, & we recurse until root
86     local s = $(<:GRD) ;
87     if [ IsRootDir $(s) ] { s = ; }
88     if $(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.
91       NotFile $(s) ;
92     } else if $(s:G=) {
93       # There's a parent; recurse.
94       Depends $(<) : $(s) ;
95       MkDirI $(s) ;
96     }
97   }
100 rule MkDir {
101   local d = $(<:G=) ;
102   NoUpdate $(<) ;
103   if $(d) && $(d) != $(DOT) && $(d) != $(DOTDOT) && ! $($(<)-mkdir) {
104     #Echo "$1:" "$(1)" ;
105     #Echo "MkDir0: $(d)" ;
106     d = [ FPathNormalize $(d) : tan ] ;
107     #Echo "MkDir1: $(d)" ;
108     d = $(<:G) $(d) ;
109     d = $(d:J) ;
110     #Echo "MkDir2: $(d)" ;
111     MkDirI $(d) ;
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) ;