Skip to content

Use pkg-config first, then icu-config if it fails. #339

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 58 additions & 30 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2201,49 +2201,77 @@ dnl
dnl Common setup macro for ICU
dnl
AC_DEFUN([PHP_SETUP_ICU],[
found_icu=no
PHP_ARG_WITH(icu-dir,,
[ --with-icu-dir=DIR Specify where ICU libraries and headers can be found], DEFAULT, no)

if test "$PHP_ICU_DIR" = "no"; then
PHP_ICU_DIR=DEFAULT
fi

if test "$PHP_ICU_DIR" = "DEFAULT"; then
dnl Try to find icu-config
AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
else
ICU_CONFIG="$PHP_ICU_DIR/bin/icu-config"
dnl First try to find pkg-config
if test -z "$PKG_CONFIG"; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
fi

AC_MSG_CHECKING([for location of ICU headers and libraries])

dnl Trust icu-config to know better what the install prefix is..
icu_install_prefix=`$ICU_CONFIG --prefix 2> /dev/null`
if test "$?" != "0" || test -z "$icu_install_prefix"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Unable to detect ICU prefix or $ICU_CONFIG failed. Please verify ICU install prefix and make sure icu-config works.])
else
AC_MSG_RESULT([$icu_install_prefix])

dnl Check ICU version
dnl If pkg-config is found try using it
if test "$PHP_ICU_DIR" = "DEFAULT" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists icu-io; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the package name is icu-io? Is it a standard name? Should any other alternatives be tried?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smalyshev: icu-io is the name of the most specific ICU library that the intl extension links to (see also line 2244 below in the old code).
As such, I don't think it's necessary to look for alternatives here.
The name is standard and comes directly from the ICU project (see http://userguide.icu-project.org/howtouseicu#TOC-pkg-config)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just check on my linux (Centos):

pkg-config --modversion icu
4.2.1
pkg-config --modversion icu-io
Package icu-io was not found in the pkg-config search path.
Perhaps you should add the directory containing `icu-io.pc'
to the PKG_CONFIG_PATH environment variable
No package 'icu-io' found

Not sure it is going to work. Also --exists returns true for icu, false for icu-io.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @smalyshev, sorry I didn't answer earlier, I've been busy with work.

RedHat created its own icu.pc (which contains the same data as if icu-uc.pc and icu-i18n.pc were combined together).
There was a discussion some time ago in the ICU project to create a file named icu.pc for compatibility with RH, but this was rejected since Fedora/RH later decided to drop that file and use the regular .pc files provided by ICU.

See also https://bugzilla.redhat.com/show_bug.cgi?id=460168 and http://bugs.icu-project.org/trac/ticket/9478 for details.

Anyway, even on RH/CentOS, PHP should still continue to build since the code falls back to the old behaviour (using icu-config) in case icu-io.pc cannot be found.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked libicu-devel-50.1.2-5 from Fedora 19 and libicu-dev 4.8.1.1-12 from Debian 7 and both have icu-uc.pc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe check both icu-io and icu packages? Having both of them with different versions is unlikely.

AC_MSG_CHECKING([for ICU 3.4 or greater])
icu_version_full=`$ICU_CONFIG --version`
ac_IFS=$IFS
IFS="."
set $icu_version_full
IFS=$ac_IFS
icu_version=`expr [$]1 \* 1000 + [$]2`
AC_MSG_RESULT([found $icu_version_full])

if test "$icu_version" -lt "3004"; then
if $PKG_CONFIG --atleast-version=3.4.0 icu-io; then
ICU_LIBS=`$PKG_CONFIG --libs icu-io`
ICU_INCS=`$PKG_CONFIG --cflags icu-io`
icu_version_full=`$PKG_CONFIG --modversion icu-io`
AC_MSG_RESULT([found $icu_version_full])
else
AC_MSG_ERROR([ICU version 3.4 or later is required])
fi

ICU_VERSION=$icu_version
ICU_INCS=`$ICU_CONFIG --cppflags-searchpath`
ICU_LIBS=`$ICU_CONFIG --ldflags --ldflags-icuio`
PHP_EVAL_INCLINE($ICU_INCS)
PHP_EVAL_LIBLINE($ICU_LIBS, $1)
if test -n "$ICU_LIBS" && test -n "$ICU_INCS"; then
PHP_EVAL_INCLINE($ICU_INCS)
PHP_EVAL_LIBLINE($ICU_LIBS, $1)
found_icu=yes
fi
fi

dnl If pkg-config fails for some reason, revert to the old method
if test "$found_icu" = "no"; then
if test "$PHP_ICU_DIR" = "DEFAULT"; then
dnl Try to find icu-config
AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
else
ICU_CONFIG="$PHP_ICU_DIR/bin/icu-config"
fi

AC_MSG_CHECKING([for location of ICU headers and libraries])

dnl Trust icu-config to know better what the install prefix is..
icu_install_prefix=`$ICU_CONFIG --prefix 2> /dev/null`
if test "$?" != "0" || test -z "$icu_install_prefix"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Unable to detect ICU prefix or $ICU_CONFIG failed. Please verify ICU install prefix and make sure icu-config works.])
else
AC_MSG_RESULT([$icu_install_prefix])

dnl Check ICU version
AC_MSG_CHECKING([for ICU 3.4 or greater])
icu_version_full=`$ICU_CONFIG --version`
ac_IFS=$IFS
IFS="."
set $icu_version_full
IFS=$ac_IFS
icu_version=`expr [$]1 \* 1000 + [$]2`
AC_MSG_RESULT([found $icu_version_full])

if test "$icu_version" -lt "3004"; then
AC_MSG_ERROR([ICU version 3.4 or later is required])
fi

ICU_VERSION=$icu_version
ICU_INCS=`$ICU_CONFIG --cppflags-searchpath`
ICU_LIBS=`$ICU_CONFIG --ldflags --ldflags-icuio`
PHP_EVAL_INCLINE($ICU_INCS)
PHP_EVAL_LIBLINE($ICU_LIBS, $1)
fi
fi
])

Expand Down