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