704410c4bae6b15f452c43f41e6bf53a9a8da510
[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_DIVERT_BEFORE_HELP(STUFF)
16 # Put STUFF early enough so that they are available for $ac_help expansion.
17 # Handle both classic (<= v2.13) and modern autoconf
18 ifdef([AC_DIVERT],
19       [AC_DEFUN([GLIB_DIVERT_BEFORE_HELP],[AC_DIVERT([NOTICE],[$1])])],
20       [AC_DEFUN([GLIB_DIVERT_BEFORE_HELP],[dnl
21 AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
22 $1
23 AC_DIVERT_POP()])])
24
25 dnl GLIB_IF_VAR_EQ (ENV_VAR, VALUE [, EQUALS_ACTION] [, ELSE_ACTION])
26 AC_DEFUN(GLIB_IF_VAR_EQ,[
27         case "$[$1]" in
28         "[$2]"[)]
29                 [$3]
30                 ;;
31         *[)]
32                 [$4]
33                 ;;
34         esac
35 ])
36 dnl GLIB_STR_CONTAINS (SRC_STRING, SUB_STRING [, CONTAINS_ACTION] [, ELSE_ACTION])
37 AC_DEFUN(GLIB_STR_CONTAINS,[
38         case "[$1]" in
39         *"[$2]"*[)]
40                 [$3]
41                 ;;
42         *[)]
43                 [$4]
44                 ;;
45         esac
46 ])
47 dnl GLIB_ADD_TO_VAR (ENV_VARIABLE, CHECK_STRING, ADD_STRING)
48 AC_DEFUN(GLIB_ADD_TO_VAR,[
49         GLIB_STR_CONTAINS($[$1], [$2], [$1]="$[$1]", [$1]="$[$1] [$3]")
50 ])
51
52 dnl GLIB_SIZEOF (INCLUDES, TYPE, ALIAS [, CROSS-SIZE])
53 AC_DEFUN(GLIB_SIZEOF,
54 [pushdef([glib_Sizeof], GLIB_TR_SH([glib_cv_sizeof_$3]))dnl
55 AC_CACHE_CHECK([size of $2], glib_Sizeof,
56 [AC_TRY_RUN([#include <stdio.h>
57 #if STDC_HEADERS
58 #include <stdlib.h>
59 #include <stddef.h>
60 #endif
61 $1
62 main()
63 {
64   FILE *f=fopen("conftestval", "w");
65   if (!f) exit(1);
66   fprintf(f, "%d\n", sizeof($2));
67   exit(0);
68 }], 
69   [glib_Sizeof=`cat conftestval`  dnl''
70 ],
71   [glib_Sizeof=0],
72   ifelse([$4], [], [], [glib_Sizeof=$4]))])
73 AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_sizeof_$3), [$[]glib_Sizeof])
74 popdef([glib_Sizeof])dnl
75 ])
76
77 dnl GLIB_BYTE_CONTENTS (INCLUDES, TYPE, ALIAS, N_BYTES, INITIALIZER)
78 AC_DEFUN(GLIB_BYTE_CONTENTS,
79 [pushdef([glib_ByteContents], GLIB_TR_SH([glib_cv_byte_contents_$3]))dnl
80 AC_CACHE_CHECK([byte contents of $5], glib_ByteContents,
81 [AC_TRY_RUN([#include <stdio.h>
82 $1
83 main()
84 {
85   static $2 tv = $5;
86   char *p = (char*) &tv;
87   int i;
88   FILE *f=fopen("conftestval", "w");
89   if (!f) exit(1);
90   for (i = 0; i < $4; i++)
91     fprintf(f, "%s%d", i?",":"", *(p++));
92   fprintf(f, "\n");
93   exit(0);
94 }], 
95    [glib_ByteContents=`cat conftestval`  dnl''
96 ], 
97    [glib_ByteContents=no],
98    [glib_ByteContents=no])])
99 AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_byte_contents_$3), [$[]glib_ByteContents])
100 popdef([glib_ByteContents])dnl
101 ])
102
103 dnl GLIB_SYSDEFS (INCLUDES, DEFS_LIST, OFILE [, PREFIX])
104 AC_DEFUN(GLIB_SYSDEFS,
105 [glib_sysdefso="translit($3, [-_a-zA-Z0-9 *], [-_a-zA-Z0-9])"
106 glib_sysdef_msg=`echo $2 | sed 's/:[[^  ]]*//g'`
107 if test "x`(echo '\n') 2>/dev/null`" != 'x\n'; then
108   glib_nl='\\n'
109 else
110   glib_nl='\n'
111 fi
112 AC_MSG_CHECKING(system definitions for $glib_sysdef_msg)
113 cat >confrun.c <<_______EOF
114 #include <stdio.h>
115 $1
116 int main (int c, char **v) {
117   FILE *f = fopen ("$glib_sysdefso", "a");
118   if (!f) return 1;
119 }
120 _______EOF
121 for glib_sysdef_input in $2 ; do
122         glib_sysdef=`echo $glib_sysdef_input | sed 's/^\([[^:]]*\):.*$/\1/'`
123         glib_default=`echo $glib_sysdef_input | sed 's/^[[^:]]*:\(.*\)$/\1/'`
124         echo "#ifdef $glib_sysdef" >>confrun.c
125         echo "  fprintf (f, \"#define GLIB_SYSDEF_%s %s%d${glib_nl}\", \"$glib_sysdef\", \"$4\", $glib_sysdef);" >>confrun.c
126         echo "#else" >>confrun.c
127         if test $glib_sysdef != $glib_default; then
128                 echo "  fprintf (f, \"#define GLIB_SYSDEF_%s %s%d${glib_nl}\", \"$glib_sysdef\", \"$4\", $glib_default);" >>confrun.c
129         else
130                 echo "  fprintf (f, \"#define GLIB_SYSDEF_%s${glib_nl}\", \"$glib_sysdef\");" >>confrun.c
131         fi
132         echo "#endif" >>confrun.c
133 done
134 echo "return 0; }" >>confrun.c
135 AC_TRY_RUN(`cat confrun.c`, AC_MSG_RESULT(done),
136 [       for glib_sysdef_input in $2 ; do
137                 glib_sysdef=`echo $glib_sysdef_input | sed 's/^\([[^:]]*\):.*$/\1/'`
138                 glib_default=`echo $glib_sysdef_input | sed 's/^[[^:]]*:\(.*\)$/\1/'`
139                 if test $glib_sysdef != $glib_default; then
140                         glib_default=" $4$glib_default"
141                 else
142                         glib_default=
143                 fi
144                 echo "#define GLIB_SYSDEF_$glib_sysdef$glib_default" >>$glib_sysdefso
145         done
146         AC_MSG_RESULT(failed)])
147 rm -f confrun.c
148 ])