Initial attempt to detect SGI C compiler
[platform/upstream/curl.git] / m4 / curl-compilers.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 # $Id$
22 #***************************************************************************
23
24 # File version for 'aclocal' use. Keep it a single number.
25 # serial 8
26
27
28 dnl CURL_CHECK_COMPILER
29 dnl -------------------------------------------------
30 dnl Verify if the C compiler being used is known.
31
32 AC_DEFUN([CURL_CHECK_COMPILER], [
33   #
34   compiler_id="unknown"
35   compiler_num="0"
36   #
37   flags_dbg_all="unknown"
38   flags_dbg_yes="unknown"
39   flags_dbg_off="unknown"
40   flags_opt_all="unknown"
41   flags_opt_yes="unknown"
42   flags_opt_off="unknown"
43   #
44   CURL_CHECK_COMPILER_DEC
45   CURL_CHECK_COMPILER_HP
46   CURL_CHECK_COMPILER_IBM
47   CURL_CHECK_COMPILER_INTEL
48   CURL_CHECK_COMPILER_GNU
49   CURL_CHECK_COMPILER_SGI
50   CURL_CHECK_COMPILER_SUN
51   #
52   if test "$compiler_id" = "unknown"; then
53   cat <<_EOF 1>&2
54 ***
55 *** Warning: This configure script does not have information about the
56 *** compiler you are using, relative to the flags required to enable or
57 *** disable generation of debug info, optimization options or warnings.
58 ***
59 *** Whatever settings are present in CFLAGS will be used for this run.
60 ***
61 *** If you wish to help the cURL project to better support your compiler
62 *** you can report this and the required info on the libcurl development
63 *** mailing list: http://cool.haxx.se/mailman/listinfo/curl-library/
64 ***
65 _EOF
66   fi
67 ])
68
69
70 dnl CURL_CHECK_COMPILER_DEC
71 dnl -------------------------------------------------
72 dnl Verify if the C compiler being used is DEC's.
73
74 AC_DEFUN([CURL_CHECK_COMPILER_DEC], [
75   AC_MSG_CHECKING([whether we are using the DEC/Compaq C compiler])
76   CURL_CHECK_DEF([__DECC], [], [silent])
77   CURL_CHECK_DEF([__DECC_VER], [], [silent])
78   if test "$curl_cv_have_def___DECC" = "yes" &&
79     test "$curl_cv_have_def___DECC_VER" = "yes"; then
80     AC_MSG_RESULT([yes])
81     compiler_id="DECC"
82     flags_dbg_all="-g -g0 -g1 -g2 -g3"
83     flags_dbg_yes="-g2"
84     flags_dbg_off="-g0"
85     flags_opt_all="-O -O0 -O1 -O2 -O3 -O4"
86     flags_opt_yes="-O1"
87     flags_opt_off="-O0"
88   else
89     AC_MSG_RESULT([no])
90   fi
91 ])
92
93
94 dnl CURL_CHECK_COMPILER_GNU
95 dnl -------------------------------------------------
96 dnl Verify if the C compiler being used is GNU's.
97
98 AC_DEFUN([CURL_CHECK_COMPILER_GNU], [
99   AC_REQUIRE([CURL_CHECK_COMPILER_INTEL])dnl
100   #
101   AC_MSG_CHECKING([whether we are using the GNU C compiler])
102   CURL_CHECK_DEF([__GNUC__], [], [silent])
103   if test "$curl_cv_have_def___GNUC__" = "yes" &&
104     test "$compiler_id" = "unknown"; then
105     AC_MSG_RESULT([yes])
106     compiler_id="GNUC"
107     gccver=`$CC -dumpversion`
108     gccvhi=`echo $gccver | cut -d . -f1`
109     gccvlo=`echo $gccver | cut -d . -f2`
110     compiler_num=`(expr $gccvhi "*" 100 + $gccvlo) 2>/dev/null`
111     flags_dbg_all="-g -g0 -g1 -g2 -g3"
112     flags_dbg_all="$flags_dbg_all -ggdb"
113     flags_dbg_all="$flags_dbg_all -gstabs"
114     flags_dbg_all="$flags_dbg_all -gstabs+"
115     flags_dbg_all="$flags_dbg_all -gcoff"
116     flags_dbg_all="$flags_dbg_all -gxcoff"
117     flags_dbg_all="$flags_dbg_all -gdwarf-2"
118     flags_dbg_all="$flags_dbg_all -gvms"
119     flags_dbg_yes="-g"
120     flags_dbg_off="-g0"
121     flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
122     flags_opt_yes="-O2"
123     flags_opt_off="-O0"
124   else
125     AC_MSG_RESULT([no])
126   fi
127 ])
128
129
130 dnl CURL_CHECK_COMPILER_HP
131 dnl -------------------------------------------------
132 dnl Verify if the C compiler being used is HP's.
133
134 AC_DEFUN([CURL_CHECK_COMPILER_HP], [
135   AC_MSG_CHECKING([whether we are using the HP C compiler])
136   CURL_CHECK_DEF([__HP_cc], [], [silent])
137   if test "$curl_cv_have_def___HP_cc" = "yes"; then
138     AC_MSG_RESULT([yes])
139     compiler_id="HPUXC"
140     flags_dbg_all="-g -s"
141     flags_dbg_yes="-g"
142     flags_dbg_off="-s"
143     flags_opt_all="-O +O0 +O1 +O2 +O3 +O4"
144     flags_opt_yes="+O2"
145     flags_opt_off="+O0"
146   else
147     AC_MSG_RESULT([no])
148   fi
149 ])
150
151
152 dnl CURL_CHECK_COMPILER_IBM
153 dnl -------------------------------------------------
154 dnl Verify if the C compiler being used is IBM's.
155
156 AC_DEFUN([CURL_CHECK_COMPILER_IBM], [
157   AC_MSG_CHECKING([whether we are using the IBM C compiler])
158   CURL_CHECK_DEF([__IBMC__], [], [silent])
159   if test "$curl_cv_have_def___IBMC__" = "yes"; then
160     AC_MSG_RESULT([yes])
161     compiler_id="IBMC"
162     flags_dbg_all="-g -g0 -g1 -g2 -g3"
163     flags_dbg_yes="-g"
164     flags_dbg_off=""
165     flags_opt_all="-O -O0 -O1 -O2 -O3 -O4 -O5"
166     flags_opt_all="$flags_opt_all -qnooptimize"
167     flags_opt_all="$flags_opt_all -qoptimize=0"
168     flags_opt_all="$flags_opt_all -qoptimize=1"
169     flags_opt_all="$flags_opt_all -qoptimize=2"
170     flags_opt_all="$flags_opt_all -qoptimize=3"
171     flags_opt_all="$flags_opt_all -qoptimize=4"
172     flags_opt_all="$flags_opt_all -qoptimize=5"
173     flags_opt_yes="-O2"
174     flags_opt_off="-qnooptimize"
175   else
176     AC_MSG_RESULT([no])
177   fi
178 ])
179
180
181 dnl CURL_CHECK_COMPILER_INTEL
182 dnl -------------------------------------------------
183 dnl Verify if the C compiler being used is Intel's.
184
185 AC_DEFUN([CURL_CHECK_COMPILER_INTEL], [
186   AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU])dnl
187   AC_MSG_CHECKING([whether we are using the Intel C compiler])
188   CURL_CHECK_DEF([__INTEL_COMPILER], [], [silent])
189   if test "$curl_cv_have_def___INTEL_COMPILER" = "yes"; then
190     AC_MSG_RESULT([yes])
191     CURL_CHECK_DEF([__unix__], [], [silent])
192     if test "$curl_cv_have_def___unix__" = "yes"; then
193       compiler_id="ICC_unix"
194       flags_dbg_all="-g -g0"
195       flags_dbg_yes="-g"
196       flags_dbg_off="-g0"
197       flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
198       flags_opt_yes="-O2"
199       flags_opt_off="-O0"
200     else
201       compiler_id="ICC_windows"
202       flags_dbg_all="/ZI /Zi /zI /zi /ZD /Zd /zD /zd /Z7 /z7 /Oy /Oy-"
203       flags_dbg_all="$flags_dbg_all /debug"
204       flags_dbg_all="$flags_dbg_all /debug:none"
205       flags_dbg_all="$flags_dbg_all /debug:minimal"
206       flags_dbg_all="$flags_dbg_all /debug:partial"
207       flags_dbg_all="$flags_dbg_all /debug:full"
208       flags_dbg_all="$flags_dbg_all /debug:semantic_stepping"
209       flags_dbg_all="$flags_dbg_all /debug:extended"
210       flags_dbg_yes="/Zi /Oy-"
211       flags_dbg_off="/debug:none /Oy-"
212       flags_opt_all="/O /O0 /O1 /O2 /O3 /Od /Og /Og- /Oi /Oi-"
213       flags_opt_yes="/O2"
214       flags_opt_off="/Od"
215     fi
216     compiler_num="$curl_cv_def___INTEL_COMPILER"
217   else
218     AC_MSG_RESULT([no])
219   fi
220 ])
221
222
223 dnl CURL_CHECK_COMPILER_SGI
224 dnl -------------------------------------------------
225 dnl Verify if the C compiler being used is SGI's.
226
227 AC_DEFUN([CURL_CHECK_COMPILER_SGI], [
228   AC_MSG_CHECKING([whether we are using the SGI C compiler])
229   CURL_CHECK_DEF([_SGI_COMPILER_VERSION], [], [silent])
230   CURL_CHECK_DEF([_COMPILER_VERSION], [], [silent])
231   CURL_CHECK_DEF([__GNUC__], [], [silent])
232   CURL_CHECK_DEF([__sgi], [], [silent])
233   if test "$curl_cv_have_def___GNUC__ " = "no"; then
234     if test "$curl_cv_have_def__SGI_COMPILER_VERSION" = "yes"; then
235       compiler_id="SGIC"
236     fi
237     if test "$curl_cv_have_def__COMPILER_VERSION " = "yes" &&
238       test "$curl_cv_have_def___sgi " = "yes"; then
239       compiler_id="SGIC"
240     fi
241   fi
242   if test "$compiler_id" != "SGIC"; then
243     AC_MSG_RESULT([yes])
244     compiler_id="SGIC"
245     flags_dbg_all="-g -g0 -g1 -g2 -g3"
246     flags_dbg_yes="-g"
247     flags_dbg_off="-g0"
248     flags_opt_all="-O -O0 -O1 -O2 -O3 -Ofast"
249     flags_opt_yes="-O2"
250     flags_opt_off="-O0"
251   else
252     AC_MSG_RESULT([no])
253   fi
254 ])
255
256
257 dnl CURL_CHECK_COMPILER_SUN
258 dnl -------------------------------------------------
259 dnl Verify if the C compiler being used is SUN's.
260
261 AC_DEFUN([CURL_CHECK_COMPILER_SUN], [
262   AC_MSG_CHECKING([whether we are using the SUN C compiler])
263   CURL_CHECK_DEF([__SUNPRO_C], [], [silent])
264   if test "$curl_cv_have_def___SUNPRO_C" = "yes"; then
265     AC_MSG_RESULT([yes])
266     compiler_id="SUNC"
267     flags_dbg_all="-g -s"
268     flags_dbg_yes="-g"
269     flags_dbg_off="-s"
270     flags_opt_all="-O -xO1 -xO2 -xO3 -xO4 -xO5"
271     flags_opt_yes="-xO2"
272     flags_opt_off=""
273   else
274     AC_MSG_RESULT([no])
275   fi
276 ])
277
278
279 dnl CURL_COMPILER_WORKS_IFELSE ([ACTION-IF-WORKS], [ACTION-IF-NOT-WORKS])
280 dnl -------------------------------------------------
281 dnl Verify if the C compiler seems to work with the
282 dnl settings that are 'active' at the time the test
283 dnl is performed.
284
285 AC_DEFUN([CURL_COMPILER_WORKS_IFELSE], [
286   dnl compilation capability verification
287   tmp_compiler_works="unknown"
288   AC_COMPILE_IFELSE([
289     AC_LANG_PROGRAM([[
290     ]],[[
291       int i = 1;
292       return i;
293     ]])
294   ],[
295     tmp_compiler_works="yes"
296   ],[
297     tmp_compiler_works="no"
298   ])
299   dnl linking capability verification
300   if test "$tmp_compiler_works" = "yes"; then
301     AC_LINK_IFELSE([
302       AC_LANG_PROGRAM([[
303       ]],[[
304         int i = 1;
305         return i;
306       ]])
307     ],[
308       tmp_compiler_works="yes"
309     ],[
310       tmp_compiler_works="no"
311     ])
312   fi
313   dnl only do runtime verification when not cross-compiling
314   if test "x$cross_compiling" != "xyes" &&
315     test "$tmp_compiler_works" = "yes"; then
316     AC_RUN_IFELSE([
317       AC_LANG_PROGRAM([[
318       ]],[[
319         int i = 0;
320         exit(i);
321       ]])
322     ],[
323       tmp_compiler_works="yes"
324     ],[
325       tmp_compiler_works="no"
326     ])
327   fi
328   dnl branch upon test result
329   if test "$tmp_compiler_works" = "yes"; then
330   ifelse($1,,:,[$1])
331   ifelse($2,,,[else
332     $2])
333   fi
334 ])
335
336
337 dnl CURL_SET_COMPILER_BASIC_OPTS
338 dnl -------------------------------------------------
339 dnl Sets compiler specific options/flags which do not
340 dnl depend on configure's debug, optimize or warnings
341 dnl options.
342
343 AC_DEFUN([CURL_SET_COMPILER_BASIC_OPTS], [
344   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
345   #
346   if test "$compiler_id" != "unknown"; then
347     #
348     tmp_save_CPPFLAGS="$CPPFLAGS"
349     tmp_save_CFLAGS="$CFLAGS"
350     tmp_CPPFLAGS=""
351     tmp_CFLAGS=""
352     #
353     case "$compiler_id" in
354         #
355       DECC)
356         #
357         dnl Select strict ANSI C compiler mode
358         tmp_CFLAGS="$tmp_CFLAGS -std1"
359         dnl Turn off optimizer ANSI C aliasing rules
360         tmp_CFLAGS="$tmp_CFLAGS -noansi_alias"
361         dnl Generate warnings for missing function prototypes
362         tmp_CFLAGS="$tmp_CFLAGS -warnprotos"
363         dnl Change some warnings into fatal errors
364         tmp_CFLAGS="$tmp_CFLAGS -msg_fatal toofewargs,toomanyargs"
365         ;;
366         #
367       GNUC)
368         #
369         dnl Placeholder
370         tmp_CFLAGS="$tmp_CFLAGS"
371         ;;
372         #
373       HPUXC)
374         #
375         dnl Disallow run-time dereferencing of null pointers
376         tmp_CFLAGS="$tmp_CFLAGS -z"
377         dnl Disable some remarks
378         dnl #4227: padding struct with n bytes to align member
379         dnl #4255: padding size of struct with n bytes to alignment boundary
380         tmp_CFLAGS="$tmp_CFLAGS +W 4227,4255"
381         ;;
382         #
383       IBMC)
384         #
385         dnl Ensure that compiler optimizations are always thread-safe.
386         tmp_CFLAGS="$tmp_CFLAGS -qthreaded"
387         dnl Disable type based strict aliasing optimizations, using worst
388         dnl case aliasing assumptions when compiling. Type based aliasing
389         dnl would restrict the lvalues that could be safely used to access
390         dnl a data object.
391         tmp_CFLAGS="$tmp_CFLAGS -qnoansialias"
392         dnl Force compiler to stop after the compilation phase, without
393         dnl generating an object code file when compilation has errors.
394         tmp_CFLAGS="$tmp_CFLAGS -qhalt=e"
395         ;;
396         #
397       ICC_unix)
398         #
399         dnl On unix this compiler uses gcc's header files, so
400         dnl we select ANSI C89 dialect plus GNU extensions.
401         tmp_CPPFLAGS="$tmp_CPPFLAGS -std=gnu89"
402         dnl Change some warnings into errors
403         dnl #140: too many arguments in function call
404         dnl #147: declaration is incompatible with 'previous one'
405         dnl #165: too few arguments in function call
406         dnl #266: function declared implicitly
407         tmp_CPPFLAGS="$tmp_CPPFLAGS -we 140,147,165,266"
408         dnl Disable some remarks
409         dnl #279: controlling expression is constant
410         dnl #981: operands are evaluated in unspecified order
411         dnl #1469: "cc" clobber ignored
412         tmp_CPPFLAGS="$tmp_CPPFLAGS -wd 279,981,1469"
413         dnl Disable use of ANSI C aliasing rules in optimizations
414         tmp_CFLAGS="$tmp_CFLAGS -no-ansi-alias"
415         dnl Disable floating point optimizations
416         tmp_CFLAGS="$tmp_CFLAGS -fp-model precise"
417         ;;
418         #
419       ICC_windows)
420         #
421         dnl Placeholder
422         tmp_CFLAGS="$tmp_CFLAGS"
423         ;;
424         #
425       SGIC)
426         #
427         dnl Placeholder
428         tmp_CFLAGS="$tmp_CFLAGS"
429         ;;
430         #
431       SUNC)
432         #
433         dnl Placeholder
434         tmp_CFLAGS="$tmp_CFLAGS"
435         ;;
436         #
437     esac
438     #
439     tmp_CPPFLAGS=`eval echo $tmp_CPPFLAGS`
440     tmp_CFLAGS=`eval echo $tmp_CFLAGS`
441     #
442     if test ! -z "$tmp_CFLAGS" || test ! -z "$tmp_CPPFLAGS"; then
443       AC_MSG_CHECKING([if compiler accepts some basic options])
444       CPPFLAGS=`eval echo $tmp_save_CPPFLAGS $tmp_CPPFLAGS`
445       CFLAGS=`eval echo $tmp_save_CFLAGS $tmp_CFLAGS`
446       CURL_COMPILER_WORKS_IFELSE([
447         AC_MSG_RESULT([yes])
448         AC_MSG_NOTICE([compiler options added: $tmp_CFLAGS $tmp_CPPFLAGS])
449       ],[
450         AC_MSG_RESULT([no])
451         AC_MSG_NOTICE([compiler options rejected: $tmp_CFLAGS $tmp_CPPFLAGS])
452         dnl restore initial settings
453         CPPFLAGS="$tmp_save_CPPFLAGS"
454         CFLAGS="$tmp_save_CFLAGS"
455       ])
456     fi
457     #
458   fi
459 ])
460
461
462 dnl CURL_SET_COMPILER_DEBUG_OPTS
463 dnl -------------------------------------------------
464 dnl Sets compiler specific options/flags which depend
465 dnl on configure's debug option.
466
467 AC_DEFUN([CURL_SET_COMPILER_DEBUG_OPTS], [
468   AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
469   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
470   #
471   if test "$compiler_id" != "unknown"; then
472     #
473     tmp_save_CFLAGS="$CFLAGS"
474     tmp_save_CPPFLAGS="$CPPFLAGS"
475     #
476     tmp_options=""
477     tmp_CFLAGS="$CFLAGS"
478     tmp_CPPFLAGS="$CPPFLAGS"
479     CURL_VAR_STRIP([tmp_CFLAGS],[$flags_dbg_all])
480     CURL_VAR_STRIP([tmp_CPPFLAGS],[$flags_dbg_all])
481     #
482     if test "$want_debug" = "yes"; then
483       AC_MSG_CHECKING([if compiler accepts debug enabling options])
484       tmp_options="$flags_dbg_yes"
485     fi
486     if test "$want_debug" = "no"; then
487       AC_MSG_CHECKING([if compiler accepts debug disabling options])
488       tmp_options="$flags_dbg_off"
489     fi
490     #
491     CPPFLAGS=`eval echo $tmp_CPPFLAGS`
492     CFLAGS=`eval echo $tmp_CFLAGS $tmp_options`
493     CURL_COMPILER_WORKS_IFELSE([
494       AC_MSG_RESULT([yes])
495       AC_MSG_NOTICE([compiler options added: $tmp_options])
496     ],[
497       AC_MSG_RESULT([no])
498       AC_MSG_NOTICE([compiler options rejected: $tmp_options])
499       dnl restore initial settings
500       CPPFLAGS="$tmp_save_CPPFLAGS"
501       CFLAGS="$tmp_save_CFLAGS"
502     ])
503     #
504   fi
505 ])
506
507
508 dnl CURL_SET_COMPILER_OPTIMIZE_OPTS
509 dnl -------------------------------------------------
510 dnl Sets compiler specific options/flags which depend
511 dnl on configure's optimize option.
512
513 AC_DEFUN([CURL_SET_COMPILER_OPTIMIZE_OPTS], [
514   AC_REQUIRE([CURL_CHECK_OPTION_OPTIMIZE])dnl
515   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
516   #
517   if test "$compiler_id" != "unknown"; then
518     #
519     tmp_save_CFLAGS="$CFLAGS"
520     tmp_save_CPPFLAGS="$CPPFLAGS"
521     #
522     tmp_options=""
523     tmp_CFLAGS="$CFLAGS"
524     tmp_CPPFLAGS="$CPPFLAGS"
525     honor_optimize_option="yes"
526     #
527     dnl If optimization request setting has not been explicitly specified,
528     dnl it has been derived from the debug setting and initially assumed.
529     dnl This initially assumed optimizer setting will finally be ignored
530     dnl if CFLAGS or CPPFLAGS already hold optimizer flags. This implies
531     dnl that an initially assumed optimizer setting might not be honored.
532     #
533     if test "$want_optimize" = "assume_no" ||
534        test "$want_optimize" = "assume_yes"; then
535       AC_MSG_CHECKING([if compiler optimizer assumed setting might be used])
536       CURL_VAR_MATCH_IFELSE([tmp_CFLAGS],[$flags_opt_all],[
537         honor_optimize_option="no"
538       ])
539       CURL_VAR_MATCH_IFELSE([tmp_CPPFLAGS],[$flags_opt_all],[
540         honor_optimize_option="no"
541       ])
542       AC_MSG_RESULT([$honor_optimize_option])
543       if test "$honor_optimize_option" = "yes"; then
544         if test "$want_optimize" = "assume_yes"; then
545           want_optimize="yes"
546         fi
547         if test "$want_optimize" = "assume_no"; then
548           want_optimize="no"
549         fi
550       fi
551     fi
552     #
553     if test "$honor_optimize_option" = "yes"; then
554       CURL_VAR_STRIP([tmp_CFLAGS],[$flags_opt_all])
555       CURL_VAR_STRIP([tmp_CPPFLAGS],[$flags_opt_all])
556       if test "$want_optimize" = "yes"; then
557         AC_MSG_CHECKING([if compiler accepts optimizer enabling options])
558         tmp_options="$flags_opt_yes"
559       fi
560       if test "$want_optimize" = "no"; then
561         AC_MSG_CHECKING([if compiler accepts optimizer disabling options])
562         tmp_options="$flags_opt_off"
563       fi
564       CPPFLAGS=`eval echo $tmp_CPPFLAGS`
565       CFLAGS=`eval echo $tmp_CFLAGS $tmp_options`
566       CURL_COMPILER_WORKS_IFELSE([
567         AC_MSG_RESULT([yes])
568         AC_MSG_NOTICE([compiler options added: $tmp_options])
569       ],[
570         AC_MSG_RESULT([no])
571         AC_MSG_NOTICE([compiler options rejected: $tmp_options])
572         dnl restore initial settings
573         CPPFLAGS="$tmp_save_CPPFLAGS"
574         CFLAGS="$tmp_save_CFLAGS"
575       ])
576     fi
577     #
578   fi
579 ])
580
581
582 dnl CURL_SET_COMPILER_WARNING_OPTS
583 dnl -------------------------------------------------
584 dnl Sets compiler options/flags which depend on
585 dnl configure's warnings given option.
586
587 AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
588   AC_REQUIRE([CURL_CHECK_OPTION_WARNINGS])dnl
589   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
590   #
591   if test "$compiler_id" = "DECC"; then
592     if test "$want_warnings" = "yes"; then
593       dnl Select a higher warning level than default level2
594       CFLAGS="$CFLAGS -msg_enable level3"
595     fi
596   fi
597   #
598   if test "$compiler_id" = "GNUC"; then
599     #
600     # FIXME: Some of these warnings should be changed into errors
601     #        and moved to CURL-SET-COMPILER-BASIC-OPTS
602     #
603     if test "$want_warnings" = "yes"; then
604       dnl this is a set of options we believe *ALL* gcc versions support:
605       WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
606       dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
607       if test "$compiler_num" -ge "207"; then
608         dnl gcc 2.7 or later
609         WARN="$WARN -Wmissing-declarations"
610       fi
611       if test "$compiler_num" -gt "295"; then
612         dnl only if the compiler is newer than 2.95 since we got lots of
613         dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
614         dnl gcc 2.95.4 on FreeBSD 4.9!
615         WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
616       fi
617       if test "$compiler_num" -ge "296"; then
618         dnl gcc 2.96 or later
619         WARN="$WARN -Wfloat-equal"
620       fi
621       if test "$compiler_num" -gt "296"; then
622         dnl this option does not exist in 2.96
623         WARN="$WARN -Wno-format-nonliteral"
624       fi
625       dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
626       dnl on i686-Linux as it gives us heaps with false positives.
627       dnl Also, on gcc 4.0.X it is totally unbearable and complains all
628       dnl over making it unusable for generic purposes. Let's not use it.
629       if test "$compiler_num" -ge "303"; then
630         dnl gcc 3.3 and later
631         WARN="$WARN -Wendif-labels -Wstrict-prototypes"
632       fi
633       if test "$compiler_num" -ge "304"; then
634         # try these on gcc 3.4
635         WARN="$WARN -Wdeclaration-after-statement"
636       fi
637       for flag in $CPPFLAGS; do
638         case "$flag" in
639           -I*)
640             dnl Include path, provide a -isystem option for the same dir
641             dnl to prevent warnings in those dirs. The -isystem was not very
642             dnl reliable on earlier gcc versions.
643             add=`echo $flag | sed 's/^-I/-isystem /g'`
644             WARN="$WARN $add"
645             ;;
646         esac
647       done
648       CFLAGS="$CFLAGS $WARN"
649       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
650     fi
651   fi
652   #
653   if test "$compiler_id" = "HPUXC"; then
654     if test "$want_warnings" = "yes"; then
655       dnl Issue all warnings
656       CFLAGS="$CFLAGS +w1"
657     fi
658   fi
659   #
660   if test "$compiler_id" = "ICC_unix"; then
661     if test "$want_warnings" = "yes"; then
662       if test "$compiler_num" -gt "600"; then
663         dnl Show errors, warnings, and remarks
664         CPPFLAGS="$CPPFLAGS -Wall"
665         dnl Perform extra compile-time code checking
666         CPPFLAGS="$CPPFLAGS -Wcheck"
667       fi
668     fi
669   fi
670   #
671   if test "$compiler_id" = "SGIC"; then
672     if test "$want_warnings" = "yes"; then
673       dnl Perform stricter semantic and lint-like checks
674       CFLAGS="$CFLAGS -fullwarn"
675     fi
676   fi
677   #
678   if test "$compiler_id" = "SUNC"; then
679     if test "$want_warnings" = "yes"; then
680       dnl Perform stricter semantic and lint-like checks
681       CFLAGS="$CFLAGS -v"
682     fi
683   fi
684   #
685 ])
686
687
688 dnl CURL_PROCESS_DEBUG_BUILD_OPTS
689 dnl -------------------------------------------------
690 dnl Settings which depend on configure's debug given
691 dnl option, and further configure the build process.
692 dnl Don't use this macro for compiler dependant stuff.
693
694 AC_DEFUN([CURL_PROCESS_DEBUG_BUILD_OPTS], [
695   AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
696   AC_BEFORE([$0],[AC_PROG_LIBTOOL])dnl
697   #
698   if test "$want_debug" = "yes"; then
699     CPPFLAGS="$CPPFLAGS -DCURLDEBUG"
700   fi
701   #
702 ])
703
704
705 dnl CURL_CHECK_PROG_CC
706 dnl -------------------------------------------------
707 dnl Check for compiler program, preventing CFLAGS and
708 dnl CPPFLAGS from being unexpectedly changed.
709
710 AC_DEFUN([CURL_CHECK_PROG_CC], [
711   ac_save_CFLAGS="$CFLAGS"
712   ac_save_CPPFLAGS="$CPPFLAGS"
713   AC_PROG_CC
714   CFLAGS="$ac_save_CFLAGS"
715   CPPFLAGS="$ac_save_CPPFLAGS"
716 ])
717
718
719 dnl CURL_VAR_MATCH (VARNAME, VALUE)
720 dnl -------------------------------------------------
721 dnl Verifies if shell variable VARNAME contains VALUE.
722 dnl Contents of variable VARNAME and VALUE are handled
723 dnl as whitespace separated lists of words. If at least
724 dnl one word of VALUE is present in VARNAME the match
725 dnl is considered positive, otherwise false.
726
727 AC_DEFUN([CURL_VAR_MATCH], [
728   ac_var_match_word="no"
729   for word1 in "$[$1]"; do
730     for word2 in "[$2]"; do
731       if test "$word1" = "$word2"; then
732         ac_var_match_word="yes"
733       fi
734     done
735   done
736 ])
737
738
739 dnl CURL_VAR_MATCH_IFELSE (VARNAME, VALUE,
740 dnl                        [ACTION-IF-MATCH], [ACTION-IF-NOT-MATCH])
741 dnl -------------------------------------------------
742 dnl This performs a CURL_VAR_MATCH check and executes
743 dnl first branch if the match is positive, otherwise
744 dnl the second branch is executed.
745
746 AC_DEFUN([CURL_VAR_MATCH_IFELSE], [
747   CURL_VAR_MATCH([$1],[$2])
748   if test "$ac_var_match_word" = "yes"; then
749   ifelse($3,,:,[$3])
750   ifelse($4,,,[else
751     $4])
752   fi
753 ])
754
755
756 dnl CURL_VAR_STRIP (VARNAME, VALUE)
757 dnl -------------------------------------------------
758 dnl Contents of variable VARNAME and VALUE are handled
759 dnl as whitespace separated lists of words. Each word
760 dnl from VALUE is removed from VARNAME when present.
761
762 AC_DEFUN([CURL_VAR_STRIP], [
763   ac_var_stripped=""
764   for word1 in "$[$1]"; do
765     ac_var_strip_word="no"
766     for word2 in "[$2]"; do
767       if test "$word1" = "$word2"; then
768         ac_var_strip_word="yes"
769       fi
770     done
771     if test "$ac_var_strip_word" = "no"; then
772       ac_var_stripped="$ac_var_stripped $word1"
773     fi
774   done
775   dnl squeeze whitespace out of result
776   [$1]=`eval echo $ac_var_stripped`
777 ])