3 # Generate the cflags script, which is used to determine what cflags
4 # to pass to the compiler.
5 # We create a temporary test c program and repeatedly compile it with
6 # various candidate flags, and from the compiler output, determine what
8 # From this we initialise the following variables in the cflags script:
15 case $PERL_CONFIG_SH in
17 if test -f config.sh; then TOP=.;
18 elif test -f ../config.sh; then TOP=..;
19 elif test -f ../../config.sh; then TOP=../..;
20 elif test -f ../../../config.sh; then TOP=../../..;
21 elif test -f ../../../../config.sh; then TOP=../../../..;
23 echo "Can't find config.sh."; exit 1
28 # This forces SH files to create target in same directory as SH file.
29 # This is so that make depend always knows where to find SH derivatives.
31 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
34 if test -f config_h.SH -a ! -f config.h; then
41 # Add -Wall for the core modules iff gcc and not already -Wall
44 Intel*) ;; # The Intel C++ plays gcc on TV but is not really it.
47 *) warn="$warn -Wall" ;;
52 # Create a test source file for testing what options can be fed to
53 # gcc in this system; include a selection of most common and commonly
54 # hairy include files.
56 cat >_cflags.c <<__EOT__
59 /* The stdio.h, errno.h, and setjmp.h should be there in any ANSI C89. */
63 /* Just in case the inclusion of perl.h did not
64 * pull in enough system headers, let's try again. */
84 #include <sys/types.h>
87 #include <sys/param.h>
90 #include <sys/resource.h>
93 #include <sys/select.h>
95 #if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* See perl.h. */
96 #include <sys/socket.h>
102 #include <sys/time.h>
105 #include <sys/times.h>
108 #include <sys/wait.h>
110 /* The gcc -ansi can cause a lot of noise in Solaris because of:
111 /usr/include/sys/resource.h:148: warning: 'struct rlimit64' declared inside parameter list
113 int main(int argc, char *argv[]) {
115 /* Add here test code found to be problematic in some gcc platform. */
117 /* Off_t/off_t is a struct in Solaris with largefiles, and with gcc -ansi
118 * that struct cannot be compared in some gcc releases with a flat
119 * integer, such as a STRLEN. */
124 int t0c = t0a == t0b;
126 /* In FreeBSD 6.2 (and probably other releases too), with -Duse64bitint,
127 perl will use atoll(3). However, that declaration is hidden in <stdlib.h>
128 if we force the compiler to use -std=c89 mode.
132 return (!t0c && (iv == 42)) ? 0 : -1; /* Try to avoid 'unused' warnings. */
138 # Further gcc warning options. Build up a list of options that work.
139 # Note that some problems may only show up with combinations of options,
140 # e.g. a warning might show up only with -Wall -ansi, not with either
142 # TODO: Ponder whether to migrate this back to Configure so hints files can
143 # tweak it. Also, be paranoid about whether results we've deduced in Configure
144 # (especially about things like long long, which are not in C89) will still be
145 # valid if we now add flags like -std=c89.
147 case "$gccversion" in
149 [12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
150 Intel*) ;; # # Is that you, Intel C++?
151 *) for opt in -ansi -std=c89 -W -Wextra -Wdeclaration-after-statement \
152 -Wendif-labels -Wc++-compat -Wwrite-strings
155 *" $opt "*) ;; # Skip if already there.
156 *) rm -f _cflags$_exe
157 case "`$cc -DPERL_NO_INLINE_FUNCTIONS $ccflags $warn $stdflags $opt _cflags.c -o _cflags$_exe 2>&1`" in
159 *"implicit declaration"*) ;; # Was something useful hidden?
161 *"is valid for C"*) ;;
162 *) if test -x _cflags$_exe
165 -std*) stdflags="$stdflags $opt" ;;
166 *) warn="$warn $opt" ;;
176 rm -f _cflags.c _cflags$_exe
178 case "$gccversion" in
181 if [ "$gccansipedantic" = "" ]; then
182 # If we have -Duse64bitint (or equivalent) in effect and the quadtype
183 # has become 'long long', gcc -pedantic becomes unbearable (moreso
184 # when combined with -Wall) because long long and LL and %lld|%Ld
185 # become warn-worthy. So let's drop the -pedantic in that case.
186 case "$quadtype:$sPRId64" in
187 "long long"*|*lld*|*Ld*)
188 ccflags="`echo $ccflags|sed 's/-pedantic/ /'`"
189 warn="`echo $warn|sed 's/-pedantic/ /'`"
192 # Similarly, since 'long long' isn't part of C89, FreeBSD 6.2 headers
193 # don't declare atoll() under -std=c89, but we need it. In general,
194 # insisting on -std=c89 is inconsistent with insisting on using
195 # 'long long'. So drop -std=c89 and -ansi as well if we're using
196 # 'long long' as our main integral type.
199 ccflags=`echo $ccflags|sed -e 's/-pedantic/ /' -e 's/-std=c89/ /' -e 's/-ansi/ /'`
200 warn=`echo $warn|sed -e 's/-pedantic/ /' -e 's/-ansi/ /'`
201 stdflags=`echo $stdflags|sed -e 's/-std=c89/ /'`
205 # Using certain features (like the gcc statement expressions)
206 # requires knowing whether -pedantic has been specified.
207 case "$warn$ccflags" in
208 *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
213 # Code to set any extra flags here.
216 echo "Extracting cflags (with variable substitutions)"
217 # This section of the file will have variable substitutions done on it.
218 # Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
219 # Protect any dollar signs and backticks that you do not want interpreted
220 # by putting a backslash in front. You may delete these comments.
222 $spitshell >cflags <<!GROK!THIS!
225 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
227 # This file is generated by cflags.SH
230 # Extra warnings, used e.g. for gcc.
232 # Extra standardness.
236 # what do executables look like?
241 # In the following dollars and backticks do not need the extra backslash.
242 $spitshell >>cflags <<'!NO!SUBS!'
243 case $PERL_CONFIG_SH in
245 if test -f config.sh; then TOP=.;
246 elif test -f ../config.sh; then TOP=..;
247 elif test -f ../../config.sh; then TOP=../..;
248 elif test -f ../../../config.sh; then TOP=../../..;
249 elif test -f ../../../../config.sh; then TOP=../../../..;
251 echo "Can't find config.sh."; exit 1
257 # syntax: cflags [optimize=XXX] [file[.suffix]] ...
258 # displays the proposed compiler command line for each 'file'
260 # with no file, dispalys it for all *.c files.
261 # The optimise=XXX arg (if present) is evalled, setting the default
262 # value of the $optimise variable, which is output on the command line
263 # (but which may be overridden for specific files below)
266 Xoptimize=*|X"optimize=*")
273 0) set *.c; echo "The current C flags are:" ;;
276 set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
282 *) echo $n " $file.c $c" ;;
285 # allow variables like toke_cflags to be evaluated
287 if echo $file | grep -v / >/dev/null
289 eval 'eval ${'"${file}_cflags"'-""}'
297 # Customization examples follow:
298 av) ccflags=`echo $ccflags | sed -e s/-pipe//` ;;
299 deb) ccflags="$ccflags -fno-jump-tables" ;;
300 hv) warn=`echo $warn | sed -e s/-Wextra//` ;;
301 toke) optimize=-O0 ;;
304 # The examples are intentionally unreachable as the '*)' case always
305 # matches. To use them, move before the '*)' and edit as appropriate.
306 # It is not a good idea to set ccflags to an absolute value here, as it
307 # often contains general -D defines which are needed for correct
308 # compilation. It is better to edit ccflags as shown, using interpolation
309 # to add flags, or sed to remove flags.
314 # Extra paranoia in case people have bad canned ccflags:
315 # bad in the sense that the flags are accepted by g++,
316 # but then whined about.
317 for f in -Wdeclaration-after-statement -std=c89
319 ccflags=`echo $ccflags|sed 's/$f/ /'`
323 cppflags=`echo $cppflags|sed 's/-Wdeclaration-after-statement/ /'`
327 # clang complains a lot about -Wunused-value which are not fixable
328 warn="$warn -Wno-unused-value"
331 # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
332 # because of all the warnings about Perl___notused, and g++ doesn't do
333 # __attribute__((unused)) (and even if at some stage it may, people do
334 # have older gcc installations), and ((void)x) isn't enough to silence
335 # the noises about XS functions not using their cv parameter, so we need
336 # the -Wno-unused-parameter too.
337 # Yes, we lose some valid warnings, but hopefully other compilers
338 # (like gcc) will still pick up those warnings.
339 for o in -Wno-unused-variable -Wno-unused-parameter
343 *) warn="$warn $o" ;;
348 # clang may not be called clang
349 case "`$cc -v 2>&1`" in
352 *-Wno-unused-value) ;;
353 *) warn="$warn -Wno-unused-value"
359 # Can we perhaps use $ansi2knr here
360 echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra"
364 # end per file behaviour