New macros to check for XML catalog contents and path, borrowed from
[platform/upstream/glib.git] / acinclude.m4
1 dnl @synopsis AC_FUNC_VSNPRINTF_C99
2 dnl
3 dnl Check whether there is a vsnprintf() function with C99 semantics installed.
4 dnl
5 AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
6 [AC_CACHE_CHECK(for C99 vsnprintf,
7   ac_cv_func_vsnprintf_c99,
8 [AC_TRY_RUN(
9 [#include <stdio.h>
10 #include <stdarg.h>
11
12 int
13 doit(char * s, ...)
14 {
15   char buffer[32];
16   va_list args;
17   int r;
18
19   va_start(args, s);
20   r = vsnprintf(buffer, 5, s, args);
21   va_end(args);
22
23   if (r != 7)
24     exit(1);
25
26   exit(0);
27 }
28
29 int
30 main(void)
31 {
32   doit("1234567");
33   exit(1);
34 }], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
35 dnl Note that the default is to be pessimistic in the case of cross compilation.
36 dnl If you know that the target has a C99 vsnprintf(), you can get around this
37 dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
38 if test $ac_cv_func_vsnprintf_c99 = yes; then
39   AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
40             [Define if you have a version of the vsnprintf function
41              with semantics as specified by the ISO C99 standard.])
42 fi
43 ])# AC_FUNC_VSNPRINTF_C99
44
45
46 dnl @synopsis AC_FUNC_PRINTF_UNIX98
47 dnl
48 dnl Check whether the printf() family supports Unix98 %n$ positional parameters 
49 dnl
50 AC_DEFUN([AC_FUNC_PRINTF_UNIX98],
51 [AC_CACHE_CHECK(whether printf supports positional parameters,
52   ac_cv_func_printf_unix98,
53 [AC_TRY_RUN(
54 [#include <stdio.h>
55
56 int
57 main (void)
58 {
59   char buffer[128];
60
61   sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
62   if (strcmp ("2 3 1", buffer) == 0)
63     exit (0);
64   exit (1);
65 }], ac_cv_func_printf_unix98=yes, ac_cv_func_printf_unix98=no, ac_cv_func_printf_unix98=no)])
66 dnl Note that the default is to be pessimistic in the case of cross compilation.
67 dnl If you know that the target printf() supports positional parameters, you can get around 
68 dnl this by setting ac_func_printf_unix98 to yes, as described in the Autoconf manual.
69 if test $ac_cv_func_printf_unix98 = yes; then
70   AC_DEFINE(HAVE_UNIX98_PRINTF, 1,
71             [Define if your printf function family supports positional parameters
72              as specified by Unix98.])
73 fi
74 ])# AC_FUNC_PRINTF_UNIX98
75
76 # Checks the location of the XML Catalog
77 # Usage:
78 #   JH_PATH_XML_CATALOG
79 # Defines XMLCATALOG and XML_CATALOG_FILE substitutions
80 AC_DEFUN([JH_PATH_XML_CATALOG],
81 [
82   # check for the presence of the XML catalog
83   AC_ARG_WITH([xml-catalog],
84               AC_HELP_STRING([--with-xml-catalog=CATALOG],
85                              [path to xml catalog to use]),,
86               [with_xml_catalog=/etc/xml/catalog])
87   XML_CATALOG_FILE="$with_xml_catalog"
88   AC_MSG_CHECKING([for XML catalog ($XML_CATALOG_FILE)])
89   if test -f "$XML_CATALOG_FILE"; then
90     AC_MSG_RESULT([found])
91   else
92     AC_MSG_RESULT([not found])
93     AC_MSG_ERROR([XML catalog not found])
94   fi
95   AC_SUBST([XML_CATALOG_FILE])
96
97   # check for the xmlcatalog program
98   AC_PATH_PROG(XMLCATALOG, xmlcatalog, no)
99   if test "x$XMLCATALOG" = xno; then
100     AC_MSG_ERROR([could not find xmlcatalog program])
101   fi
102 ])
103
104 # Checks if a particular URI appears in the XML catalog
105 # Usage:
106 #   JH_CHECK_XML_CATALOG(URI, [FRIENDLY-NAME], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
107 AC_DEFUN([JH_CHECK_XML_CATALOG],
108 [
109   AC_REQUIRE([JH_PATH_XML_CATALOG])dnl
110   AC_MSG_CHECKING([for ifelse([$2],,[$1],[$2]) in XML catalog])
111   if AC_RUN_LOG([$XMLCATALOG --noout "$XML_CATALOG_FILE" "$1" >&2]); then
112     AC_MSG_RESULT([found])
113     ifelse([$3],,,[$3
114 ])dnl
115   else
116     AC_MSG_RESULT([not found])
117     ifelse([$4],,
118        [AC_MSG_ERROR([could not find ifelse([$2],,[$1],[$2]) in XML catalog])],
119        [$4])
120   fi
121 ])
122
123
124