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