Sun 05 Sep 2004 02:31:04 PM UTC, original submission:
Hello,
The attached patch implements a so called ".ALIAS" special target.
An .ALIAS target is firts of all a .PHONY target, which means there's no real file on disk with the name of the target; however, unlike .PHONY targets, .ALIAS targets can - and that's their main purpose - be used as prerequisites of normal targets, acting as a sort of "bridge" between the real target and all the prerequisites of the .ALIAS targert: basically, the .ALIAS target can be considered an "alias" for all of its prerequisites.
An .ALIAS target is given "virtual" timestamps. These timestamps are used to connect the parent of the .ALIAS target with the prerequisites of the .ALIAS target. Basically, an .ALIAS target, at the moment of being considered, has an OLD_MTIME mtime, so that it appears older than anything else. However, at the moment it's finished being considered, and thus at the moment all of its prerequisites are finished being considered, its mtime is the mtime of the youngest of its prerequisites.
An example:
.ALIAS alias
target1 : alias
alias : target2 target3 target4
is completely equivalent to
target1: target2
target1: target3
target1: target4
whilst it's not equivalent to:
.PHONY alias
target1 : alias
alias : target2 target3 target4
because, in the above case, target1 would always be remade, regardless of whether target2, target3 and target4 have been brought up to date.
I found the need for this special target in my build system, where I make heavy use of the $(eval) function, and where there are "modules" that depend on other "modules": the modules are defined as .ALIAS'es to the real files, and other modules list their dependencies using those aliases, rather than the real files, as they have no way to know where the real files are going to be, but they do know there are certain modules named in a certain way.
Another way of looking at the .ALIAS targets is to consider them as sort of symlinks, although they're very special symlinks as they can refer to more than one file at any given time.
I'm quite new to Make hacking, hence I might have not considered certain situations which I might not be aware of, but I tried to keep the patch to a minimum size and make it as less intrusive as possible. However, I've tested the patch for the cases I need it and it works perfectly.
I'll be happy to discuss any issues I've not considered, in order to let the patch make it to the mainline. Also, I will document the .ALIAS target should this patch be accepted.
|