This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The op slab allocator can call calloc() instead of malloc(), and save
[perl5.git] / cflags.SH
1 case $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         ;;
13 esac
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.
16 case "$0" in
17 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
18 esac
19
20 if test -f config_h.SH -a ! -f config.h; then
21     . ./config_h.SH
22     CONFIG_H=already-done
23 fi
24
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
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
69 #ifdef I_SYSTYPES
70 #include <sys/types.h>
71 #endif
72 #ifdef I_SYSPARAM
73 #include <sys/param.h>
74 #endif
75 #ifdef I_SYSRESOURCE
76 #include <sys/resource.h>
77 #endif
78 #ifdef I_SYSSELECT
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_SYSSTAT
85 #include <sys/stat.h>
86 #endif
87 #ifdef I_SYSTIME
88 #include <sys/time.h>
89 #endif
90 #ifdef I_SYSTIMES
91 #include <sys/times.h>
92 #endif
93 #ifdef I_SYSWAIT
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
107   Off_t t0a = 2;
108   STRLEN t0b = 3;
109   int t0c = t0a == t0b;
110
111   return 0;
112 }
113 __EOT__
114
115 stdflags=''
116
117 # Further gcc warning options.
118 case "$gccversion" in
119 '') ;;
120 [12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
121 Intel*) ;; # # Is that you, Intel C++?
122 *)  for opt in -ansi -pedantic -std=c89 -W -Wextra -Wdeclaration-after-statement -Wendif-labels -Wc++-compat
123     do
124        case " $ccflags " in
125        *" $opt "*) ;; # Skip if already there.
126        *) rm -f _cflags$_exe
127           case "`$cc $cflags $opt _cflags.c -o _cflags$_exe 2>&1`" in
128           *"unrecognized"*) ;;
129           *"Invalid"*) ;;
130           *"is valid for C"*) ;;
131           *) if test -x _cflags$_exe
132              then
133                case "$opt" in
134                -std*) stdflags="$stdflags $opt" ;;
135                *) warn="$warn $opt" ;;
136                esac
137              fi
138              ;;
139           esac
140           ;;
141        esac
142     done
143     ;;
144 esac
145 rm -f _cflags.c _cflags$_exe
146
147 case "$gccversion" in
148 '') ;;
149 *)
150   if [ "$gccansipedantic" = "" ]; then
151     # If we have -Duse64bitint (or equivalent) in effect and the quadtype
152     # has become 'long long', gcc -pedantic becomes unbearable (moreso
153     # when combined with -Wall) because long long and LL and %lld|%Ld
154     # become warn-worthy.  So let's drop the -pedantic in that case.
155     case "$quadtype:$sPRId64" in
156     "long long"*|*lld*|*Ld*)
157       ccflags="`echo $ccflags|sed 's/-pedantic/ /'`"
158       warn="`echo $warn|sed 's/-pedantic/ /'`"
159       ;;
160     esac
161   fi
162   # Using certain features (like the gcc statement expressions)
163   # requires knowing whether -pedantic has been specified.
164   case "$warn$ccflags" in
165   *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
166   esac
167   ;;
168 esac
169
170 # Code to set any extra flags here.
171 extra=''
172
173 echo "Extracting cflags (with variable substitutions)"
174 : This section of the file will have variable substitutions done on it.
175 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
176 : Protect any dollar signs and backticks that you do not want interpreted
177 : by putting a backslash in front.  You may delete these comments.
178 rm -f cflags
179 $spitshell >cflags <<!GROK!THIS!
180 $startsh
181
182 # Extra warnings, used e.g. for gcc.
183 warn="$warn"
184 # Extra standardness.
185 stdflags="$stdflags"
186 # Extra extra.
187 extra="$extra"
188
189 !GROK!THIS!
190
191 : In the following dollars and backticks do not need the extra backslash.
192 $spitshell >>cflags <<'!NO!SUBS!'
193 case $PERL_CONFIG_SH in
194 '')
195         if 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         elif test -f ../../../../config.sh; then TOP=../../../..;
200         else
201                 echo "Can't find config.sh."; exit 1
202         fi
203         . $TOP/config.sh
204         ;;
205 esac
206
207 : syntax: cflags [optimize=XXX] [file[.suffix]]
208 : displays the compiler command line for file
209
210 case "X$1" in
211 Xoptimize=*|X"optimize=*")
212         eval "$1"
213         shift
214         ;;
215 esac
216
217 also=': '
218 case $# in
219 1) also='echo 1>&2 "      CCCMD = "'
220 esac
221
222 case $# in
223 0) set *.c; echo "The current C flags are:" ;;
224 esac
225
226 set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
227
228 for file do
229
230     case "$#" in
231     1) ;;
232     *) echo $n "    $file.c     $c" ;;
233     esac
234
235     : allow variables like toke_cflags to be evaluated
236
237     if echo $file | grep -v / >/dev/null
238     then
239       eval 'eval ${'"${file}_cflags"'-""}'
240     fi
241
242     : or customize here
243
244     case "$file" in
245     DB_File) ;;
246     GDBM_File) ;;
247     NDBM_File) ;;
248     ODBM_File) ;;
249     POSIX) ;;
250     SDBM_File) ;;
251     av) ;;
252     byterun) ;;
253     deb) ;;
254     dl) ;;
255     doio) ;;
256     doop) ;;
257     dump) ;;
258     globals) ;;
259     gv) ;;
260     hv) ;;
261     locale) ;;
262     madly) ;;
263     main) ;;
264     malloc) ;;
265     mg) ;;
266     miniperlmain) ;;
267     numeric) ;;
268     op) ;;
269     opmini) ;;
270     pad) ;;
271     perl) ;;
272     perlapi) ;;
273     perlmain) ;;
274     perly) ;;
275     pp) ;;
276     pp_ctl) ;;
277     pp_hot) ;;
278     pp_pack) ;;
279     pp_sort) ;;
280     pp_sys) ;;
281     regcomp) ;;
282     regexec) ;;
283     run) ;;
284     scope) ;;
285     sv) ;;
286     taint) ;;
287     toke) ;;
288     universal) ;;
289     usersub) ;;
290     utf8) ;;
291     util) ;;
292     xsutils) ;;
293     *) ;;
294     esac
295
296 case "$cc" in
297 *g++*)
298   # Extra paranoia in case people have bad canned ccflags:
299   # bad in the sense that the flags are accepted by g++,
300   # but then whined about.
301   for f in -Wdeclaration-after-statement -std=c89
302   do
303     ccflags=`echo $ccflags|sed 's/$f/ /'`
304   done
305   ;;
306 esac
307
308 case "$cc" in
309 *g++*)
310   # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
311   # because of all the warnings about Perl___notused, and g++ doesn't do
312   # __attribute__((unused)) (and even if at some stage it may, people do
313   # have older gcc installations), and ((void)x) isn't enough to silence
314   # the noises about XS functions not using their cv parameter, so we need
315   # the -Wno-unused-parameter too.
316   # Yes, we lose some valid warnings, but hopefully other compilers
317   # (like gcc) will still pick up those warnings.
318   for o in -Wno-unused-variable -Wno-unused-parameter
319   do
320     case "$warn" in
321     *$o*) ;;
322     *) warn="$warn $o" ;;
323     esac
324   done
325   ;;
326 esac
327
328 if test -f .patch; then
329   ccflags="-DPERL_PATCHNUM=`cat .patch` $ccflags"
330 fi
331
332     : Can we perhaps use $ansi2knr here
333     echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra"
334     eval "$also "'"$cc -DPERL_CORE -c $ccflags $stdflags $optimize $warn $extra"'
335
336     . $TOP/config.sh
337
338 done
339 !NO!SUBS!
340 chmod 755 cflags
341 $eunicefix cflags