1#!/bin/sh
2#
3#
4
5datarootdir=@datarootdir@
6AWK=@AWK@
7DIR="${DIR-@datadir@/et}"
8ET_DIR="@ET_DIR@"
9
10if test "$1" = "--build-tree" ; then
11    shift;
12    DIR="$ET_DIR"
13fi
14
15if test "x$1" = x ; then
16    echo "Usage: compile_et file"
17    exit 1
18fi
19
20for as_var in \
21  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
22  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
23  LC_TELEPHONE LC_TIME
24do
25  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
26    eval $as_var=C; export $as_var
27  else
28    $as_unset $as_var
29  fi
30done
31
32if test ! -f "$DIR/et_h.awk" || test ! -f "$DIR/et_c.awk" ; then
33    DIR="$ET_DIR"
34#    echo "Falling back to $DIR..."
35    if test ! -f "$DIR/et_h.awk" || test ! -f "$DIR/et_c.awk" ; then
36	echo "compile_et: Couldn't find compile_et's template files."
37	exit 1
38    fi
39fi
40
41ROOT=`echo $1 | sed -e s/.et$//`
42BASE=`basename $ROOT`
43
44if test ! -f "$ROOT.et" ; then
45    echo "compile_et: $ROOT.et: File not found"
46    exit 1;
47fi
48
49$AWK -f "${DIR}/et_h.awk" "outfile=${BASE}.h.$$" "outfn=${BASE}.h" "$ROOT.et"
50if test -f ${BASE}.h && cmp -s ${BASE}.h.$$ ${BASE}.h ; then
51    rm -f ${BASE}.h.$$
52else
53    mv -f ${BASE}.h.$$ ${BASE}.h
54    chmod -w ${BASE}.h
55fi
56$AWK -f "${DIR}/et_c.awk" "outfile=${BASE}.c.$$" "outfn=${BASE}.c" "$ROOT.et"
57if test -f ${BASE}.c && cmp -s ${BASE}.c.$$ ${BASE}.c ; then
58    rm -f ${BASE}.c.$$
59else
60    mv -f ${BASE}.c.$$ ${BASE}.c
61    chmod -w ${BASE}.c
62fi
63