1AC_DEFUN([AX_SUBMODULE],
2[
3
4AC_ARG_WITH($1,
5	[AS_HELP_STRING([--with-$1=$2],
6			[Which $1 to use])])
7case "system" in
8$2)
9	AC_ARG_WITH($1_prefix,
10		    [AS_HELP_STRING([--with-$1-prefix=DIR],
11				    [Prefix of $1 installation])])
12	AC_ARG_WITH($1_exec_prefix,
13		    [AS_HELP_STRING([--with-$1-exec-prefix=DIR],
14				    [Exec prefix of $1 installation])])
15esac
16case "build" in
17$2)
18	AC_ARG_WITH($1_builddir,
19		    [AS_HELP_STRING([--with-$1-builddir=DIR],
20				    [Location of $1 builddir])])
21esac
22if test "x$with_$1_prefix" != "x" -a "x$with_$1_exec_prefix" = "x"; then
23	with_$1_exec_prefix=$with_$1_prefix
24fi
25if test "x$with_$1_prefix" != "x" -o "x$with_$1_exec_prefix" != "x"; then
26	if test "x$with_$1" != "x" -a "x$with_$1" != "xsystem"; then
27		AC_MSG_ERROR([Setting $with_$1_prefix implies use of system $1])
28	fi
29	with_$1="system"
30fi
31if test "x$with_$1_builddir" != "x"; then
32	if test "x$with_$1" != "x" -a "x$with_$1" != "xbuild"; then
33		AC_MSG_ERROR([Setting $with_$1_builddir implies use of build $1])
34	fi
35	with_$1="build"
36	$1_srcdir=`echo @abs_srcdir@ | $with_$1_builddir/config.status --file=-`
37	AC_MSG_NOTICE($1 sources in $$1_srcdir)
38fi
39case "$with_$1" in
40$2)
41	;;
42*)
43	if test -d $srcdir/.git -a \
44		-d $srcdir/$1 -a \
45		! -d $srcdir/$1/.git; then
46		AC_MSG_WARN(
47[git repo detected, but submodule $1 not initialized])
48		AC_MSG_WARN([You may want to run])
49		AC_MSG_WARN([	git submodule init])
50		AC_MSG_WARN([	git submodule update])
51		AC_MSG_WARN([	sh autogen.sh])
52	fi
53	if test -f $srcdir/$1/configure -a "$3" != "no"; then
54		with_$1="bundled"
55	else
56		with_$1="$3"
57	fi
58	;;
59esac
60AC_MSG_CHECKING([which $1 to use])
61AC_MSG_RESULT($with_$1)
62
63])
64