1#!/bin/sh 2LC_ALL=C 3export LC_ALL 4 5if test "$#" -ne 3; then 6 echo "Usage $0 int_kinds real_kinds compile" 7 exit 1 8fi 9 10# Possible kinds must be listed in ascending order 11possible_integer_kinds="$1" 12possible_real_kinds="$2" 13compile="$3" 14 15largest="" 16smallest="" 17for k in $possible_integer_kinds; do 18 echo " integer (kind=$k) :: i" > tmp$$.f90 19 echo " i = 1_$k" >> tmp$$.f90 20 echo " end" >> tmp$$.f90 21 if $compile -S tmp$$.f90 > /dev/null 2>&1; then 22 s=`expr 8 \* $k` 23 largest="$k" 24 25 if [ $s -eq 128 ]; then 26 prefix="__" 27 else 28 prefix="" 29 fi 30 31 if [ "$smallest" = "" ]; then 32 smallest="$k" 33 fi 34 35 echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};" 36 echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};" 37 echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};" 38 echo "#define HAVE_GFC_LOGICAL_${k}" 39 echo "#define HAVE_GFC_INTEGER_${k}" 40 echo "" 41 fi 42 rm -f tmp$$.* 43done 44 45echo "#define GFC_INTEGER_LARGEST GFC_INTEGER_${largest}" 46echo "#define GFC_UINTEGER_LARGEST GFC_UINTEGER_${largest}" 47echo "#define GFC_DEFAULT_CHAR ${smallest}" 48echo "" 49 50 51# Get the kind value for long double, so we may disambiguate it 52# from __float128. 53echo "use iso_c_binding; print *, c_long_double ; end" > tmq$$.f90 54long_double_kind=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \ 55 | sed 's/ *TRANSFER *//'` 56rm -f tmq$$.* 57 58 59for k in $possible_real_kinds; do 60 echo " real (kind=$k) :: x" > tmp$$.f90 61 echo " x = 1.0_$k" >> tmp$$.f90 62 echo " end" >> tmp$$.f90 63 if $compile -S tmp$$.f90 > /dev/null 2>&1; then 64 case $k in 65 4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;; 66 8) ctype="double" ; cplxtype="complex double" ; suffix="" ;; 67 # If we have a REAL(KIND=10), it is always long double 68 10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;; 69 # If we have a REAL(KIND=16), it is either long double or __float128 70 16) if [ $long_double_kind -ne 16 ]; then 71 ctype="__float128" 72 cplxtype="_Complex float __attribute__((mode(TC)))" 73 suffix="q" 74 echo "#define GFC_REAL_16_IS_FLOAT128" 75 else 76 ctype="long double" 77 cplxtype="complex long double" 78 suffix="l" 79 echo "#define GFC_REAL_16_IS_LONG_DOUBLE" 80 fi ;; 81 *) echo "$0: Unknown type" >&2 ; exit 1 ;; 82 esac 83 84 # Check for the value of HUGE 85 echo "print *, huge(0._$k) ; end" > tmq$$.f90 86 huge=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \ 87 | sed 's/ *TRANSFER *//' | sed 's/_.*//'` 88 rm -f tmq$$.* 89 90 # Check for the value of TINY 91 echo "print *, tiny(0._$k) ; end" > tmq$$.f90 92 tiny=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \ 93 | sed 's/ *TRANSFER *//' | sed 's/_.*//'` 94 rm -f tmq$$.* 95 96 # Check for the value of DIGITS 97 echo "print *, digits(0._$k) ; end" > tmq$$.f90 98 digits=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \ 99 | sed 's/ *TRANSFER *//'` 100 rm -f tmq$$.* 101 102 # Check for the value of RADIX 103 echo "print *, radix(0._$k) ; end" > tmq$$.f90 104 radix=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \ 105 | sed 's/ *TRANSFER *//'` 106 rm -f tmq$$.* 107 108 # Output the information we've gathered 109 echo "typedef ${ctype} GFC_REAL_${k};" 110 echo "typedef ${cplxtype} GFC_COMPLEX_${k};" 111 echo "#define HAVE_GFC_REAL_${k}" 112 echo "#define HAVE_GFC_COMPLEX_${k}" 113 echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}" 114 echo "#define GFC_REAL_${k}_TINY ${tiny}${suffix}" 115 echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}" 116 if [ "x$suffix" = "x" ]; then 117 echo "#define GFC_REAL_${k}_LITERAL(X) (X)" 118 else 119 echo "#define GFC_REAL_${k}_LITERAL(X) (X ## ${suffix})" 120 fi 121 echo "#define GFC_REAL_${k}_DIGITS ${digits}" 122 echo "#define GFC_REAL_${k}_RADIX ${radix}" 123 echo "" 124 fi 125 rm -f tmp$$.* 126done 127 128 129# After this, we include a header that can override some of the 130# autodetected settings. 131echo '#include "kinds-override.h"' 132 133exit 0 134