1 # psi_add_redir(name, symbol)
2 # Add a function redirection to $PSI_REDIRS.
4 cat >>$PSI_REDIRS <<<" {\"$1\", (void(*)(void))$2}, "
7 # psi_add_decl(decl, options)
8 # Add a pre-defined decl to $PSI_VA_DECLS/$PSI_DECLS.
12 cat >>$PSI_VA_DECLS <<<" $1, {0}, "
15 cat >>$PSI_DECLS <<<" $1, {0}, "
20 dnl PSI_REDIR(name, custom symbol)
21 dnl Create a function redirection to an optional custom symbol.
23 psi_add_redir $1 ifelse([$2],[],[$1],[$2])
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, [
33 AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [
34 psi_libc_main=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
36 psi_cv_libc_main=$psi_libc_main
40 dnl PSI_FUNC(fn, action-if-yes, action-if-no)
41 dnl Check for a possible function redirection.
43 AC_REQUIRE([PSI_FUNC_LIBC_MAIN])
45 AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [
47 AC_TRY_LINK(PSI_INCLUDES, [
48 void (*fn)(void) = (void (*)(void)) $psi_symbol;
50 psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
52 psi_cv_fn_$1=$psi_symbol_redirect
54 case "$psi_cv_fn_$1" in
58 "$psi_symbol"|"_$psi_symbol")
68 dnl PSI_DECL_ARG(decl arg)
69 dnl INTERNAL: build psi_decl_args
70 AC_DEFUN(PSI_DECL_ARG, [
71 m4_define([member_name], PSI_VAR_NAME($1))
72 m4_define([member_type], PSI_VAR_TYPE($1))
74 PSI_TYPE_INDIRECTION([$1],, pl, as)
75 if test -n "$psi_decl_args"; then
76 psi_decl_args="$psi_decl_args, "
78 psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
81 dnl PSI_DECL(type func, args, flags)
82 dnl Check for a function or macro declaration.
83 dnl Adds a pre-defined (vararg) decl to $PSI_VA_DECLS/$PSI_DECLS.
84 dnl Calls PSI_MACRO if PSI_FUNC fails.
91 [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
92 PSI_FUNC(PSI_VAR_NAME($1), [
93 psi_add_decl "$psi_decl_args" $3
96 ifelse([$3], vararg, [
97 AC_MSG_ERROR(varargs macro support is not implemented)
99 psi_add_decl "$psi_decl_args"