beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / m4 / ax_cflags_no_writable_strings.m4
blobdb9997ea6fd213e1a33ad7b24ff923a3bd3e74f4
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]])]
3 dnl
4 dnl Try to find a compiler option that makes all stringliteral
5 dnl readonly.
6 dnl
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.
10 dnl
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
13 dnl default.
14 dnl
15 dnl DEFAULTS:
16 dnl
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
21 dnl
22 dnl @category C
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"
32  AC_LANG_SAVE
33  AC_LANG_C
34  ac_save_[]FLAGS="$[]FLAGS"
35 # IRIX C compiler:
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
40 for ac_arg dnl
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
47    #
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])
51 done
52 case ".$VAR" in
53    .|.no|.no,*) ;;
54    *) # sanity check - testing strcpy() from string.h
55       cp config.log config.tmp
56       AC_TRY_COMPILE([#include <string.h>],[
57       char test[16];
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"])
63       rm config.tmp
64    ;;
65 esac
66    FLAGS="$ac_save_[]FLAGS"
67    AC_LANG_RESTORE
69 case ".$VAR" in
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"])]) ;;
74    *) m4_ifvaln($3,$3,[
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"
79    fi ]) ;;
80 esac
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"
92  AC_LANG_SAVE
93  AC_LANG_CPLUSPLUS
94  ac_save_[]FLAGS="$[]FLAGS"
95 # IRIX C compiler:
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
100 for ac_arg dnl
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
108    #
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])
112 done
113 case ".$VAR" in
114    .|.no|.no,*) ;;
115    *) # sanity check - testing strcpy() from string.h
116       cp config.log config.tmp
117       AC_TRY_COMPILE([#include <string.h>],[
118       char test[16];
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"])
124       rm config.tmp
125    ;;
126 esac
127  FLAGS="$ac_save_[]FLAGS"
128  AC_LANG_RESTORE
130 case ".$VAR" in
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"])]) ;;
135    *) m4_ifvaln($3,$3,[
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"
140    fi ]) ;;
141 esac
142 AS_VAR_POPDEF([VAR])dnl
143 AS_VAR_POPDEF([FLAGS])dnl