1275970Scy#!/bin/sh
2275970Scy# libevent rpcgen_wrapper.sh
3275970Scy# Transforms event_rpcgen.py failure into success for make, only if
4275970Scy# regress.gen.c and regress.gen.h already exist in $srcdir.  This
5275970Scy# is needed for "make distcheck" to pass the read-only $srcdir build,
6275970Scy# as with read-only sources fresh from tarball, regress.gen.[ch] will
7275970Scy# be correct in $srcdir but unwritable.  This previously triggered
8275970Scy# Makefile.am to create stub regress.gen.c and regress.gen.h in the
9275970Scy# distcheck _build directory, which were then detected as leftover
10275970Scy# files in the build tree after distclean, breaking distcheck.
11275970Scy# Note that regress.gen.[ch] are not in fresh git clones, making
12275970Scy# working Python a requirement for make distcheck of a git tree.
13275970Scy
14275970Scyexit_updated() {
15275970Scy#    echo "Updated ${srcdir}/regress.gen.c and ${srcdir}/regress.gen.h"
16275970Scy    exit 0
17275970Scy}
18275970Scy
19275970Scyexit_reuse() {
20275970Scy    echo "event_rpcgen.py failed, ${srcdir}/regress.gen.\[ch\] will be reused." >&2
21275970Scy    exit 0
22275970Scy}
23275970Scy
24275970Scyexit_failed() {
25275970Scy    echo "Could not generate regress.gen.\[ch\] using event_rpcgen.sh" >&2
26275970Scy    exit 1
27275970Scy}
28275970Scy
29275970Scyif [ -x /usr/bin/python2 ] ; then
30275970Scy  PYTHON2=/usr/bin/python2
31275970Scyelif [ "x`which python2`" != x ] ; then
32275970Scy  PYTHON2=python2
33275970Scyelse
34275970Scy  PYTHON2=python
35275970Scyfi
36275970Scy
37275970Scysrcdir=$1
38275970Scysrcdir=${srcdir:-.}
39275970Scy
40275970Scy${PYTHON2} ${srcdir}/../event_rpcgen.py --quiet ${srcdir}/regress.rpc \
41275970Scy               test/regress.gen.h test/regress.gen.c
42275970Scy
43275970Scycase "$?" in
44275970Scy 0)
45275970Scy    exit_updated
46275970Scy    ;;
47275970Scy *)
48275970Scy    test -r ${srcdir}/regress.gen.c -a -r ${srcdir}/regress.gen.h && \
49275970Scy	exit_reuse
50275970Scy    exit_failed
51275970Scy    ;;
52275970Scyesac
53