1 1.3 rillig # $NetBSD: impsrc.mk,v 1.3 2020/08/07 13:43:50 rillig Exp $ 2 1.1 christos 3 1.2 sjg # Does ${.IMPSRC} work properly? 4 1.2 sjg # It should be set, in order of precedence, to ${.TARGET} of: 5 1.1 christos # 1) the implied source of a transformation rule, 6 1.1 christos # 2) the first prerequisite from the dependency line of an explicit rule, or 7 1.1 christos # 3) the first prerequisite of an explicit rule. 8 1.1 christos # 9 1.3 rillig # Items 2 and 3 work in GNU make. 10 1.3 rillig # Items 2 and 3 are not required by POSIX 2018. 11 1.1 christos 12 1.1 christos all: target1.z target2 target3 target4 13 1.1 christos 14 1.1 christos .SUFFIXES: .x .y .z 15 1.1 christos 16 1.1 christos .x.y: source1 17 1.1 christos @echo 'expected: target1.x' 18 1.1 christos @echo 'actual: $<' 19 1.1 christos 20 1.1 christos .y.z: source2 21 1.1 christos @echo 'expected: target1.y' 22 1.1 christos @echo 'actual: $<' 23 1.1 christos 24 1.3 rillig # (3) Making target1.z out of target1.y is done because of an inference rule. 25 1.3 rillig # Therefore $< is available here. 26 1.3 rillig 27 1.3 rillig # (2) This is an additional dependency on the inference rule .x.y. 28 1.3 rillig # The dependency target1.x comes from the inference rule, 29 1.3 rillig # therefore it is available as $<. 30 1.1 christos target1.y: source3 31 1.1 christos 32 1.3 rillig # (1) This is an explicit dependency, not an inference rule. 33 1.3 rillig # Therefore POSIX does not specify that $< be available here. 34 1.1 christos target1.x: source4 35 1.3 rillig @echo 'expected: ' # either 'source4' or '' 36 1.1 christos @echo 'actual: $<' 37 1.1 christos 38 1.3 rillig # (4) This is an explicit dependency, independent of any inference rule. 39 1.3 rillig # Therefore $< is not available here. 40 1.1 christos target2: source1 source2 41 1.3 rillig @echo 'expected: ' 42 1.1 christos @echo 'actual: $<' 43 1.1 christos 44 1.3 rillig # (5) These are two explicit dependency rules. 45 1.3 rillig # The first doesn't have any dependencies, only the second has. 46 1.3 rillig # If any, the value of $< would be 'source2'. 47 1.1 christos target3: source1 48 1.1 christos target3: source2 source3 49 1.3 rillig @echo 'expected: ' 50 1.1 christos @echo 'actual: $<' 51 1.1 christos 52 1.3 rillig # (6) The explicit rule does not have associated commands. 53 1.3 rillig # The value of $< might come from that rule, 54 1.3 rillig # but it's equally fine to leave $< undefined. 55 1.1 christos target4: source1 56 1.1 christos target4: 57 1.3 rillig @echo 'expected: ' 58 1.1 christos @echo 'actual: $<' 59 1.1 christos 60 1.1 christos source1 source2 source3 source4: 61