- dnl PSI_COMPUTE_STR(variable, string or expression, includes)
- AC_DEFUN(PSI_COMPUTE_STR, [
- AC_TRY_RUN([
- $3
- int main() {
- return EOF == fputs($2, fopen("conftest.out", "w"));
- }
- ], [
- eval $1=\\\"`cat conftest.out`\\\"
- ])
- ])
-
- PSI_CONSTS=""
- dnl PSI_CONST(const name, type, headers to include)
- AC_DEFUN(PSI_CONST, [
- AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
- psi_const_val=
- case $2 in
- str*|quoted_str*)
- if test "$cross_compiling" = "yes"
- then
- AC_TRY_CPP(PSI_INCLUDES_DEFAULT($3)$1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
- else
- PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES_DEFAULT($3))
- fi
- ;;
- *)
- AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES_DEFAULT($3))
- ;;
- esac
- psi_cv_const_$1=$psi_const_val
- ])
- if test "$psi_cv_const_$1"
- then
- case $2 in
- str*|quoted_str*)
- PSI_CONSTS="{PSI_T_STRING, \"string\", \"psi\\\\$1\", $psi_cv_const_$1, PSI_T_QUOTED_STRING}, $PSI_CONSTS"
- ;;
- *)
- PSI_CONSTS="{PSI_T_INT, \"int\", \"psi\\\\$1\", \"$psi_cv_const_$1\", PSI_T_NUMBER}, $PSI_CONSTS"
- ;;
- esac
- fi
- ])
-
- AC_DEFUN([AX_CHECK_SIGN], [
- typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"`
- AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [
- AC_TRY_COMPILE([$4],
- [ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ],
- [ eval "ax_cv_decl_${typename}_signed=\"yes\"" ],
- [ eval "ax_cv_decl_${typename}_signed=\"no\"" ])])
- symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"`
- if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then
- $2
- elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then
- $3
- fi
- ])
- dnl PSI_CHECK_OFFSETOF(struct, member, include)
- dnl[AS_LITERAL_IF([$1], [], [m4_fatal([$0: requires literal arguments])])]dnl
- dnl[AS_LITERAL_IF([$2], [], [m4_fatal([$0: requires literal arguments])])]dnl
- AC_DEFUN(PSI_CHECK_OFFSETOF, [
- _AC_CACHE_CHECK_INT(
- [offset of $2 in $1],
- [AS_TR_SH([ac_cv_offsetof_$1_$2])],
- [(long int) (offsetof ($1, $2))],
- [AC_INCLUDES_DEFAULT([$3])],
- [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
- )
- AC_DEFINE_UNQUOTED(
- AS_TR_CPP(offsetof_$1_$2),
- $AS_TR_SH([ac_cv_offsetof_$1_$2]),
- [The offset of `$2' in `$1', as computed by offsetof.]
- )
- ])
-
- dnl PSI_STRUCT(struct name, members, member type cases, includes)
- PSI_STRUCTS=
- AC_DEFUN(PSI_STRUCT, [
- AC_CHECK_SIZEOF($1, [], PSI_INCLUDES_DEFAULT($4))
- psi_struct_name=`echo $1 | cut -d" " -f2`
- psi_struct_size=$AS_TR_SH(ac_cv_sizeof_$1)
- psi_struct_members=
- m4_foreach(member, [$2], [
- AC_CHECK_MEMBER($1.member, [
- psi_member_name=member
- AC_CHECK_SIZEOF(AS_TR_SH($1)[_]member, [], PSI_INCLUDES_DEFAULT($4,
- [#define ]AS_TR_SH($1)[_]member (($1 *)0)->member
- ))
- psi_member_size=$AS_TR_SH(ac_cv_sizeof_$1[]_[]member)
- PSI_CHECK_OFFSETOF($1, member, PSI_INCLUDES_DEFAULT($4))
- psi_member_offset=$AS_TR_SH(ac_cv_offsetof_$1[]_[]member)
- # type
- case member in
- $3
- *) psi_member_type=int ;;
- esac
- # pointer level
- psi_struct_member_pl=`echo $psi_member_type | tr -cd '*' | wc -c`
- # array size
- psi_struct_member_as=`echo $psi_member_type | $AWK -F'@<:@@:>@@<:@@:>@' 'END {if(!found)print 0} /\@<:@@<:@@<:@:digit:@:>@@:>@+\@:>@/ {found=1; print$[]2}'`
- if test $psi_struct_member_as -gt 0
- then
- psi_struct_member_pl=`expr $psi_struct_member_pl + 1`
- fi
- psi_struct_member="{`psi_type_pair $psi_member_type $psi_member_size`, \"$psi_member_name\", $psi_member_offset, $psi_member_size, $psi_struct_member_pl, $psi_struct_member_as}"
- if test "$psi_struct_members"
- then
- psi_struct_members="$psi_struct_members, $psi_struct_member"
- else
- psi_struct_members="$psi_struct_member"
- fi
- ], [], PSI_INCLUDES_DEFAULT($4))
- ])
- if test "$1" != "$psi_struct_name"
- then
- PSI_TYPES="{PSI_T_STRUCT, \"$psi_struct_name\", \"$psi_struct_name\"}, $PSI_TYPES"
- fi
- PSI_STRUCTS="{\"$psi_struct_name\", $psi_struct_size, {$psi_struct_members}}, $PSI_STRUCTS"
- ])
-
- PSI_INCLUDES=
- AC_PROG_NM
- AC_PROG_AWK
- PSI_FUNCS=
- dnl PSI_FUNC(fn)
- AC_DEFUN(PSI_FUNC, [
- psi_symbol=$1
- AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [
- psi_symbol_redirect=
- AC_TRY_LINK_FUNC($1, [
- psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/ U .*$1.*/ {print$[]3}'`
- ])
- case "$psi_symbol_redirect" in
- "_$psi_symbol"|"$psi_symbol"|"")
- psi_cv_fn_$1=$psi_symbol
- ;;
- *)
- psi_cv_fn_$1=$psi_symbol_redirect
- ;;
- esac
- ])
- if test "$psi_cv_fn_$1" != "$psi_symbol"
- then
- PSI_FUNCS="{\"$psi_symbol\", (void *) $psi_symbol}, $PSI_FUNCS"
- fi
- ])
-
- PSI_MACROS=
- dnl PSI_MACRO(macro, return type, decl args, call args, include)
- AC_DEFUN(PSI_MACRO, [
- AC_CHECK_DECL($1$3, [
- PSI_MACROS="static $2 psi_macro_$1$3 {return $1$4;} $PSI_MACROS"
- PSI_FUNCS="{\"$1\", (void *) psi_macro_$1}, $PSI_FUNCS"
- ], [], PSI_INCLUDES_DEFAULT($5))
- ])
-
- AC_TYPE_INT8_T
- AC_CHECK_ALIGNOF(int8_t)
- AC_TYPE_UINT8_T
- AC_CHECK_ALIGNOF(uint8_t)
- AC_TYPE_INT16_T
- AC_CHECK_ALIGNOF(int16_t)
- AC_TYPE_UINT16_T
- AC_CHECK_ALIGNOF(uint16_t)
- AC_TYPE_INT32_T
- AC_CHECK_ALIGNOF(int32_t)
- AC_TYPE_UINT32_T
- AC_CHECK_ALIGNOF(uint32_t)
- AC_TYPE_INT64_T
- AC_CHECK_ALIGNOF(int64_t)
- AC_TYPE_UINT64_T
- AC_CHECK_ALIGNOF(uint64_t)
-
- PSI_TYPE(char, int)
- PSI_TYPE(short, int)
- PSI_TYPE(int, int)
- PSI_TYPE(long, int)
- PSI_TYPE(float)
- PSI_TYPE(double)
- PSI_TYPE(void *)
-
- dnl errno.h
- PSI_MACRO(errno, int, [()], [], errno.h)
- PSI_CONST(E2BIG, int, errno.h)
- PSI_CONST(EACCES, int, errno.h)
- PSI_CONST(EADDRINUSE, int, errno.h)
- PSI_CONST(EADDRNOTAVAIL, int, errno.h)
- PSI_CONST(EAFNOSUPPORT, int, errno.h)
- PSI_CONST(EAGAIN, int, errno.h)
- PSI_CONST(EALREADY, int, errno.h)
- PSI_CONST(EBADF, int, errno.h)
- PSI_CONST(EBADMSG, int, errno.h)
- PSI_CONST(EBUSY, int, errno.h)
- PSI_CONST(ECANCELED, int, errno.h)
- PSI_CONST(ECHILD, int, errno.h)
- PSI_CONST(ECONNABORTED, int, errno.h)
- PSI_CONST(ECONNREFUSED, int, errno.h)
- PSI_CONST(ECONNRESET, int, errno.h)
- PSI_CONST(EDEADLK, int, errno.h)
- PSI_CONST(EDESTADDRREQ, int, errno.h)
- PSI_CONST(EDOM, int, errno.h)
- PSI_CONST(EDQUOT, int, errno.h)
- PSI_CONST(EEXIST, int, errno.h)
- PSI_CONST(EFAULT, int, errno.h)
- PSI_CONST(EFBIG, int, errno.h)
- PSI_CONST(EHOSTUNREACH, int, errno.h)
- PSI_CONST(EIDRM, int, errno.h)
- PSI_CONST(EILSEQ, int, errno.h)
- PSI_CONST(EINPROGRESS, int, errno.h)
- PSI_CONST(EINTR, int, errno.h)
- PSI_CONST(EINVAL, int, errno.h)
- PSI_CONST(EIO, int, errno.h)
- PSI_CONST(EISCONN, int, errno.h)
- PSI_CONST(EISDIR, int, errno.h)
- PSI_CONST(ELOOP, int, errno.h)
- PSI_CONST(EMFILE, int, errno.h)
- PSI_CONST(EMLINK, int, errno.h)
- PSI_CONST(EMSGSIZE, int, errno.h)
- PSI_CONST(EMULTIHOP, int, errno.h)
- PSI_CONST(ENAMETOOLONG, int, errno.h)
- PSI_CONST(ENETDOWN, int, errno.h)
- PSI_CONST(ENETRESET, int, errno.h)
- PSI_CONST(ENETUNREACH, int, errno.h)
- PSI_CONST(ENFILE, int, errno.h)
- PSI_CONST(ENOBUFS, int, errno.h)
- PSI_CONST(ENODATA, int, errno.h)
- PSI_CONST(ENODEV, int, errno.h)
- PSI_CONST(ENOENT, int, errno.h)
- PSI_CONST(ENOEXEC, int, errno.h)
- PSI_CONST(ENOLCK, int, errno.h)
- PSI_CONST(ENOLINK, int, errno.h)
- PSI_CONST(ENOMEM, int, errno.h)
- PSI_CONST(ENOMSG, int, errno.h)
- PSI_CONST(ENOPROTOOPT, int, errno.h)
- PSI_CONST(ENOSPC, int, errno.h)
- PSI_CONST(ENOSR, int, errno.h)
- PSI_CONST(ENOSTR, int, errno.h)
- PSI_CONST(ENOSYS, int, errno.h)
- PSI_CONST(ENOTCONN, int, errno.h)
- PSI_CONST(ENOTDIR, int, errno.h)
- PSI_CONST(ENOTEMPTY, int, errno.h)
- PSI_CONST(ENOTRECOVERABLE, int, errno.h)
- PSI_CONST(ENOTSOCK, int, errno.h)
- PSI_CONST(ENOTSUP, int, errno.h)
- PSI_CONST(ENOTTY, int, errno.h)
- PSI_CONST(ENXIO, int, errno.h)
- PSI_CONST(EOPNOTSUPP, int, errno.h)
- PSI_CONST(EOVERFLOW, int, errno.h)
- PSI_CONST(EOWNERDEAD, int, errno.h)
- PSI_CONST(EPERM, int, errno.h)
- PSI_CONST(EPIPE, int, errno.h)
- PSI_CONST(EPROTO, int, errno.h)
- PSI_CONST(EPROTONOSUPPORT, int, errno.h)
- PSI_CONST(EPROTOTYPE, int, errno.h)
- PSI_CONST(ERANGE, int, errno.h)
- PSI_CONST(EROFS, int, errno.h)
- PSI_CONST(ESPIPE, int, errno.h)
- PSI_CONST(ESRCH, int, errno.h)
- PSI_CONST(ESTALE, int, errno.h)
- PSI_CONST(ETIME, int, errno.h)
- PSI_CONST(ETIMEDOUT, int, errno.h)
- PSI_CONST(ETXTBSY, int, errno.h)
- PSI_CONST(EWOULDBLOCK, int, errno.h)
- PSI_CONST(EXDEV, int, errno.h)
-
- dnl glob.h
- PSI_FUNC(glob)
- PSI_FUNC(globfree)
- PSI_STRUCT(glob_t, [
- [gl_pathc], [gl_matchc],
- [gl_pathv],
- [gl_offs],
- [gl_flags]], [
- gl_pathc|gloffs) psi_member_type=uint ;;
- gl_pathv) psi_member_type="char**" ;;
- ], glob.h)
- PSI_CONST(GLOB_APPEND, int, glob.h)
- PSI_CONST(GLOB_DOOFFS, int, glob.h)
- PSI_CONST(GLOB_ERR, int, glob.h)
- PSI_CONST(GLOB_MARK, int, glob.h)
- PSI_CONST(GLOB_NOCHECK, int, glob.h)
- PSI_CONST(GLOB_NOESCAPE, int, glob.h)
- PSI_CONST(GLOB_NOSORT, int, glob.h)
- PSI_CONST(GLOB_ABORTED, int, glob.h)
- PSI_CONST(GLOB_NOMATCH, int, glob.h)
- PSI_CONST(GLOB_NOSPACE, int, glob.h)