Subject: Should make use 'sh -ec "..."' ?
To: None <tech-toolchain@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: tech-toolchain
Date: 11/14/2003 23:04:12
NetBSD make seems to run commands using sh -ec "commands".

This means that in rules that contains commands:
	cd dir; command
then command won't be run if the 'cd dir' fails, ie it is equivalent to:
	cd dir && command

Now bsd.obj.mk contains:

obj:
	<test for MAKEOBJDIRPREFIX snipped>
	@if [ ! -d ${__objdir} ]; then \
		mkdir -p ${__objdir}; \
		if [ ! -d ${__objdir} ]; then \
			mkdir ${__objdir}; exit 1; \
		fi; \
		${_MKSHMSG} " objdir  ${__objdir}"; \
	fi

If the 'mkdir -p ${__objdir}' fails, then the shell aborts and the rest of
the commands (the 'mkdir ${__objdir}' to find the real error) isn't actually
executed.

Actually it is probably enough to replace the above with:

obj: ${__objdir} ${MAKEOBJDIRPREFIX}

${__objdir}:
	mkdir -p ${.TARGET}

	David

(Found by doing a 'ktrace -di -ta -p <build.sh's pid>' while it was chewing
through 'make obj'.)

-- 
David Laight: david@l8s.co.uk