| 256 | rule UntarArchive directory : entries : tarFile : grist |
| 257 | { |
| 258 | # UntarArchive <directory> : <entries> : <tarFile> [ : <grist> ] |
| 259 | # |
| 260 | # Untars the tar file target <tarFile> to directory <directory>. The rule |
| 261 | # can be called multiple times for different <entries> for the same |
| 262 | # <directory> and <tarFile> combo. |
| 263 | # |
| 264 | # <directory> - The directory into which to untar the tar file. The |
| 265 | # directory is created is by this rule and it is the target |
| 266 | # that the untar action is associated with. |
| 267 | # <entries> - The entries of the tar file one is interested in. The rule |
| 268 | # always untars the complete tar file, from the given entries |
| 269 | # the rule creates targets (using <grist>) representing the |
| 270 | # untarred entries. Those targets are returned by the rule. |
| 271 | # <tarFile> - The tar file target to untar. |
| 272 | # <grist> - The grist used to create targets from <entries>. Defaults to |
| 273 | # "untarred". |
| 275 | grist ?= untarred ; |
| 276 | |
| 277 | # Turn the entries into targets to build. |
| 278 | local targets ; |
| 279 | local entry ; |
| 280 | for entry in $(entries) { |
| 281 | local target = $(entry:G=$(grist)) ; |
| 282 | targets += $(target) ; |
| 283 | } |
| 284 | |
| 285 | LOCATE on $(targets) = $(directory) ; |
| 286 | Depends $(targets) : $(directory) ; |
| 287 | NoUpdate $(targets) ; |
| 288 | |
| 289 | # one-time initialization for the main target (the directory) |
| 290 | if ! [ on $(directory) return $(INITIALIZED) ] { |
| 291 | # make sure the parent dir exists |
| 292 | local parentDir = $(directory:PG=dir) ; |
| 293 | Depends $(directory) : $(parentDir) ; |
| 294 | MkDir $(parentDir) ; |
| 295 | |
| 296 | NoUpdate $(directory) ; |
| 297 | Depends $(directory) : $(tarFile) ; |
| 298 | UntarArchive1 $(directory) : $(tarFile) ; |
| 299 | INITIALIZED on $(directory) = 1 ; |
| 300 | } |
| 301 | |
| 302 | # Use a dummy rule so that it looks to jam like the targets are actually |
| 303 | # built from the directory target. |
| 304 | UnArchiveDummy $(targets) : $(directory) ; |
| 305 | |
| 306 | return $(targets) ; |
| 307 | } |
| 308 | |
| 309 | actions UntarArchive1 |
| 310 | { |
| 311 | mkdir -p $(1[1]) |
| 312 | tar -C $(1[1]) -xf $(2) |
| 313 | } |
| 314 | |