Update to work with more recent versions of Oracle
[freeradius.git] / src / modules / rlm_sql / drivers / rlm_sql_oracle / configure.in
1 AC_INIT(sql_oracle.c)
2 AC_REVISION($Revision: 1.10 $)
3 AC_DEFUN(modname,[rlm_sql_oracle])
4
5 fail=
6 sql_oracle_ldflags=
7 sql_oracle_cflags=
8 if test x$with_[]modname != xno; then
9
10         AC_MSG_CHECKING([for oci.h])
11
12         dnl #
13         dnl # See if the user passed in the oracle_home_dir option and
14         dnl # use that first.  If not, use $ORACLE_HOME.  If that's
15         dnl # not defined, give up.  There's no point in blindly
16         dnl # hunting around for Oracle - there's no standard place
17         dnl # for it.  Any sane Oracle user/developer should have $ORACLE_HOME
18         dnl # defined anyways.
19         dnl #
20
21         dnl ############################################################
22         dnl # Check for command line options
23         dnl ############################################################
24
25         dnl extra argument: --with-oracle-include-dir=DIR
26         oracle_include_dir=
27         AC_ARG_WITH(oracle-include-dir,
28                 [AS_HELP_STRING([--with-oracle-include-dir=DIR],
29                             [Directory where the Oracle includes may be found. It should be located under ORACLE_HOME if you have client SDK installed. Use --with-oracle-include-dir=yes if you are sure that your compiler include path includes Oracle include dir. Hint: you might try to do: locate oci.h])],
30                 [case "$withval" in
31                         no)
32                             AC_MSG_ERROR(Need oracle-include-dir)
33                             ;;
34                         yes)
35                             ;;
36                         *)
37                             oracle_include_dir="$withval"
38                             ;;
39                 esac])
40
41         dnl extra argument: --with-oracle-lib-dir=DIR
42         oracle_lib_dir=
43         AC_ARG_WITH(oracle-lib-dir,
44                 [AS_HELP_STRING([--with-oracle-lib-dir=DIR],
45                             [Directory where the oracle libraries may be found. It should be located under ORACLE_HOME. iUse --with-oracle-lib-dir=yes if you are sure that your linker will find the necessary Oracle client libs. Hint: you might try to do: locate libclntsh.so])],
46                 [case "$withval" in
47                         no)
48                             AC_MSG_ERROR(Need oracle-lib-dir)
49                             ;;
50                         yes)
51                             ;;
52                         *)
53                             oracle_lib_dir="$withval"
54                             ;;
55         esac])
56
57
58
59         AC_TRY_COMPILE([#include <oci.h>],
60                 [ int a = 1;],
61                 ORACLE_INCLUDE=" ",
62                 ORACLE_INCLUDE=
63         )
64
65         RLM_SQL_ORA_WORKING_CFLAGS_FOR_LINKING_TEST=
66         if test "x$ORACLE_INCLUDE" = "x" ; then
67                 old_CFLAGS="$CFLAGS"
68                 CFLAGS="$old_CFLAGS -I$oracle_include_dir"
69                 AC_TRY_COMPILE([#include <oci.h>],
70                         [ int a = 1;],
71                         ORACLE_INCLUDE="-I$oracle_include_dir",
72                         ORACLE_INCLUDE=
73                 )
74
75                 RLM_SQL_ORA_WORKING_CFLAGS_FOR_LINKING_TEST="$CFLAGS"
76                 CFLAGS="$old_CFLAGS"
77         fi
78
79         # Proceed to linking makes only sense if include dir is OK.
80         if test "x$ORACLE_INCLUDE" != "x" ; then
81                 old_LIBS="$LIBS"
82                 old_CFLAGS="$CFLAGS"
83                 CFLAGS="$RLM_SQL_ORA_WORKING_CFLAGS_FOR_LINKING_TEST"
84
85                 ORACLE_LIBDIR_SWITCH=
86                 if test "x$oracle_lib_dir" != "x" ; then
87                         ORACLE_LIBDIR_SWITCH="-L${oracle_lib_dir} "
88                 fi
89                 for oracle_version in 10 11 9 ""; do
90                         LIBS="$old_LIBS $ORACLE_LIBDIR_SWITCH -lclntsh -lnnz${oracle_version}"
91                         AC_TRY_LINK([#include <oci.h>
92                 
93                                         static OCIEnv           *p_env;
94                                         static OCIError         *p_err;
95                                         static OCISvcCtx        *p_svc;
96                                         static OCIStmt          *p_sql;
97                                         static OCIDefine        *p_dfn    = (OCIDefine *) 0;
98                                         static OCIBind          *p_bnd    = (OCIBind *) 0;
99                                 ],
100                                 [
101                                           int             p_bvi;
102                                           char            p_sli[20];
103                                           int             rc;
104                                           char            errbuf[100];
105                                           int             errcode;
106                                         
107                                           rc = OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0,  /* Initialize OCI */
108                                                           (dvoid * (*)(dvoid *, size_t)) 0,
109                                                           (dvoid * (*)(dvoid *, dvoid *, size_t))0,
110                                                           (void (*)(dvoid *, dvoid *)) 0 );
111
112                                 ],
113                                 ORACLE_LIBS="$ORACLE_LIBDIR_SWITCH -lclntsh -lnnz${oracle_version}",
114                                 ORACLE_LIBS=
115                         )
116                         if test "x$ORACLE_LIBS" != "x"; then
117                                 break
118                         fi
119                 done
120
121                 LIBS="$old_LIBS"
122                 CFLAGS="$old_CFLAGS"
123         fi
124
125
126         if test "x$ORACLE_INCLUDE" = "x"; then
127                 AC_MSG_RESULT(no)
128                 AC_MSG_WARN([oracle headers not found.  Use --with-oracle-include-dir=<path>.])
129                 fail="$fail oci.h"
130         else
131                 sql_oracle_cflags="${sql_oracle_cflags} ${ORACLE_INCLUDE}"
132                 AC_MSG_RESULT(yes)
133
134
135                 if test "x$ORACLE_LIBS" = "x"; then
136                         AC_MSG_WARN([oracle libraries not found.  Use --with-oracle-lib-dir=<path>.])
137                         fail="$fail libclntsh libnnz${oracle_version}"
138                 else
139                         sql_oracle_ldflags="${sql_oracle_ldflags} $ORACLE_LIBS"
140                         AC_MSG_RESULT(yes)
141                 fi
142         fi
143
144         targetname=modname
145 else
146         targetname=
147         echo \*\*\* module modname is disabled.
148 fi
149
150 dnl Don't change this section.
151 if test "x$fail" != x; then
152         if test "x${enable_strict_dependencies}" = xyes; then
153                 AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
154         else
155                 AC_MSG_WARN([silently not building ]modname[.])
156                 AC_MSG_WARN([FAILURE: ]modname[ requires:$fail.]);
157                 targetname=
158         fi
159 fi
160
161 AC_SUBST(sql_oracle_ldflags)
162 AC_SUBST(sql_oracle_cflags)
163 AC_SUBST(targetname)
164 AC_OUTPUT(Makefile)