1 # psi_add_redir(name, symbol)
2 # Add a function redirection to $PSI_REDIRS_H.
4 PSI_REDIRS="$PSI_REDIRS
5 {\"$1\", (psi_func_ptr) $2},"
8 # psi_add_decl(decl, options)
9 # Add a pre-defined decl to $PSI_VA_DECLS_H/$PSI_DECLS_H.
15 dnl PSI_DECL_TYPE(type functor_name, args)
16 dnl Adds a pre-defined functor decl to $PSI_FN_DECLS_H.
17 AC_DEFUN(PSI_DECL_TYPE, [
18 PSI_DECL_ARGS($1, $2, functor)
19 psi_add_decl "$psi_decl_args"
21 dnl PSI_REDIR(name, custom symbol)
22 dnl Create a function redirection to an optional custom symbol.
24 psi_add_redir $1 ifelse([$2],[],[$1],[$2])
27 dnl PSI_FUNC_LIBC_MAIN()
28 dnl Check for the platforms default stub in executables.
29 AC_DEFUN(PSI_FUNC_LIBC_MAIN, [
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 func, decl args, options)
41 dnl INTERNAL: build psi_decl_args
42 AC_DEFUN(PSI_DECL_ARGS, [
44 PSI_DECL_ARG([$1], [$3])
50 [PSI_DECL_ARG(m4_normalize(],
51 [), [0])], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
54 dnl PSI_DECL_ARG(decl arg, options)
55 dnl INTERNAL: build psi_decl_args
56 AC_DEFUN(PSI_DECL_ARG, [
57 m4_define([member_name], PSI_VAR_NAME([$1]))
58 m4_define([member_type], PSI_VAR_TYPE([$1]))
60 PSI_TYPE_INDIRECTION([$1],, pl, as)
61 if test -n "$psi_decl_args"; then
62 psi_decl_args="$psi_decl_args, "
64 psi_decl_args="[$psi_decl_args{]ifelse([$2],,DECL_KIND_STD,[ifelse([$2],0,0,AS_TR_CPP([DECL_KIND_$2]))])[, ]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
67 dnl PSI_DECL(type func, args, flags, libs)
68 dnl Check for a function or macro declaration and a possible asm redirection.
69 dnl Adds a pre-defined (vararg) decl to $PSI_VA_DECLS_H/$PSI_DECLS_H.
70 dnl Calls PSI_MACRO if PSI_FUNC fails.
72 AC_REQUIRE([PSI_FUNC_LIBC_MAIN])dnl
74 PSI_DECL_ARGS($1, $2, $3)
76 psi_symbol="PSI_VAR_NAME($1)"
77 AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [
83 AC_TRY_LINK(PSI_INCLUDES, [
84 void (*fn)(long, long, long) = (void (*)(long,long,long)) $psi_symbol;
87 psi_symbol_redirect=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
91 if test -n "$psi_symbol_redirect"; then
92 if test -n "$lib"; then
93 psi_decl_check="$psi_symbol_redirect in $lib"
95 psi_decl_check="$psi_symbol_redirect"
100 [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_decl_check
103 psi_symbol_redirect=`AS_ECHO("$[psi_cv_fn_]PSI_VAR_NAME($1)") | $AWK -F " in " '{print [$]1}'`
104 psi_symbol_libflag=`AS_ECHO("$[psi_cv_fn_]PSI_VAR_NAME($1)") | $AWK -F " in " '{print [$]2}'`
106 if test -n "$psi_symbol_libflag"; then
107 if ! expr "X$LIBS" : "X.*\b$psi_symbol_libflag\b" >/dev/null; then
108 LIBS="$psi_symbol_libflag $LIBS"
112 case "$psi_symbol_redirect" in
113 "$psi_symbol"|"_$psi_symbol")
114 case "$PSI_EXTRA_REDIRS-$3" in
117 psi_add_decl "$psi_decl_args"
121 if test -n "$psi_symbol_libflag"
123 PSI_REDIR($psi_symbol)
125 psi_add_decl "$psi_decl_args"
130 ifelse([$3], vararg, [
131 AC_MSG_WARN(varargs macro support is not implemented)
134 psi_add_decl "$psi_decl_args"
139 PSI_REDIR($psi_symbol)
140 psi_add_decl "$psi_decl_args"