dnl CF_PROG_GNAT version: 12 updated: 2021/01/02 17:09:14
dnl ------------
dnl Check for gnat/gnatmake/etc, ensure that the toolset is complete.
AC_DEFUN([CF_PROG_GNAT],[
for cf_prog_gnat in gnat gnatmake gprconfig gprbuild
do
	CF_UPPER(cf_upper_prog_gnat,${cf_prog_gnat})

	unset ac_cv_path_cf_TEMP_gnat
	unset cf_TEMP_gnat
	AC_PATH_PROG(cf_TEMP_gnat,$cf_prog_gnat,no)
	eval "cf_cv_PATH_$cf_upper_prog_gnat=[$]ac_cv_path_cf_TEMP_gnat"

	if test "x$cf_TEMP_gnat" != xno; then
		unset cf_cv_gnat_version
		unset cf_TEMP_gnat
		CF_GNAT_VERSION(cf_TEMP_gnat,$cf_prog_gnat)
	fi
	eval "cf_cv_VERSION_$cf_upper_prog_gnat=[$]cf_TEMP_gnat"

	unset cf_TEMP_gnat
	unset cf_cv_gnat_version
	unset ac_cv_path_cf_TEMP_gnat
done

if test "x$cf_cv_VERSION_GNATMAKE" = "xno"; then
	cf_ada_make=
	cf_cv_prog_gnat_correct=no
else
	cf_ada_make=gnatmake
	if test "x$cf_cv_VERSION_GPRCONFIG" = "xno"; then
		# gprconfig is newer than gnatmake; we can continue...
		cf_ada_config="##"
	else
		rm -rf ./conftest* ./*~conftest*
		if mkdir conftest.src
		then
			cf_ada_config=""
			cd conftest.src
			for cf_gprconfig in Ada C
			do
				AC_MSG_CHECKING(for gprconfig name for $cf_gprconfig)
				if test "$cf_gprconfig" = C
				then
					for cf_gprconfig_param in \
						"$cf_gprconfig,,,,GNATGCC" \
						"$cf_gprconfig,,,,GCC" \
						"$cf_gprconfig"
					do
						cf_gprconfig_value=`echo s| gprconfig --config=$cf_gprconfig_param 2>&AC_FD_CC | ${AWK:-awk} '/^\*/{print [$]3;}' | head -n 1`
						test -n "$cf_gprconfig_value" && break
					done
				else
					cf_gprconfig_param=$cf_gprconfig
					cf_gprconfig_value=`echo s| gprconfig --config=$cf_gprconfig_param 2>&AC_FD_CC | ${AWK:-awk} '/^\*/{print [$]3;}' | head -n 1`
				fi
				if test -n "$cf_gprconfig_value"
				then
					eval "cf_ada_config_[$]cf_gprconfig=[$]cf_gprconfig_value"
					AC_MSG_RESULT($cf_gprconfig_value)
				else
					AC_MSG_RESULT(missing)
					cf_ada_config="#"
					break
				fi
			done
			cd ..
			rm -rf ./conftest* ./*~conftest*
		fi
	fi
	if test "x$cf_ada_config" != "x#"
	then
		CF_GNAT_VERSION
		CF_CHECK_GNAT_VERSION
		AC_CHECK_PROG(M4_exists, m4, yes, no)
		if test "$ac_cv_prog_M4_exists" = no; then
			cf_cv_prog_gnat_correct=no
			AC_MSG_WARN(Ada95 binding required program m4 not found. Ada95 binding disabled)
		fi
		if test "$cf_cv_prog_gnat_correct" = yes; then
			AC_MSG_CHECKING(if GNAT works)
			CF_GNAT_TRY_RUN([procedure conftest;],
[with Text_IO;
with GNAT.OS_Lib;
procedure conftest is
begin
   Text_IO.Put ("Hello World");
   Text_IO.New_Line;
   GNAT.OS_Lib.OS_Exit (0);
end conftest;],
[cf_cv_prog_gnat_correct=yes],
[cf_cv_prog_gnat_correct=no])
			AC_MSG_RESULT($cf_cv_prog_gnat_correct)
		fi
	else
		cf_cv_prog_gnat_correct=no
	fi
fi

AC_SUBST(cf_ada_make)
AC_SUBST(cf_ada_config)
AC_SUBST(cf_ada_config_Ada)
AC_SUBST(cf_ada_config_C)
])dnl
