Debian Codegraph @

texk/web2c/ctangleboot-sh.in

raw
1 #! @SHELL@
2 # $Id: ctangleboot-sh.in 61575 2022-01-11 22:47:10Z karl $
3 # ctangleboot-sh: shell script to invoke ctangleboot and, if required,
4 # update c{tangle,web}boot.[ch]in from c{tangle,web}.[ch].
5 # For details see tangle-sh[.in].
6 #
7 # Copyright 2015-2022 Karl Berry <[email protected]>
8 # Copyright 2009-2012 Peter Breitenlohner <[email protected]>
9 #
10 # This file is free software; the copyright holder
11 # gives unlimited permission to copy and/or distribute it,
12 # with or without modifications, as long as this notice is preserved.
13 #
14 prg=`basename $0`
15 target=$1; shift
16 base=$1
17 case $base in
18 common) file=cweb; exts=c;;
19 ctangle) file=ctangle; exts=c;;
20 *) echo "Usage: $0 TARGET common|ctangle [CHANGEFILE] [OUTFILE]" >&2
21 exit 1;;
22 esac
23
24 TEXMFCNF=@srcdir@/../kpathsea; export TEXMFCNF
25 CWEBINPUTS=@srcdir@/cwebdir; export CWEBINPUTS
26
27 do_ctangleboot () {
28 echo timestamp >$stamp.tmp
29 if $AM_V_P; then
30 echo "$prg: @CTANGLEBOOT@ $@"
31 @CTANGLEBOOT@ "$@" || exit 1
32 test -s $file.$exts \
33 || { echo "$prg: $file.$exts empty." >&2; rm -f $file.$exts; exit 1; }
34 else
35 echo " CTANGLE " $base
36 @CTANGLEBOOT@ "$@" >$base.out 2>&1; rc=$?
37 # succeed and generate nonempty file
38 (test $rc -eq 0 && test -s $file.$exts) \
39 || { cat $base.out; rm -f $file.$exts exit $rc; }
40 rm -f $base.out
41 fi
42 mv -f $stamp.tmp $stamp
43 }
44
45 stamp=$base-ctangle
46 case $target in
47 $stamp)
48 # Normal build.
49 rm -f $stamp.tmp
50 do_ctangleboot "$@"
51 ;;
52 *)
53 # Recover from removal of $target if necessary.
54 if test -f $target; then
55 $AM_V_P && echo "$prg: checking for $target ... ok"
56 exit 0
57 else
58 $AM_V_P && echo "$prg: recovering $target"
59 fi
60 #
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
65 do_ctangleboot "$@"
66 rmdir $stamp.lock
67 else
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 $?
73 fi
74 ;;
75 esac
76
77 for ext in $exts; do
78 src=$file.$ext
79 dst=@srcdir@/${file}boot.${ext}in
80 sed -e 's,@srcdir@/cwebdir,cwebdir,' \
81 $src >$stamp.tmp
82 if cmp -s $stamp.tmp $dst; then
83 rm -f $stamp.tmp
84 else
85 if $AM_V_P; then
86 echo "Updating $src => $dst"
87 else
88 echo " UPD " ${file}boot.${ext}in
89 fi
90 mv -f $stamp.tmp $dst || exit 1
91 fi
92 done
93
94 exit 0