Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/share/mk ${GENCMD} is used to generate only one output from ...



details:   https://anonhg.NetBSD.org/src/rev/afd58d22ef13
branches:  trunk
changeset: 749846:afd58d22ef13
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Fri Dec 11 08:37:34 2009 +0000

description:
${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.

diffstat:

 share/mk/bsd.own.mk |  24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diffs (38 lines):

diff -r a306d2c43b13 -r afd58d22ef13 share/mk/bsd.own.mk
--- a/share/mk/bsd.own.mk       Fri Dec 11 05:52:03 2009 +0000
+++ b/share/mk/bsd.own.mk       Fri Dec 11 08:37:34 2009 +0000
@@ -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



Home | Main Index | Thread Index | Old Index