summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xConfigure49
-rw-r--r--Cross/cflags-cross-arm16
-rwxr-xr-xcflags.SH89
3 files changed, 78 insertions, 76 deletions
diff --git a/Configure b/Configure
index 5879d7a233..4bb420f7a7 100755
--- a/Configure
+++ b/Configure
@@ -4665,6 +4665,55 @@ case "$gccversion" in
esac
esac
+# Really old versions of gcc default to C89 and will error for this code.
+# See if the compiler (gcc or otherwise) needs a flag to compile C99 code
+# Initialisations in for loops seem to be the particular problem
+# (Does this syntax conflict with something else that was valid C89?)
+# Annoyingly -std=c99 will cause gcc to tell glibc not to define prototypes for
+# syscall, drand48 etc when including <unistd.h>, which messes up our build.
+# I guess we *could* loop round trying -std=c99 first with checks both for the
+# prototype found and the code compiling (because -std=gnu99 might do other
+# things we don't want, particularly on non-GCC compilers) but
+# 1) We would need to check for the prototype first (without any flags)
+# 2) We would still end up with most Linux systems either being -std=gnu99
+# or "" (no flag), and so both common options would not rigorously check our
+# portability to other platforms.
+# So it doesn't seem worth the complexity and chance of different failure.
+$cat >try.c <<'EOCP'
+int main(int argc, char **argv) {
+ unsigned long long count = 0;
+ for (char **p = argv; *p; ++p) {
+ ++count;
+ }
+ return count == 1 ? 0 : 1;
+}
+EOCP
+c99_for=no
+for flag in '' '-std=gnu99' '-std=c99'; do
+ if $cc -o try $flag $ccflags $ldflags try.c 2>/dev/null && ./try; then
+ c99_for="$flag"
+ break;
+ fi
+done
+case "$c99_for" in
+'') echo "Your C compiler doesn't need any special flags to compile C99 for loops with declarations"
+ ;;
+no) echo "Your C compiler doesn't seem to be able to compile C99 for loops with declarations"
+ rp='Do you really want to continue?'
+ dflt='n'
+ . ./myread
+ case "$ans" in
+ [yY]) echo >&4 "Okay, continuing." ;;
+ *) exit 1 ;;
+ esac
+ ;;
+*) echo "Your C compiler needs $c99_for to compile C99 for loops with declarations"
+ ccflags="$c99_for $ccflags"
+ ;;
+esac
+$rm -f try try.*
+
+
: What should the include directory be ?
: Use sysroot if set, so findhdr looks in the right place.
echo " "
diff --git a/Cross/cflags-cross-arm b/Cross/cflags-cross-arm
index 93d4f1eaee..4d7f05a4f6 100644
--- a/Cross/cflags-cross-arm
+++ b/Cross/cflags-cross-arm
@@ -1,9 +1,9 @@
#!/bin/sh
# Extra warnings, used e.g. for gcc.
-warn="-Wall -ansi -W -Wextra -Wdeclaration-after-statement -Wendif-labels -Wc++-compat"
+warn="-Wall -W -Wextra -Wendif-labels -Wc++-compat"
# Extra standardness.
-stdflags=" -std=c89"
+stdflags=" -std=c99"
# Extra extra.
extra=""
@@ -113,18 +113,6 @@ for file do
case "$cc" in
*g++*)
- # Extra paranoia in case people have bad canned ccflags:
- # bad in the sense that the flags are accepted by g++,
- # but then whined about.
- for f in -Wdeclaration-after-statement -std=c89
- do
- ccflags=`echo $ccflags|sed 's/$f/ /'`
- done
- ;;
-esac
-
-case "$cc" in
-*g++*)
# Without -Wno-unused-variable g++ 4.x compiles are rather unwatchable
# because of all the warnings about Perl___notused, and g++ doesn't do
# __attribute__((unused)) (and even if at some stage it may, people do
diff --git a/cflags.SH b/cflags.SH
index 162538583d..3244a56969 100755
--- a/cflags.SH
+++ b/cflags.SH
@@ -146,8 +146,7 @@ stdflags=''
# one individually.
# TODO: Ponder whether to migrate this back to Configure so hints files can
# tweak it. Also, be paranoid about whether results we've deduced in Configure
-# (especially about things like long long, which are not in C89) will still be
-# valid if we now add flags like -std=c89.
+# will still be valid if we now add flags like -std=c99.
pedantic=''
case "$gccansipedantic" in
@@ -159,36 +158,39 @@ case "$gccversion" in
[12].*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
Intel*) ;; # # Is that you, Intel C++?
#
-# NOTE 1: the -std=c89 without -pedantic is a bit pointless.
-# Just -std=c89 means "if there is room for interpretation,
-# interpret the C89 way." It does NOT mean "strict C89" on its own.
+# These comments are adapted from the originals, which were for -std=c89.
+# I believe that my updates close to correct, and better than throwing the
+# entire comments away, but please check for discrepencies.
+#
+# NOTE 1: the -std=c99 without -pedantic is a bit pointless.
+# Just -std=c99 means "if there is room for interpretation,
+# interpret the C99 way." It does NOT mean "strict C99" on its own.
# You need to add the -pedantic for that. To do this with Configure,
-# do -Dgccansipedantic (note that the -ansi is included in any case,
-# the option is a bit oddly named, for historical reasons.)
+# do -Dgccansipedantic (note that this is named from the time when we also
+# added the -ansi option. That forces -std=c89, so we no longer use it.)
+# *Because* we aren't adding -std=c99 if we don't have to, but will add -W,
+# some versions of gcc will accept C99 code but warn about not-C89 features.
+# (If we added -std=c99 then the warnings enabled by -W would be consistent)
+# Hence we add -Wno-long-long and -Wno-declaration-after-statement to cover
+# these cases.
#
# NOTE 2: -pedantic necessitates adding a couple of flags:
# * -PERL_GCC_PEDANTIC so that the perl code can adapt: there's nothing
# added by gcc itself to indicate pedanticness.
# * -Wno-overlength-strings under -DDEBUGGING because quite many of
# the LEAVE_with_name() and assert() calls generate string literals
-# longer then the ANSI minimum of 509 bytes.
+# longer then the ANSI C99 minimum of 4095 bytes.
#
# NOTE 3: the relative order of these options matters:
# -Wextra before -W
-# -std=c89 before -ansi
-# -pedantic* before -Werror=d-a-s
+# -W before -Wno-long-long -Wno-declaration-after-statement
#
-*) warns="-std=c89 -ansi $pedantic \
+*) warns="-std=c99 $pedantic \
-Werror=pointer-arith \
-Werror=vla \
-Wextra -W \
+ -Wno-long-long -Wno-declaration-after-statement \
-Wc++-compat -Wwrite-strings"
- # declaration after statement is normal in C++ rather than an
- # extension and compilers complain if we try to warn about it
- case "$d_cplusplus" in
- define) ;;
- *) warns="$warns -Werror=declaration-after-statement" ;;
- esac
for opt in $warns
do
case " $ccflags " in
@@ -215,17 +217,6 @@ Intel*) ;; # # Is that you, Intel C++?
echo "cflags.SH: Adding $opt."
stdflags="$stdflags $opt"
;;
- -ansi)
- # -std=c89 is the modern form of -ansi, so add
- # -ansi only if -std=c89 is not there already.
- case " $stdflags " in
- *-std=c89*) ;;
- *)
- echo "cflags.SH: Adding $opt."
- stdflags="$stdflags $opt"
- ;;
- esac
- ;;
-W)
# -Wextra is the modern form of -W, so add
# -W only if -Wextra is not there already.
@@ -237,16 +228,6 @@ Intel*) ;; # # Is that you, Intel C++?
;;
esac
;;
- -Werror=declaration-after-statement)
- # -pedantic* (with -std=c89) covers -Werror=d-a-s.
- case "$stdflags$warn" in
- *-std=c89*-pedantic*|*-pedantic*-std=c89*) ;;
- *)
- echo "cflags.SH: Adding $opt."
- warn="$warn $opt"
- ;;
- esac
- ;;
-Werror=pointer-arith)
# -pedantic* covers -Werror=p-a
case "$warn" in
@@ -293,22 +274,14 @@ case "$gccversion" in
*)
case "$warn$ccflags" in
*-pedantic*)
- # If we have -Duse64bitint (or equivalent) in effect and the quadtype
- # has become 'long long', gcc -pedantic* becomes unbearable
- # (moreso when combined with -Wall) because long long and LL and %lld|%Ld
- # become warn-worthy. So let's drop the -pedantic in that case.
- #
- # Similarly, since 'long long' isn't part of C89, FreeBSD 6.2 headers
- # don't declare atoll() under -std=c89, but we need it. In general,
- # insisting on -std=c89 is inconsistent with insisting on using
- # 'long long'. So drop -std=c89 and -ansi as well if we're using
- # 'long long' as our main integral type.
+ # For -std=c99 -pedantic, only the %Ld format seems to be warn-worthy.
+ # 'long long' and '%lld' are now kosher.
#
# usedtrace (DTrace) uses unportable features (dollars in identifiers,
# and gcc statement expressions), it is just easier to turn off pedantic.
remove=''
case "$quadtype:$ivtype:$sPRId64:$usedtrace" in
- *"long long"*|*lld*|*Ld*) remove='long long' ;;
+ **Ld*) remove='Ld' ;;
*) case "$usedtrace" in
define) remove='usedtrace' ;;
esac
@@ -316,10 +289,9 @@ case "$gccversion" in
esac
case "$remove" in
'') ;;
- *) echo "cflags.SH: Removing -pedantic*, -std=c89, and -ansi because of $remove."
- ccflags=`echo $ccflags|sed -e 's/-pedantic-errors/ /' -e 's/-pedantic/ /' -e 's/-std=c89/ /' -e 's/-ansi/ /' -e 's/-DPERL_GCC_PEDANTIC/ /'`
- warn=`echo $warn|sed -e 's/-pedantic-errors/ /' -e 's/-pedantic/ /' -e 's/-ansi/ /' -e 's/-DPERL_GCC_PEDANTIC/ /'`
- stdflags=`echo $stdflags|sed -e 's/-std=c89/ /'`
+ *) echo "cflags.SH: Removing -pedantic* -ansi because of $remove."
+ ccflags=`echo $ccflags|sed -e 's/-pedantic-errors/ /' -e 's/-pedantic/ /'`
+ warn=`echo $warn|sed -e 's/-pedantic-errors/ /' -e 's/-pedantic/ /'`
;;
esac
;;
@@ -358,13 +330,7 @@ case "$cc" in
# Extra paranoia in case people have bad canned ccflags:
# bad in the sense that the flags are accepted by g++,
# but then whined about.
- #
- # -Werror=d-a-s option is valid for g++, by definition,
- # but we remove it just for cleanliness and shorter command lines.
- for f in -Wdeclaration-after-statement \
- -Werror=declaration-after-statement \
- -Wc++-compat \
- -std=c89
+ for f in -Wc++-compat -std=c99
do
case "$ccflags$warn" in
*"$f"*)
@@ -377,8 +343,7 @@ case "$cc" in
;;
esac
-for f in -Wdeclaration-after-statement -Werror=declaration-after-statement \
- -Wpointer-arith -Werror=pointer-arith
+for f in -Wpointer-arith -Werror=pointer-arith
do
case "$cppflags" in
*"$f"*)