General improvement on viewing wide and long slog2 files. This added features needed...
[mpe.git] / aclocal_inttypes.m4
1 dnl
2 dnl PAC_GET_STDINT_HEADER - Get system header that defines C99 intXX_t.
3 dnl
4 dnl PAC_GET_STDINT_HEADER( STDINT_H )
5 dnl
6 dnl STDINT_H      - returned header which defines C99 intXX_t. Empty string
7 dnl                 if there is no system header that defines intXX_t.
8 dnl
9 AC_DEFUN( [PAC_GET_STDINT_HEADER], [
10 AC_MSG_CHECKING( [for header that defines C99 integer types, intXX_t] )
11 $1=""
12 for hdr in stdint.h inttypes.h sys/inttypes.h ; do
13     AC_COMPILE_IFELSE( [
14         AC_LANG_PROGRAM( [#include <$hdr>], [
15             int8_t   ii08 = 0;
16             int16_t  ii16 = 0;
17             int32_t  ii32 = 0;
18             int64_t  ii64 = 0;
19         ] )
20     ], [
21         $1=$hdr
22         break
23     ] )
24 done
25 if test -n "[$]$1" ; then
26     AC_MSG_RESULT( [<[$]$1>] )
27 else
28     AC_MSG_RESULT( [none] )
29 fi
30 ] )dnl
31 dnl
32 dnl
33 dnl PAC_GET_BASIC_INT_TYPES - Get stdint types based on basic types, i.e.
34 dnl                           char, short, int, long & long long.
35 dnl
36 dnl PAC_GET_BASIC_INT_TYPES( INT8, INT16, INT32, INT64 )
37 dnl
38 dnl INT8              - returned int8_t.
39 dnl INT16             - returned int16_t.
40 dnl INT32             - returned int32_t.
41 dnl INT64             - returned int64_t.
42 dnl
43 AC_DEFUN( [PAC_GET_BASIC_INT_TYPES], [
44 #   dnl Determine the sizeof(char)
45     AC_CHECK_SIZEOF(char)
46     if test "$ac_cv_sizeof_char" = 1 ; then
47         $1="char"
48     else
49         PAC_MSG_ERROR( $enable_softerror,
50                        [sizeof(char) isn't 1! Aborting...] )
51     fi
52
53 #   dnl Determine the sizeof(short)
54     AC_CHECK_SIZEOF(short)
55     if test "$ac_cv_sizeof_short" = 2 ; then
56         $2="short"
57     else
58         PAC_MSG_ERROR( $enable_softerror,
59                        [sizeof(short) isn't 2! Aborting...] )     fi
60
61 #   dnl Determine the sizeof(int)
62     AC_CHECK_SIZEOF(int)
63     if test "$ac_cv_sizeof_int" = 4 ; then
64         $3="int"
65     else
66         PAC_MSG_ERROR( $enable_softerror,
67                        [sizeof(int) isn't 4! Aborting...] )
68     fi
69
70 #   dnl Determine the sizeof(long) and sizeof(long long)
71     AC_CHECK_SIZEOF(long)
72     AC_CHECK_SIZEOF(long long)
73     if test "$ac_cv_sizeof_long" = 8 ; then
74         $4=long
75     else
76         if test "$ac_cv_sizeof_long_long" = 8 ; then
77             $4="long long"
78         else
79             PAC_MSG_ERROR( $enable_softerror,
80                 [Neither sizeof(long) or sizeof(long long) is 8! Aborting...] )
81         fi
82     fi
83 ] ) dnl
84 dnl
85 dnl
86 dnl PAC_GET_STDINT_FORMATS - Get printf format specifiers for intXX_t's
87 dnl
88 dnl PAC_GET_STDINT_FORMATS( INT8, INT16, INT32, INT64,
89 dnl                         INT8FMT, INT16FMT, INT32FMT, INT64FMT,
90 dnl                         INTFMT_H )
91 dnl
92 dnl INT8                  - int8_t or char.
93 dnl INT16                 - int16_t or short.
94 dnl INT32                 - int32_t or int.
95 dnl INT64                 - int64_t or long/long long.
96 dnl INT8FMT               - returned format specifiers for int8_t.
97 dnl INT16FMT              - returned format specifiers for int16_t.
98 dnl INT32FMT              - returned format specifiers for int32_t.
99 dnl INT64FMT              - returned format specifiers for int64_t.
100 dnl INTFMT_H              - returned headers for the format specifiers.
101 dnl
102 AC_DEFUN( [PAC_GET_STDINT_FORMATS], [
103 mpe_c99_inttypes_h=""
104 if test "$3" = "int32_t" -a "$4" = "int64_t" ; then
105     AC_CHECK_HEADERS( inttypes.h, [
106     dnl If inttypes.h exists, check for PRIdXX
107         AC_MSG_CHECKING( [whether <inttypes.h> defines the PRIdXX macros] )
108         AC_COMPILE_IFELSE( [
109             AC_LANG_PROGRAM( [
110                 #include <inttypes.h>
111                 #ifdef HAVE_STDIO_H
112                 #include <stdio.h>
113                 #endif
114                 #ifdef HAVE_SYS_TYPES_H
115                 #include <sys/types.h>
116                 #endif
117                 #ifdef HAVE_SYS_BITYPES_H
118                 #include <sys/bitypes.h>
119                 #endif
120             ], [
121                 printf( "%" PRId8 "\n",  ($1) 1 );
122                 printf( "%" PRId16 "\n", ($2) 1 );
123                 printf( "%" PRId32 "\n", ($3) 1 );
124                 printf( "%" PRId64 "\n", ($4) 1 );
125             ] )
126         ], [
127             AC_MSG_RESULT(yes)
128             mpe_c99_inttypes_h="inttypes.h"
129         ], [
130             AC_MSG_RESULT(no)
131         ] ) dnl Endof AC_COMPILE_IFELSE
132     ] ) dnl Endof AC_CHECK_HEADERS
133 fi
134 if test "X$mpe_c99_inttypes_h" != "X" ; then
135     $5="\"%\"PRId8"
136     $6="\"%\"PRId16"
137     $7="\"%\"PRId32"
138     $8="\"%\"PRId64"
139     $9="$mpe_c99_inttypes_h"
140 else
141     $5="\"%d\""
142     $6="\"%d\""
143     $7="\"%d\""
144     if test "$4" = "long" ; then
145         $8="\"%ld\""
146     else
147         $8="\"%lld\""
148     fi
149     $9=""
150 fi
151 ] ) dnl
152 dnl
153 dnl
154 dnl PAC_OUTPUT_STDINT_HEADER - Create/Output an header file that define
155 dnl                            integer types.
156 dnl
157 dnl PAC_OUTPUT_STDINT_HEADER( OUTPUT_H, STDINT_H, PRIDXX_H,
158 dnl                           INT8, INT16, INT32, INT64,
159 dnl                           INT8FMT, INT16FMT, INT32FMT, INT64FMT,
160 dnl
161 dnl OUTPUT_H              - output header
162 dnl STDINT_H              - header that defines integer types
163 dnl PRIDXX_H              - header that defines integer printf format specifiers
164 dnl INT8                  - int8_t or char.
165 dnl INT16                 - int16_t or short.
166 dnl INT32                 - int32_t or int.
167 dnl INT64                 - int64_t or long/long long.
168 dnl INT8FMT               - returned format specifiers for int8_t.
169 dnl INT16FMT              - returned format specifiers for int16_t.
170 dnl INT32FMT              - returned format specifiers for int32_t.
171 dnl INT64FMT              - returned format specifiers for int64_t.
172 dnl
173 AC_DEFUN( [PAC_OUTPUT_STDINT_HEADER], [
174 AC_CONFIG_COMMANDS( [$pac_output_h], [
175     AC_MSG_NOTICE( [creating $pac_output_h] )
176     rm -f $pac_output_h
177     echo "/* MPE logging header for C99 integer types */" > $pac_output_h
178     echo "#if !defined( _CLOG_STDINT )" >> $pac_output_h
179     echo "#define  _CLOG_STDINT" >> $pac_output_h
180     echo >> $pac_output_h
181 #   dnl /* Put in the system headers */
182     if test "X$pac_c99_stdint_h" != "X" ; then
183         echo "#include <$pac_c99_stdint_h>" >> $pac_output_h
184         if test "X$pac_c99_pridxx_h" != "X" ; then
185             if test "$pac_c99_pridxx_h" != "$pac_c99_stdint_h" ; then
186                 echo "#include <$pac_c99_pridxx_h>" >> $pac_output_h
187             fi
188         fi
189     fi
190     echo >> $pac_output_h
191     echo "typedef $pac_int8_t     CLOG_int8_t;"  >> $pac_output_h
192     echo "typedef $pac_int16_t    CLOG_int16_t;" >> $pac_output_h
193     echo "typedef $pac_int32_t    CLOG_int32_t;" >> $pac_output_h
194     echo "typedef $pac_int64_t    CLOG_int64_t;" >> $pac_output_h
195     echo >> $pac_output_h
196 #   dnl /* Define iXXfmt printf format specifiers */
197     echo "#define i8fmt     $pac_int8_fmt"  >> $pac_output_h
198     echo "#define i16fmt    $pac_int16_fmt" >> $pac_output_h
199     echo "#define i32fmt    $pac_int32_fmt" >> $pac_output_h
200     echo "#define i64fmt    $pac_int64_fmt" >> $pac_output_h
201     echo >> $pac_output_h
202     echo "#endif" >> $pac_output_h
203 ], [
204     PACKAGE="$PACKAGE"
205     VERSION="$VERSION"
206     pac_output_h="$1"
207     pac_c99_stdint_h="$2"
208     pac_c99_pridxx_h="$3"
209     pac_int8_t="$4"
210     pac_int16_t="$5"
211     pac_int32_t="$6"
212     pac_int64_t="$7"
213     pac_int8_fmt="$8"
214     pac_int16_fmt="$9"
215     pac_int32_fmt="$10"
216     pac_int64_fmt="$11"
217 ] ) dnl Endof AC_CONFIG_COMMANDS()
218 ] ) dnl