beta-0.89.2
[luatex.git] / source / texk / web2c / ctangleboot-sh.in
blobdb5da006b6cdb544aac478907c04b1ac3e5ead81
1 #! @SHELL@
2 # ctangleboot-sh: shell script to invoke ctangleboot and if required
3 #    update c{tangle,web}boot.[ch]in from c{tangle,web}.[ch].
4 #    For details see tangle-sh.
6 #   Copyright (C) 2009-2012 Peter Breitenlohner <tex-live@tug.org>
8 #   This file is free software; the copyright holder
9 #   gives unlimited permission to copy and/or distribute it,
10 #   with or without modifications, as long as this notice is preserved.
12 target=$1; shift
13 base=$1
14 case $base in
15   common) file=cweb; exts='c h';;
16   ctangle) file=ctangle; exts=c;;
17   *) echo "Usage: $0 TARGET {common|ctangle} [CHANGEFILE]" >&2; exit 1;;
18 esac
20 TEXMFCNF=@srcdir@/../kpathsea; export TEXMFCNF
21 CWEBINPUTS=@srcdir@/cwebdir; export CWEBINPUTS
23 do_ctangleboot () {
24   echo timestamp >$stamp.tmp
25   if $AM_V_P; then
26     echo "@CTANGLEBOOT@ $@"
27     @CTANGLEBOOT@ "$@" || exit 1
28   else
29     echo "  CTANGLE " $base
30     @CTANGLEBOOT@ "$@" >$base.out 2>&1; rc=$?
31     test $rc -eq 0 || { cat $base.out; exit $rc; }
32     rm -f $base.out
33   fi
34   mv -f $stamp.tmp $stamp
37 stamp=$base-ctangle
38 case $target in
39   $stamp)
40     # Normal build.
41     rm -f $stamp.tmp
42     do_ctangleboot "$@"
43   ;;
44   *)
45     # Recover from removal of $target
46     test -f $target && exit 0
47     trap "rm -rf $stamp $stamp.lock" 1 2 13 15
48     if mkdir $stamp.lock 2>/dev/null; then
49       # Code executed by the first process.
50       rm -f $stamp $stamp.tmp
51       do_ctangleboot "$@"
52       rmdir $stamp.lock
53     else
54       # Code executed by the follower processes.
55       # Wait until the first process is done.
56       while test -d $stamp.lock; do sleep 1; done
57       # Succeed if and only if the first process succeeded.
58       test -f $stamp; exit $?
59     fi
60   ;;
61 esac
63 for ext in $exts; do
64   src=$file.$ext
65   dst=@srcdir@/${file}boot.${ext}in
66   sed -e 's,@srcdir@/cwebdir,cwebdir,' \
67       -e 's,^#include "cweb.h",#include "cwebboot.h",' \
68       $src >$stamp.tmp
69   if cmp -s $stamp.tmp $dst; then
70     rm -f $stamp.tmp
71   else
72     if $AM_V_P; then
73       echo "Updating $src => $dst"
74     else
75       echo "  UPD     " ${file}boot.${ext}in
76     fi
77     mv -f $stamp.tmp $dst || exit 1
78   fi
79 done
81 exit 0