source: m4/ax_check_xml2.m4

Last change on this file was d6439d4, checked in by Mei <mei@…>, 11 years ago

1) tweak m4s more for bsd

  • Property mode set to 100644
File size: 3.9 KB
Line 
1# ===========================================================================
2#     ax_check_xml2.m4
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_CHECK_XML2([action-if-found[, action-if-not-found]])
8#
9# DESCRIPTION
10#
11#   Look for xml2in a number of default spots, or in a user-selected
12#   spot (via --with-xml2).  Sets
13#
14#     XML2_INCLUDES to the include directives required
15#     XML2_LIBS to the -l directives required
16#     XML2_LDFLAGS to the -L or -R flags required
17#
18#   and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
19#
20#   This macro sets XML2_INCLUDES such that source files should use the
21#   libxml2/ directory in include directives:
22#    ... <libxml/tree.h>
23#
24AU_ALIAS([CHECK_XML2], [AX_CHECK_XML2])
25AC_DEFUN([AX_CHECK_XML2], [
26    found=false
27    AC_ARG_WITH([xml2],
28        [AS_HELP_STRING([--with-xml2=DIR],
29            [root of the XML2 directory])],
30        [
31            case "$withval" in
32            "" | y | ye | yes | n | no)
33            AC_MSG_ERROR([Invalid --with-xml2 value])
34              ;;
35            *) xml2dirs="$withval"
36              ;;
37            esac
38        ], [
39            # if pkg-config is installed and xmlsec1 has installed a .pc file,
40            # then use that information and don't search ssldirs
41            AC_PATH_PROG([PKG_CONFIG], [pkg-config])
42            if test x"$PKG_CONFIG" != x""; then
43                XML2_LDFLAGS=`$PKG_CONFIG xml2 --libs-only-L 2>/dev/null`
44                if test $? = 0; then
45                    XML2_LIBS=`$PKG_CONFIG xml2 --libs-only-l 2>/dev/null`
46                    XML2_INCLUDES=`$PKG_CONFIG xml2 --cflags 2>/dev/null`
47                    found=true
48                fi
49            fi
50
51            # no such luck; use some default ssldirs
52            if ! $found; then
53                xml2dirs="/usr/local /usr"
54            fi
55        ]
56        )
57
58
59    # XML2 headers have to be in libxml and xml2dir subdirectories
60    # CFLAGS =-g -Wall `xmlsec1-config --cflags --crypto=default` `xml2-config --cflags`
61    # LDFLAGS += `xml2-config --libs` `xmlsec1-config --libs --crypto=default`
62
63    if ! $found; then
64        AC_PATH_PROG([XML2_CONFIG], [xml2-config])
65        if test x"$XML2_CONFIG" != x""; then
66            for xml2dir in $xml2dirs; do
67                AC_MSG_CHECKING([for libxml/tree.h in $xml2dir])
68                if test -f "$xml2dir/include/libxml2/libxml/tree.h"; then
69                    XML2_INCLUDES=`$XML2_CONFIG --cflags 2>/dev/null`
70                    XML2_LDFLAGS=`$XML2_CONFIG --libs 2>/dev/null`
71                    XML2_LIBS=`$XML2_CONFIG --libs 2>/dev/null`
72                    found=true
73                    AC_MSG_RESULT([yes])
74                    break
75                else
76                    AC_MSG_RESULT([no])
77                fi
78            done
79        else
80            # cannot even find the xml2-config
81            AC_MSG_ERROR([Cannot find xml2-config in your system path])
82        fi
83
84        # if the file wasn't found, well, go ahead and try the link anyway -- maybe
85        # it will just work!
86    fi
87
88    # try the preprocessor and linker with our new flags,
89    # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
90
91    AC_MSG_CHECKING([whether compiling and linking against XML2 works])
92    echo "Trying link with XML2_LDFLAGS=$XML2_LDFLAGS;" \
93        "XML2_LIBS=$XML2_LIBS; XML2_INCLUDES=$XML2_INCLUDES" >&AS_MESSAGE_LOG_FD
94
95    save_LIBS="$LIBS"
96    save_LDFLAGS="$LDFLAGS"
97    save_CPPFLAGS="$CPPFLAGS"
98    LDFLAGS="$LDFLAGS $XML2_LDFLAGS"
99    LIBS="$XML2_LIBS $LIBS"
100    CPPFLAGS="$XML2_INCLUDES $CPPFLAGS"
101    AC_LINK_IFELSE(
102        [AC_LANG_PROGRAM([#include <libxml/tree.h>], [xmlMalloc(1)])],
103        [
104            AC_MSG_RESULT([yes])
105            $1
106        ], [
107            AC_MSG_RESULT([no])
108            $2
109        ])
110    CPPFLAGS="$save_CPPFLAGS"
111    LDFLAGS="$save_LDFLAGS"
112    LIBS="$save_LIBS"
113
114    AC_SUBST([XML2_INCLUDES])
115    AC_SUBST([XML2_LIBS])
116    AC_SUBST([XML2_LDFLAGS])
117])
118
Note: See TracBrowser for help on using the repository browser.