1 psi_type_pair() { # (type, size)
2 local psi_type_name=`tr -cd A-Za-z <<<$1`
3 local psi_type_lower=`tr A-Z a-z <<<$psi_type_name`
4 case $psi_type_lower in
6 local psi_type_upper=`tr a-z A-Z <<<$psi_type_name`
7 local psi_type_bits=`expr $2 \* 8`
8 echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
11 echo "PSI_T_STRUCT, \"$2\""
14 echo "PSI_T_VOID, \"void\""
17 echo "PSI_T_NAME, \"$psi_type_name\""
23 dnl PSI_TYPE(type name, basic type, includes)
25 ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
26 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES)
28 case $psi_basic_type in
30 AX_CHECK_SIGN($1, :, [
38 if test "$2" && test "$ac_cv_sizeof_[]$1" -gt 0; then
39 AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
40 PSI_TYPES="{`psi_type_pair $psi_basic_type $ac_cv_sizeof_[]$1`, \""$1"\"}, $PSI_TYPES"
45 # add_str_const(name, value)
47 PSI_CONSTS="{PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING}, $PSI_CONSTS"
49 # add_int_const(name, value)
51 PSI_CONSTS="{PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER}, $PSI_CONSTS"
53 dnl PSI_CONST(const name, type)
55 AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
59 if test "$cross_compiling" = "yes"
61 AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
63 PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES)
67 AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES)
70 psi_cv_const_$1=$psi_const_val
72 if test "$psi_cv_const_$1"
76 add_str_const "$1" "$psi_cv_const_$1"
79 add_int_const "$1" "$psi_cv_const_$1"
86 # add_decl(ret type, symbol, args)
89 eval size=\$ac_cv_sizeof_$1
90 PSI_DECLS="{`psi_type_pair \"$1\" \"$size\"`, \"$2\"}, $PSI_DECLS"
93 # add_redir(symbol, macro=symbol)
96 test -z "$sym" && sym=$1
97 PSI_REDIR="{\"$1\", (void (*)(void)) $sym}, $PSI_REDIR"
99 # arg_names(typed args)
103 | $AWK -F, '{for (i=1;i<NF;++i) print $i ","; print $NF}' \
104 | $AWK '{print $NF}' \
108 # gen_macro(ret type, symbol, args)
111 test -z "$3" && dargs="()"
112 AS_ECHO_N(["static $1 psi_macro_$2$dargs {"])
113 if test "$1" != "void"; then
114 AS_ECHO_N(["return "])
117 AS_ECHO_N(["$2`arg_names \"$3\"`;}"])
119 # add_macro(ret type, symbol, args)
121 PSI_MACROS="`gen_macro \"$1\" \"$2\" \"$3\"` $PSI_MACROS"
122 add_redir "$2" "psi_macro_$2"
125 dnl PSI_MACRO(macro, decl args, action-if-true)
126 AC_DEFUN(PSI_MACRO, [
127 AC_CHECK_DECL($1$2, $3, [], PSI_INCLUDES)
130 dnl PSI_FUNC(fn, action-if-yes, action-if-no)
132 AC_REQUIRE([AC_PROG_NM])
133 AC_REQUIRE([AC_PROG_AWK])
135 AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [
137 AC_TRY_LINK(PSI_INCLUDES, [
138 void (*fn)(void) = (void (*)(void)) $psi_symbol;
140 psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/ U .*$1.*/ {print$[]3; exit}'`
142 psi_cv_fn_$1=$psi_symbol_redirect
144 case "$psi_cv_fn_$1" in
146 "$psi_symbol"|"_$psi_symbol") $2 ;;
147 *) add_redir "$psi_symbol"; $2 ;;
151 dnl PSI_EXTVAR(var, type)
152 AC_DEFUN(PSI_EXTVAR, [
159 dnl PSI_DECL(ret type, func, args)
162 add_decl "$1" "$2" "$3"
165 add_macro "$1" "$2" "$3"
166 add_decl "$1" "$2" "$3"
171 AC_DEFUN(PSI_STRUCT_MEMBER, [
174 m4_map_args_w([$1], [
175 psi_member_type="$psi_member_type $psi_member_name"
178 AC_MSG_RESULT([member=$psi_member_name - $psi_member_type])
181 AC_DEFUN(PSI_STRUCT, [
182 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES)
183 m4_map_args([PSI_STRUCT_MEMBER], $2)
187 AC_DEFUN(PSI_CHECK_STD_TYPES, [
188 AC_CHECK_HEADERS(stdint.h)
191 AC_CHECK_SIZEOF(int8_t)
192 AC_CHECK_ALIGNOF(int8_t)
194 AC_CHECK_SIZEOF(uint8_t)
195 AC_CHECK_ALIGNOF(uint8_t)
197 AC_CHECK_SIZEOF(int16_t)
198 AC_CHECK_ALIGNOF(int16_t)
200 AC_CHECK_SIZEOF(uint16_t)
201 AC_CHECK_ALIGNOF(uint16_t)
203 AC_CHECK_SIZEOF(int32_t)
204 AC_CHECK_ALIGNOF(int32_t)
206 AC_CHECK_SIZEOF(uint32_t)
207 AC_CHECK_ALIGNOF(uint32_t)
209 AC_CHECK_SIZEOF(int64_t)
210 AC_CHECK_ALIGNOF(int64_t)
212 AC_CHECK_SIZEOF(uint64_t)
213 AC_CHECK_ALIGNOF(uint64_t)
216 AC_CHECK_ALIGNOF(float)
218 AC_CHECK_ALIGNOF(double)
220 AC_CHECK_ALIGNOF(void *)