1#
2# Zabbix
3# Copyright (C) 2001-2021 Zabbix SIA
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18#
19
20AC_DEFUN([LIBXML2_CHECK_CONFIG],
21[
22    LIBXML2_CONFIG="no"
23
24    AC_ARG_WITH(libxml2,
25        [
26If you want to use XML library:
27AC_HELP_STRING([--with-libxml2@<:@=ARG@:>@],
28    [use libxml2 client library @<:@default=no@:>@, see PKG_CONFIG_PATH environment variable to specify .pc file location]
29        )],
30        [
31        if test "$withval" = "no"; then
32            want_libxml2="no"
33        elif test "$withval" = "yes"; then
34            want_libxml2="yes"
35        else
36            want_libxml2="yes"
37        fi
38        ],
39        [want_libxml2="no"]
40    )
41
42    LIBXML2_CFLAGS=""
43    LIBXML2_LDFLAGS=""
44    LIBXML2_LIBS=""
45    LIBXML2_VERSION=""
46
47    dnl
48    dnl Check libxml2 libraries
49    dnl
50
51    if test "$want_libxml2" = "yes"; then
52        AC_REQUIRE([PKG_PROG_PKG_CONFIG])
53        PKG_PROG_PKG_CONFIG()
54
55        if test -x "$PKG_CONFIG"; then
56
57            LIBXML2_CFLAGS="`$PKG_CONFIG --cflags libxml-2.0`"
58
59            _full_libxml2_libs="`$PKG_CONFIG --libs libxml-2.0`"
60
61            for i in $_full_libxml2_libs; do
62                case $i in
63                   -lxml2)
64                        ;;
65                   -L*)
66                        LIBXML2_LDFLAGS="${LIBXML2_LDFLAGS} $i"
67                        ;;
68                   -R*)
69                        LIBXML2_LDFLAGS="${LIBXML2_LDFLAGS} -Wl,$i"
70                        ;;
71                esac
72            done
73
74            if test "x$enable_static" = "xyes"; then
75                for i in $_full_libxml2_libs; do
76                    case $i in
77                        -lxml2)
78                            ;;
79                        -l*)
80                            _lib_name="`echo "$i" | cut -b3-`"
81                            AC_CHECK_LIB($_lib_name, main, [
82                                    LIBXML2_LIBS="$LIBXML2_LIBS $i"
83                                    ],[
84                                    AC_MSG_ERROR([Not found $_lib_name library])
85                                    ])
86                            ;;
87                    esac
88                done
89            fi
90
91            _save_libxml2_libs="${LIBS}"
92            _save_libxml2_ldflags="${LDFLAGS}"
93            _save_libxml2_cflags="${CFLAGS}"
94            LIBS="${LIBS} ${LIBXML2_LIBS}"
95            LDFLAGS="${LDFLAGS} ${LIBXML2_LDFLAGS}"
96            CFLAGS="${CFLAGS} ${LIBXML2_CFLAGS}"
97
98            AC_CHECK_LIB(xml2, xmlReadMemory, [
99                    LIBXML2_LIBS="-lxml2 ${LIBXML2_LIBS}"
100                    ],[
101                    AC_MSG_ERROR([Not found libxml2 library])
102                    ])
103
104            LIBS="${_save_libxml2_libs}"
105            LDFLAGS="${_save_libxml2_ldflags}"
106            CFLAGS="${_save_libxml2_cflags}"
107            unset _save_libxml2_libs
108            unset _save_libxml2_ldflags
109            unset _save_libxml2_cflags
110
111            LIBXML2_VERSION=`$PKG_CONFIG --version libxml-2.0`
112
113            AC_DEFINE([HAVE_LIBXML2], [1], [Define to 1 if libxml2 libraries are available])
114
115            found_libxml2="yes"
116        else
117            found_libxml2="no"
118        fi
119    fi
120
121    AC_SUBST([LIBXML2_VERSION])
122    AC_SUBST([LIBXML2_CFLAGS])
123    AC_SUBST([LIBXML2_LDFLAGS])
124    AC_SUBST([LIBXML2_LIBS])
125])
126