This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Skip this test if "use open" fails due to an unknown encoding
[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; then
21     . ./config_h.SH
22 fi
23
24 warn=''
25
26 # Add -Wall for the core modules iff gcc and not already -Wall
27 case "$gccversion" in
28 '') ;;
29 Intel*) ;; # 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     ;;
35 esac
36
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
41 cat >_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  */
98 int 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
114 stdflags=''
115
116 # Further gcc warning options.
117 case "$gccversion" in
118 '') ;;
119 [12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
120 Intel*) ;; # # Is that you, Intel C++?
121 *)  for opt in -ansi -pedantic -std=c89 -W -Wextra -Wdeclaration-after-statement -Wendif-labels
122     do
123        case " $ccflags " in
124        *" $opt "*) ;; # Skip if already there.
125        *) rm -f _cflags$_exe
126           case "`$cc $cflags $opt _cflags.c -o _cflags$_exe 2>&1`" in
127           *"unrecognized"*) ;;
128           *"Invalid"*) ;;
129           *"is valid for C"*) ;;
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              ;;
138           esac
139           ;;
140        esac
141     done
142     ;;
143 esac
144 rm -f _cflags.c _cflags$_exe
145
146 case "$gccversion" in
147 '') ;;
148 *)
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
161   # Using certain features (like the gcc statement expressions)
162   # requires knowing whether -pedantic has been specified.
163   case "$warn$ccflags" in
164   *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
165   esac
166   ;;
167 esac
168
169 # Code to set any extra flags here.
170 extra=''
171
172 echo "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.
177 rm -f cflags
178 $spitshell >cflags <<!GROK!THIS!
179 $startsh
180
181 # Extra warnings, used e.g. for gcc.
182 warn="$warn"
183 # Extra standardness.
184 stdflags="$stdflags"
185 # Extra extra.
186 extra="$extra"
187
188 !GROK!THIS!
189
190 : In the following dollars and backticks do not need the extra backslash.
191 $spitshell >>cflags <<'!NO!SUBS!'
192 case $PERL_CONFIG_SH in
193 '')
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         ;;
204 esac
205
206 : syntax: cflags [optimize=XXX] [file[.suffix]]
207 : displays the compiler command line for file
208
209 case "X$1" in
210 Xoptimize=*|X"optimize=*")
211         eval "$1"
212         shift
213         ;;
214 esac
215
216 also=': '
217 case $# in
218 1) also='echo 1>&2 "      CCCMD = "'
219 esac
220
221 case $# in
222 0) set *.c; echo "The current C flags are:" ;;
223 esac
224
225 set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
226
227 for file do
228
229     case "$#" in
230     1) ;;
231     *) echo $n "    $file.c     $c" ;;
232     esac
233
234     : allow variables like toke_cflags to be evaluated
235
236     if echo $file | grep -v / >/dev/null
237     then
238       eval 'eval ${'"${file}_cflags"'-""}'
239     fi
240
241     : or customize here
242
243     case "$file" in
244     DB_File) ;;
245     GDBM_File) ;;
246     NDBM_File) ;;
247     ODBM_File) ;;
248     POSIX) ;;
249     SDBM_File) ;;
250     av) ;;
251     byterun) ;;
252     deb) ;;
253     dl) ;;
254     doio) ;;
255     doop) ;;
256     dump) ;;
257     globals) ;;
258     gv) ;;
259     hv) ;;
260     locale) ;;
261     madly) ;;
262     main) ;;
263     malloc) ;;
264     mg) ;;
265     miniperlmain) ;;
266     numeric) ;;
267     op) ;;
268     opmini) ;;
269     pad) ;;
270     perl) ;;
271     perlapi) ;;
272     perlmain) ;;
273     perly) ;;
274     pp) ;;
275     pp_ctl) ;;
276     pp_hot) ;;
277     pp_pack) ;;
278     pp_sort) ;;
279     pp_sys) ;;
280     regcomp) ;;
281     regexec) ;;
282     run) ;;
283     scope) ;;
284     sv) ;;
285     taint) ;;
286     toke) ;;
287     universal) ;;
288     usersub) ;;
289     utf8) ;;
290     util) ;;
291     xsutils) ;;
292     *) ;;
293     esac
294
295 case "$cc" in
296 *g++*)
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
304   ;;
305 esac
306
307 case "$cc" in
308 *g++*)
309   # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
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
318   do
319     case "$warn" in
320     *$o*) ;;
321     *) warn="$warn $o" ;;
322     esac
323   done
324   ;;
325 esac
326
327 if test -f .patch; then
328   ccflags="-DPERL_PATCHNUM=`cat .patch` $ccflags"
329 fi
330
331     : Can we perhaps use $ansi2knr here
332     echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra"
333     eval "$also "'"$cc -DPERL_CORE -c $ccflags $stdflags $optimize $warn $extra"'
334
335     . $TOP/config.sh
336
337 done
338 !NO!SUBS!
339 chmod 755 cflags
340 $eunicefix cflags