Module Name: src Committed By: uebayasi Date: Fri Dec 11 08:37:34 UTC 2009
Modified Files: src/share/mk: bsd.own.mk Log Message: ${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. To generate a diff of this commit: cvs rdiff -u -r1.603 -r1.604 src/share/mk/bsd.own.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/mk/bsd.own.mk diff -u src/share/mk/bsd.own.mk:1.603 src/share/mk/bsd.own.mk:1.604 --- src/share/mk/bsd.own.mk:1.603 Sun Dec 6 16:15:15 2009 +++ src/share/mk/bsd.own.mk Fri Dec 11 08:37:34 2009 @@ -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 @@ -977,6 +977,28 @@ _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") # 1 Describe what is occurring