Subject: Re: toolchain/30842: build.sh fails with mksh
To: None <gnats-bugs@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: netbsd-bugs
Date: 07/26/2005 22:13:31
On Tue, 26 Jul 2005, tg@MirBSD.org wrote:
> mksh is the MirBSD version of the public domain korn shell,
> which includes patches from the OpenBSD and Debian pdksh
> derivates.
> 
> As such, it needs a special handling for the braceexpand
> mode as well, else MAKEOBJDIR creation in the nbmake wrapper
> will fail.

So, if I understand correctly, this shell interprets braces inside here
documents as special characters, unless you "set +o braceexpand".

Can we solve this problem without adding more special cases to build.sh
by just adding backslashes in appropriate places, so it doesn't matter
whether or not the shell does brace expansion?  For example, does the
following patch work (in the absence of the "set +o braceexpand" patch)?
It changes all "\${...}" to "\$\{...\}" in the here-document that
build.sh uses to create the makewrapper.

--apb (Alan Barrett)

--- build.sh.orig	2005-07-26 22:05:38.000000000 +0200
+++ build.sh	2005-07-26 22:07:10.000000000 +0200
@@ -872,7 +872,7 @@
 #
 EOF
 	for f in ${makeenv}; do
-		if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
+		if eval "[ -z \"\$\{$f\}\" -a \"\$\{${f}-X\}\" = \"X\" ]"; then
 			eval echo "unset ${f}" ${makewrapout}
 		else
 			eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}" ${makewrapout}
@@ -882,7 +882,7 @@
 
 	eval cat <<EOF ${makewrapout}
 
-exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
+exec "\$\{TOOLDIR\}/bin/${toolprefix}make" \$\{1+"\$@"\}
 EOF
 	[ "${runcmd}" = "echo" ] && echo EOF
 	${runcmd} chmod +x "${makewrapper}"