# --enable-clang-plugin=yes/no
AC_ARG_ENABLE([clang-plugin],
              [AS_HELP_STRING([--enable-clang-plugin=@<:@auto/yes/no@:>@],
                              [Build with support for the clang compiler toolchain.])],
              [enable_clang_plugin=$enableval],
              [enable_clang_plugin=auto])

# If clang is auto/yes, check that it is available.
AS_IF([test "$enable_clang_plugin" != "no"],[
	real_enable_clang_plugin=$enable_clang_plugin
	enable_clang_plugin=no
	AC_CHECK_PROGS([LLVM_CONFIG], [ \
		llvm-config-4.0 llvm-config40 \
		llvm-config-3.9 llvm-config39 \
		llvm-config-3.8 llvm-config38 \
		llvm-config-3.7 llvm-config37 \
		llvm-config-3.6 llvm-config36 \
		llvm-config-3.5 llvm-config35 \
		llvm-config llvm-config-devel], [])
	AS_IF([test "x$LLVM_CONFIG" = "x"],[],[
		CLANG_INCLUDEDIR=`$LLVM_CONFIG --includedir`
		CLANG_CFLAGS="-I$CLANG_INCLUDEDIR"
		CLANG_LDFLAGS=`$LLVM_CONFIG --ldflags`
		AC_SUBST([CLANG_INCLUDEDIR])
		AC_SUBST([CLANG_CFLAGS])
		AC_SUBST([CLANG_LDFLAGS])
		CPPFLAGS_SAVE=${CPPFLAGS}
		CPPFLAGS=-I${CLANG_INCLUDEDIR}
		AC_CHECK_HEADER([clang-c/Index.h], [enable_clang_plugin=yes], [
		    AC_MSG_RESULT([Failed to locage clang-c/Index.h. Please install clang-devel.])
		])
		CPPFLAGS=${CPPFLAGS_SAVE}
	])

	# Bail if --enable-clang-plugin=yes and we failed to locate it.
	AS_IF([test "$real_enable_clang_plugin" = "yes" && test "$enable_clang_plugin" = "no"],[
		AC_MSG_ERROR([Failed to locate clang dependencies.])
	])
])

# for if ENABLE_CLANG_PLUGIN in Makefile.am
AM_CONDITIONAL(ENABLE_CLANG_PLUGIN, test x$enable_clang_plugin = xyes)

# Ensure our makefile is generated by autoconf
AC_CONFIG_FILES([plugins/clang/Makefile])
