fix bug #135723
[platform/upstream/glib.git] / acglib.m4
1 ## Portability defines that help interoperate with classic and modern autoconfs
2 ifdef([AC_TR_SH],[
3 define([GLIB_TR_SH],[AC_TR_SH([$1])])
4 define([GLIB_TR_CPP],[AC_TR_CPP([$1])])
5 ], [
6 define([GLIB_TR_SH],
7        [patsubst(translit([[$1]], [*+], [pp]), [[^a-zA-Z0-9_]], [_])])
8 define([GLIB_TR_CPP],
9        [patsubst(translit([[$1]],
10                           [*abcdefghijklmnopqrstuvwxyz],
11                           [PABCDEFGHIJKLMNOPQRSTUVWXYZ]),
12                  [[^A-Z0-9_]], [_])])
13 ])
14
15 # GLIB_AC_DIVERT_BEFORE_HELP(STUFF)
16 # ---------------------------------
17 # Put STUFF early enough so that they are available for $ac_help expansion.
18 # Handle both classic (<= v2.13) and modern autoconf
19 AC_DEFUN([GLIB_AC_DIVERT_BEFORE_HELP],
20 [ifdef([m4_divert_text], [m4_divert_text([NOTICE],[$1])],
21        [ifdef([AC_DIVERT], [AC_DIVERT([NOTICE],[$1])],
22               [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
23 $1
24 AC_DIVERT_POP()])])])
25
26 dnl GLIB_IF_VAR_EQ (ENV_VAR, VALUE [, EQUALS_ACTION] [, ELSE_ACTION])
27 AC_DEFUN([GLIB_IF_VAR_EQ],[
28         case "$[$1]" in
29         "[$2]"[)]
30                 [$3]
31                 ;;
32         *[)]
33                 [$4]
34                 ;;
35         esac
36 ])
37 dnl GLIB_STR_CONTAINS (SRC_STRING, SUB_STRING [, CONTAINS_ACTION] [, ELSE_ACTION])
38 AC_DEFUN([GLIB_STR_CONTAINS],[
39         case "[$1]" in
40         *"[$2]"*[)]
41                 [$3]
42                 ;;
43         *[)]
44                 [$4]
45                 ;;
46         esac
47 ])
48 dnl GLIB_ADD_TO_VAR (ENV_VARIABLE, CHECK_STRING, ADD_STRING)
49 AC_DEFUN([GLIB_ADD_TO_VAR],[
50         GLIB_STR_CONTAINS($[$1], [$2], [$1]="$[$1]", [$1]="$[$1] [$3]")
51 ])
52
53 # GLIB_SIZEOF (INCLUDES, TYPE, ALIAS)
54 # ---------------------------------------------------------------
55 # The definition here is based of that of AC_CHECK_SIZEOF
56 AC_DEFUN([GLIB_SIZEOF],
57 [AS_LITERAL_IF([$3], [],
58                [AC_FATAL([$0: requires literal arguments])])dnl
59 AC_CACHE_CHECK([size of $2], AS_TR_SH([glib_cv_sizeof_$3]),
60 [ # The cast to unsigned long works around a bug in the HP C Compiler
61   # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
62   # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
63   # This bug is HP SR number 8606223364.
64   _AC_COMPUTE_INT([(long) (sizeof ($2))],
65                   [AS_TR_SH([glib_cv_sizeof_$3])],
66                   [AC_INCLUDES_DEFAULT([$1])],
67                   [AC_MSG_ERROR([cannot compute sizeof ($2), 77])])
68 ])dnl
69 AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_sizeof_$3), $AS_TR_SH([glib_cv_sizeof_$3]),
70                    [The size of $3, as computed by sizeof.])
71 ])# GLIB_SIZEOF
72
73 dnl GLIB_BYTE_CONTENTS (INCLUDES, TYPE, ALIAS, N_BYTES, INITIALIZER)
74 AC_DEFUN([GLIB_BYTE_CONTENTS],
75 [pushdef([glib_ByteContents], GLIB_TR_SH([glib_cv_byte_contents_$3]))dnl
76 AC_CACHE_CHECK([byte contents of $5], glib_ByteContents,
77 [AC_TRY_RUN([#include <stdio.h>
78 $1
79 main()
80 {
81   static $2 tv = $5;
82   char *p = (char*) &tv;
83   int i;
84   FILE *f=fopen("conftestval", "w");
85   if (!f) exit(1);
86   for (i = 0; i < $4; i++)
87     fprintf(f, "%s%d", i?",":"", *(p++));
88   fprintf(f, "\n");
89   exit(0);
90 }], 
91    [glib_ByteContents=`cat conftestval`  dnl''
92 ], 
93    [glib_ByteContents=no],
94    [glib_ByteContents=no])])
95 AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_byte_contents_$3), [$[]glib_ByteContents],
96         [Byte contents of $3])
97 popdef([glib_ByteContents])dnl
98 ])
99
100 # GLIB_CHECK_VALUE(SYMBOL, INCLUDES, ACTION-IF-FAIL)
101 # ---------------------------------------------------------------
102 AC_DEFUN([GLIB_CHECK_VALUE],
103 [AC_CACHE_CHECK([value of $1], AS_TR_SH([glib_cv_value_$1]),
104   [_AC_COMPUTE_INT([$1], AS_TR_SH([glib_cv_value_$1]), [$2], [$3])])
105 ])dnl
106
107 # GLIB_CHECK_COMPILE_WARNINGS(PROGRAM, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
108 # ---------------------------------------------------------------------
109 # Try to compile PROGRAM, check for warnings
110 m4_define([GLIB_CHECK_COMPILE_WARNINGS],
111 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
112 rm -f conftest.$ac_objext
113 glib_ac_compile_save="$ac_compile"
114 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext'
115 AS_IF([_AC_EVAL_STDERR($ac_compile) &&
116          AC_TRY_COMMAND([(if test -s conftest.err; then false ; else true; fi)])],
117       [$2],
118       [echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD
119 cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD
120 m4_ifvaln([$3],[$3])dnl])dnl
121 ac_compile="$glib_ac_compile_save"
122 rm -f conftest.$ac_objext conftest.err m4_ifval([$1], [conftest.$ac_ext])[]dnl
123 ])# GLIB_CHECK_COMPILE_WARNINGS
124
125 # GLIB_ASSERT_SET(VARIABLE)
126 # -------------------------
127 AC_DEFUN([GLIB_ASSERT_SET],
128 [if test "x${$1+set}" != "xset" ; then
129   AC_MSG_ERROR($1 [must be set in cache file when cross-compiling.])
130 fi
131 ])dnl