128fd0771e2d56202a703a52d09633bff460b487
[platform/upstream/glib.git] / acglib.m4
1 dnl GLIB_IF_VAR_EQ (ENV_VAR, VALUE [, EQUALS_ACTION] [, ELSE_ACTION])
2 AC_DEFUN(GLIB_IF_VAR_EQ,[
3         case "$[$1]" in
4         "[$2]"[)]
5                 [$3]
6                 ;;
7         *[)]
8                 [$4]
9                 ;;
10         esac
11 ])
12 dnl GLIB_STR_CONTAINS (SRC_STRING, SUB_STRING [, CONTAINS_ACTION] [, ELSE_ACTION])
13 AC_DEFUN(GLIB_STR_CONTAINS,[
14         case "[$1]" in
15         *"[$2]"*[)]
16                 [$3]
17                 ;;
18         *[)]
19                 [$4]
20                 ;;
21         esac
22 ])
23 dnl GLIB_ADD_TO_VAR (ENV_VARIABLE, CHECK_STRING, ADD_STRING)
24 AC_DEFUN(GLIB_ADD_TO_VAR,[
25         GLIB_STR_CONTAINS($[$1], [$2], [$1]="$[$1]", [$1]="$[$1] [$3]")
26 ])
27
28 dnl GLIB_SIZEOF (INCLUDES, TYPE, ALIAS [, CROSS-SIZE])
29 AC_DEFUN(GLIB_SIZEOF,
30 [changequote(<<, >>)dnl
31 dnl The name to #define.
32 define(<<AC_TYPE_NAME>>, translit(glib_sizeof_$3, [a-z *], [A-Z_P]))dnl
33 dnl The cache variable name.
34 define(<<AC_CV_NAME>>, translit(glib_cv_sizeof_$3, [ *], [_p]))dnl
35 changequote([, ])dnl
36 AC_MSG_CHECKING(size of $2)
37 AC_CACHE_VAL(AC_CV_NAME,
38 [AC_TRY_RUN([#include <stdio.h>
39 $1
40 main()
41 {
42   FILE *f=fopen("conftestval", "w");
43   if (!f) exit(1);
44   fprintf(f, "%d\n", sizeof($2));
45   exit(0);
46 }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, ifelse([$4], , , AC_CV_NAME=$4))])dnl
47 AC_MSG_RESULT($AC_CV_NAME)
48 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
49 undefine([AC_TYPE_NAME])dnl
50 undefine([AC_CV_NAME])dnl
51 ])
52
53 dnl GLIB_BYTE_CONTENTS (INCLUDES, TYPE, ALIAS, N_BYTES, INITIALIZER)
54 AC_DEFUN(GLIB_BYTE_CONTENTS,
55 [changequote(<<, >>)dnl
56 dnl The name to #define.
57 define(<<AC_TYPE_NAME>>, translit(glib_byte_contents_$3, [a-z *], [A-Z_P]))dnl
58 dnl The cache variable name.
59 define(<<AC_CV_NAME>>, translit(glib_cv_byte_contents_$3, [ *], [_p]))dnl
60 changequote([, ])dnl
61 AC_MSG_CHECKING(byte contents of $2)
62 AC_CACHE_VAL(AC_CV_NAME,
63 [AC_TRY_RUN([#include <stdio.h>
64 $1
65 main()
66 {
67   static $2 tv = $5;
68   char *p = (char*) &tv;
69   int i;
70   FILE *f=fopen("conftestval", "w");
71   if (!f) exit(1);
72   for (i = 0; i < $4; i++)
73     fprintf(f, "%s%d", i?",":"", *(p++));
74   fprintf(f, "\n");
75   exit(0);
76 }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, AC_CV_NAME=0)])dnl
77 AC_MSG_RESULT($AC_CV_NAME)
78 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
79 undefine([AC_TYPE_NAME])dnl
80 undefine([AC_CV_NAME])dnl
81 ])
82
83 dnl GLIB_SYSDEFS (INCLUDES, DEFS_LIST, OFILE [, PREFIX])
84 AC_DEFUN(GLIB_SYSDEFS,
85 [glib_sysdefso="translit($3, [-_a-zA-Z0-9 *], [-_a-zA-Z0-9])"
86 AC_MSG_CHECKING(system definitions for $2)
87 cat >confrun.c <<_______EOF
88 #include <stdio.h>
89 $1
90 int main (int c, char **v) {
91   FILE *f = fopen ("$glib_sysdefso", "a");
92   if (!f) return 1;
93 _______EOF
94 for glib_sysdef in $2 ; do
95         echo "#ifdef $glib_sysdef" >>confrun.c
96         echo "  fprintf (f, \"#define GLIB_SYSDEF_%s %s%d\\n\", \"$glib_sysdef\", \"$4\", $glib_sysdef);" >>confrun.c
97         echo "#else" >>confrun.c
98         echo "  fprintf (f, \"#define GLIB_SYSDEF_%s\\n\", \"$glib_sysdef\");" >>confrun.c
99         echo "#endif" >>confrun.c
100 done
101 echo "return 0; }" >>confrun.c
102 AC_TRY_RUN(`cat confrun.c`, AC_MSG_RESULT(done),
103         for glib_sysdef in $2 ; do
104                 echo "#define GLIB_SYSDEF_$glib_sysdef" >>$glib_sysdefso
105         done
106         AC_MSG_RESULT(failed),)
107 rm -f confrun.c
108 ])