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