1# =========================================================================== 2# http://www.nongnu.org/autoconf-archive/ax_lib_oracle_oci.html 3# =========================================================================== 4# 5# SYNOPSIS 6# 7# AX_LIB_ORACLE_OCI([MINIMUM-VERSION]) 8# 9# DESCRIPTION 10# 11# This macro provides tests of availability of Oracle OCI API of 12# particular version or newer. This macros checks for Oracle OCI headers 13# and libraries and defines compilation flags. 14# 15# Macro supports following options and their values: 16# 17# 1) Single-option usage: 18# 19# --with-oci -- path to ORACLE_HOME directory 20# 21# 2) Two-options usage (both options are required): 22# 23# --with-oci-include -- path to directory with OCI headers 24# --with-oci-lib -- path to directory with OCI libraries 25# 26# NOTE: These options described above do not take yes|no values. If 'yes' 27# value is passed, then WARNING message will be displayed, 'no' value, as 28# well as the --without-oci-* variations will cause the macro to not check 29# enything. 30# 31# This macro calls: 32# 33# AC_SUBST(ORACLE_OCI_CFLAGS) 34# AC_SUBST(ORACLE_OCI_LDFLAGS) 35# AC_SUBST(ORACLE_OCI_VERSION) 36# 37# And sets: 38# 39# HAVE_ORACLE_OCI 40# 41# LICENSE 42# 43# Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net> 44# 45# Copying and distribution of this file, with or without modification, are 46# permitted in any medium without royalty provided the copyright notice 47# and this notice are preserved. This file is offered as-is, without any 48# warranty. 49 50#serial 9 51 52AC_DEFUN([AX_LIB_ORACLE_OCI], 53[ 54 AC_ARG_WITH([oci], 55 AS_HELP_STRING([--with-oci=ARG], 56 [Use Oracle OCI API from given Oracle home (ARG=path); use existing ORACLE_HOME (ARG=yes); 57 disable Oracle OCI support (ARG=no). If you only have Oracle Instant Client libs installed, 58 and in a non-standard location, use; --with-oci-include and --with-oci-lib. See description below.] 59 ), 60 [ 61 if test "$withval" = "yes"; then 62 if test -n "$ORACLE_HOME"; then 63 oracle_home_dir="$ORACLE_HOME" 64 else 65 oracle_home_dir="" 66 fi 67 elif test -d "$withval"; then 68 oracle_home_dir="$withval" 69 else 70 oracle_home_dir="" 71 fi 72 ], 73 [ 74 if test -n "$ORACLE_HOME"; then 75 oracle_home_dir="$ORACLE_HOME" 76 else 77 oracle_home_dir="" 78 fi 79 ] 80 ) 81 82 AC_ARG_WITH([oci-include], 83 AS_HELP_STRING([--with-oci-include=DIR], 84 [Use Oracle OCI API headers from given path] 85 ), 86 [oracle_home_include_dir="$withval"], 87 [oracle_home_include_dir=""] 88 ) 89 AC_ARG_WITH([oci-lib], 90 AS_HELP_STRING([--with-oci-lib=DIR], 91 [Use Oracle OCI API libraries from given path] 92 ), 93 [oracle_home_lib_dir="$withval"], 94 [oracle_home_lib_dir=""] 95 ) 96 97 ORACLE_OCI_CFLAGS="" 98 ORACLE_OCI_LDFLAGS="" 99 ORACLE_OCI_VERSION="" 100 101 dnl 102 dnl Collect include/lib paths 103 dnl 104 want_oracle_but_no_path="no" 105 106 if test -n "$oracle_home_dir"; then 107 108 if test "$oracle_home_dir" != "no" -a "$oracle_home_dir" != "yes"; then 109 dnl ORACLE_HOME path provided 110 111 dnl Primary path to OCI headers, available in Oracle>=10 112 oracle_include_dir="$oracle_home_dir/rdbms/public" 113 114 dnl Secondary path to OCI headers used by older versions 115 oracle_include_dir2="$oracle_home_dir/rdbms/demo" 116 117 dnl Library path 118 oracle_lib_dir="$oracle_home_dir/lib" 119 elif test "$oracle_home_dir" = "yes"; then 120 want_oracle_but_no_path="yes" 121 fi 122 123 elif test -n "$oracle_home_include_dir" -o -n "$oracle_home_lib_dir"; then 124 125 if test "$oracle_home_include_dir" != "no" -a "$oracle_home_include_dir" != "yes"; then 126 oracle_include_dir="$oracle_home_include_dir" 127 elif test "$oracle_home_include_dir" = "yes"; then 128 want_oracle_but_no_path="yes" 129 fi 130 131 if test "$oracle_home_lib_dir" != "no" -a "$oracle_home_lib_dir" != "yes"; then 132 oracle_lib_dir="$oracle_home_lib_dir" 133 elif test "$oracle_home_lib_dir" = "yes"; then 134 want_oracle_but_no_path="yes" 135 fi 136 fi 137 138 if test "$want_oracle_but_no_path" = "yes"; then 139 AC_MSG_WARN([Oracle support is requested but no Oracle paths have been provided. \ 140Please, locate Oracle directories using --with-oci or \ 141--with-oci-include and --with-oci-lib options.]) 142 fi 143 144 dnl 145 dnl Check OCI files 146 dnl 147 if test -n "$oracle_include_dir" -a -n "$oracle_lib_dir"; then 148 149 saved_CPPFLAGS="$CPPFLAGS" 150 CPPFLAGS="$CPPFLAGS -I$oracle_include_dir" 151 152 dnl Additional path for older Oracle installations 153 if test -n "$oracle_include_dir2"; then 154 CPPFLAGS="$CPPFLAGS -I$oracle_include_dir2" 155 fi 156 157 dnl Depending on later Oracle version detection, 158 dnl -lnnz10 flag might be removed for older Oracle < 10.x 159 saved_LDFLAGS="$LDFLAGS" 160 oci_ldflags="-L$oracle_lib_dir -lclntsh" 161 LDFLAGS="$LDFLAGS $oci_ldflags" 162 163 dnl 164 dnl Check OCI headers 165 dnl 166 AC_MSG_CHECKING([for Oracle OCI headers in $oracle_include_dir]) 167 168 AC_COMPILE_IFELSE([ 169 AC_LANG_PROGRAM([[@%:@include <oci.h>]], 170 [[ 171#if defined(OCI_MAJOR_VERSION) 172#if OCI_MAJOR_VERSION == 10 && OCI_MINOR_VERSION == 2 173// Oracle 10.2 detected 174#endif 175#elif defined(OCI_V7_SYNTAX) 176// OK, older Oracle detected 177// TODO - mloskot: find better macro to check for older versions; 178#else 179# error Oracle oci.h header not found 180#endif 181 ]] 182 )], 183 [ 184 ORACLE_OCI_CFLAGS="-I$oracle_include_dir" 185 186 if test -n "$oracle_include_dir2"; then 187 ORACLE_OCI_CFLAGS="$ORACLE_OCI_CFLAGS -I$oracle_include_dir2" 188 fi 189 190 oci_header_found="yes" 191 AC_MSG_RESULT([yes]) 192 ], 193 [ 194 oci_header_found="no" 195 AC_MSG_RESULT([not found]) 196 ] 197 ) 198 199 dnl 200 dnl Check OCI libraries 201 dnl 202 if test "$oci_header_found" = "yes"; then 203 204 AC_MSG_CHECKING([for Oracle OCI libraries in $oracle_lib_dir]) 205 206 AC_LINK_IFELSE([ 207 AC_LANG_PROGRAM([[@%:@include <oci.h>]], 208 [[ 209OCIEnv* envh = 0; 210OCIEnvCreate(&envh, OCI_DEFAULT, 0, 0, 0, 0, 0, 0); 211if (envh) OCIHandleFree(envh, OCI_HTYPE_ENV); 212 ]] 213 )], 214 [ 215 ORACLE_OCI_LDFLAGS="$oci_ldflags" 216 oci_lib_found="yes" 217 AC_MSG_RESULT([yes]) 218 ], 219 [ 220 oci_lib_found="no" 221 AC_MSG_RESULT([not found]) 222 ] 223 ) 224 fi 225 226 CPPFLAGS="$saved_CPPFLAGS" 227 LDFLAGS="$saved_LDFLAGS" 228 fi 229 230 dnl 231 dnl Check required version of Oracle is available 232 dnl 233 oracle_version_req=ifelse([$1], [], [], [$1]) 234 235 if test "$oci_header_found" = "yes" -a "$oci_lib_found" = "yes" -a \ 236 -n "$oracle_version_req"; then 237 238 oracle_version_major=`cat $oracle_include_dir/oci.h \ 239 | grep '#define.*OCI_MAJOR_VERSION.*' \ 240 | sed -e 's/#define OCI_MAJOR_VERSION *//' \ 241 | sed -e 's/ *\/\*.*\*\///'` 242 243 oracle_version_minor=`cat $oracle_include_dir/oci.h \ 244 | grep '#define.*OCI_MINOR_VERSION.*' \ 245 | sed -e 's/#define OCI_MINOR_VERSION *//' \ 246 | sed -e 's/ *\/\*.*\*\///'` 247 248 AC_MSG_CHECKING([if Oracle OCI version is >= $oracle_version_req]) 249 250 if test -n "$oracle_version_major" -a -n $"oracle_version_minor"; then 251 252 ORACLE_OCI_VERSION="$oracle_version_major.$oracle_version_minor" 253 254 dnl Decompose required version string of Oracle 255 dnl and calculate its number representation 256 oracle_version_req_major=`expr $oracle_version_req : '\([[0-9]]*\)'` 257 oracle_version_req_minor=`expr $oracle_version_req : '[[0-9]]*\.\([[0-9]]*\)'` 258 259 oracle_version_req_number=`expr $oracle_version_req_major \* 1000000 \ 260 \+ $oracle_version_req_minor \* 1000` 261 262 dnl Calculate its number representation 263 oracle_version_number=`expr $oracle_version_major \* 1000000 \ 264 \+ $oracle_version_minor \* 1000` 265 266 oracle_version_check=`expr $oracle_version_number \>\= $oracle_version_req_number` 267 if test "$oracle_version_check" = "1"; then 268 269 oracle_version_checked="yes" 270 AC_MSG_RESULT([yes]) 271 272 dnl Add -lnnz10 flag to Oracle >= 10.x 273 AC_MSG_CHECKING([for Oracle version >= 10.x to use -lnnz10 flag]) 274 oracle_nnz10_check=`expr $oracle_version_number \>\= 10 \* 1000000` 275 if test "$oracle_nnz10_check" = "1"; then 276 ORACLE_OCI_LDFLAGS="$ORACLE_OCI_LDFLAGS -lnnz10" 277 AC_MSG_RESULT([yes]) 278 else 279 AC_MSG_RESULT([no]) 280 fi 281 else 282 oracle_version_checked="no" 283 AC_MSG_RESULT([no]) 284 AC_MSG_ERROR([Oracle $ORACLE_OCI_VERSION found, but required version is $oracle_version_req]) 285 fi 286 else 287 ORACLE_OCI_VERSION="UNKNOWN" 288 AC_MSG_RESULT([no]) 289 AC_MSG_WARN([Oracle version unknown, probably OCI older than 10.2 is available]) 290 fi 291 fi 292 293 AC_MSG_CHECKING([if Oracle support is enabled]) 294 295 if test "$oci_header_found" = "yes" -a "$oci_lib_found" = "yes"; then 296 297 AC_SUBST([ORACLE_OCI_VERSION]) 298 AC_SUBST([ORACLE_OCI_CFLAGS]) 299 AC_SUBST([ORACLE_OCI_LDFLAGS]) 300 301 HAVE_ORACLE_OCI="yes" 302 else 303 HAVE_ORACLE_OCI="no" 304 fi 305 306 AC_MSG_RESULT([$HAVE_ORACLE_OCI]) 307]) 308