1 case $PERL_CONFIG_SH in
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=../../../..;
9 echo "Can't find config.sh."; exit 1
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.
17 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
20 if test -f config_h.SH -a ! -f config.h; then
27 # Add -Wall for the core modules iff gcc and not already -Wall
30 Intel*) ;; # The Intel C++ plays gcc on TV but is not really it.
33 *) warn="$warn -Wall" ;;
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.
42 cat >_cflags.c <<__EOT__
45 /* The stdio.h, errno.h, and setjmp.h should be there in any ANSI C89. */
49 /* Just in case the inclusion of perl.h did not
50 * pull in enough system headers, let's try again. */
70 #include <sys/types.h>
73 #include <sys/param.h>
76 #include <sys/resource.h>
79 #include <sys/select.h>
81 #if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* See perl.h. */
82 #include <sys/socket.h>
91 #include <sys/times.h>
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
99 int main(int argc, char *argv[]) {
101 /* Add here test code found to be problematic in some gcc platform. */
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. */
110 int t0c = t0a == t0b;
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.
118 return (!t0c && (iv == 42)) ? 0 : -1; /* Try to avoid 'unused' warnings. */
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
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.
133 case "$gccversion" in
135 [12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
136 Intel*) ;; # # Is that you, Intel C++?
137 *) for opt in -ansi -std=c89 -W -Wextra -Wdeclaration-after-statement \
138 -Wendif-labels -Wc++-compat -Wwrite-strings
141 *" $opt "*) ;; # Skip if already there.
142 *) rm -f _cflags$_exe
143 case "`$cc $cflags $warn $stdflags $opt _cflags.c -o _cflags$_exe 2>&1`" in
145 *"implicit declaration"*) ;; # Was something useful hidden?
147 *"is valid for C"*) ;;
148 *) if test -x _cflags$_exe
151 -std*) stdflags="$stdflags $opt" ;;
152 *) warn="$warn $opt" ;;
162 rm -f _cflags.c _cflags$_exe
164 case "$gccversion" in
167 if [ "$gccansipedantic" = "" ]; then
168 # If we have -Duse64bitint (or equivalent) in effect and the quadtype
169 # has become 'long long', gcc -pedantic becomes unbearable (moreso
170 # when combined with -Wall) because long long and LL and %lld|%Ld
171 # become warn-worthy. So let's drop the -pedantic in that case.
172 case "$quadtype:$sPRId64" in
173 "long long"*|*lld*|*Ld*)
174 ccflags="`echo $ccflags|sed 's/-pedantic/ /'`"
175 warn="`echo $warn|sed 's/-pedantic/ /'`"
178 # Similarly, since 'long long' isn't part of C89, FreeBSD 6.2 headers
179 # don't declare atoll() under -std=c89, but we need it. In general,
180 # insisting on -std=c89 is inconsistent with insisting on using
181 # 'long long'. So drop -std=c89 and -ansi as well if we're using
182 # 'long long' as our main integral type.
185 ccflags=`echo $ccflags|sed -e 's/-pedantic/ /' -e 's/-std=c89/ /' -e 's/-ansi/ /'`
186 warn=`echo $warn|sed -e 's/-pedantic/ /' -e 's/-ansi/ /'`
187 stdflags=`echo $stdflags|sed -e 's/-std=c89/ /'`
191 # Using certain features (like the gcc statement expressions)
192 # requires knowing whether -pedantic has been specified.
193 case "$warn$ccflags" in
194 *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
199 # Code to set any extra flags here.
202 echo "Extracting cflags (with variable substitutions)"
203 : This section of the file will have variable substitutions done on it.
204 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
205 : Protect any dollar signs and backticks that you do not want interpreted
206 : by putting a backslash in front. You may delete these comments.
208 $spitshell >cflags <<!GROK!THIS!
211 # Extra warnings, used e.g. for gcc.
213 # Extra standardness.
217 # what do executables look like?
222 : In the following dollars and backticks do not need the extra backslash.
223 $spitshell >>cflags <<'!NO!SUBS!'
224 case $PERL_CONFIG_SH in
226 if test -f config.sh; then TOP=.;
227 elif test -f ../config.sh; then TOP=..;
228 elif test -f ../../config.sh; then TOP=../..;
229 elif test -f ../../../config.sh; then TOP=../../..;
230 elif test -f ../../../../config.sh; then TOP=../../../..;
232 echo "Can't find config.sh."; exit 1
238 : syntax: cflags [optimize=XXX] [file[.suffix]]
239 : displays the compiler command line for file
242 Xoptimize=*|X"optimize=*")
250 1) also='echo 1>&2 " CCCMD = "'
254 0) set *.c; echo "The current C flags are:" ;;
257 set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
263 *) echo $n " $file.c $c" ;;
266 : allow variables like toke_cflags to be evaluated
268 if echo $file | grep -v / >/dev/null
270 eval 'eval ${'"${file}_cflags"'-""}'
278 *) : Customization examples follow: ;;
279 av) ccflags=`echo $ccflags | sed -e s/-pipe//` ;;
280 deb) ccflags="$ccflags -fno-jump-tables" ;;
281 hv) warn=`echo $warn | sed -e s/-Wextra//` ;;
282 toke) optimize=-O0 ;;
285 : The examples are intentionally unreachable as the '*)' case always
286 : matches. To use them, move before the '*)' and edit as appropriate.
287 : It is not a good idea to set ccflags to an absolute value here, as it
288 : often contains general -D defines which are needed for correct
289 : compilation. It is better to edit ccflags as shown, using interpolation
290 : to add flags, or sed to remove flags.
295 # Extra paranoia in case people have bad canned ccflags:
296 # bad in the sense that the flags are accepted by g++,
297 # but then whined about.
298 for f in -Wdeclaration-after-statement -std=c89
300 ccflags=`echo $ccflags|sed 's/$f/ /'`
304 cppflags=`echo $cppflags|sed 's/-Wdeclaration-after-statement/ /'`
308 # clang complains a lot about -Wunused-value which are not fixable
309 warn="$warn -Wno-unused-value"
312 # Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
313 # because of all the warnings about Perl___notused, and g++ doesn't do
314 # __attribute__((unused)) (and even if at some stage it may, people do
315 # have older gcc installations), and ((void)x) isn't enough to silence
316 # the noises about XS functions not using their cv parameter, so we need
317 # the -Wno-unused-parameter too.
318 # Yes, we lose some valid warnings, but hopefully other compilers
319 # (like gcc) will still pick up those warnings.
320 for o in -Wno-unused-variable -Wno-unused-parameter
324 *) warn="$warn $o" ;;
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"'
337 # end per file behaviour