cca227d2929386ee11e4aa23464681ef35eb9679Aki TuomiAC_DEFUN([AC_TYPEOF], [
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi dnl * first check if we can get the size with redefining typedefs
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi order="$2"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$2" = ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi order="int long long-long"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result=""
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="unknown"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi AC_MSG_CHECKING([type of $1])
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi AC_CACHE_VAL(i_cv_typeof_$1,[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi dnl * try with printf() + -Werror
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi old_CFLAGS="$CFLAGS"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi CFLAGS="$CFLAGS -Werror"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi for type in $order; do
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi case "$type" in
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi int)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt="%d"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi unsigned-int)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt="%u"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi long)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt="%ld"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi unsigned-long)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt="%lu"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi long-long)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt="%lld"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi unsigned-long-long)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt="%llu"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi *)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fmt=""
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ;;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi esac
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$fmt" != ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi #include <sys/types.h>
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi #include <stdio.h>
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ]], [[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi printf("$fmt", ($1)0);
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ]])],[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$result" != ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi dnl * warning check isn't working
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result=""
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="unknown"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi break
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result="`echo $type|sed 's/-/ /g'`"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="$result"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ],[])
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi done
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi CFLAGS="$old_CFLAGS"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$result" = ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi for type in $order; do
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi type="`echo $type|sed 's/-/ /g'`"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi #include <sys/types.h>
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi typedef $type $1;
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ]], [[]])],[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$result" != ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi dnl * compiler allows redefining to anything
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result=""
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="unknown"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi break
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result="$type"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="$type"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ],[])
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi done
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$result" = ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi dnl * check with sizes
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi dnl * older autoconfs don't include sys/types.h, so do it manually
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi AC_RUN_IFELSE([AC_LANG_SOURCE([[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi #include <stdio.h>
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi #include <sys/types.h>
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi int main() {
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi FILE *f=fopen("conftestval", "w");
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if (!f) exit(1);
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fprintf(f, "%d\n", sizeof($1));
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi exit(0);
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi }
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ]])],[
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi size=`cat conftestval`
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi rm -f conftestval
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi for type in $order; do
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi actype="ac_cv_sizeof_`echo $type|sed 's/-/_/g'`"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$size" = "`eval echo \\$$actype`"; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result="`echo $type|sed 's/-/ /g'`"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="`expr $size \* 8`bit (using $result)"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi break
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi done
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi if test "$result" = ""; then
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi result=unknown
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible="`expr $size \* 8`bit (unknown type)"
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ],[],[])
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi fi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi i_cv_typeof_$1=$result/$visible
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi ])
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi typeof_$1=`echo $i_cv_typeof_$1 | sed s,/.*$,,`
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi visible=`echo $i_cv_typeof_$1 | sed s,^.*/,,`
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi AC_MSG_RESULT($visible)
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi])
cca227d2929386ee11e4aa23464681ef35eb9679Aki Tuomi