remove obsolete macro
[m6w6/ext-psi] / m4 / psi_decl.m4
1 # psi_add_redir(name, symbol)
2 # Add a function redirection to $PSI_REDIRS.
3 psi_add_redir() {
4 cat >>$PSI_REDIRS <<<" {\"$1\", (psi_func_ptr) $2}, "
5 }
6
7 # psi_add_decl(decl, options)
8 # Add a pre-defined decl to $PSI_VA_DECLS/$PSI_DECLS.
9 psi_add_decl() {
10 case "$2" in
11 *vararg*)
12 cat >>$PSI_VA_DECLS <<<" $1, {0}, "
13 ;;
14 *)
15 cat >>$PSI_DECLS <<<" $1, {0}, "
16 ;;
17 esac
18 }
19
20 dnl PSI_REDIR(name, custom symbol)
21 dnl Create a function redirection to an optional custom symbol.
22 AC_DEFUN(PSI_REDIR, [
23 psi_add_redir $1 ifelse([$2],[],[$1],[$2])
24 ])
25
26 dnl PSI_FUNC_LIBC_MAIN()
27 dnl Check for the platforms default stub in executables.
28 AC_DEFUN(PSI_FUNC_LIBC_MAIN, [
29 AC_REQUIRE([AC_PROG_NM])
30 AC_REQUIRE([AC_PROG_AWK])
31 AC_CACHE_CHECK(for libc start main symbol, psi_cv_libc_main, [
32 psi_libc_main=
33 AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [
34 psi_libc_main=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
35 ])
36 psi_cv_libc_main=$psi_libc_main
37 ])
38 ])
39
40 dnl PSI_DECL_ARGS(decl args)
41 dnl INTERNAL: build psi_decl_args
42 AC_DEFUN(PSI_DECL_ARGS, [
43 psi_decl_args=
44 PSI_DECL_ARG($1)
45 m4_case([$2],
46 [(void)], [],
47 [()], [],
48 [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
49 ])
50
51 dnl PSI_DECL_ARG(decl arg)
52 dnl INTERNAL: build psi_decl_args
53 AC_DEFUN(PSI_DECL_ARG, [
54 m4_define([member_name], PSI_VAR_NAME($1))
55 m4_define([member_type], PSI_VAR_TYPE($1))
56
57 PSI_TYPE_INDIRECTION([$1],, pl, as)
58 if test -n "$psi_decl_args"; then
59 psi_decl_args="$psi_decl_args, "
60 fi
61 psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
62 ])
63
64 dnl PSI_DECL(type func, args, flags)
65 dnl Check for a function or macro declaration and a possible asm redirection.
66 dnl Adds a pre-defined (vararg) decl to $PSI_VA_DECLS/$PSI_DECLS.
67 dnl Calls PSI_MACRO if PSI_FUNC fails.
68 AC_DEFUN(PSI_DECL, [
69 AC_REQUIRE([PSI_FUNC_LIBC_MAIN])
70 PSI_DECL_ARGS($1, $2)
71
72 psi_symbol="PSI_VAR_NAME($1)"
73 AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [
74 psi_symbol_redirect=
75 AC_TRY_LINK(PSI_INCLUDES, [
76 void (*fn)(void) = (void (*)(void)) $psi_symbol;
77 ], [
78 psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
79 ])
80 [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_symbol_redirect
81 ])
82 case "$[psi_cv_fn_]PSI_VAR_NAME($1)" in
83 "$psi_symbol"|"_$psi_symbol")
84 psi_add_decl "$psi_decl_args" $3
85 ;;
86 *)
87 ifelse([$3], vararg, [
88 AC_MSG_ERROR(varargs macro support is not implemented)
89 ],[
90 PSI_MACRO($1, $2, [psi_add_decl "$psi_decl_args"])
91 ])
92 ;;
93 esac
94 ])