tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: make: avoid breaking backwards compatability



As an aide to the discussion, the patch below adds a unit-test
for some of the common behavior that some existing makefiles rely on.

target0 is the fiding some dir/foo.c via .PATH even when foo.c is
present in '.'

target1 is relying on the suffix rules to apply the dependency foo.c ->
foo.o even when there is an explicit rule for foo.o

target2 is stupid case that my first attempts to fix target1 broke ;-)

Stupid or not, in each case the real makefiles that rely on this
behavior have worked with every version of bmake posted for the last 15
years.  They should contine to work.

The expected ouput is approximately the same with our older make 
and a "fixed" new one.  The older make does not necessarily set impsrc=
in all cases but otherwise the result is the same and the lack of or
value of .IMPSRC does no harm.

The current make outputs - which fails target0 and target1

target=lstInit.o impsrc=lstInit.c
target=target0 impsrc=lstInit.o all=lstInit.o
spontaneous: source1.b
target=target1.z impsrc=source1.b all=source1.b
spontaneous: source2.a
spontaneous: source2.b
target=target2 impsrc=source2.a all=source2.a source2.b
target=target2.x impsrc=target2 all=target2

now if someone can come up with a better patch that passes impsrc-compat
that would be cool.

diff -r 60c0e077d44f bmake/unit-tests/impsrc-compat.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/bmake/unit-tests/impsrc-compat.exp        Thu Sep 04 16:24:06 2014 -0700
@@ -0,0 +1,11 @@
+target=lstInit.o impsrc=<src>/lst.lib/lstInit.c
+target=target0 impsrc=lstInit.o all=lstInit.o
+spontaneous: source1.b
+spontaneous: source1.a
+target=target1.y impsrc=source1.a all=source1.a
+target=target1.z impsrc=target1.y all=source1.b target1.y
+spontaneous: source2.a
+spontaneous: source2.b
+target=target2 impsrc=source2.a all=source2.a source2.b
+target=target2.x impsrc=target2 all=target2
+exit status 0
diff -r 60c0e077d44f bmake/unit-tests/impsrc-compat.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/bmake/unit-tests/impsrc-compat.mk Thu Sep 04 16:24:06 2014 -0700
@@ -0,0 +1,46 @@
+# $NetBSD$
+
+# Test historical behavior
+
+all: target0 target1.z target2 target2.x 
+
+.SUFFIXES: .x .y .z .c .o
+
+.x:
+       @echo "oops"
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC}'
+
+.y.z:
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC}'
+
+.c.o:
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC:S,${_src},<src>,}'
+
+# this just allows for repeatable results
+_src:= ${.PARSEDIR:H:tA}
+# and ensures that lstInit.c can be found - even when it shouldn't be
+.OBJDIR: ${_src}/lst.lib
+
+.PATH: ${_src}
+
+target0: lstInit.o
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC} all=${.ALLSRC}'
+
+lstInit.o:     lst.lib/lstInit.c
+
+target1.z: source1.b
+target1.z:
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC} all=${.ALLSRC}'
+
+target1.y:     source1.a
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC} all=${.ALLSRC}'
+
+target2: source2.a source2.b
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC} all=${.ALLSRC}'
+
+# opposite of .x: but should not cause cycle
+target2.x: target2
+       @echo 'target=${.TARGET} impsrc=${.IMPSRC} all=${.ALLSRC}'
+
+source1.a source1.b source2.a source2.b:
+       @echo spontaneous: ${.TARGET} 


Home | Main Index | Thread Index | Old Index