-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Check for iODBC and unixODBC with pkg-config in PDO_ODBC #14963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
Some nitpicks I've already thought of:
|
Then this headers check needs to be moved a bitdiff --git a/ext/pdo_odbc/config.m4 b/ext/pdo_odbc/config.m4
index 6de1a363f5..a3de406213 100644
--- a/ext/pdo_odbc/config.m4
+++ b/ext/pdo_odbc/config.m4
@@ -97,9 +97,6 @@ if test "$PHP_PDO_ODBC" != "no"; then
AC_MSG_WARN([library dir $PDO_ODBC_LIBDIR does not exist])
fi
- AS_VAR_IF([php_pdo_odbc_have_header], [yes],,
- [AC_MSG_ERROR([Cannot find header file(s) for pdo_odbc.])])
-
PDO_ODBC_INCLUDE="$pdo_odbc_def_cflags -I$PDO_ODBC_INCDIR -DPDO_ODBC_TYPE=\\\"$pdo_odbc_flavour\\\""
PDO_ODBC_LDFLAGS="$pdo_odbc_def_ldflags -L$PDO_ODBC_LIBDIR -l$pdo_odbc_def_lib"
@@ -141,6 +138,9 @@ functions required for PDO support.
PHP_PDO_ODBC_CHECK_HEADER([sqlunix.h])
PHP_PDO_ODBC_CHECK_HEADER([udbcext.h])
+ AS_VAR_IF([php_pdo_odbc_have_header], [yes],,
+ [AC_MSG_ERROR([Cannot find header file(s) for pdo_odbc.])])
+
PHP_NEW_EXTENSION(pdo_odbc, pdo_odbc.c odbc_driver.c odbc_stmt.c, $ext_shared,, $PDO_ODBC_INCLUDE)
PHP_SUBST([PDO_ODBC_SHARED_LIBADD])
PHP_ADD_EXTENSION_DEP(pdo_odbc, pdo) If these ODBC libraries have pkg-config/pkgconf integrated then that's fine. I haven't checked this so much in details across the systems out there. This pkg-config would ideally be optional but since existing PHP extensions already use it unconditionally, then I think that's ok. Perhaps also good to push on the distributions a bit to integrate it if they haven't already. For those headers I was already checking it how it could be done with AC_CHECK_HEADER(S) but the issue is that some special order needs to be done. For example, sqlucode.h needs sqltypes.h and probably some others - sqlunix.h. This AC_CHECK_HEADER does a minor compilation step also if header can be included in the code. |
Or if that check becomes something like this: AC_DEFUN([PHP_PDO_ODBC_CHECK_HEADER],
[AC_MSG_CHECKING([for $1])
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([#include <$1>], [])], [
php_pdo_odbc_have_header=yes
AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
[Define to 1 if you have the <$1> header file.])
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])])
]) then the CFLAGS can be used. |
unixODBC and iODBC upstreams ship .pc files. Procedural ODBC already uses pkg-config unconditionally for iODBC, but offers manually setting it for unixODBC. Since autoconf does allow overriding the flags that pkg-config would set on it (well, except for invoking pkg-config manually), I think using I tried using |
Hmm, your proposed fix doesn't work. I think |
...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]>
Ah, the AC_PREPROC_IFELSE is a preprocessor check only, yes. Nice catch. This AC_CHECK_HEADER not using the CFLAGS is something buggy indeed. Then we have to fix some checks also elsewhere. |
Tested: AC_CHECK_HEADER and CFLAGS work ok. There is over-escaped double quote in there somewhere. |
Unfortunately, I think those are load bearing escapes; seems they're needed so cpp embeds them as strings:
|
Then something like this might be simpler to simply avoid those quotes handling in the shell: diff --git a/ext/pdo_odbc/config.m4 b/ext/pdo_odbc/config.m4
index 7e2e53b594..dc28444812 100644
--- a/ext/pdo_odbc/config.m4
+++ b/ext/pdo_odbc/config.m4
@@ -75,7 +75,6 @@ if test "$PHP_PDO_ODBC" != "no"; then
PKG_CHECK_MODULES([PDO_ODBC], [$pdo_odbc_pkgconfig_module])
PHP_EVAL_INCLINE([$PDO_ODBC_CFLAGS])
PHP_EVAL_LIBLINE([$PDO_ODBC_LIBS], [PDO_ODBC_SHARED_LIBADD])
- PDO_ODBC_INCLUDE="$PDO_ODBC_CFLAGS -DPDO_ODBC_TYPE=\\\"$pdo_odbc_flavour\\\""
else
if test -n "$pdo_odbc_dir"; then
PDO_ODBC_INCDIR="$pdo_odbc_dir/include"
@@ -93,7 +92,7 @@ if test "$PHP_PDO_ODBC" != "no"; then
AC_MSG_WARN([library dir $PDO_ODBC_LIBDIR does not exist])
fi
- PDO_ODBC_INCLUDE="$pdo_odbc_def_cflags -I$PDO_ODBC_INCDIR -DPDO_ODBC_TYPE=\\\"$pdo_odbc_flavour\\\""
+ PDO_ODBC_CFLAGS="$pdo_odbc_def_cflags -I$PDO_ODBC_INCDIR"
PDO_ODBC_LDFLAGS="$pdo_odbc_def_ldflags -L$PDO_ODBC_LIBDIR -l$pdo_odbc_def_lib"
PHP_EVAL_LIBLINE([$PDO_ODBC_LDFLAGS], [PDO_ODBC_SHARED_LIBADD])
@@ -117,7 +116,7 @@ functions required for PDO support.
fi
OLD_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $PDO_ODBC_INCLUDE"
+ CPPFLAGS="$CPPFLAGS $PDO_ODBC_CFLAGS"
PHP_PDO_ODBC_CHECK_HEADER([cli0cli.h])
PHP_PDO_ODBC_CHECK_HEADER([cli0core.h])
PHP_PDO_ODBC_CHECK_HEADER([cli0defs.h])
@@ -140,7 +139,10 @@ functions required for PDO support.
AS_VAR_IF([php_pdo_odbc_have_header], [yes],,
[AC_MSG_ERROR([Cannot find header file(s) for pdo_odbc.])])
- PHP_NEW_EXTENSION(pdo_odbc, pdo_odbc.c odbc_driver.c odbc_stmt.c, $ext_shared,, $PDO_ODBC_INCLUDE)
+ AC_DEFINE_UNQUOTED([PDO_ODBC_TYPE], ["$pdo_odbc_flavour"],
+ [Define to the ODBC driver or driver manager value.])
+
+ PHP_NEW_EXTENSION(pdo_odbc, pdo_odbc.c odbc_driver.c odbc_stmt.c, $ext_shared,, $PDO_ODBC_CFLAGS)
PHP_SUBST([PDO_ODBC_SHARED_LIBADD])
PHP_ADD_EXTENSION_DEP(pdo_odbc, pdo) |
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]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the CS and quotes could be further synced here, specially in that PHP_CHECK_LIBRARY, but it works anyway, so all good to go then.
Thanks @NattyNarwhal for the pkg-config integration. That is one step better and simpler.
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.