13839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#!/bin/sh
23839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#
33839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#
4b6b65c3de480c8e17c2bf9ab12196c7dde325380Theodore Ts'o
5b6b65c3de480c8e17c2bf9ab12196c7dde325380Theodore Ts'odatarootdir=@datarootdir@
63839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oAWK=@AWK@
7e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'oDIR="${DIR-@datadir@/et}"
87eb0669dd711b57eda839de65b59ac5501cb1fe2Theodore Ts'oET_DIR="@ET_DIR@"
9e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o
1091835c151fd48fd03bfe74133b8214486af18c12Theodore Ts'oif test "$1" = "--build-tree" ; then
1191835c151fd48fd03bfe74133b8214486af18c12Theodore Ts'o    shift;
1291835c151fd48fd03bfe74133b8214486af18c12Theodore Ts'o    DIR="$ET_DIR"
1391835c151fd48fd03bfe74133b8214486af18c12Theodore Ts'ofi
1491835c151fd48fd03bfe74133b8214486af18c12Theodore Ts'o
15e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'oif test "x$1" = x ; then
16e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o    echo "Usage: compile_et file"
17e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o    exit 1
18e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'ofi
19e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o
2005155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'ofor as_var in \
2105155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
2205155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
2305155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o  LC_TELEPHONE LC_TIME
2405155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'odo
2505155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
2605155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o    eval $as_var=C; export $as_var
2705155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o  else
2805155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o    $as_unset $as_var
2905155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o  fi
3005155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'odone
3105155f9bff3935bd45a506a0fe0a277070d23094Theodore Ts'o
3256eb4d47492c975b25ab1737a6fffefc80e5c137Theodore Ts'oif test ! -f "$DIR/et_h.awk" || test ! -f "$DIR/et_c.awk" ; then
337eb0669dd711b57eda839de65b59ac5501cb1fe2Theodore Ts'o    DIR="$ET_DIR"
34e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o#    echo "Falling back to $DIR..."
3556eb4d47492c975b25ab1737a6fffefc80e5c137Theodore Ts'o    if test ! -f "$DIR/et_h.awk" || test ! -f "$DIR/et_c.awk" ; then
36e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o	echo "compile_et: Couldn't find compile_et's template files."
37e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o	exit 1
38e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o    fi
39e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'ofi
403839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
413839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oROOT=`echo $1 | sed -e s/.et$//`
423839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oBASE=`basename $ROOT`
433839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
447eb0669dd711b57eda839de65b59ac5501cb1fe2Theodore Ts'oif test ! -f "$ROOT.et" ; then
45e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o    echo "compile_et: $ROOT.et: File not found"
46e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o    exit 1;
47e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'ofi
48e5fa0e3031822d3da46ac78230c0595c6c462f87Theodore Ts'o
49153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'o$AWK -f "${DIR}/et_h.awk" "outfile=${BASE}.h.$$" "outfn=${BASE}.h" "$ROOT.et"
50153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'oif test -f ${BASE}.h && cmp -s ${BASE}.h.$$ ${BASE}.h ; then
513f5ef9642bc08bf2a9088a0ec58ec9b0abadf0a6Andreas Dilger    rm -f ${BASE}.h.$$
52153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'oelse
533f5ef9642bc08bf2a9088a0ec58ec9b0abadf0a6Andreas Dilger    mv -f ${BASE}.h.$$ ${BASE}.h
543f5ef9642bc08bf2a9088a0ec58ec9b0abadf0a6Andreas Dilger    chmod -w ${BASE}.h
55153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'ofi
56153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'o$AWK -f "${DIR}/et_c.awk" "outfile=${BASE}.c.$$" "outfn=${BASE}.c" "$ROOT.et"
57153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'oif test -f ${BASE}.c && cmp -s ${BASE}.c.$$ ${BASE}.c ; then
583f5ef9642bc08bf2a9088a0ec58ec9b0abadf0a6Andreas Dilger    rm -f ${BASE}.c.$$
59153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'oelse
603f5ef9642bc08bf2a9088a0ec58ec9b0abadf0a6Andreas Dilger    mv -f ${BASE}.c.$$ ${BASE}.c
613f5ef9642bc08bf2a9088a0ec58ec9b0abadf0a6Andreas Dilger    chmod -w ${BASE}.c
62153b4495c1bdf38e84f75986563dbae336000fadTheodore Ts'ofi
63