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