makefile - prevent order-only prerequisite from being rebuilt if out of date -
a collegue came across this, , thought i'd ask if there's neat solution following problem: have gnu makefile:
a: | b touch $@ b:c touch $@ c: touch $@ then run:
~/tmp> make touch c touch b touch ~/tmp> make make: `a' date. ~/tmp> touch b ~/tmp> make make: `a' date. ~/tmp> touch c ~/tmp> make touch b it rebuilds b not a if touch c. there way not rebuild b if being invoked order-only prerequisite? ( in real-life case b file hundreds of dependencies, may not around when make a invoked. can't make b's prerequisites order-only break make b)
the behavior correct. instructed make ignore tight dependency between a , b , depend on b presence. whilst a , c share date dependency.
this difference between a: b , a: | b.
if 1 wants investigate case (or other make magic :) ):
try following, you'll see make keen , tells doing b target:
% touch b % lang=c make -rd | awk '/^considering/,/^$/ {print}' considering target file `a'. considering target file `b'. considering target file `c'. finished prerequisites of target file `c'. no need remake target `c'. finished prerequisites of target file `b'. prerequisite `c' older target `b'. no need remake target `b'. finished prerequisites of target file `a'. prerequisite `b' order-only target `a'. <--- "order-only" no need remake target `a'. now, add tight dependency:
% echo "a:b" >> makefile and compare results:
% touch b % lang=c make -rd | awk '/^considering/,/^$/ {print}' considering target file 'a'. considering target file 'b'. considering target file 'c'. finished prerequisites of target file 'c'. no need remake target 'c'. finished prerequisites of target file 'b'. prerequisite 'c' older target 'b'. no need remake target 'b'. pruning file 'b'. finished prerequisites of target file 'a'. prerequisite 'b' order-only target 'a'. prerequisite 'b' newer target 'a'. <--- additional "date dependency" must remake target 'a'. touch <--- 'a' rebuilt putting child 0x1b09ec0 (a) pid 5940 on chain. live child 0x1b09ec0 (a) pid 5940 reaping winning child 0x1b09ec0 pid 5940 removing child 0x1b09ec0 pid 5940 chain. remade target file 'a'. i used make -r (no implicit rules) example doesn't use them , it's boring read.
Comments
Post a Comment