From ad547a6b5986815fda458221149728d9d9ab1d87 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 25 Feb 2021 19:22:25 +0000 Subject: restore Build,TODO from r57911 git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/tangle-sh.in | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Build/source/texk/web2c/tangle-sh.in (limited to 'Build/source/texk/web2c/tangle-sh.in') diff --git a/Build/source/texk/web2c/tangle-sh.in b/Build/source/texk/web2c/tangle-sh.in new file mode 100644 index 00000000000..6af8991f042 --- /dev/null +++ b/Build/source/texk/web2c/tangle-sh.in @@ -0,0 +1,77 @@ +#! @SHELL@ +# tangle-sh: shell script to invoke tangle (or ctangle, etc). +# +# Copyright (C) 2009, 2012 Peter Breitenlohner +# +# This file is free software; the copyright holder +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. +# +# Tangle may create several files, e.g., tex.p and tex.pool from tex.web +# and tex.ch. The naive rule +# tex.p tex.pool: tex.web tex.ch tangle$(EXEEXT) +# $(tangle) tex tex +# could run 'tangle tex tex' twice in parallel and fail. To avoid this +# and yet recover from removal of tex.p and/or tex.pool, we use an +# auxiliary stamp file tex-tangle and the two rules +# tex.p tex.pool: tex-tangle +# WEBINPUTS=.:$(srcdir) $(SHELL) ./tangle-sh $@ $(TANGLE) tex tex +# tex-tangle: tex.web tex.ch tangle$(EXEEXT) tangle-sh +# WEBINPUTS=.:$(srcdir) $(SHELL) ./tangle-sh $@ $(TANGLE) tex tex +# Compare Automake manual (info Automake) 27.9: Multiple Outputs +# +TEXMFCNF=@srcdir@/../kpathsea; export TEXMFCNF + +env="TEXMFCNF=$TEXMFCNF" +test "x$WEBINPUTS" = x || env="WEBINPUTS=$WEBINPUTS $env" +test "x$CWEBINPUTS" = x || env="CWEBINPUTS=$CWEBINPUTS $env" + +target=$1; shift +tangle=$1; shift +base=$1 + +do_tangle () { + echo timestamp >$stamp.tmp + if $AM_V_P; then + echo "$env $tangle $@" + $tangle "$@" || exit 1 + else + case $base in + aleph | xetex) echo " OTANGLE " $base;; + *tex | mf*) echo " TANGLE " $base;; + *) echo " CTANGLE " $base;; + esac + $tangle "$@" >$base.out 2>&1; rc=$? + test $rc -eq 0 || { cat $base.out; exit $rc; } + rm -f $base.out + fi + mv -f $stamp.tmp $stamp +} + +stamp=$base-tangle +case $target in + $stamp) + # Normal build. + rm -f $stamp.tmp + do_tangle "$@" + ;; + *) + # Recover from removal of $target + test -f $target && exit 0 + trap "rm -rf $stamp $stamp.lock" 1 2 13 15 + if mkdir $stamp.lock 2>/dev/null; then + # Code executed by the first process. + rm -f $stamp $stamp.tmp + do_tangle "$@" + rmdir $stamp.lock + else + # Code executed by the follower processes. + # Wait until the first process is done. + while test -d $stamp.lock; do sleep 1; done + # Succeed if and only if the first process succeeded. + test -f $stamp; exit $? + fi + ;; +esac + +exit 0 -- cgit v1.2.3