bison++.in 2.98 KB
Newer Older
Benoit Perrot's avatar
Benoit Perrot committed
1
2
#! /bin/sh

3
4
5
# Exit status.
status=0

Benoit Perrot's avatar
Benoit Perrot committed
6
7
8
# Any tool failure is a failure of the script.
set -e

9
10
: ${BISON=@BISON@}

11
12
# bison++ INPUT OUTPUT OPTIONS
# ----------------------------
Benoit Perrot's avatar
Benoit Perrot committed
13
14

me=$(basename $0)
15
move_if_change='@abs_srcdir@/move-if-change'
Benoit Perrot's avatar
Benoit Perrot committed
16
17

input=$1
18
input_base=$(basename "$input")
Benoit Perrot's avatar
Benoit Perrot committed
19
20
shift
output=$1
21
output_base=$(basename "$output")
Roland Levillain's avatar
Roland Levillain committed
22
output_base_noext=$(echo "$output_base" | sed -e 's/\.[^.]*//')
23
output_dir=$(dirname "$output")
Benoit Perrot's avatar
Benoit Perrot committed
24
shift
Roland Levillain's avatar
Roland Levillain committed
25

26
options="$@"
Roland Levillain's avatar
Roland Levillain committed
27
28
29
30
if $BISON --xml --version >/dev/null 2>&1; then
  options="$options --xml"
fi

Benoit Perrot's avatar
Benoit Perrot committed
31
32
33
34
35
36
37
38
39
40
41

# Alexandre Duret-Lutz also notes that in VPATH-builds $(srcdir) can
# be an absolute path depending on how ./configure is called ...
# In that case

#   bison $(srcdir)/parsetiger.yy [...]

# will hard code the path in the maintainer's tree.  Hence, do not use
# paths with Bison, chdir there.

# A tmp dir.
Roland Levillain's avatar
Roland Levillain committed
42
tmp=$output_base_noext.dir
Benoit Perrot's avatar
Benoit Perrot committed
43
44
45
46
47
rm -rf $tmp
mkdir $tmp

# Compile in this dir.
# Don't use `ln -s' as its semantics of paths sucks.
48
cp $input $tmp
Benoit Perrot's avatar
Benoit Perrot committed
49
cd $tmp
50
51
52
53
54
set +e
$BISON $options $input_base -o $output_base
status=$?
set -e

Roland Levillain's avatar
Roland Levillain committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

# fix_bison_output FILE
# ---------------------
# Fixes in place.
fix_bison_output ()
{
  # Fix doxygen tags.
  perl -pi -e "s|\Q\\file $base\E\b|\\\\file parse/$base|g;" "$1"

}

# Go back to where we were and use relative paths instead of using
# absolute file names.  The messages look nicer.
cd ..
case $status in
  0)
    for file in $tmp/*
72
    do
Roland Levillain's avatar
Roland Levillain committed
73
74
75
76
77
      base=$(basename $file)
      base_noext=$(echo "$base" | sed -e 's/\.[^.]*//')
      out=$output_dir/$base
      case $base in
      $input_base)
78
79
	    # Leave it here.
	    ;;
Roland Levillain's avatar
Roland Levillain committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

      *.xml)
        # Computing the HTML is slow.  Do it when the XML changed.
        fix_bison_output "$file"
        if ! test -r "$out" || ! cmp -s "$file" "$out"; then
          xml2html="xsltproc $($BISON --print-datadir)/xslt/xml2xhtml.xsl"
          if $xml2html "$file" >$tmp/$base_noext.html; then
            $move_if_change "$tmp/$base_noext.html" \
                            "$output_dir/$base_noext.html"
          else
            echo >&2 "$0: cannot convert XML report to HTML"
            rm $tmp/$base_noext.html
          fi
        fi
        $move_if_change "$file" "$out"
        ;;

      *.hh)
        fix_bison_output "$file"
        # To save cycles, if the file differs only on sync lines,
        # update it (to be right), but keep the original timestamps.
        if test -r "$out" &&
           diff -I '^#line' -I '/\* Line .* of .*  \*/' -q "$file" "$out"; then
            touch -r "$out" "$file"
            cp "$out" "$out.bak"
            echo >&2 "$0: kept the stamps of $file"
        fi
        $move_if_change "$file" "$out"
        ;;

      *)
        fix_bison_output "$file"
        $move_if_change "$file" "$out"
        ;;
      esac
115
    done
Roland Levillain's avatar
Roland Levillain committed
116
117
118
119
120
121
122
123
124
    ;;

  *) # We really want to keep the *.output files.
    for file in $(ls $tmp/*.output $tmp/*.xml $tmp/*.html 2>/dev/null)
    do
      $move_if_change "$file" "$output_dir/$(basename $file)"
    done
    ;;
esac
Benoit Perrot's avatar
Benoit Perrot committed
125
126
127

# Get rid of the tmp dir.
rm -rf $tmp
128
exit $status