avoid busting bash's stack with a too big if body in configure
[m6w6/ext-psi] / m4 / psi_decl.m4
1 AC_DEFUN(PSI_REDIR, [psi_symbol=ifelse([$2],[],[$1],[$2])
2 cat >>$PSI_REDIRS <<<" {\"$1\", (void(*)(void))$psi_symbol}, "])
3
4 AC_DEFUN(PSI_FUNC_LIBC_MAIN, [
5 AC_REQUIRE([AC_PROG_NM])
6 AC_REQUIRE([AC_PROG_AWK])
7 AC_CACHE_CHECK(for libc start main symbol, psi_cv_libc_main, [
8 psi_libc_main=
9 AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [
10 psi_libc_main=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
11 ])
12 psi_cv_libc_main=$psi_libc_main
13 ])
14 ])
15
16 dnl PSI_FUNC(fn, action-if-yes, action-if-no)
17 AC_DEFUN(PSI_FUNC, [
18 AC_REQUIRE([PSI_FUNC_LIBC_MAIN])
19 psi_symbol=$1
20 AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [
21 psi_symbol_redirect=
22 AC_TRY_LINK(PSI_INCLUDES, [
23 void (*fn)(void) = (void (*)(void)) $psi_symbol;
24 ], [
25 psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
26 ])
27 psi_cv_fn_$1=$psi_symbol_redirect
28 ])
29 case "$psi_cv_fn_$1" in
30 "")
31 $3
32 ;;
33 "$psi_symbol"|"_$psi_symbol")
34 $2
35 ;;
36 *)
37 $2
38 PSI_REDIR($1)
39 ;;
40 esac
41 ])
42
43 AC_DEFUN(PSI_DECL_ARG, [
44 m4_define([member_name], PSI_VAR_NAME($1))
45 m4_define([member_type], PSI_VAR_TYPE($1))
46
47 PSI_TYPE_INDIRECTION([$1],, pl, as)
48 if test -n "$psi_decl_args"; then
49 psi_decl_args="$psi_decl_args, "
50 fi
51 psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
52 ])
53
54 dnl PSI_DECL(type func, args, flags)
55 AC_DEFUN(PSI_DECL, [
56 psi_decl_args=
57 PSI_DECL_ARG($1)
58 m4_case([$2],
59 [(void)], [],
60 [()], [],
61 [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
62 PSI_FUNC(PSI_VAR_NAME($1), [
63 ifelse([$3], vararg, [
64 cat >>$PSI_VA_DECLS <<<" $psi_decl_args, {0}, "
65 ], [
66 cat >>$PSI_DECLS <<<" $psi_decl_args, {0}, "
67 ])
68 ], [
69 PSI_MACRO($1, $2, [
70 ifelse([$3], vararg, AC_MSG_ERROR(varargs macro support is not implemented),[])
71 cat >>$PSI_DECLS <<<" $psi_decl_args, {0}, "
72 ])
73 ])
74 ])