Git init
[external/mawk.git] / mawk.ac.m4
1 dnl 
2 dnl custom mawk macros for autoconf
3 dnl 
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
7 dnl
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.
11 dnl
12 dnl Revision 1.13  1996/08/25 19:31:03  mike
13 dnl Added work-around for solaris strtod overflow bug.
14 dnl
15 dnl Revision 1.12  1996/01/18  11:51:36  mike
16 dnl 1.2.2 release
17 dnl
18 dnl Revision 1.11  1995/10/16  12:25:03  mike
19 dnl configure cleanup
20 dnl
21 dnl Revision 1.10  1995/04/20  20:26:54  mike
22 dnl beta improvements from Carl Mascott
23 dnl
24 dnl Revision 1.9  1994/12/18  20:46:23  mike
25 dnl fpe_check -> ./fpe_check
26 dnl
27 dnl Revision 1.8  1994/12/14  14:38:22  mike
28 dnl don't assume siginfo.h is inside signal.h
29 dnl
30 dnl Revision 1.7  1994/12/11  21:25:18  mike
31 dnl tweak XDEFINE
32 dnl
33 dnl Revision 1.6  1994/10/16  18:38:26  mike
34 dnl use sed on defines.out
35 dnl
36 dnl Revision 1.5  1994/10/11  02:49:08  mike
37 dnl systemVr4 siginfo
38 dnl
39 dnl Revision 1.4  1994/10/11  00:39:27  mike
40 dnl fpe check stuff
41 dnl
42 dnl
43 dnl **********  look for math library *****************
44 dnl
45 define(MIKE, brennan@whidbey.com)
46 dnl
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)
52 if test "$log$" = yes
53 then
54    MATHLIB='' # evidently don't need one
55 else
56    AC_MSG_ERROR(
57 Cannot find a math library. You need to set MATHLIB in config.user)
58 fi])dnl
59 fi
60 AC_SUBST(MATHLIB)])dnl
61 dnl
62 dnl *********  utility macros **********************
63 dnl
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
67 define([XXDEFINE],
68 [echo  X '$1' '$2' >> defines.out])dnl
69 dnl
70 dnl
71 dnl We want #define NO_STRERROR
72 dnl instead of #define HAVE_STRERROR
73 dnl
74 dnl
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
79 dnl
80 dnl how to repeat a macro on a list of args
81 dnl (probably won't work if the args are expandable
82 dnl
83 define([REPEAT_IT],
84 [ifelse($#,1,[$1],$#,2,[$1($2)],
85 [$1($2) 
86 REPEAT_IT([$1],
87 builtin(shift,builtin(shift,$*)))])])dnl
88
89 define([CHECK_HEADERS],[REPEAT_IT([HEADER_CHECK],$*)])dnl
90 define([CHECK_FUNCTIONS],[REPEAT_IT([FUNC_CHECK],$*)])dnl
91 dnl
92 dnl ******* find size_t ********************
93 dnl
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]
98    AC_TRY_COMPILE([
99 #include <$1>],
100 [size_t *n ;
101 ], [size_t_defed=1;
102 XXDEFINE($2,1)
103 echo getting size_t from '<$1>'])
104 [fi;fi]])dnl
105 define(WHERE_SIZE_T,
106 [SIZE_T_CHECK(stddef.h,SIZE_T_STDDEF_H)
107 SIZE_T_CHECK(sys/types.h,SIZE_T_TYPES_H)])dnl
108 dnl
109 dnl  **********  check compiler ******************
110 dnl
111 define(COMPILER_ATTRIBUTES,
112 [AC_MSG_CHECKING(compiler supports void*)
113 AC_TRY_COMPILE(
114 [char *cp ;
115 void *foo() ;] ,
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)
123 AC_C_CONST
124 test "$ac_cv_c_const" = no && XXDEFINE(const)])dnl
125 dnl
126 dnl
127 dnl
128 dnl **********  which yacc ***********
129 define(WHICH_YACC,
130 [AC_CHECK_PROGS(YACC, byacc bison yacc)
131 test "$YACC" = bison && YACC='bison -y'])dnl
132 dnl
133 dnl *************  header and footer for config.h *******************
134 dnl
135 define(CONFIG_H_HEADER,
136 [cat<<'EOF'
137 /* config.h -- generated by configure */
138 #ifndef CONFIG_H
139 #define CONFIG_H
140
141 EOF])dnl
142 define(CONFIG_H_TRAILER,
143 [cat<<'EOF'
144
145 #define HAVE_REAL_PIPES 1
146 #endif /* CONFIG_H */
147 EOF])dnl
148 dnl
149 dnl *************  build config.h ***********************
150 define(DO_CONFIG_H,
151 [# output config.h
152 rm -f config.h
153 (
154 CONFIG_H_HEADER
155 [sed 's/^X/#define/' defines.out]
156 CONFIG_H_TRAILER
157 ) | tee config.h
158 rm defines.out])dnl
159 dnl
160 dnl
161 dnl *************** [sf]printf checks needed for print.c ***********
162 dnl
163 dnl sometimes fprintf() and sprintf() are not proto'ed in
164 dnl stdio.h
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
168 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],
173 [[#include <stdio.h>
174 int main()
175 { int y ; long yy ;
176   FILE *out ;
177
178     if ( !(out = fopen("maxint.out","w")) ) exit(1) ;
179     /* find max int and max long */
180     y = 0x1000 ;
181     while ( y > 0 ) y *= 2 ;
182     fprintf(out,"X MAX__INT 0x%x\n", y-1) ;
183     yy = 0x1000 ;
184     while ( yy > 0 ) yy *= 2 ;
185     fprintf(out,"X MAX__LONG 0x%lx\n", yy-1) ;
186     exit(0) ;
187     return 0 ;
188  }]])dnl
189 dnl
190 dnl *** Try to find a definition of MAX__INT from limits.h else compute***
191 dnl
192 define(FIND_OR_COMPUTE_MAX__INT,
193 [AC_CHECK_HEADER(limits.h,limits_h=yes)
194 if test "$limits_h" = yes ; then :
195 else
196 AC_CHECK_HEADER(values.h,values_h=yes)
197    if test "$values_h" = yes ; then
198    AC_TRY_RUN(
199 [#include <values.h>
200 #include <stdio.h>
201 int main()
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) ;
207 }
208 ], maxint_set=1,[MAX_INT_ERRMSG])
209    fi
210 if test "$maxint_set" != 1 ; then 
211 # compute it  --  assumes two's complement
212 AC_TRY_RUN(MAX__INT_PROGRAM,:,[MAX_INT_ERRMSG])
213 fi
214 cat maxint.out >> defines.out ; rm -f maxint.out
215 fi ;])dnl
216 dnl
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
220 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])
229 dnl
230 dnl ************************************************
231 dnl
232 define([NOTSET_THEN_DEFAULT],
233 [test "[$]{$1+set}" = set || $1="$2"
234 AC_SUBST($1)])dnl
235 dnl
236 dnl ******************  sysV and solaris fpe checks ***********
237 dnl  
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
242    XDEFINE(SV_SIGINFO)
243 else
244    AC_CHECK_FUNC(sigvec,sigvec=1)
245    if test "$sigvec" = 1 && ./fpe_check phoney_arg >> defines.out ; then :
246    else XDEFINE(NOINFO_SIGFPE)
247    fi
248 fi])
249 dnl
250 dnl
251 dnl ******** AC_PROG_CC with defaultout -g to cflags **************
252 dnl 
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)
256 dnl
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
261 #ifdef __GNUC__
262   yes;
263 #endif
264 EOF
265 if ${CC-cc} -E conftest.c 2>&AC_FD_CC | egrep yes >/dev/null 2>&1; then
266   ac_cv_prog_gcc=yes
267 else
268   ac_cv_prog_gcc=no
269 fi])dnl
270 AC_MSG_RESULT($ac_cv_prog_gcc)
271 rm -f conftest*
272 ])dnl
273 dnl
274 dnl ***********  dreaded fpe tests *************
275 dnl
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
279 else
280 AC_TYPE_SIGNAL
281 [
282 echo checking handling of floating point exceptions
283 rm -f fpe_check
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
287    status=$?
288 else 
289    echo fpe_check.c failed to compile 1>&2
290    status=100
291 fi
292
293 case $status in
294    0)  ;;  # good news do nothing
295    3)      # reasonably good news]
296 XDEFINE(FPE_TRAPS_ON)
297 LOOK_FOR_FPE_SIGINFO ;;
298
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)])
308 LOOK_FOR_FPE_SIGINFO 
309 # look for strtod overflow bug
310 AC_MSG_CHECKING([strtod bug on overflow])
311 rm -f fpe_check
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
315 then 
316    AC_MSG_RESULT([no bug])
317 else
318    AC_MSG_RESULT([buggy -- will use work around])
319    XXDEFINE([HAVE_STRTOD_OVF_BUG],1)
320 fi
321
322 else
323    [if test $status != 4 ; then]
324       XDEFINE(FPE_TRAPS_ON)
325       LOOK_FOR_FPE_SIGINFO 
326     fi
327
328     [case $status in
329     1) 
330 cat 1>&2 <<'EOF'
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.
335 EOF
336 ;;
337     2)
338 cat 1>&2 <<'EOF'
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.
343 EOF
344 ;;
345     4)
346 cat 1>&2 <<'EOF'
347 Warning: Your system defaults do not generate floating point
348 exceptions, but your math library does not support this behavior.
349 You need to
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.
352 EOF
353 ;;
354     esac]
355 echo MIKE
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.
358 fi  ;;
359
360   *)  # some sort of disaster
361 cat 1>&2 <<'EOF'
362 The program `fpe_check' compiled from fpe_check.c seems to have
363 unexpectly blown up.  Please report this to ]MIKE.[
364 EOF
365 # quit or not ???
366 ;;
367 esac 
368 rm -f fpe_check  # whew!!]
369 fi])