This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence a few pedantic warnings
[perl5.git] / cflags.SH
CommitLineData
a02608de 1case $PERL_CONFIG_SH in
1c3d792e 2'')
a0d0e21e
LW
3 if test -f config.sh; then TOP=.;
4 elif test -f ../config.sh; then TOP=..;
5 elif test -f ../../config.sh; then TOP=../..;
6 elif test -f ../../../config.sh; then TOP=../../..;
7 elif test -f ../../../../config.sh; then TOP=../../../..;
8 else
9 echo "Can't find config.sh."; exit 1
10 fi
11 . $TOP/config.sh
12 ;;
1c3d792e 13esac
2b317908
LW
14: This forces SH files to create target in same directory as SH file.
15: This is so that make depend always knows where to find SH derivatives.
1c3d792e
LW
16case "$0" in
17*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
18esac
bc730b18
JH
19
20warn=''
21
22# Add -Wall for the core modules iff gcc and not already -Wall
23case "$gccversion" in
24'') ;;
25Intel*) ;; # The Intel C++ plays gcc on TV but is not really it.
26*) case "$ccflags" in
27 *-Wall*) ;;
28 *) warn="$warn -Wall" ;;
29 esac
30 ;;
31esac
32
a07cd53d
JH
33# Create a test source file for testing what options can be fed to
34# gcc in this system; include a selection of most common and commonly
35# hairy include files.
36
37cat >_cflags.c <<__EOT__
38#include "EXTERN.h"
39#include "perl.h"
40/* The stdio.h, errno.h, and setjmp.h should be there in any ANSI C89. */
41#include <stdio.h>
42#include <errno.h>
43#include <setjmp.h>
44/* Just in case the inclusion of perl.h did not
45 * pull in enough system headers, let's try again. */
46#ifdef I_STDLIB
47#include <stdlib.h>
48#endif
49#ifdef I_STDDEF
50#include <stddef.h>
51#endif
52#ifdef I_STDARG
53#include <stdarg.h>
54#endif
55#ifdef I_LIMITS
56#include <limits.h>
57#endif
58#ifdef I_DIRENT
59#include <dirent.h>
60#endif
61#ifdef I_UNISTD
62#include <unistd.h>
63#endif
64#ifdef I_SYSTYPES
65#include <sys/types.h>
66#endif
67#ifdef I_SYSPARAM
68#include <sys/param.h>
69#endif
70#ifdef I_SYSRESOURCE
71#include <sys/resource.h>
72#endif
73#ifdef I_SYSSELECT
74#include <sys/select.h>
75#endif
76#if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* See perl.h. */
77#include <sys/socket.h>
78#endif
79#ifdef I_SYSSTAT
80#include <sys/stat.h>
81#endif
82#ifdef I_SYSTIME
83#include <sys/time.h>
84#endif
85#ifdef I_SYSTIMES
86#include <sys/times.h>
87#endif
88#ifdef I_SYSWAIT
89#include <sys/wait.h>
90#endif
91/* The gcc -ansi can cause a lot of noise in Solaris because of:
92 /usr/include/sys/resource.h:148: warning: 'struct rlimit64' declared inside parameter list
93 */
94int main(int argc, char *argv[]) {
95
96/* Add here test code found to be problematic in some gcc platform. */
97
98/* Off_t/off_t is a struct in Solaris with largefiles, and with gcc -ansi
99 * that struct cannot be compared in some gcc releases with a flat
100 * integer, such as a STRLEN. */
101
102 Off_t t0a = 2;
103 STRLEN t0b = 3;
104 int t0c = t0a == t0b;
105
106 return 0;
107}
108__EOT__
109
110stdflags=''
bc730b18
JH
111
112# Further gcc warning options.
113case "$gccversion" in
114'') ;;
a07cd53d
JH
115[12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
116Intel*) ;; # # Is that you, Intel C++?
117*) for opt in -ansi -pedantic -std=c89 -W -Wextra -Wdeclaration-after-statement -Wendif-labels
bc730b18
JH
118 do
119 case " $ccflags " in
a07cd53d
JH
120 *" $opt "*) ;; # Skip if already there.
121 *) rm -f _cflags$_exe
122 case "`$cc $cflags $opt _cflags.c -o _cflags$_exe 2>&1`" in
bc730b18
JH
123 *"unrecognized"*) ;;
124 *"Invalid"*) ;;
9ac4c107 125 *"is valid for C"*) ;;
a07cd53d
JH
126 *) if test -x _cflags$_exe
127 then
128 case "$opt" in
129 -std*) stdflags="$stdflags $opt" ;;
130 *) warn="$warn $opt" ;;
131 esac
132 fi
133 ;;
bc730b18
JH
134 esac
135 ;;
136 esac
bc730b18
JH
137 done
138 ;;
139esac
a07cd53d 140rm -f _cflags.c _cflags$_exe
bc730b18 141
9ac4c107
JH
142case "$gccversion" in
143'') ;;
144*)
3e8416a3
RGS
145 if [ "$gccansipedantic" = "" ]; then
146 # If we have -Duse64bitint (or equivalent) in effect and the quadtype
147 # has become 'long long', gcc -pedantic becomes unbearable (moreso
148 # when combined with -Wall) because long long and LL and %lld|%Ld
149 # become warn-worthy. So let's drop the -pedantic in that case.
150 case "$quadtype:$sPRId64" in
151 "long long"*|*lld*|*Ld*)
152 ccflags="`echo $ccflags|sed 's/-pedantic/ /'`"
153 warn="`echo $warn|sed 's/-pedantic/ /'`"
154 ;;
155 esac
156 fi
5cf489d6
RGS
157 # Using certain features (like the gcc statement expressions)
158 # requires knowing whether -pedantic has been specified.
9ac4c107
JH
159 case "$warn$ccflags" in
160 *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
161 esac
a07cd53d
JH
162 ;;
163esac
b1e55cab 164
10edeb5d 165# Code to set any extra flags here.
a07cd53d 166extra=''
11fcce85 167
2b317908
LW
168echo "Extracting cflags (with variable substitutions)"
169: This section of the file will have variable substitutions done on it.
170: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
171: Protect any dollar signs and backticks that you do not want interpreted
172: by putting a backslash in front. You may delete these comments.
165b7424 173rm -f cflags
2b317908 174$spitshell >cflags <<!GROK!THIS!
ecfc5424 175$startsh
bc730b18 176
11fcce85 177# Extra warnings, used e.g. for gcc.
bc730b18 178warn="$warn"
11fcce85
JH
179# Extra standardness.
180stdflags="$stdflags"
b1e55cab
JH
181# Extra extra.
182extra="$extra"
bc730b18 183
2b317908
LW
184!GROK!THIS!
185
186: In the following dollars and backticks do not need the extra backslash.
187$spitshell >>cflags <<'!NO!SUBS!'
a02608de 188case $PERL_CONFIG_SH in
2b317908 189'')
a0d0e21e
LW
190 if test -f config.sh; then TOP=.;
191 elif test -f ../config.sh; then TOP=..;
192 elif test -f ../../config.sh; then TOP=../..;
193 elif test -f ../../../config.sh; then TOP=../../..;
194 elif test -f ../../../../config.sh; then TOP=../../../..;
195 else
196 echo "Can't find config.sh."; exit 1
197 fi
198 . $TOP/config.sh
199 ;;
200esac
201
75550b4e
PG
202: syntax: cflags [optimize=XXX] [file[.suffix]]
203: displays the compiler command line for file
204
1167a30e 205case "X$1" in
26102cc7 206Xoptimize=*|X"optimize=*")
1167a30e
IZ
207 eval "$1"
208 shift
209 ;;
210esac
211
1c3d792e
LW
212also=': '
213case $# in
2b317908 2141) also='echo 1>&2 " CCCMD = "'
1c3d792e
LW
215esac
216
217case $# in
2180) set *.c; echo "The current C flags are:" ;;
1c3d792e 219esac
2b317908 220
578789a7 221set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
2b317908 222
1c3d792e
LW
223for file do
224
225 case "$#" in
226 1) ;;
2b317908 227 *) echo $n " $file.c $c" ;;
1c3d792e
LW
228 esac
229
2b317908
LW
230 : allow variables like toke_cflags to be evaluated
231
8736538c
AS
232 if echo $file | grep -v / >/dev/null
233 then
234 eval 'eval ${'"${file}_cflags"'-""}'
235 fi
2b317908
LW
236
237 : or customize here
238
1c3d792e 239 case "$file" in
a0d0e21e
LW
240 DB_File) ;;
241 GDBM_File) ;;
2304df62
AD
242 NDBM_File) ;;
243 ODBM_File) ;;
244 POSIX) ;;
245 SDBM_File) ;;
246 av) ;;
4b6be2dd 247 byterun) ;;
2304df62
AD
248 deb) ;;
249 dl) ;;
2b317908 250 doio) ;;
2304df62 251 doop) ;;
2b317908 252 dump) ;;
59bea8cf 253 globals) ;;
2304df62
AD
254 gv) ;;
255 hv) ;;
a6ec74c1 256 locale) ;;
59bea8cf 257 madly) ;;
2304df62 258 main) ;;
2b317908 259 malloc) ;;
2304df62
AD
260 mg) ;;
261 miniperlmain) ;;
a6ec74c1 262 numeric) ;;
2304df62 263 op) ;;
59bea8cf
JH
264 opmini) ;;
265 pad) ;;
2b317908 266 perl) ;;
6f4183fe 267 perlapi) ;;
2304df62 268 perlmain) ;;
2b317908 269 perly) ;;
2304df62 270 pp) ;;
a0d0e21e
LW
271 pp_ctl) ;;
272 pp_hot) ;;
a6ec74c1 273 pp_pack) ;;
59bea8cf 274 pp_sort) ;;
a0d0e21e 275 pp_sys) ;;
2b317908
LW
276 regcomp) ;;
277 regexec) ;;
2304df62
AD
278 run) ;;
279 scope) ;;
280 sv) ;;
281 taint) ;;
2b317908 282 toke) ;;
59bea8cf 283 universal) ;;
2b317908 284 usersub) ;;
59bea8cf 285 utf8) ;;
2b317908 286 util) ;;
59bea8cf 287 xsutils) ;;
1c3d792e
LW
288 *) ;;
289 esac
290
666ea192 291case "$cc" in
7e827271 292*g++*)
9ac4c107
JH
293 # Extra paranoia in case people have bad canned ccflags:
294 # bad in the sense that the flags are accepted by g++,
295 # but then whined about.
296 for f in -Wdeclaration-after-statement -std=c89
297 do
298 ccflags="`echo $ccflags|sed 's/$f/ /'`"
299 done
7e827271
JH
300 ;;
301esac
302
303case "$cc" in
304*g++*)
305 # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
a7ae1e4a
JH
306 # because of all the warnings about Perl___notused, and g++ doesn't do
307 # __attribute__((unused)) (and even if at some stage it may, people do
308 # have older gcc installations), and ((void)x) isn't enough to silence
309 # the noises about XS functions not using their cv parameter, so we need
310 # the -Wno-unused-parameter too.
311 # Yes, we lose some valid warnings, but hopefully other compilers
312 # (like gcc) will still pick up those warnings.
313 for o in -Wno-unused-variable -Wno-unused-parameter
7e827271
JH
314 do
315 case "$warn" in
316 *$o*) ;;
317 *) warn="$warn $o" ;;
318 esac
319 done
320 ;;
666ea192
JH
321esac
322
69c7f294
NC
323if test -f .patch; then
324 ccflags="-DPERL_PATCHNUM=`cat .patch` $ccflags"
325fi
326
c4f23d77 327 : Can we perhaps use $ansi2knr here
b1e55cab
JH
328 echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra"
329 eval "$also "'"$cc -DPERL_CORE -c $ccflags $stdflags $optimize $warn $extra"'
2b317908 330
a0d0e21e 331 . $TOP/config.sh
2b317908 332
1c3d792e 333done
2b317908 334!NO!SUBS!
a0d0e21e 335chmod 755 cflags
2b317908 336$eunicefix cflags