Subject: toolchain/14615: make with MAKEOBJDIR set behaves strange on sub-makes
To: None <>
From: Juergen Hannken-Illjes <>
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
>Originator:     Juergen Hannken-Illjes
>Release:        NetBSD 1.5Y as of Nov 16, 2001
	TU Braunschweig / EIS
System: NetBSD 1.5Y (CUSTOM) #75: Fri Nov 16 10:54:43 MET 2001
Architecture: i386
Machine: i386
	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.
	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`"

	@${MAKE} b0

	@cd . && ${MAKE} c0

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


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

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


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

	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.