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