2 # tangle-sh: shell script to invoke tangle (or ctangle, etc).
4 # Copyright (C) 2009, 2012 Peter Breitenlohner <tex-live@tug.org>
6 # This file is free software; the copyright holder
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
10 # Tangle may create several files, e.g., tex.p and tex.pool from tex.web
11 # and tex.ch. The naive rule
12 # tex.p tex.pool: tex.web tex.ch tangle$(EXEEXT)
14 # could run 'tangle tex tex' twice in parallel and fail. To avoid this
15 # and yet recover from removal of tex.p and/or tex.pool, we use an
16 # auxiliary stamp file tex-tangle and the two rules
17 # tex.p tex.pool: tex-tangle
18 # WEBINPUTS=.:$(srcdir) $(SHELL) ./tangle-sh $@ $(TANGLE) tex tex
19 # tex-tangle: tex.web tex.ch tangle$(EXEEXT) tangle-sh
20 # WEBINPUTS=.:$(srcdir) $(SHELL) ./tangle-sh $@ $(TANGLE) tex tex
21 # Compare Automake manual (info Automake) 27.9: Multiple Outputs
23 TEXMFCNF=@srcdir@/../kpathsea; export TEXMFCNF
25 env="TEXMFCNF=$TEXMFCNF"
26 test "x$WEBINPUTS" = x || env="WEBINPUTS=$WEBINPUTS $env"
27 test "x$CWEBINPUTS" = x || env="CWEBINPUTS=$CWEBINPUTS $env"
34 echo timestamp >$stamp.tmp
36 echo "$env $tangle $@"
37 $tangle "$@" || exit 1
40 aleph | xetex) echo " OTANGLE " $base;;
41 *tex | mf*) echo " TANGLE " $base;;
42 *) echo " CTANGLE " $base;;
44 $tangle "$@" >$base.out 2>&1; rc=$?
45 test $rc -eq 0 || { cat $base.out; exit $rc; }
48 mv -f $stamp.tmp $stamp
59 # Recover from removal of $target
60 test -f $target && exit 0
61 trap "rm -rf $stamp $stamp.lock" 1 2 13 15
62 if mkdir $stamp.lock 2>/dev/null; then
63 # Code executed by the first process.
64 rm -f $stamp $stamp.tmp
68 # Code executed by the follower processes.
69 # Wait until the first process is done.
70 while test -d $stamp.lock; do sleep 1; done
71 # Succeed if and only if the first process succeeded.
72 test -f $stamp; exit $?