Skip to content

Commit 6635948

Browse files
NattyNarwhalpetk
andauthored
Check for iODBC and unixODBC with pkg-config in PDO_ODBC (#14963)
* Check for iODBC and unixODBC with pkg-config in PDO_ODBC PDO_ODBC required that these backends had their path specified manually, which was clumsy and contrary to how procedural ODBC checked it. This adds a pkg-config based path to check for these backends that ignores the 'dir' part of the flag, so i.e. --with-pdo-odbc=unixODBC should pick it up from the correct location. Generic and the special ibm-db2 usecase should be unaffected. The header situation is unfortunately ugly, and has a workaround; this should also be cleaned up. * Move check for valid headers to after * Use existing CFLAGS for PDO_ODBC header check ...instead of a separate funny variable. It does mean we have to save and restore the value of CPPFLAGS, as AC_CHECK_HEADERS and friends rely on that variable instead of CFLAGS. Co-authored-by: Peter Kokot <[email protected]> * Move PDO_ODBC_TYPE to AC_DEFINE, simplify CFLAGS handling The variable PDO_ODBC_INCLUDE becomes redundant, as is the CFLAGS override for PHP_NEW_EXTENSION if we call PHP_EVAL_INCLINE in the generic case. Co-authored-by: Peter Kokot <[email protected]> * Use same variable names so evals can be combined * Fix identation * Suggested shell syntax cleanups --------- Co-authored-by: Peter Kokot <[email protected]>
1 parent 7b3d7c6 commit 6635948

File tree

1 file changed

+62
-50
lines changed

1 file changed

+62
-50
lines changed

ext/pdo_odbc/config.m4

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
define([PDO_ODBC_HELP_TEXT],[[
2-
The include and lib dirs are looked for under 'dir'. The 'flavour' can be one
3-
of: ibm-db2, iODBC, unixODBC, generic. If ',dir' part is omitted, default for
4-
the flavour you have selected will be used. e.g.: --with-pdo-odbc=unixODBC
5-
will check for unixODBC under /usr/local. You may attempt to use an otherwise
6-
unsupported driver using the 'generic' flavour. The syntax for generic ODBC
7-
support is: --with-pdo-odbc=generic,dir,libname,ldflags,cflags. When built as
8-
'shared' the extension filename is always pdo_odbc.so]])
2+
The 'flavour' part determines what driver or driver manager to use; it can be
3+
either ibm-db2, iODBC, unixODBC, or generic.
4+
5+
The include and lib dirs are looked for under 'dir'. You may attempt to use
6+
an otherwise unsupported driver using the 'generic' flavour. The syntax for
7+
generic ODBC support is: --with-pdo-odbc=generic,dir,libname,ldflags,cflags.
8+
When built as 'shared' the extension filename is always 'pdo_odbc.so'.
9+
10+
For unixODBC and iODBC, the 'dir' part is ignored and can be omitted, as
11+
pkg-config will be searched instead. For ibm-db2, it will search for the DB2
12+
driver at that path.]])
913

1014
PHP_ARG_WITH([pdo-odbc],
1115
[for ODBC v3 support for PDO],
1216
[AS_HELP_STRING([--with-pdo-odbc=flavour,dir],
1317
[PDO: Support for 'flavour' ODBC driver.]PDO_ODBC_HELP_TEXT)])
1418

1519
AC_DEFUN([PHP_PDO_ODBC_CHECK_HEADER],
16-
[AC_MSG_CHECKING([for $1 in $PDO_ODBC_INCDIR])
17-
AS_IF([test -f "$PDO_ODBC_INCDIR/$1"], [
20+
[AC_MSG_CHECKING([for $1])
21+
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([#include <$1>], [])], [
1822
php_pdo_odbc_have_header=yes
1923
AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
2024
[Define to 1 if you have the <$1> header file.])
21-
AC_MSG_RESULT([yes])
25+
AC_MSG_RESULT([yes])
2226
],
2327
[AC_MSG_RESULT([no])])
2428
])
@@ -48,15 +52,11 @@ if test "$PHP_PDO_ODBC" != "no"; then
4852
;;
4953

5054
iODBC|iodbc)
51-
pdo_odbc_def_libdir=/usr/local/$PHP_LIBDIR
52-
pdo_odbc_def_incdir=/usr/local/include
53-
pdo_odbc_def_lib=iodbc
55+
pdo_odbc_pkgconfig_module=libiodbc
5456
;;
5557

5658
unixODBC|unixodbc)
57-
pdo_odbc_def_libdir=/usr/local/$PHP_LIBDIR
58-
pdo_odbc_def_incdir=/usr/local/include
59-
pdo_odbc_def_lib=odbc
59+
pdo_odbc_pkgconfig_module=odbc
6060
;;
6161

6262
generic)
@@ -71,22 +71,52 @@ if test "$PHP_PDO_ODBC" != "no"; then
7171
;;
7272
esac
7373

74-
if test -n "$pdo_odbc_dir"; then
75-
PDO_ODBC_INCDIR="$pdo_odbc_dir/include"
76-
PDO_ODBC_LIBDIR="$pdo_odbc_dir/$PHP_LIBDIR"
74+
if test -n "$pdo_odbc_pkgconfig_module"; then
75+
AC_MSG_RESULT([$pdo_odbc_flavour using pkg-config])
76+
PKG_CHECK_MODULES([PDO_ODBC], [$pdo_odbc_pkgconfig_module])
7777
else
78-
PDO_ODBC_INCDIR="$pdo_odbc_def_incdir"
79-
PDO_ODBC_LIBDIR="$pdo_odbc_def_libdir"
78+
if test -n "$pdo_odbc_dir"; then
79+
PDO_ODBC_INCDIR="$pdo_odbc_dir/include"
80+
PDO_ODBC_LIBDIR="$pdo_odbc_dir/$PHP_LIBDIR"
81+
else
82+
PDO_ODBC_INCDIR="$pdo_odbc_def_incdir"
83+
PDO_ODBC_LIBDIR="$pdo_odbc_def_libdir"
84+
fi
85+
86+
AC_MSG_RESULT([$pdo_odbc_flavour
87+
libs $PDO_ODBC_LIBDIR,
88+
headers $PDO_ODBC_INCDIR])
89+
90+
if test ! -d "$PDO_ODBC_LIBDIR" ; then
91+
AC_MSG_WARN([library dir $PDO_ODBC_LIBDIR does not exist])
92+
fi
93+
94+
PDO_ODBC_CFLAGS="$pdo_odbc_def_cflags -I$PDO_ODBC_INCDIR"
95+
PDO_ODBC_LIBS="$pdo_odbc_def_ldflags -L$PDO_ODBC_LIBDIR -l$pdo_odbc_def_lib"
96+
97+
dnl Check first for an ODBC 1.0 function to assert that the libraries work
98+
PHP_CHECK_LIBRARY($pdo_odbc_def_lib, SQLBindCol,
99+
[
100+
dnl And now check for an ODBC 3.0 function to assert that they're *good*
101+
dnl libraries.
102+
PHP_CHECK_LIBRARY($pdo_odbc_def_lib, SQLAllocHandle,
103+
[], [
104+
AC_MSG_ERROR([
105+
Your ODBC library does not appear to be ODBC 3 compatible.
106+
You should consider using iODBC or unixODBC instead, and loading your
107+
libraries as a driver in that environment; it will emulate the
108+
functions required for PDO support.
109+
])], $PDO_ODBC_LIBS)
110+
],[
111+
AC_MSG_ERROR([Your ODBC library does not exist or there was an error. Check config.log for more information])
112+
], $PDO_ODBC_LIBS)
80113
fi
81114

82-
AC_MSG_RESULT([$pdo_odbc_flavour
83-
libs $PDO_ODBC_LIBDIR,
84-
headers $PDO_ODBC_INCDIR])
85-
86-
if test ! -d "$PDO_ODBC_LIBDIR" ; then
87-
AC_MSG_WARN([library dir $PDO_ODBC_LIBDIR does not exist])
88-
fi
115+
PHP_EVAL_INCLINE([$PDO_ODBC_CFLAGS])
116+
PHP_EVAL_LIBLINE([$PDO_ODBC_LIBS], [PDO_ODBC_SHARED_LIBADD])
89117

118+
OLD_CPPFLAGS=$CPPFLAGS
119+
CPPFLAGS="$CPPFLAGS $PDO_ODBC_CFLAGS"
90120
PHP_PDO_ODBC_CHECK_HEADER([cli0cli.h])
91121
PHP_PDO_ODBC_CHECK_HEADER([cli0core.h])
92122
PHP_PDO_ODBC_CHECK_HEADER([cli0defs.h])
@@ -104,33 +134,15 @@ if test "$PHP_PDO_ODBC" != "no"; then
104134
PHP_PDO_ODBC_CHECK_HEADER([sqlucode.h])
105135
PHP_PDO_ODBC_CHECK_HEADER([sqlunix.h])
106136
PHP_PDO_ODBC_CHECK_HEADER([udbcext.h])
137+
CPPFLAGS=$OLD_CPPFLAGS
107138

108139
AS_VAR_IF([php_pdo_odbc_have_header], [yes],,
109140
[AC_MSG_ERROR([Cannot find header file(s) for pdo_odbc.])])
110141

111-
PDO_ODBC_INCLUDE="$pdo_odbc_def_cflags -I$PDO_ODBC_INCDIR -DPDO_ODBC_TYPE=\\\"$pdo_odbc_flavour\\\""
112-
PDO_ODBC_LDFLAGS="$pdo_odbc_def_ldflags -L$PDO_ODBC_LIBDIR -l$pdo_odbc_def_lib"
113-
114-
PHP_EVAL_LIBLINE([$PDO_ODBC_LDFLAGS], [PDO_ODBC_SHARED_LIBADD])
115-
116-
dnl Check first for an ODBC 1.0 function to assert that the libraries work
117-
PHP_CHECK_LIBRARY($pdo_odbc_def_lib, SQLBindCol,
118-
[
119-
dnl And now check for an ODBC 3.0 function to assert that they're *good*
120-
dnl libraries.
121-
PHP_CHECK_LIBRARY($pdo_odbc_def_lib, SQLAllocHandle,
122-
[], [
123-
AC_MSG_ERROR([
124-
Your ODBC library does not appear to be ODBC 3 compatible.
125-
You should consider using iODBC or unixODBC instead, and loading your
126-
libraries as a driver in that environment; it will emulate the
127-
functions required for PDO support.
128-
])], $PDO_ODBC_LDFLAGS)
129-
],[
130-
AC_MSG_ERROR([Your ODBC library does not exist or there was an error. Check config.log for more information])
131-
], $PDO_ODBC_LDFLAGS)
142+
AC_DEFINE_UNQUOTED([PDO_ODBC_TYPE], ["$pdo_odbc_flavour"],
143+
[Define to the ODBC driver or driver manager value.])
132144

133-
PHP_NEW_EXTENSION(pdo_odbc, pdo_odbc.c odbc_driver.c odbc_stmt.c, $ext_shared,, $PDO_ODBC_INCLUDE)
145+
PHP_NEW_EXTENSION(pdo_odbc, pdo_odbc.c odbc_driver.c odbc_stmt.c, $ext_shared)
134146
PHP_SUBST([PDO_ODBC_SHARED_LIBADD])
135147
PHP_ADD_EXTENSION_DEP(pdo_odbc, pdo)
136148
fi

0 commit comments

Comments
 (0)