1dnl Id
2dnl
3dnl CHECK_COMPILE_ET
4AC_DEFUN([CHECK_COMPILE_ET], [
5
6AC_CHECK_PROG(COMPILE_ET, compile_et, [compile_et], [no])
7
8krb_cv_compile_et="no"
9krb_cv_com_err_need_r=""
10krb_cv_compile_et_cross=no
11if test "${COMPILE_ET}" != "no"; then
12
13dnl We have compile_et.  Now let's see if it supports `prefix' and `index'.
14AC_MSG_CHECKING(whether compile_et has the features we need)
15cat > conftest_et.et <<'EOF'
16error_table test conf
17prefix CONFTEST
18index 1
19error_code CODE1, "CODE1"
20index 128
21error_code CODE2, "CODE2"
22end
23EOF
24if ${COMPILE_ET} conftest_et.et >/dev/null 2>&1; then
25  dnl XXX Some systems have <et/com_err.h>.
26  save_CPPFLAGS="${CPPFLAGS}"
27  if test -d "/usr/include/et"; then
28    CPPFLAGS="-I/usr/include/et ${CPPFLAGS}"
29  fi
30  dnl Check that the `prefix' and `index' directives were honored.
31  AC_LANG(C)
32  AC_RUN_IFELSE([AC_LANG_SOURCE([
33#include <com_err.h>
34#include <string.h>
35#include "conftest_et.h"
36int main(int argc, char **argv){
37#ifndef ERROR_TABLE_BASE_conf
38#error compile_et does not handle error_table N M
39#endif
40return (CONFTEST_CODE2 - CONFTEST_CODE1) != 127;}
41  ])], [krb_cv_compile_et="yes"],[CPPFLAGS="${save_CPPFLAGS}"],
42  [krb_cv_compile_et="yes" krb_cv_compile_et_cross=yes] )
43fi
44AC_MSG_RESULT(${krb_cv_compile_et})
45if test "${krb_cv_compile_et}" = "yes" -a "${krb_cv_compile_et_cross}" = no; then
46  AC_MSG_CHECKING([for if com_err generates a initialize_conf_error_table_r])
47  AC_EGREP_CPP([initialize_conf_error_table_r.*struct et_list],
48     [#include "conftest_et.h"],
49     [krb_cv_com_err_need_r="ok"])
50  if test X"$krb_cv_com_err_need_r" = X ; then
51    AC_MSG_RESULT(no)
52    krb_cv_compile_et=no
53  else
54    AC_MSG_RESULT(yes)
55  fi
56fi
57rm -fr conftest*
58fi
59
60if test "${krb_cv_compile_et_cross}" = yes ; then
61  krb_cv_com_err="cross"
62elif test "${krb_cv_compile_et}" = "yes"; then
63  dnl Since compile_et seems to work, let's check libcom_err
64  krb_cv_save_LIBS="${LIBS}"
65  LIBS="${LIBS} -lcom_err"
66  AC_MSG_CHECKING(for com_err)
67  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <com_err.h>]],[[
68    const char *p;
69    p = error_message(0);
70    initialize_error_table_r(0,0,0,0);
71    com_right_r(0, 0, 0, 0);
72  ]])],[krb_cv_com_err="yes"],[krb_cv_com_err="no"; CPPFLAGS="${save_CPPFLAGS}"])
73  AC_MSG_RESULT(${krb_cv_com_err})
74  LIBS="${krb_cv_save_LIBS}"
75else
76  dnl Since compile_et doesn't work, forget about libcom_err
77  krb_cv_com_err="no"
78fi
79
80dnl Only use the system's com_err if we found compile_et, libcom_err, and
81dnl com_err.h.
82if test "${krb_cv_com_err}" = "yes"; then
83    DIR_com_err=""
84    LIB_com_err="-lcom_err"
85    LIB_com_err_a=""
86    LIB_com_err_so=""
87    AC_MSG_NOTICE(Using the already-installed com_err)
88    COMPILE_ET="${ac_cv_prog_COMPILE_ET}"
89    localcomerr=no
90elif test "${krb_cv_com_err}" = "cross"; then
91    DIR_com_err="com_err"
92    LIB_com_err="\$(top_builddir)/lib/com_err/libcom_err.la"
93    LIB_com_err_a="\$(top_builddir)/lib/com_err/.libs/libcom_err.a"
94    LIB_com_err_so="\$(top_builddir)/lib/com_err/.libs/libcom_err.so"
95    AC_MSG_NOTICE(Using our own com_err with toolchain compile_et)
96    COMPILE_ET="${ac_cv_prog_COMPILE_ET}"
97    localcomerr=yes
98else
99    COMPILE_ET="\$(top_builddir)/lib/com_err/compile_et"
100    DIR_com_err="com_err"
101    LIB_com_err="\$(top_builddir)/lib/com_err/libcom_err.la"
102    LIB_com_err_a="\$(top_builddir)/lib/com_err/.libs/libcom_err.a"
103    LIB_com_err_so="\$(top_builddir)/lib/com_err/.libs/libcom_err.so"
104    AC_MSG_NOTICE(Using our own com_err)
105    localcomerr=yes
106fi
107AM_CONDITIONAL(COM_ERR, test "$localcomerr" = yes)dnl
108AC_SUBST(COMPILE_ET)
109AC_SUBST(DIR_com_err)
110AC_SUBST(LIB_com_err)
111AC_SUBST(LIB_com_err_a)
112AC_SUBST(LIB_com_err_so)
113
114])
115