1 # psi_add_redir(name, symbol)
2 # Add a function redirection to $PSI_REDIRS.
4 cat >>$PSI_REDIRS <<<" {\"$1\", (psi_func_ptr) $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_DECL_ARGS(decl args)
41 dnl INTERNAL: build psi_decl_args
42 AC_DEFUN(PSI_DECL_ARGS, [
48 [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
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))
57 PSI_TYPE_INDIRECTION([$1],, pl, as)
58 if test -n "$psi_decl_args"; then
59 psi_decl_args="$psi_decl_args, "
61 psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
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.
69 AC_REQUIRE([PSI_FUNC_LIBC_MAIN])
72 psi_symbol="PSI_VAR_NAME($1)"
73 AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [
75 AC_TRY_LINK(PSI_INCLUDES, [
76 void (*fn)(void) = (void (*)(void)) $psi_symbol;
78 psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
80 [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_symbol_redirect
82 case "$[psi_cv_fn_]PSI_VAR_NAME($1)" in
83 "$psi_symbol"|"_$psi_symbol")
84 psi_add_decl "$psi_decl_args" $3
87 ifelse([$3], vararg, [
88 AC_MSG_ERROR(varargs macro support is not implemented)
90 PSI_MACRO($1, $2, [psi_add_decl "$psi_decl_args"])