Subject: toolchain/14615: make with MAKEOBJDIR set behaves strange on sub-makes
To: None <gnats-bugs@gnats.netbsd.org>
From: Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
List: netbsd-bugs
Date: 11/17/2001 16:34:57
>Number:         14615
>Category:       toolchain
>Synopsis:       make with MAKEOBJDIR set behaves strange on sub-makes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 17 07:35:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Juergen Hannken-Illjes
>Release:        NetBSD 1.5Y as of Nov 16, 2001
>Organization:
	TU Braunschweig / EIS
>Environment:
System: NetBSD 1.5Y (CUSTOM) #75: Fri Nov 16 10:54:43 MET 2001
Architecture: i386
Machine: i386
>Description:
	make(1) contains logic to check the shell commands for occurences
	of `make' or `${MAKE}' commands. If MAKEOBJDIR is set and a shell
	command contains `make' and this is not preceded by a `chdir' or
	`cd' the command will run in ${.SRCDIR}. This behaviour is not
	documented outside the code (main.c). The logic is buggy as it
	doesn't detect commands after `if', `then' etc.
>How-To-Repeat:
	Run the following shell script and try to explain the result:

#! /bin/sh

mkdir -p /tmp/test/src /tmp/test/obj

cat <<'EOF' >/tmp/test/src/Makefile

a b0 c0 d0:
	@echo "${.TARGET}:	src `pwd`"

b:
	@${MAKE} b0

c:
	@cd . && ${MAKE} c0

d:
	@if true; then cd . && ${MAKE} d0; fi

EOF

cat <<'EOF' >/tmp/test/obj/Makefile

a b c d b0 c0 d0:
	@echo "${.TARGET}:	obj `pwd`"

EOF

export MAKEOBJDIR='${.CURDIR:C,^/tmp/test/src,//tmp/test/obj,}'

(cd /tmp/test/src && make a b c d)

	My result is:

a:	src /tmp/test/obj
b0:	src /tmp/test/obj
c0:	obj /tmp/test/obj
d0:	src /tmp/test/obj

>Fix:
	1. update the documentation so the current behaviour is documented
	   and fix the simple shell parser.
	2. simply remove the chdir-checks and correct the offending Makefiles.
>Release-Note:
>Audit-Trail:
>Unformatted: