2 dnl custom mawk macros for autoconf
4 dnl $Log: mawk.ac.m4,v $
5 dnl Revision 1.15 1996/09/04 23:40:34 mike
6 dnl Small tweak to strtod bug check
8 dnl Revision 1.14 1996/08/30 00:07:18 mike
9 dnl Modifications to the test and implementation of the bug fix for
10 dnl solaris overflow in strtod.
12 dnl Revision 1.13 1996/08/25 19:31:03 mike
13 dnl Added work-around for solaris strtod overflow bug.
15 dnl Revision 1.12 1996/01/18 11:51:36 mike
18 dnl Revision 1.11 1995/10/16 12:25:03 mike
21 dnl Revision 1.10 1995/04/20 20:26:54 mike
22 dnl beta improvements from Carl Mascott
24 dnl Revision 1.9 1994/12/18 20:46:23 mike
25 dnl fpe_check -> ./fpe_check
27 dnl Revision 1.8 1994/12/14 14:38:22 mike
28 dnl don't assume siginfo.h is inside signal.h
30 dnl Revision 1.7 1994/12/11 21:25:18 mike
33 dnl Revision 1.6 1994/10/16 18:38:26 mike
34 dnl use sed on defines.out
36 dnl Revision 1.5 1994/10/11 02:49:08 mike
39 dnl Revision 1.4 1994/10/11 00:39:27 mike
43 dnl ********** look for math library *****************
45 define(MIKE, brennan@whidbey.com)
47 define(LOOK_FOR_MATH_LIBRARY,[
48 if test "${MATHLIB+set}" != set ; then
49 AC_CHECK_LIB(m,log,[MATHLIB=-lm ; LIBS="$LIBS -lm"],
50 [# maybe don't need separate math library
51 AC_CHECK_FUNC(log, log=yes)
54 MATHLIB='' # evidently don't need one
57 Cannot find a math library. You need to set MATHLIB in config.user)
60 AC_SUBST(MATHLIB)])dnl
62 dnl ********* utility macros **********************
64 dnl I can't get AC_DEFINE_NOQUOTE to work so give up
65 define([XDEFINE],[AC_DEFINE($1)
66 echo X '$1' 'ifelse($2,,1,$2)' >> defines.out])dnl
68 [echo X '$1' '$2' >> defines.out])dnl
71 dnl We want #define NO_STRERROR
72 dnl instead of #define HAVE_STRERROR
75 define([XADD_NO],[NO_[$1]])dnl
76 define([ADD_NO], [XADD_NO(translit($1, a-z. , A-Z_))])dnl
77 define([HEADER_CHECK],[AC_CHECK_HEADER($1, ,XDEFINE(ADD_NO($1)))])dnl
78 define([FUNC_CHECK],[AC_CHECK_FUNC($1, ,XDEFINE(ADD_NO($1)))])dnl
80 dnl how to repeat a macro on a list of args
81 dnl (probably won't work if the args are expandable
84 [ifelse($#,1,[$1],$#,2,[$1($2)],
87 builtin(shift,builtin(shift,$*)))])])dnl
89 define([CHECK_HEADERS],[REPEAT_IT([HEADER_CHECK],$*)])dnl
90 define([CHECK_FUNCTIONS],[REPEAT_IT([FUNC_CHECK],$*)])dnl
92 dnl ******* find size_t ********************
94 define([SIZE_T_CHECK],[
95 [if test "$size_t_defed" != 1 ; then]
96 AC_CHECK_HEADER($1,size_t_header=ok)
97 [if test "$size_t_header" = ok ; then]
103 echo getting size_t from '<$1>'])
106 [SIZE_T_CHECK(stddef.h,SIZE_T_STDDEF_H)
107 SIZE_T_CHECK(sys/types.h,SIZE_T_TYPES_H)])dnl
109 dnl ********** check compiler ******************
111 define(COMPILER_ATTRIBUTES,
112 [AC_MSG_CHECKING(compiler supports void*)
116 [cp = (char*)(void*)(int*)foo() ;],void_star=yes,void_star=no)
117 AC_MSG_RESULT($void_star)
118 test "$void_star" = no && XXDEFINE(NO_VOID_STAR,1)
119 AC_MSG_CHECKING(compiler groks prototypes)
120 AC_TRY_COMPILE(,[int x(char*);],protos=yes,protos=no)
121 AC_MSG_RESULT([$protos])
122 test "$protos" = no && XXDEFINE(NO_PROTOS,1)
124 test "$ac_cv_c_const" = no && XXDEFINE(const)])dnl
128 dnl ********** which yacc ***********
130 [AC_CHECK_PROGS(YACC, byacc bison yacc)
131 test "$YACC" = bison && YACC='bison -y'])dnl
133 dnl ************* header and footer for config.h *******************
135 define(CONFIG_H_HEADER,
137 /* config.h -- generated by configure */
142 define(CONFIG_H_TRAILER,
145 #define HAVE_REAL_PIPES 1
146 #endif /* CONFIG_H */
149 dnl ************* build config.h ***********************
155 [sed 's/^X/#define/' defines.out]
161 dnl *************** [sf]printf checks needed for print.c ***********
163 dnl sometimes fprintf() and sprintf() are not proto'ed in
165 define(FPRINTF_IN_STDIO,
166 [AC_EGREP_HEADER([[[^v]]fprintf],stdio.h,,XDEFINE(NO_FPRINTF_IN_STDIO))
167 AC_EGREP_HEADER([[[^v]]sprintf],stdio.h,,XDEFINE(NO_SPRINTF_IN_STDIO))])dnl
169 dnl **************************************************
170 dnl C program to compute MAX__INT and MAX__LONG
171 dnl if looking at headers fails
172 define([MAX__INT_PROGRAM],
178 if ( !(out = fopen("maxint.out","w")) ) exit(1) ;
179 /* find max int and max long */
181 while ( y > 0 ) y *= 2 ;
182 fprintf(out,"X MAX__INT 0x%x\n", y-1) ;
184 while ( yy > 0 ) yy *= 2 ;
185 fprintf(out,"X MAX__LONG 0x%lx\n", yy-1) ;
190 dnl *** Try to find a definition of MAX__INT from limits.h else compute***
192 define(FIND_OR_COMPUTE_MAX__INT,
193 [AC_CHECK_HEADER(limits.h,limits_h=yes)
194 if test "$limits_h" = yes ; then :
196 AC_CHECK_HEADER(values.h,values_h=yes)
197 if test "$values_h" = yes ; then
202 { FILE *out = fopen("maxint.out", "w") ;
203 if ( ! out ) exit(1) ;
204 fprintf(out, "X MAX__INT 0x%x\n", MAXINT) ;
205 fprintf(out, "X MAX__LONG 0x%lx\n", MAXLONG) ;
206 exit(0) ; return(0) ;
208 ], maxint_set=1,[MAX_INT_ERRMSG])
210 if test "$maxint_set" != 1 ; then
211 # compute it -- assumes two's complement
212 AC_TRY_RUN(MAX__INT_PROGRAM,:,[MAX_INT_ERRMSG])
214 cat maxint.out >> defines.out ; rm -f maxint.out
217 define(MAX_INT_ERRMSG,
218 [AC_MSG_ERROR(C program to compute maxint and maxlong failed.
219 Please send bug report to MIKE.)])dnl
221 dnl ********** input config.user ******************
222 define(GET_USER_DEFAULTS,
223 [cat < /dev/null > defines.out
224 test -f config.user && . ./config.user
225 NOTSET_THEN_DEFAULT(BINDIR,/usr/local/bin)
226 NOTSET_THEN_DEFAULT(MANDIR,/usr/local/man/man1)
227 NOTSET_THEN_DEFAULT(MANEXT,1)
228 echo "$USER_DEFINES" >> defines.out])
230 dnl ************************************************
232 define([NOTSET_THEN_DEFAULT],
233 [test "[$]{$1+set}" = set || $1="$2"
236 dnl ****************** sysV and solaris fpe checks ***********
238 define(LOOK_FOR_FPE_SIGINFO,
239 [AC_CHECK_FUNC(sigaction, sigaction=1)
240 AC_CHECK_HEADER(siginfo.h,siginfo_h=1)
241 if test "$sigaction" = 1 && test "$siginfo_h" = 1 ; then
244 AC_CHECK_FUNC(sigvec,sigvec=1)
245 if test "$sigvec" = 1 && ./fpe_check phoney_arg >> defines.out ; then :
246 else XDEFINE(NOINFO_SIGFPE)
251 dnl ******** AC_PROG_CC with defaultout -g to cflags **************
253 AC_DEFUN([PROG_CC_NO_MINUS_G_NONSENSE],
254 [AC_BEFORE([$0], [AC_PROG_CPP])dnl
255 AC_CHECK_PROG(CC, gcc, gcc, cc)
257 AC_MSG_CHECKING(whether we are using GNU C)
258 AC_CACHE_VAL(ac_cv_prog_gcc,
259 [dnl The semicolon is to pacify NeXT's syntax-checking cpp.
260 cat > conftest.c <<EOF
265 if ${CC-cc} -E conftest.c 2>&AC_FD_CC | egrep yes >/dev/null 2>&1; then
270 AC_MSG_RESULT($ac_cv_prog_gcc)
274 dnl *********** dreaded fpe tests *************
276 define(DREADED_FPE_TESTS,
277 [if echo "$USER_DEFINES" | grep FPE_TRAPS_ON >/dev/null
278 then echo skipping fpe tests based on '$'USER_DEFINES
282 echo checking handling of floating point exceptions
284 $CC $CFLAGS -DRETSIGTYPE=$ac_cv_type_signal -o fpe_check fpe_check.c $MATHLIB
285 if test -f fpe_check ; then
286 ./fpe_check 2>/dev/null
289 echo fpe_check.c failed to compile 1>&2
294 0) ;; # good news do nothing
295 3) # reasonably good news]
296 XDEFINE(FPE_TRAPS_ON)
297 LOOK_FOR_FPE_SIGINFO ;;
299 1|2|4) # bad news have to turn off traps
300 # only know how to do this on systemV and solaris
301 AC_CHECK_HEADER(ieeefp.h, ieeefp_h=1)
302 AC_CHECK_FUNC(fpsetmask, fpsetmask=1)
303 [if test "$ieeefp_h" = 1 && test "$fpsetmask" = 1 ; then]
304 XDEFINE(FPE_TRAPS_ON)
305 XDEFINE(USE_IEEEFP_H)
306 XXDEFINE([TURN_ON_FPE_TRAPS()],
307 [fpsetmask(fpgetmask()|FP_X_DZ|FP_X_OFL)])
309 # look for strtod overflow bug
310 AC_MSG_CHECKING([strtod bug on overflow])
312 $CC $CFLAGS -DRETSIGTYPE=$ac_cv_type_signal -DUSE_IEEEFP_H \
313 -o fpe_check fpe_check.c $MATHLIB
314 if ./fpe_check phoney_arg phoney_arg 2>/dev/null
316 AC_MSG_RESULT([no bug])
318 AC_MSG_RESULT([buggy -- will use work around])
319 XXDEFINE([HAVE_STRTOD_OVF_BUG],1)
323 [if test $status != 4 ; then]
324 XDEFINE(FPE_TRAPS_ON)
331 Warning: Your system defaults generate floating point exception
332 on divide by zero but not on overflow. You need to
333 #define TURN_ON_FPE_TRAPS() to handle overflow.
334 Please report this so I can fix this script to do it automatically.
339 Warning: Your system defaults generate floating point exception
340 on overflow but not on divide by zero. You need to
341 #define TURN_ON_FPE_TRAPS() to handle divide by zero.
342 Please report this so I can fix this script to do it automatically.
347 Warning: Your system defaults do not generate floating point
348 exceptions, but your math library does not support this behavior.
350 #define TURN_ON_FPE_TRAPS() to use fp exceptions for consistency.
351 Please report this so I can fix this script to do it automatically.
356 [echo You can continue with the build and the resulting mawk will be
357 echo useable, but getting FPE_TRAPS_ON correct eventually is best.
360 *) # some sort of disaster
362 The program `fpe_check' compiled from fpe_check.c seems to have
363 unexpectly blown up. Please report this to ]MIKE.[
368 rm -f fpe_check # whew!!]