Commit | Line | Data |
---|---|---|
a02608de | 1 | case $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 | 13 | esac |
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 |
16 | case "$0" in |
17 | */*) cd `expr X$0 : 'X\(.*\)/'` ;; | |
18 | esac | |
bc730b18 | 19 | |
37723ebb | 20 | if test -f config_h.SH -a ! -f config.h; then |
6ef8aa7c | 21 | . ./config_h.SH |
11e2f395 | 22 | CONFIG_H=already-done |
6ef8aa7c RGS |
23 | fi |
24 | ||
bc730b18 JH |
25 | warn='' |
26 | ||
27 | # Add -Wall for the core modules iff gcc and not already -Wall | |
28 | case "$gccversion" in | |
29 | '') ;; | |
30 | Intel*) ;; # 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 | ;; | |
36 | esac | |
37 | ||
a07cd53d JH |
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 | ||
42 | cat >_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 | |
463bdbaf | 69 | #ifdef I_SYS_TYPES |
a07cd53d JH |
70 | #include <sys/types.h> |
71 | #endif | |
463bdbaf | 72 | #ifdef I_SYS_PARAM |
a07cd53d JH |
73 | #include <sys/param.h> |
74 | #endif | |
463bdbaf | 75 | #ifdef I_SYS_RESOURCE |
a07cd53d JH |
76 | #include <sys/resource.h> |
77 | #endif | |
463bdbaf | 78 | #ifdef I_SYS_SELECT |
a07cd53d JH |
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 | |
463bdbaf | 84 | #ifdef I_SYS_STAT |
a07cd53d JH |
85 | #include <sys/stat.h> |
86 | #endif | |
463bdbaf | 87 | #ifdef I_SYS_TIME |
a07cd53d JH |
88 | #include <sys/time.h> |
89 | #endif | |
463bdbaf | 90 | #ifdef I_SYS_TIMES |
a07cd53d JH |
91 | #include <sys/times.h> |
92 | #endif | |
463bdbaf | 93 | #ifdef I_SYS_WAIT |
a07cd53d JH |
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 | */ | |
99 | int 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 | ||
215ed6ce | 107 | IV iv; |
a07cd53d JH |
108 | Off_t t0a = 2; |
109 | STRLEN t0b = 3; | |
110 | int t0c = t0a == t0b; | |
111 | ||
215ed6ce AD |
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. */ | |
a07cd53d JH |
119 | } |
120 | __EOT__ | |
121 | ||
122 | stdflags='' | |
bc730b18 | 123 | |
215ed6ce AD |
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 | ||
bc730b18 JH |
133 | case "$gccversion" in |
134 | '') ;; | |
a07cd53d JH |
135 | [12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this. |
136 | Intel*) ;; # # Is that you, Intel C++? | |
288b8c02 | 137 | *) for opt in -ansi -std=c89 -W -Wextra -Wdeclaration-after-statement -Wendif-labels -Wc++-compat |
bc730b18 JH |
138 | do |
139 | case " $ccflags " in | |
a07cd53d JH |
140 | *" $opt "*) ;; # Skip if already there. |
141 | *) rm -f _cflags$_exe | |
463bdbaf | 142 | case "`$cc $cflags $warn $stdflags $opt _cflags.c -o _cflags$_exe 2>&1`" in |
bc730b18 | 143 | *"unrecognized"*) ;; |
215ed6ce | 144 | *"implicit declaration"*) ;; # Was something useful hidden? |
bc730b18 | 145 | *"Invalid"*) ;; |
9ac4c107 | 146 | *"is valid for C"*) ;; |
a07cd53d JH |
147 | *) if test -x _cflags$_exe |
148 | then | |
149 | case "$opt" in | |
150 | -std*) stdflags="$stdflags $opt" ;; | |
151 | *) warn="$warn $opt" ;; | |
152 | esac | |
153 | fi | |
154 | ;; | |
bc730b18 JH |
155 | esac |
156 | ;; | |
157 | esac | |
bc730b18 JH |
158 | done |
159 | ;; | |
160 | esac | |
a07cd53d | 161 | rm -f _cflags.c _cflags$_exe |
bc730b18 | 162 | |
9ac4c107 JH |
163 | case "$gccversion" in |
164 | '') ;; | |
165 | *) | |
3e8416a3 RGS |
166 | if [ "$gccansipedantic" = "" ]; then |
167 | # If we have -Duse64bitint (or equivalent) in effect and the quadtype | |
168 | # has become 'long long', gcc -pedantic becomes unbearable (moreso | |
169 | # when combined with -Wall) because long long and LL and %lld|%Ld | |
170 | # become warn-worthy. So let's drop the -pedantic in that case. | |
171 | case "$quadtype:$sPRId64" in | |
172 | "long long"*|*lld*|*Ld*) | |
173 | ccflags="`echo $ccflags|sed 's/-pedantic/ /'`" | |
174 | warn="`echo $warn|sed 's/-pedantic/ /'`" | |
175 | ;; | |
176 | esac | |
215ed6ce AD |
177 | # Similarly, since 'long long' isn't part of C89, FreeBSD 6.2 headers |
178 | # don't declare atoll() under -std=c89, but we need it. In general, | |
179 | # insisting on -std=c89 is inconsistent with insisting on using | |
180 | # 'long long'. So drop -std=c89 and -ansi as well if we're using | |
181 | # 'long long' as our main integral type. | |
182 | case "$ivtype" in | |
183 | "long long") | |
184 | ccflags=`echo $ccflags|sed -e 's/-pedantic/ /' -e 's/-std=c89/ /' -e 's/-ansi/ /'` | |
185 | warn=`echo $warn|sed -e 's/-pedantic/ /' -e 's/-ansi/ /'` | |
a5105380 | 186 | stdflags=`echo $stdflags|sed -e 's/-std=c89/ /'` |
215ed6ce AD |
187 | ;; |
188 | esac | |
3e8416a3 | 189 | fi |
5cf489d6 RGS |
190 | # Using certain features (like the gcc statement expressions) |
191 | # requires knowing whether -pedantic has been specified. | |
9ac4c107 JH |
192 | case "$warn$ccflags" in |
193 | *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;; | |
194 | esac | |
a07cd53d JH |
195 | ;; |
196 | esac | |
b1e55cab | 197 | |
10edeb5d | 198 | # Code to set any extra flags here. |
a07cd53d | 199 | extra='' |
11fcce85 | 200 | |
2b317908 LW |
201 | echo "Extracting cflags (with variable substitutions)" |
202 | : This section of the file will have variable substitutions done on it. | |
203 | : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!. | |
204 | : Protect any dollar signs and backticks that you do not want interpreted | |
205 | : by putting a backslash in front. You may delete these comments. | |
165b7424 | 206 | rm -f cflags |
2b317908 | 207 | $spitshell >cflags <<!GROK!THIS! |
ecfc5424 | 208 | $startsh |
bc730b18 | 209 | |
11fcce85 | 210 | # Extra warnings, used e.g. for gcc. |
bc730b18 | 211 | warn="$warn" |
11fcce85 JH |
212 | # Extra standardness. |
213 | stdflags="$stdflags" | |
b1e55cab JH |
214 | # Extra extra. |
215 | extra="$extra" | |
bc730b18 | 216 | |
2b317908 LW |
217 | !GROK!THIS! |
218 | ||
219 | : In the following dollars and backticks do not need the extra backslash. | |
220 | $spitshell >>cflags <<'!NO!SUBS!' | |
a02608de | 221 | case $PERL_CONFIG_SH in |
2b317908 | 222 | '') |
a0d0e21e LW |
223 | if test -f config.sh; then TOP=.; |
224 | elif test -f ../config.sh; then TOP=..; | |
225 | elif test -f ../../config.sh; then TOP=../..; | |
226 | elif test -f ../../../config.sh; then TOP=../../..; | |
227 | elif test -f ../../../../config.sh; then TOP=../../../..; | |
228 | else | |
229 | echo "Can't find config.sh."; exit 1 | |
230 | fi | |
231 | . $TOP/config.sh | |
232 | ;; | |
233 | esac | |
234 | ||
75550b4e PG |
235 | : syntax: cflags [optimize=XXX] [file[.suffix]] |
236 | : displays the compiler command line for file | |
237 | ||
1167a30e | 238 | case "X$1" in |
26102cc7 | 239 | Xoptimize=*|X"optimize=*") |
1167a30e IZ |
240 | eval "$1" |
241 | shift | |
242 | ;; | |
243 | esac | |
244 | ||
1c3d792e LW |
245 | also=': ' |
246 | case $# in | |
2b317908 | 247 | 1) also='echo 1>&2 " CCCMD = "' |
1c3d792e LW |
248 | esac |
249 | ||
250 | case $# in | |
251 | 0) set *.c; echo "The current C flags are:" ;; | |
1c3d792e | 252 | esac |
2b317908 | 253 | |
578789a7 | 254 | set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"` |
2b317908 | 255 | |
1c3d792e LW |
256 | for file do |
257 | ||
258 | case "$#" in | |
259 | 1) ;; | |
2b317908 | 260 | *) echo $n " $file.c $c" ;; |
1c3d792e LW |
261 | esac |
262 | ||
2b317908 LW |
263 | : allow variables like toke_cflags to be evaluated |
264 | ||
8736538c AS |
265 | if echo $file | grep -v / >/dev/null |
266 | then | |
267 | eval 'eval ${'"${file}_cflags"'-""}' | |
268 | fi | |
2b317908 LW |
269 | |
270 | : or customize here | |
271 | ||
1c3d792e | 272 | case "$file" in |
a0d0e21e LW |
273 | DB_File) ;; |
274 | GDBM_File) ;; | |
2304df62 AD |
275 | NDBM_File) ;; |
276 | ODBM_File) ;; | |
277 | POSIX) ;; | |
278 | SDBM_File) ;; | |
279 | av) ;; | |
4b6be2dd | 280 | byterun) ;; |
2304df62 AD |
281 | deb) ;; |
282 | dl) ;; | |
2b317908 | 283 | doio) ;; |
2304df62 | 284 | doop) ;; |
2b317908 | 285 | dump) ;; |
59bea8cf | 286 | globals) ;; |
2304df62 AD |
287 | gv) ;; |
288 | hv) ;; | |
a6ec74c1 | 289 | locale) ;; |
59bea8cf | 290 | madly) ;; |
2304df62 | 291 | main) ;; |
2b317908 | 292 | malloc) ;; |
2304df62 AD |
293 | mg) ;; |
294 | miniperlmain) ;; | |
a6ec74c1 | 295 | numeric) ;; |
2304df62 | 296 | op) ;; |
59bea8cf JH |
297 | opmini) ;; |
298 | pad) ;; | |
2b317908 | 299 | perl) ;; |
6f4183fe | 300 | perlapi) ;; |
2304df62 | 301 | perlmain) ;; |
2b317908 | 302 | perly) ;; |
2304df62 | 303 | pp) ;; |
a0d0e21e LW |
304 | pp_ctl) ;; |
305 | pp_hot) ;; | |
a6ec74c1 | 306 | pp_pack) ;; |
59bea8cf | 307 | pp_sort) ;; |
a0d0e21e | 308 | pp_sys) ;; |
2b317908 LW |
309 | regcomp) ;; |
310 | regexec) ;; | |
2304df62 AD |
311 | run) ;; |
312 | scope) ;; | |
313 | sv) ;; | |
314 | taint) ;; | |
2b317908 | 315 | toke) ;; |
59bea8cf | 316 | universal) ;; |
2b317908 | 317 | usersub) ;; |
59bea8cf | 318 | utf8) ;; |
2b317908 | 319 | util) ;; |
59bea8cf | 320 | xsutils) ;; |
1c3d792e LW |
321 | *) ;; |
322 | esac | |
323 | ||
666ea192 | 324 | case "$cc" in |
7e827271 | 325 | *g++*) |
9ac4c107 JH |
326 | # Extra paranoia in case people have bad canned ccflags: |
327 | # bad in the sense that the flags are accepted by g++, | |
328 | # but then whined about. | |
329 | for f in -Wdeclaration-after-statement -std=c89 | |
330 | do | |
59497074 | 331 | ccflags=`echo $ccflags|sed 's/$f/ /'` |
9ac4c107 | 332 | done |
7e827271 JH |
333 | ;; |
334 | esac | |
4f3b19ea | 335 | cppflags=`echo $cppflags|sed 's/-Wdeclaration-after-statement/ /'` |
7e827271 JH |
336 | |
337 | case "$cc" in | |
338 | *g++*) | |
339 | # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable | |
a7ae1e4a JH |
340 | # because of all the warnings about Perl___notused, and g++ doesn't do |
341 | # __attribute__((unused)) (and even if at some stage it may, people do | |
342 | # have older gcc installations), and ((void)x) isn't enough to silence | |
343 | # the noises about XS functions not using their cv parameter, so we need | |
344 | # the -Wno-unused-parameter too. | |
345 | # Yes, we lose some valid warnings, but hopefully other compilers | |
346 | # (like gcc) will still pick up those warnings. | |
347 | for o in -Wno-unused-variable -Wno-unused-parameter | |
7e827271 JH |
348 | do |
349 | case "$warn" in | |
350 | *$o*) ;; | |
351 | *) warn="$warn $o" ;; | |
352 | esac | |
353 | done | |
354 | ;; | |
666ea192 JH |
355 | esac |
356 | ||
69c7f294 NC |
357 | if test -f .patch; then |
358 | ccflags="-DPERL_PATCHNUM=`cat .patch` $ccflags" | |
359 | fi | |
360 | ||
c4f23d77 | 361 | : Can we perhaps use $ansi2knr here |
b1e55cab JH |
362 | echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra" |
363 | eval "$also "'"$cc -DPERL_CORE -c $ccflags $stdflags $optimize $warn $extra"' | |
2b317908 | 364 | |
a0d0e21e | 365 | . $TOP/config.sh |
2b317908 | 366 | |
1c3d792e | 367 | done |
2b317908 | 368 | !NO!SUBS! |
a0d0e21e | 369 | chmod 755 cflags |
2b317908 | 370 | $eunicefix cflags |