rpcgen_wrapper.sh revision 285612
187866Ssheldonh#!/bin/sh
287866Ssheldonh# libevent rpcgen_wrapper.sh
387866Ssheldonh# Transforms event_rpcgen.py failure into success for make, only if
487866Ssheldonh# regress.gen.c and regress.gen.h already exist in $srcdir.  This
587866Ssheldonh# is needed for "make distcheck" to pass the read-only $srcdir build,
687866Ssheldonh# as with read-only sources fresh from tarball, regress.gen.[ch] will
787866Ssheldonh# be correct in $srcdir but unwritable.  This previously triggered
887866Ssheldonh# Makefile.am to create stub regress.gen.c and regress.gen.h in the
988282Ssheldonh# distcheck _build directory, which were then detected as leftover
1088282Ssheldonh# files in the build tree after distclean, breaking distcheck.
1187866Ssheldonh# Note that regress.gen.[ch] are not in fresh git clones, making
1287866Ssheldonh# working Python a requirement for make distcheck of a git tree.
1387866Ssheldonh
1487866Ssheldonhexit_updated() {
1587866Ssheldonh#    echo "Updated ${srcdir}/regress.gen.c and ${srcdir}/regress.gen.h"
1687866Ssheldonh    exit 0
1787866Ssheldonh}
1887866Ssheldonh
1987866Ssheldonhexit_reuse() {
2087866Ssheldonh    echo "event_rpcgen.py failed, ${srcdir}/regress.gen.\[ch\] will be reused." >&2
21    exit 0
22}
23
24exit_failed() {
25    echo "Could not generate regress.gen.\[ch\] using event_rpcgen.sh" >&2
26    exit 1
27}
28
29if [ -x /usr/bin/python2 ] ; then
30  PYTHON2=/usr/bin/python2
31elif [ "x`which python2`" != x ] ; then
32  PYTHON2=python2
33else
34  PYTHON2=python
35fi
36
37srcdir=$1
38srcdir=${srcdir:-.}
39
40${PYTHON2} ${srcdir}/../event_rpcgen.py --quiet ${srcdir}/regress.rpc \
41               test/regress.gen.h test/regress.gen.c
42
43case "$?" in
44 0)
45    exit_updated
46    ;;
47 *)
48    test -r ${srcdir}/regress.gen.c -a -r ${srcdir}/regress.gen.h && \
49	exit_reuse
50    exit_failed
51    ;;
52esac
53