1 dnl /usr/share/aclocal/guidod-cvs/ax_cflags_no_writable_strings.m4
2 dnl @synopsis AX_CFLAGS_NO_WRITABLE_STRINGS [(shellvar [,default, [A/NA]])]
4 dnl Try to find a compiler option that makes all stringliteral
7 dnl The sanity check is done by looking at string.h which has a set of
8 dnl strcpy definitions that should be defined with const-modifiers to
9 dnl not emit a warning in all so many places.
11 dnl For the GNU CC compiler it will be -fno-writable-strings
12 dnl -Wwrite-strings The result is added to the shellvar being CFLAGS by
17 dnl - $1 shell-variable-to-add-to : CFLAGS
18 dnl - $2 add-value-if-not-found : nothing
19 dnl - $3 action-if-found : add value to shellvariable
20 dnl - $4 action-if-not-found : nothing
23 dnl @author Guido U. Draheim <guidod@gmx.de>
24 dnl @version 2006-12-12
25 dnl @license GPLWithACException
27 AC_DEFUN([AX_CFLAGS_NO_WRITABLE_STRINGS],[dnl
28 AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
29 AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_no_writable_strings])dnl
30 AC_CACHE_CHECK([m4_ifval([$1],[$1],FLAGS) making strings readonly],
31 VAR,[VAR="no, unknown"
34 ac_save_[]FLAGS="$[]FLAGS"
36 # -use_readonly_const is the default for IRIX C,
37 # puts them into .rodata, but they are copied later.
38 # need to be "-G0 -rdatashared" for strictmode but
39 # I am not sure what effect that has really. - guidod
41 in "-pedantic % -fno-writable-strings -Wwrite-strings" dnl GCC
42 "-pedantic % -fconst-strings -Wwrite-strings" dnl newer GCC
43 "-v -Xc % -xstrconst" dnl Solaris C - strings go into readonly segment
44 "+w1 -Aa % +ESlit" dnl HP-UX C - strings go into readonly segment
45 "-w0 -std1 % -readonly_strings" dnl Digital Unix - again readonly segment
46 "-fullwarn -use_readonly_const %% ok, its the default" dnl IRIX C
48 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
49 AC_TRY_COMPILE([],[return 0;],
50 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
54 *) # sanity check - testing strcpy() from string.h
55 cp config.log config.tmp
56 AC_TRY_COMPILE([#include <string.h>],[
58 if (strcpy (test, "test")) return 1;],
59 dnl the original did use test -n `$CC testprogram.c`
60 [if test `diff config.log config.tmp | grep -i warning | wc -l` != 0
61 then VAR="no, suppressed, string.h," ; fi],
62 [VAR="no, suppressed, string.h"])
66 FLAGS="$ac_save_[]FLAGS"
70 .ok|.ok,*) m4_ifvaln($3,$3) ;;
71 .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
72 AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
73 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
75 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
76 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
77 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
78 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
81 AS_VAR_POPDEF([VAR])dnl
82 AS_VAR_POPDEF([FLAGS])dnl
85 dnl the only difference - the LANG selection... and the default FLAGS
87 AC_DEFUN([AX_CXXFLAGS_NO_WRITABLE_STRINGS],[dnl
88 AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
89 AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_no_writable_strings])dnl
90 AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) making strings readonly],
91 VAR,[VAR="no, unknown"
94 ac_save_[]FLAGS="$[]FLAGS"
96 # -use_readonly_const is the default for IRIX C,
97 # puts them into .rodata, but they are copied later.
98 # need to be "-G0 -rdatashared" for strictmode but
99 # I am not sure what effect that has really. - guidod
101 in "-pedantic -Werror % -fno-writable-strings -Wwrite-strings" dnl GCC
102 "-pedantic -Werror % -fconst-strings -Wwrite-strings" dnl newer GCC
103 "-pedantic % -fconst-strings %% no, const-strings is default" dnl newer GCC
104 "-v -Xc % -xstrconst" dnl Solaris C - strings go into readonly segment
105 "+w1 -Aa % +ESlit" dnl HP-UX C - strings go into readonly segment
106 "-w0 -std1 % -readonly_strings" dnl Digital Unix - again readonly segment
107 "-fullwarn -use_readonly_const %% ok, its the default" dnl IRIX C
109 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
110 AC_TRY_COMPILE([],[return 0;],
111 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
115 *) # sanity check - testing strcpy() from string.h
116 cp config.log config.tmp
117 AC_TRY_COMPILE([#include <string.h>],[
119 if (strcpy (test, "test")) return 1;],
120 dnl the original did use test -n `$CC testprogram.c`
121 [if test `diff config.log config.tmp | grep -i warning | wc -l` != 0
122 then VAR="no, suppressed, string.h," ; fi],
123 [VAR="no, suppressed, string.h"])
127 FLAGS="$ac_save_[]FLAGS"
131 .ok|.ok,*) m4_ifvaln($3,$3) ;;
132 .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
133 AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
134 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
136 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
137 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
138 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
139 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
142 AS_VAR_POPDEF([VAR])dnl
143 AS_VAR_POPDEF([FLAGS])dnl