"Fossies" - the Fresh Open Source Software Archive

Member "cln-1.3.6/m4/intparam.m4" (4 Dec 2019, 12529 Bytes) of package /linux/privat/cln-1.3.6.tar.bz2:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "intparam.m4": 1.3.5_vs_1.3.6.

    1 # intparam.m4 serial 1
    2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
    3 dnl This file is free software; the Free Software Foundation
    4 dnl gives unlimited permission to copy and/or distribute it,
    5 dnl with or without modifications, as long as this notice is preserved.
    6 
    7 dnl From Bruno Haible.
    8 
    9 AC_DEFUN([CL_INTPARAM_CROSS],
   10 [
   11   AC_REQUIRE([CL_LONGLONG])
   12   AC_REQUIRE([CL_LONGDOUBLE])
   13   AC_REQUIRE([AC_C_BIGENDIAN])
   14   cl_machine_file_h=$1
   15   {
   16     CL_INTPARAM_BITSIZE([signed char], [char_bitsize])
   17     CL_INTPARAM_BITSIZE([short], [short_bitsize])
   18     CL_INTPARAM_BITSIZE([int], [int_bitsize])
   19     CL_INTPARAM_BITSIZE([long], [long_bitsize])
   20     if test $cl_cv_c_longlong = yes; then
   21       CL_INTPARAM_BITSIZE([long long], [longlong_bitsize])
   22     fi
   23     CL_INTPARAM_BITSIZE([unsigned char], [uchar_bitsize])
   24     CL_INTPARAM_BITSIZE([unsigned short], [ushort_bitsize])
   25     CL_INTPARAM_BITSIZE([unsigned int], [uint_bitsize])
   26     CL_INTPARAM_BITSIZE([unsigned long], [ulong_bitsize])
   27     if test $cl_cv_c_longlong = yes; then
   28       CL_INTPARAM_BITSIZE([unsigned long long], [ulonglong_bitsize])
   29     fi
   30     if test -n "$char_bitsize"; then
   31       echo "/* Integers of type char have $char_bitsize bits. */"
   32       echo "#define char_bitsize $char_bitsize"
   33       echo
   34     else
   35       echo "#error \"Integers of type char have no binary representation!!\""
   36     fi
   37     if test -n "$short_bitsize"; then
   38       echo "/* Integers of type short have $short_bitsize bits. */"
   39       echo "#define short_bitsize $short_bitsize"
   40       echo
   41     else
   42       echo "#error \"Integers of type short have no binary representation!!\""
   43     fi
   44     if test -n "$int_bitsize"; then
   45       echo "/* Integers of type int have $int_bitsize bits. */"
   46       echo "#define int_bitsize $int_bitsize"
   47       echo
   48     else
   49       echo "#error \"Integers of type int have no binary representation!!\""
   50     fi
   51     if test -n "$long_bitsize"; then
   52       echo "/* Integers of type long have $long_bitsize bits. */"
   53       echo "#define long_bitsize $long_bitsize"
   54       echo
   55     else
   56       echo "#error \"Integers of type long have no binary representation!!\""
   57     fi
   58     if test $cl_cv_c_longlong = yes; then
   59       if test -n "$longlong_bitsize"; then
   60         echo "/* Integers of type long long have $longlong_bitsize bits. */"
   61         echo "#define long_long_bitsize $longlong_bitsize"
   62         echo
   63       else
   64         echo "#error \"Integers of type long long have no binary representation!!\""
   65       fi
   66     fi
   67     if test -n "$uchar_bitsize"; then
   68       echo "/* Integers of type unsigned char have $uchar_bitsize bits. */"
   69       echo
   70     else
   71       echo "#error \"Integers of type unsigned char have no binary representation!!\""
   72     fi
   73     if test -n "$ushort_bitsize"; then
   74       echo "/* Integers of type unsigned short have $ushort_bitsize bits. */"
   75       echo
   76     else
   77       echo "#error \"Integers of type unsigned short have no binary representation!!\""
   78     fi
   79     if test -n "$uint_bitsize"; then
   80       echo "/* Integers of type unsigned int have $uint_bitsize bits. */"
   81       echo
   82     else
   83       echo "#error \"Integers of type unsigned int have no binary representation!!\""
   84     fi
   85     if test -n "$ulong_bitsize"; then
   86       echo "/* Integers of type unsigned long have $ulong_bitsize bits. */"
   87       echo
   88     else
   89       echo "#error \"Integers of type unsigned long have no binary representation!!\""
   90     fi
   91     if test $cl_cv_c_longlong = yes; then
   92       if test -n "$ulonglong_bitsize"; then
   93         echo "/* Integers of type unsigned long long have $ulonglong_bitsize bits. */"
   94         echo
   95       else
   96         echo "#error \"Integers of type unsigned long long have no binary representation!!\""
   97       fi
   98     fi
   99     if test "$char_bitsize" != "$uchar_bitsize"; then
  100       echo "#error \"Integer types char and unsigned char have different sizes!!\""
  101     fi
  102     if test "$short_bitsize" != "$ushort_bitsize"; then
  103       echo "#error \"Integer types short and unsigned short have different sizes!!\""
  104     fi
  105     if test "$int_bitsize" != "$uint_bitsize"; then
  106       echo "#error \"Integer types int and unsigned int have different sizes!!\""
  107     fi
  108     if test "$long_bitsize" != "$ulong_bitsize"; then
  109       echo "#error \"Integer types long and unsigned long have different sizes!!\""
  110     fi
  111     if test $cl_cv_c_longlong = yes; then
  112       if test "$longlong_bitsize" != "$ulonglong_bitsize"; then
  113         echo "#error \"Integer types long long and unsigned long long have different sizes!!\""
  114       fi
  115     fi
  116     AC_TRY_COMPILE([], [static_assert(sizeof(char*) <= sizeof(intptr_t), "");],
  117       [], [echo "#error \"Type char * does not fit into an intptr_t!!\""])
  118     _AC_COMPUTE_INT([sizeof (char *)], [pointer_size])
  119     pointer_bitsize=`expr $pointer_size '*' $char_bitsize`
  120     echo "/* Pointers of type char * have $pointer_bitsize bits. */"
  121     echo "#define pointer_bitsize $pointer_bitsize"
  122     echo
  123     CL_INTPARAM_SIZEOF([char], [sizeof_char])
  124     CL_INTPARAM_ALIGNOF([char], [alignment_char])
  125     echo "/* Type char has sizeof = $sizeof_char and alignment = $alignment_char. */"
  126     echo "#define sizeof_char $sizeof_char"
  127     echo "#define alignment_char $alignment_char"
  128     echo
  129     CL_INTPARAM_SIZEOF([unsigned char], [sizeof_uchar])
  130     CL_INTPARAM_ALIGNOF([unsigned char], [alignment_uchar])
  131     echo "/* Type unsigned char has sizeof = $sizeof_uchar and alignment = $alignment_uchar. */"
  132     echo
  133     CL_INTPARAM_SIZEOF([short], [sizeof_short])
  134     CL_INTPARAM_ALIGNOF([short], [alignment_short])
  135     echo "/* Type short has sizeof = $sizeof_short and alignment = $alignment_short. */"
  136     echo "#define sizeof_short $sizeof_short"
  137     echo "#define alignment_short $alignment_short"
  138     echo
  139     CL_INTPARAM_SIZEOF([unsigned short], [sizeof_ushort])
  140     CL_INTPARAM_ALIGNOF([unsigned short], [alignment_ushort])
  141     echo "/* Type unsigned short has sizeof = $sizeof_ushort and alignment = $alignment_ushort. */"
  142     echo
  143     CL_INTPARAM_SIZEOF([int], [sizeof_int])
  144     CL_INTPARAM_ALIGNOF([int], [alignment_int])
  145     echo "/* Type int has sizeof = $sizeof_int and alignment = $alignment_int. */"
  146     echo "#define sizeof_int $sizeof_int"
  147     echo "#define alignment_int $alignment_int"
  148     echo
  149     CL_INTPARAM_SIZEOF([unsigned int], [sizeof_uint])
  150     CL_INTPARAM_ALIGNOF([unsigned int], [alignment_uint])
  151     echo "/* Type unsigned int has sizeof = $sizeof_uint and alignment = $alignment_uint. */"
  152     echo
  153     CL_INTPARAM_SIZEOF([long], [sizeof_long])
  154     CL_INTPARAM_ALIGNOF([long], [alignment_long])
  155     echo "/* Type long has sizeof = $sizeof_long and alignment = $alignment_long. */"
  156     echo "#define sizeof_long $sizeof_long"
  157     echo "#define alignment_long $alignment_long"
  158     echo
  159     CL_INTPARAM_SIZEOF([unsigned long], [sizeof_ulong])
  160     CL_INTPARAM_ALIGNOF([unsigned long], [alignment_ulong])
  161     echo "/* Type unsigned long has sizeof = $sizeof_ulong and alignment = $alignment_ulong. */"
  162     echo
  163     if test $cl_cv_c_longlong = yes; then
  164       CL_INTPARAM_SIZEOF([long long], [sizeof_longlong])
  165       CL_INTPARAM_ALIGNOF([long long], [alignment_longlong])
  166       echo "/* Type long long has sizeof = $sizeof_longlong and alignment = $alignment_longlong. */"
  167       echo "#define sizeof_long_long $sizeof_longlong"
  168       echo "#define alignment_long_long $alignment_longlong"
  169       echo
  170       CL_INTPARAM_SIZEOF([unsigned long long], [sizeof_ulonglong])
  171       CL_INTPARAM_ALIGNOF([unsigned long long], [alignment_ulonglong])
  172       echo "/* Type unsigned long long has sizeof = $sizeof_ulonglong and alignment = $alignment_ulonglong. */"
  173       echo
  174     fi
  175     CL_INTPARAM_SIZEOF([float], [sizeof_float])
  176     CL_INTPARAM_ALIGNOF([float], [alignment_float])
  177     echo "/* Type float has sizeof = $sizeof_float and alignment = $alignment_float. */"
  178     echo "#define sizeof_float $sizeof_float"
  179     echo "#define alignment_float $alignment_float"
  180     echo
  181     CL_INTPARAM_SIZEOF([double], [sizeof_double])
  182     CL_INTPARAM_ALIGNOF([double], [alignment_double])
  183     echo "/* Type double has sizeof = $sizeof_double and alignment = $alignment_double. */"
  184     echo "#define sizeof_double $sizeof_double"
  185     echo "#define alignment_double $alignment_double"
  186     echo
  187     if test $cl_cv_c_longdouble = yes; then
  188       CL_INTPARAM_SIZEOF([long double], [sizeof_longdouble])
  189       CL_INTPARAM_ALIGNOF([long double], [alignment_longdouble])
  190       echo "/* Type long double has sizeof = $sizeof_longdouble and alignment = $alignment_longdouble. */"
  191       echo "#define sizeof_long_double $sizeof_longdouble"
  192       echo "#define alignment_long_double $alignment_longdouble"
  193       echo
  194     fi
  195     CL_INTPARAM_SIZEOF([char *], [sizeof_char_ptr])
  196     CL_INTPARAM_ALIGNOF([char *], [alignment_char_ptr])
  197     echo "/* Type char * has sizeof = $sizeof_char_ptr and alignment = $alignment_char_ptr. */"
  198     echo
  199     CL_INTPARAM_SIZEOF([long *], [sizeof_long_ptr])
  200     CL_INTPARAM_ALIGNOF([long *], [alignment_long_ptr])
  201     echo "/* Type long * has sizeof = $sizeof_long_ptr and alignment = $alignment_long_ptr. */"
  202     echo
  203     CL_INTPARAM_SIZEOF([void (*)(void)], [sizeof_function_ptr])
  204     CL_INTPARAM_ALIGNOF([void (*)(void)], [alignment_function_ptr])
  205     echo "/* Type function * has sizeof = $sizeof_function_ptr and alignment = $alignment_function_ptr. */"
  206     echo
  207     case $ac_cv_c_bigendian in
  208       yes)
  209         echo "/* Type unsigned short is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  210         echo "#define short_big_endian"
  211         echo "/* Type unsigned int is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  212         echo "#define int_big_endian"
  213         echo "/* Type unsigned long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  214         echo "#define long_big_endian"
  215         if test $cl_cv_c_longlong = yes; then
  216           echo "/* Type unsigned long long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
  217           echo "#define long_long_big_endian"
  218         fi
  219         ;;
  220       no)
  221         echo "/* Type unsigned short is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  222         echo "#define short_little_endian"
  223         echo "/* Type unsigned int is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  224         echo "#define int_little_endian"
  225         echo "/* Type unsigned long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  226         echo "#define long_little_endian"
  227         if test $cl_cv_c_longlong = yes; then
  228           echo "/* Type unsigned long long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
  229           echo "#define long_long_little_endian"
  230         fi
  231         ;;
  232       *)
  233         echo "#error \"Type short is stored in memory in an obscure manner!!\""
  234         echo "#error \"Type int is stored in memory in an obscure manner!!\""
  235         echo "#error \"Type long is stored in memory in an obscure manner!!\""
  236         if test $cl_cv_c_longlong = yes; then
  237           echo "#error \"Type long long is stored in memory in an obscure manner!!\""
  238         fi
  239         ;;
  240     esac
  241     echo
  242     case $host_cpu in
  243       hppa)
  244         echo "/* Stack grows up. */"
  245         echo "#define stack_grows_up"
  246         ;;
  247       *)
  248         echo "/* Stack grows down. */"
  249         echo "#define stack_grows_down"
  250         ;;
  251     esac
  252   } > "$cl_machine_file_h"
  253 ])
  254 
  255 dnl CL_INTPARAM_BITSIZE(type, variable)
  256 dnl puts into variable the determined bitsize of the type.
  257 AC_DEFUN([CL_INTPARAM_BITSIZE],
  258 [
  259   n=1; x="($1)2"
  260   while true; do
  261     AC_TRY_COMPILE([], [typedef int verify[2*(($1)($x) == 0) - 1];],
  262       [$2=$n; break;],
  263       [if test $n = 1000; then $2=; break; fi;])
  264     n=`expr $n + 1`; x="$x * ($1)2"
  265   done
  266 ])
  267 
  268 dnl CL_INTPARAM_SIZEOF(type, variable)
  269 dnl puts into variable the determined size of the type.
  270 AC_DEFUN([CL_INTPARAM_SIZEOF],
  271 [
  272   _AC_COMPUTE_INT([sizeof($1)], [$2])
  273 ])
  274 
  275 dnl CL_INTPARAM_ALIGNOF(type, variable)
  276 dnl puts into variable the determined alignment of the type.
  277 AC_DEFUN([CL_INTPARAM_ALIGNOF],
  278 [
  279   dnl Simplify the guessing by assuming that the alignment is a power of 2.
  280   n=1
  281   while true; do
  282     AC_TRY_COMPILE([
  283 #ifdef __cplusplus
  284 # ifdef __GNUC__
  285 #  define alignof(type)  __alignof__ (type)
  286 # else
  287    template <class type> struct alignof_helper { char slot1; type slot2; };
  288 #  define alignof(type)  offsetof (alignof_helper<type>, slot2)
  289 # endif
  290 #else
  291 # define alignof(type)  offsetof (struct { char slot1; type slot2; }, slot2)
  292 #endif
  293 ], [static_assert(alignof($1) == $n, "");],
  294       [$2=$n; break;]
  295       [if test $n = 0; then $2=; break; fi])
  296     n=`expr $n '*' 2`
  297   done
  298 ])