configure: generate less files, and do that in build dir
[m6w6/ext-psi] / m4 / psi / psi_decl.m4
1 # psi_add_redir(name, symbol)
2 # Add a function redirection to $PSI_REDIRS_H.
3 psi_add_redir() {
4 PSI_REDIRS="$PSI_REDIRS
5 {\"$1\", (psi_func_ptr) $2},"
6 }
7
8 # psi_add_decl(decl, options)
9 # Add a pre-defined decl to $PSI_VA_DECLS_H/$PSI_DECLS_H.
10 psi_add_decl() {
11 PSI_DECLS="$PSI_DECLS
12 $1, {0},"
13 }
14
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"
20 ])
21 dnl PSI_REDIR(name, custom symbol)
22 dnl Create a function redirection to an optional custom symbol.
23 AC_DEFUN(PSI_REDIR, [
24 psi_add_redir $1 ifelse([$2],[],[$1],[$2])
25 ])
26
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, [
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 func, decl args, options)
41 dnl INTERNAL: build psi_decl_args
42 AC_DEFUN(PSI_DECL_ARGS, [
43 psi_decl_args=
44 PSI_DECL_ARG([$1], [$3])
45 m4_case([$2],
46 [(void)], [],
47 [()], [],
48 [], [],
49 [m4_map_args_sep(
50 [PSI_DECL_ARG(m4_normalize(],
51 [), [0])], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
52 ])
53
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]))
59
60 PSI_TYPE_INDIRECTION([$1],, pl, as)
61 if test -n "$psi_decl_args"; then
62 psi_decl_args="$psi_decl_args, "
63 fi
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[}]"
65 ])
66
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.
71 AC_DEFUN(PSI_DECL, [
72 AC_REQUIRE([PSI_FUNC_LIBC_MAIN])dnl
73
74 PSI_DECL_ARGS($1, $2, $3)
75
76 psi_symbol="PSI_VAR_NAME($1)"
77 AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [
78 psi_decl_check=
79 psi_symbol_redirect=
80 for lib in "" $4; do
81 decl_save_LIBS=$LIBS
82 LIBS=$lib
83 AC_TRY_LINK(PSI_INCLUDES, [
84 void (*fn)(long, long, long) = (void (*)(long,long,long)) $psi_symbol;
85 fn(1,2,3);
86 ], [
87 psi_symbol_redirect=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
88 ])
89 LIBS=$decl_save_LIBS
90
91 if test -n "$psi_symbol_redirect"; then
92 if test -n "$lib"; then
93 psi_decl_check="$psi_symbol_redirect in $lib"
94 else
95 psi_decl_check="$psi_symbol_redirect"
96 fi
97 break
98 fi
99 done
100 [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_decl_check
101 ])
102
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}'`
105
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"
109 fi
110 fi
111
112 case "$psi_symbol_redirect" in
113 "$psi_symbol"|"_$psi_symbol")
114 case "$PSI_EXTRA_REDIRS-$3" in
115 "true-")
116 PSI_MACRO($1, $2, [
117 psi_add_decl "$psi_decl_args"
118 ])
119 ;;
120 *)
121 if test -n "$psi_symbol_libflag"
122 then
123 PSI_REDIR($psi_symbol)
124 fi
125 psi_add_decl "$psi_decl_args"
126 ;;
127 esac
128 ;;
129 "")
130 ifelse([$3], vararg, [
131 AC_MSG_WARN(varargs macro support is not implemented)
132 ],[
133 PSI_MACRO($1, $2, [
134 psi_add_decl "$psi_decl_args"
135 ])
136 ])
137 ;;
138 *)
139 PSI_REDIR($psi_symbol)
140 psi_add_decl "$psi_decl_args"
141 ;;
142 esac
143 ])