This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
doio.c: Stop semop from modifying its argument
[perl5.git] / cflags.SH
CommitLineData
1f00b0d6
S
1#!/bin/sh
2
a02608de 3case $PERL_CONFIG_SH in
1c3d792e 4'')
a0d0e21e
LW
5 if test -f config.sh; then TOP=.;
6 elif test -f ../config.sh; then TOP=..;
7 elif test -f ../../config.sh; then TOP=../..;
8 elif test -f ../../../config.sh; then TOP=../../..;
9 elif test -f ../../../../config.sh; then TOP=../../../..;
10 else
11 echo "Can't find config.sh."; exit 1
12 fi
13 . $TOP/config.sh
14 ;;
1c3d792e 15esac
2b317908
LW
16: This forces SH files to create target in same directory as SH file.
17: This is so that make depend always knows where to find SH derivatives.
1c3d792e
LW
18case "$0" in
19*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
20esac
bc730b18 21
37723ebb 22if test -f config_h.SH -a ! -f config.h; then
6ef8aa7c 23 . ./config_h.SH
11e2f395 24 CONFIG_H=already-done
6ef8aa7c
RGS
25fi
26
bc730b18
JH
27warn=''
28
29# Add -Wall for the core modules iff gcc and not already -Wall
30case "$gccversion" in
31'') ;;
32Intel*) ;; # The Intel C++ plays gcc on TV but is not really it.
33*) case "$ccflags" in
34 *-Wall*) ;;
35 *) warn="$warn -Wall" ;;
36 esac
37 ;;
38esac
39
a07cd53d
JH
40# Create a test source file for testing what options can be fed to
41# gcc in this system; include a selection of most common and commonly
42# hairy include files.
43
44cat >_cflags.c <<__EOT__
45#include "EXTERN.h"
46#include "perl.h"
47/* The stdio.h, errno.h, and setjmp.h should be there in any ANSI C89. */
48#include <stdio.h>
49#include <errno.h>
50#include <setjmp.h>
51/* Just in case the inclusion of perl.h did not
52 * pull in enough system headers, let's try again. */
53#ifdef I_STDLIB
54#include <stdlib.h>
55#endif
56#ifdef I_STDDEF
57#include <stddef.h>
58#endif
59#ifdef I_STDARG
60#include <stdarg.h>
61#endif
62#ifdef I_LIMITS
63#include <limits.h>
64#endif
65#ifdef I_DIRENT
66#include <dirent.h>
67#endif
68#ifdef I_UNISTD
69#include <unistd.h>
70#endif
463bdbaf 71#ifdef I_SYS_TYPES
a07cd53d
JH
72#include <sys/types.h>
73#endif
463bdbaf 74#ifdef I_SYS_PARAM
a07cd53d
JH
75#include <sys/param.h>
76#endif
463bdbaf 77#ifdef I_SYS_RESOURCE
a07cd53d
JH
78#include <sys/resource.h>
79#endif
463bdbaf 80#ifdef I_SYS_SELECT
a07cd53d
JH
81#include <sys/select.h>
82#endif
83#if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* See perl.h. */
84#include <sys/socket.h>
85#endif
463bdbaf 86#ifdef I_SYS_STAT
a07cd53d
JH
87#include <sys/stat.h>
88#endif
463bdbaf 89#ifdef I_SYS_TIME
a07cd53d
JH
90#include <sys/time.h>
91#endif
463bdbaf 92#ifdef I_SYS_TIMES
a07cd53d
JH
93#include <sys/times.h>
94#endif
463bdbaf 95#ifdef I_SYS_WAIT
a07cd53d
JH
96#include <sys/wait.h>
97#endif
98/* The gcc -ansi can cause a lot of noise in Solaris because of:
99 /usr/include/sys/resource.h:148: warning: 'struct rlimit64' declared inside parameter list
100 */
101int main(int argc, char *argv[]) {
102
103/* Add here test code found to be problematic in some gcc platform. */
104
105/* Off_t/off_t is a struct in Solaris with largefiles, and with gcc -ansi
106 * that struct cannot be compared in some gcc releases with a flat
107 * integer, such as a STRLEN. */
108
215ed6ce 109 IV iv;
a07cd53d
JH
110 Off_t t0a = 2;
111 STRLEN t0b = 3;
112 int t0c = t0a == t0b;
113
215ed6ce
AD
114/* In FreeBSD 6.2 (and probably other releases too), with -Duse64bitint,
115 perl will use atoll(3). However, that declaration is hidden in <stdlib.h>
116 if we force the compiler to use -std=c89 mode.
117*/
118 iv = Atol("42");
119
120 return (!t0c && (iv == 42)) ? 0 : -1; /* Try to avoid 'unused' warnings. */
a07cd53d
JH
121}
122__EOT__
123
124stdflags=''
bc730b18 125
215ed6ce
AD
126# Further gcc warning options. Build up a list of options that work.
127# Note that some problems may only show up with combinations of options,
128# e.g. a warning might show up only with -Wall -ansi, not with either
129# one individually.
130# TODO: Ponder whether to migrate this back to Configure so hints files can
131# tweak it. Also, be paranoid about whether results we've deduced in Configure
132# (especially about things like long long, which are not in C89) will still be
133# valid if we now add flags like -std=c89.
134
bc730b18
JH
135case "$gccversion" in
136'') ;;
a07cd53d
JH
137[12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
138Intel*) ;; # # Is that you, Intel C++?
db7198b5
RB
139*) for opt in -ansi -std=c89 -W -Wextra -Wdeclaration-after-statement \
140 -Wendif-labels -Wc++-compat -Wwrite-strings
bc730b18
JH
141 do
142 case " $ccflags " in
a07cd53d
JH
143 *" $opt "*) ;; # Skip if already there.
144 *) rm -f _cflags$_exe
4b76cb9d 145 case "`$cc -DPERL_NO_INLINE_FUNCTIONS $ccflags $warn $stdflags $opt _cflags.c -o _cflags$_exe 2>&1`" in
bc730b18 146 *"unrecognized"*) ;;
215ed6ce 147 *"implicit declaration"*) ;; # Was something useful hidden?
bc730b18 148 *"Invalid"*) ;;
9ac4c107 149 *"is valid for C"*) ;;
a07cd53d
JH
150 *) if test -x _cflags$_exe
151 then
152 case "$opt" in
153 -std*) stdflags="$stdflags $opt" ;;
154 *) warn="$warn $opt" ;;
155 esac
156 fi
157 ;;
bc730b18
JH
158 esac
159 ;;
160 esac
bc730b18
JH
161 done
162 ;;
163esac
a07cd53d 164rm -f _cflags.c _cflags$_exe
bc730b18 165
9ac4c107
JH
166case "$gccversion" in
167'') ;;
168*)
3e8416a3
RGS
169 if [ "$gccansipedantic" = "" ]; then
170 # If we have -Duse64bitint (or equivalent) in effect and the quadtype
171 # has become 'long long', gcc -pedantic becomes unbearable (moreso
172 # when combined with -Wall) because long long and LL and %lld|%Ld
173 # become warn-worthy. So let's drop the -pedantic in that case.
174 case "$quadtype:$sPRId64" in
175 "long long"*|*lld*|*Ld*)
176 ccflags="`echo $ccflags|sed 's/-pedantic/ /'`"
177 warn="`echo $warn|sed 's/-pedantic/ /'`"
178 ;;
179 esac
215ed6ce
AD
180 # Similarly, since 'long long' isn't part of C89, FreeBSD 6.2 headers
181 # don't declare atoll() under -std=c89, but we need it. In general,
182 # insisting on -std=c89 is inconsistent with insisting on using
183 # 'long long'. So drop -std=c89 and -ansi as well if we're using
184 # 'long long' as our main integral type.
185 case "$ivtype" in
186 "long long")
187 ccflags=`echo $ccflags|sed -e 's/-pedantic/ /' -e 's/-std=c89/ /' -e 's/-ansi/ /'`
188 warn=`echo $warn|sed -e 's/-pedantic/ /' -e 's/-ansi/ /'`
a5105380 189 stdflags=`echo $stdflags|sed -e 's/-std=c89/ /'`
215ed6ce
AD
190 ;;
191 esac
3e8416a3 192 fi
5cf489d6
RGS
193 # Using certain features (like the gcc statement expressions)
194 # requires knowing whether -pedantic has been specified.
9ac4c107
JH
195 case "$warn$ccflags" in
196 *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
197 esac
a07cd53d
JH
198 ;;
199esac
b1e55cab 200
10edeb5d 201# Code to set any extra flags here.
a07cd53d 202extra=''
11fcce85 203
2b317908
LW
204echo "Extracting cflags (with variable substitutions)"
205: This section of the file will have variable substitutions done on it.
206: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
207: Protect any dollar signs and backticks that you do not want interpreted
208: by putting a backslash in front. You may delete these comments.
165b7424 209rm -f cflags
2b317908 210$spitshell >cflags <<!GROK!THIS!
ecfc5424 211$startsh
bc730b18 212
11fcce85 213# Extra warnings, used e.g. for gcc.
bc730b18 214warn="$warn"
11fcce85
JH
215# Extra standardness.
216stdflags="$stdflags"
b1e55cab
JH
217# Extra extra.
218extra="$extra"
dcff826f
YO
219# what do executables look like?
220_exe="$_exe"
bc730b18 221
2b317908
LW
222!GROK!THIS!
223
224: In the following dollars and backticks do not need the extra backslash.
225$spitshell >>cflags <<'!NO!SUBS!'
a02608de 226case $PERL_CONFIG_SH in
2b317908 227'')
a0d0e21e
LW
228 if test -f config.sh; then TOP=.;
229 elif test -f ../config.sh; then TOP=..;
230 elif test -f ../../config.sh; then TOP=../..;
231 elif test -f ../../../config.sh; then TOP=../../..;
232 elif test -f ../../../../config.sh; then TOP=../../../..;
233 else
234 echo "Can't find config.sh."; exit 1
235 fi
236 . $TOP/config.sh
237 ;;
238esac
239
75550b4e
PG
240: syntax: cflags [optimize=XXX] [file[.suffix]]
241: displays the compiler command line for file
242
1167a30e 243case "X$1" in
26102cc7 244Xoptimize=*|X"optimize=*")
1167a30e
IZ
245 eval "$1"
246 shift
247 ;;
248esac
249
1c3d792e
LW
250also=': '
251case $# in
2b317908 2521) also='echo 1>&2 " CCCMD = "'
1c3d792e
LW
253esac
254
255case $# in
2560) set *.c; echo "The current C flags are:" ;;
1c3d792e 257esac
2b317908 258
578789a7 259set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
2b317908 260
1c3d792e
LW
261for file do
262
263 case "$#" in
264 1) ;;
2b317908 265 *) echo $n " $file.c $c" ;;
1c3d792e
LW
266 esac
267
2b317908
LW
268 : allow variables like toke_cflags to be evaluated
269
8736538c
AS
270 if echo $file | grep -v / >/dev/null
271 then
272 eval 'eval ${'"${file}_cflags"'-""}'
273 fi
2b317908
LW
274
275 : or customize here
276
1c3d792e 277 case "$file" in
1c3d792e 278 *) ;;
5729ffdd
NC
279
280 *) : Customization examples follow: ;;
281 av) ccflags=`echo $ccflags | sed -e s/-pipe//` ;;
282 deb) ccflags="$ccflags -fno-jump-tables" ;;
283 hv) warn=`echo $warn | sed -e s/-Wextra//` ;;
284 toke) optimize=-O0 ;;
1c3d792e
LW
285 esac
286
5729ffdd
NC
287 : The examples are intentionally unreachable as the '*)' case always
288 : matches. To use them, move before the '*)' and edit as appropriate.
289 : It is not a good idea to set ccflags to an absolute value here, as it
290 : often contains general -D defines which are needed for correct
291 : compilation. It is better to edit ccflags as shown, using interpolation
292 : to add flags, or sed to remove flags.
293
294
a7d59441
YO
295 case "$cc" in
296 *g++*)
297 # Extra paranoia in case people have bad canned ccflags:
298 # bad in the sense that the flags are accepted by g++,
299 # but then whined about.
300 for f in -Wdeclaration-after-statement -std=c89
301 do
302 ccflags=`echo $ccflags|sed 's/$f/ /'`
303 done
304 ;;
305 esac
306 cppflags=`echo $cppflags|sed 's/-Wdeclaration-after-statement/ /'`
307
308 case "$cc" in
eb387cb8 309 *clang*)
d5db65c0
RU
310 # clang complains a lot about -Wunused-value which are not fixable
311 warn="$warn -Wno-unused-value"
312 ;;
a7d59441
YO
313 *g++*)
314 # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
315 # because of all the warnings about Perl___notused, and g++ doesn't do
316 # __attribute__((unused)) (and even if at some stage it may, people do
317 # have older gcc installations), and ((void)x) isn't enough to silence
318 # the noises about XS functions not using their cv parameter, so we need
319 # the -Wno-unused-parameter too.
320 # Yes, we lose some valid warnings, but hopefully other compilers
321 # (like gcc) will still pick up those warnings.
322 for o in -Wno-unused-variable -Wno-unused-parameter
323 do
324 case "$warn" in
325 *$o*) ;;
326 *) warn="$warn $o" ;;
327 esac
328 done
329 ;;
7a5b1e22
FC
330 *)
331 # clang may not be called clang
332 case "`$cc -v 2>&1`" in
333 *clang*)
334 case "$warn" in
335 *-Wno-unused-value) ;;
336 *) warn="$warn -Wno-unused-value"
337 esac
338 esac
7e827271 339 esac
666ea192 340
69c7f294 341
c4f23d77 342 : Can we perhaps use $ansi2knr here
b1e55cab
JH
343 echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra"
344 eval "$also "'"$cc -DPERL_CORE -c $ccflags $stdflags $optimize $warn $extra"'
2b317908 345
a0d0e21e 346 . $TOP/config.sh
2b317908 347
a7d59441 348 # end per file behaviour
1c3d792e 349done
2b317908 350!NO!SUBS!
a0d0e21e 351chmod 755 cflags
2b317908 352$eunicefix cflags