Clarify recursion issues with GMutex. (#78171)
[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 dnl GLIB_SIZEOF (INCLUDES, TYPE, ALIAS [, CROSS-SIZE])
54 AC_DEFUN(GLIB_SIZEOF,
55 [pushdef([glib_Sizeof], GLIB_TR_SH([glib_cv_sizeof_$3]))dnl
56 AC_CACHE_CHECK([size of $2], glib_Sizeof,
57 [AC_TRY_RUN([#include <stdio.h>
58 #if STDC_HEADERS
59 #include <stdlib.h>
60 #include <stddef.h>
61 #endif
62 $1
63 main()
64 {
65   FILE *f=fopen("conftestval", "w");
66   if (!f) exit(1);
67   fprintf(f, "%d\n", sizeof($2));
68   exit(0);
69 }], 
70   [glib_Sizeof=`cat conftestval`  dnl''
71 ],
72   [glib_Sizeof=0],
73   ifelse([$4], [], [], [glib_Sizeof=$4]))])
74 AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_sizeof_$3), [$[]glib_Sizeof], [Size of $3])
75 popdef([glib_Sizeof])dnl
76 ])
77
78 dnl GLIB_BYTE_CONTENTS (INCLUDES, TYPE, ALIAS, N_BYTES, INITIALIZER)
79 AC_DEFUN(GLIB_BYTE_CONTENTS,
80 [pushdef([glib_ByteContents], GLIB_TR_SH([glib_cv_byte_contents_$3]))dnl
81 AC_CACHE_CHECK([byte contents of $5], glib_ByteContents,
82 [AC_TRY_RUN([#include <stdio.h>
83 $1
84 main()
85 {
86   static $2 tv = $5;
87   char *p = (char*) &tv;
88   int i;
89   FILE *f=fopen("conftestval", "w");
90   if (!f) exit(1);
91   for (i = 0; i < $4; i++)
92     fprintf(f, "%s%d", i?",":"", *(p++));
93   fprintf(f, "\n");
94   exit(0);
95 }], 
96    [glib_ByteContents=`cat conftestval`  dnl''
97 ], 
98    [glib_ByteContents=no],
99    [glib_ByteContents=no])])
100 AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_byte_contents_$3), [$[]glib_ByteContents],
101         [Byte contents of $3])
102 popdef([glib_ByteContents])dnl
103 ])
104
105 dnl GLIB_SYSDEFS (INCLUDES, DEFS_LIST, OFILE [, PREFIX])
106 AC_DEFUN(GLIB_SYSDEFS,
107 [glib_sysdefso="translit($3, [-_a-zA-Z0-9 *], [-_a-zA-Z0-9])"
108 glib_sysdef_msg=`echo $2 | sed 's/:[[^  ]]*//g'`
109 if test "x`(echo '\n') 2>/dev/null`" != 'x\n'; then
110   glib_nl='\\n'
111 else
112   glib_nl='\n'
113 fi
114 AC_MSG_CHECKING(system definitions for $glib_sysdef_msg)
115 cat >confrun.c <<_______EOF
116 #include <stdio.h>
117 $1
118 int main (int c, char **v) {
119   FILE *f = fopen ("$glib_sysdefso", "a");
120   if (!f) return 1;
121 _______EOF
122 for glib_sysdef_input in $2 ; do
123         glib_sysdef=`echo $glib_sysdef_input | sed 's/^\([[^:]]*\):.*$/\1/'`
124         glib_default=`echo $glib_sysdef_input | sed 's/^[[^:]]*:\(.*\)$/\1/'`
125         echo "#ifdef $glib_sysdef" >>confrun.c
126         echo "  fprintf (f, \"#define GLIB_SYSDEF_%s %s%d${glib_nl}\", \"$glib_sysdef\", \"$4\", $glib_sysdef);" >>confrun.c
127         echo "#else" >>confrun.c
128         if test $glib_sysdef != $glib_default; then
129                 echo "  fprintf (f, \"#define GLIB_SYSDEF_%s %s%d${glib_nl}\", \"$glib_sysdef\", \"$4\", $glib_default);" >>confrun.c
130         else
131                 echo "  fprintf (f, \"#define GLIB_SYSDEF_%s${glib_nl}\", \"$glib_sysdef\");" >>confrun.c
132         fi
133         echo "#endif" >>confrun.c
134 done
135 echo "return 0; }" >>confrun.c
136 AC_TRY_RUN(`cat confrun.c`, AC_MSG_RESULT(done),
137 [       for glib_sysdef_input in $2 ; do
138                 glib_sysdef=`echo $glib_sysdef_input | sed 's/^\([[^:]]*\):.*$/\1/'`
139                 glib_default=`echo $glib_sysdef_input | sed 's/^[[^:]]*:\(.*\)$/\1/'`
140                 if test $glib_sysdef != $glib_default; then
141                         glib_default=" $4$glib_default"
142                 else
143                         glib_default=
144                 fi
145                 echo "#define GLIB_SYSDEF_$glib_sysdef$glib_default" >>$glib_sysdefso
146         done
147         AC_MSG_RESULT(failed)])
148 rm -f confrun.c
149 ])