beta-0.89.2
[luatex.git] / source / texk / web2c / web2c-sh.in
blobbeab55e08a2c3ce7c1b6747325375c14933a14dc
1 #! @SHELL@
2 # web2c-sh: shell script to invoke ${srcdir}/web2c/convert.
4 #   Copyright (C) 2009-2014 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 # Convert creates several files, e.g., FOO.c and FOO.h from FOO.p.
11 # The naive rule
12 #       FOO.c FOO.h: FOO.p $(web2c_depend)
13 #               srcdir=$(srcdir) $(SHELL) $(srcdir)/web2c/convert FOO
14 # could run 'convert FOO' twice in parallel and fail.  To avoid this
15 # and yet recover from removal of FOO.c and/or FOO.h, we use an auxiliary
16 # stamp file FOO-web2c and the two rules
17 #       FOO.c FOO.h: FOO-web2c
18 #               $(SHELL) ./web2c-sh $@ FOO
19 #       FOO-web2c: FOO.p $(web2c_depend)
20 #               $(SHELL) ./web2c-sh $@ FOO
21 # Compare Automake manual (info Automake) 27.9: Multiple Outputs
23 srcdir=@srcdir@; export srcdir
24 target=$1
25 base=$2
27 do_convert () {
28   echo timestamp >$stamp.tmp
29   if $AM_V_P; then
30     echo "@SHELL@ $srcdir/web2c/convert $base"
31     @SHELL@ $srcdir/web2c/convert $base || exit 1
32   else
33     echo "  WEB2C   " $base
34     @SHELL@ $srcdir/web2c/convert $base >$base.out 2>&1; rc=$?
35     test $rc -eq 0 || { cat $base.out; exit $rc; }
36     rm -f $base.out
37   fi
38   mv -f $stamp.tmp $stamp
41 stamp=$base-web2c
42 case $target in
43   $stamp)
44     # Normal build.
45     rm -f $stamp.tmp
46     do_convert
47   ;;
48   *)
49     # Recover from removal of $target
50     test -f $target && exit 0
51     trap "rm -rf $stamp $stamp.lock" 1 2 13 15
52     if mkdir $stamp.lock 2>/dev/null; then
53       # Code executed by the first process.
54       rm -f $stamp $stamp.tmp
55       do_convert
56       rmdir $stamp.lock
57     else
58       # Code executed by the follower processes.
59       # Wait until the first process is done.
60       while test -d $stamp.lock; do sleep 1; done
61       # Succeed if and only if the first process succeeded.
62       test -f $stamp; exit $?
63     fi
64   ;;
65 esac
67 exit 0