${GENCMD} is used to generate only one output from file generation commands

which potentially have multiple output files, which confuses make(1).

This wrapper copies all involved files into /tmp, execute the command, and
copy the wanted file back to ${.OBJDIR}.  If this is expensive, consider to
rewrite the generation command to output files individually.

XXX bsd.own.mk is too bloated.
This commit is contained in:
uebayasi 2009-12-11 08:37:34 +00:00
parent 0a8b38422e
commit bf4c37b84c
1 changed files with 23 additions and 1 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.own.mk,v 1.603 2009/12/06 16:15:15 uebayasi Exp $
# $NetBSD: bsd.own.mk,v 1.604 2009/12/11 08:37:34 uebayasi Exp $
.if !defined(_BSD_OWN_MK_)
_BSD_OWN_MK_=1
@ -976,6 +976,28 @@ MAKEDIRTARGET=\
}; \
_makedirtarget
#
# ${GENCMD} <generated name> <command and arguments>
# Extract only one output from generation command so that make rule is
# written straight and avoid race (duplicate generation). <generated
# name> is usually ${.TARGET}; if you want foo.c from foo.y, yacc
# generates y.tab.c, so <generated name> is y.tab.c. See bin/sh/Makefile
# for examples.
#
GENCMD=\
@_gencmd() { \
local _dst="$$1"; shift; local _src="$$1"; shift; local _gen="$$1"; shift; \
local _tmp=$$( ${TOOL_MKTEMP} -d /tmp/XXXXXX ); \
local _opwd=$$PWD; \
local _exit; \
cp $$_src $$_tmp; \
{ cd $$_tmp && eval $$@; _exit=$$?; cd $$_opwd; }; \
[ $$_exit = 0 ] && cp $${_tmp}/$${_gen} $$_dst; \
rm -fr $$_tmp; \
return $$_exit; \
}; \
_gencmd "${.TARGET}" "${.ALLSRC}"
#
# MAKEVERBOSE support. Levels are:
# 0 Minimal output ("quiet")