Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I patch libxml2 so it will compile with ICU support when using a prefix?

I'm trying to fix a bug in libxml2. I cannot get it to compile with --with-icu when using --prefix=/Server/software. I have submitted a bug report here, but I need to get it to compile for resolving a conflict when compiling PHP with intl support. I suspect it's a problem with the Makefile. My experience with Makefile's is limited. The desired result is coming up with a patch that can be submitted to the linked bug report.

The --with-icu flag causes LIBXML_ICU_ENABLED to be defined. The included code is supposed to resolve a conflict when including headers from both icu and libxml2 (specifically, both use UChar). The PHP plugin intl, activated with --enable-intl, requires icu. libxml2 is needed by PHP for DOM/XML functions.

There are two problems.

First, this config:

./configure --prefix=/Server/software --enable-shared --enable-static --with-icu

Results in:

configure: error: libicu config program icu-config not found

This happens because of this code in configure.in:

WITH_ICU=0
if test "$with_icu" != "yes" ; then
    echo Disabling ICU support
else
    ICU_CONFIG=icu-config
    if ${ICU_CONFIG} --cflags >/dev/null 2>&1
    then
        ICU_LIBS=`icu-config --ldflags`
        LDFLAGS="$LDFLAGS $ICU_LIBS"
        WITH_ICU=1
        echo Enabling ICU support
    else
        AC_MSG_ERROR([libicu config program icu-config not found])
    fi
fi

Specifically ICUCONFIG=icu-config isn't respecting --prefix=/Server/software. I can work around this by doing export PATH=/Server/software/bin:$PATH.

This "fixes" the ./configure problem.

Second, when I run make I get errors, the most relavent being:

./include/libxml/encoding.h:31:26: error: unicode/ucnv.h: No such file or directory

The unicode/uncv.h file is in /Server/software/include/unicode/uncv.h. I suspect the compiler is looking for this file in the local directory and in my /usr directory.

This is what the error is referring to:

#ifdef LIBXML_ICU_ENABLED
#include <unicode/ucnv.h>
#endif

Clearly this is a path issue when using --with-icu and --prefix=/Server/software. Without --with-icu it compiles fine, but this is needed to resolve a define UChar conflict when compiling PHP with both icu and libxml2.

The result of icu-config --cflags is:

-O2 -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -Wno-long-long

This is being piped into /dev/null.

The result of icu-config --ldflags is:

-lpthread -lm -L/Server/software/lib -licui18n -licuuc -licudata -lpthread -lm

What needs to be changed to resolve these issues?

like image 214
Luke Avatar asked Nov 04 '22 11:11

Luke


1 Answers

So, take a look at where it's using icu-config. It should be doing something like icu-config --cppflags which should set -I/Server/Software/include or similar. You could work around it by setting CPPFLAGS to include such a parameter yourself.

Can you include the actual compile command line immediately before the error?

Sounds like a bug in libxml - it ought to search ${PREFIX}/bin for icu-config.

Also, ICU now exports pkg-config files, which are more of a standard way to find such items.


Try this before WITH_ICU :

    ICU_CPPFLAGS=`icu-config --cppflags`
    CPPFLAGS="$CPPFLAGS $ICU_CPPFLAGS"

update I'm going to quote Luke's last response. Glad it's working.

I solved the linker problems, so now it all works. For this question using libxml 2.7.7 was the solution. It seems OX X 10.6 ships with 2.7.8. So for it to work you have to compile libxml2 yourself with 2.7.7. The linker problems are solved by adding LIBS="-lresolv -lstdc++" just before PHP's ./configure. If installing to a non-standard location you also need to compile ICU with --enable-rpath. I've accepted your answer. Feel free to update it with this information :). – Luke 17 hours ago

like image 55
Steven R. Loomis Avatar answered Dec 03 '22 08:12

Steven R. Loomis