OSDN Git Service

Probe for -Wno-string-plus-int.
authorRob Landley <rob@landley.net>
Sat, 9 May 2015 22:07:22 +0000 (17:07 -0500)
committerRob Landley <rob@landley.net>
Sat, 9 May 2015 22:07:22 +0000 (17:07 -0500)
LLVM has its own nuts warnings about things that aren't wrong, but disabling
them with the relevant -Wno-* warning disabling command line option drives
gcc nuts because it's a command line option it doesn't recognize. (gcc 4.2.1
dies with an error. gcc 4.6 warns about it _only_ if it's warning about
something else. (PICK ONE, either you warn about this or you don't, distract
people from actual problems with noise about something clearly unrelated to
what just changed is extra-stupid.)

So just probe for it, and add the flag only if it doesn't complain about it
while we're producing an unrelated warning.

configure
scripts/genconfig.sh
scripts/make.sh

index 5831e1a..21d56f3 100644 (file)
--- a/configure
+++ b/configure
@@ -7,7 +7,7 @@
 
 # CFLAGS and OPTIMIZE are different so you can add extra CFLAGS without
 # disabling default optimizations
-[ -z "$CFLAGS" ] && CFLAGS="-Wall -Wundef -Wno-char-subscripts -Wno-string-plus-int"
+[ -z "$CFLAGS" ] && CFLAGS="-Wall -Wundef -Wno-char-subscripts"
 # Required for our expected ABI. we're 8-bit clean thus "char" must be unsigned.
 CFLAGS="$CFLAGS -funsigned-char"
 [ -z "$OPTIMIZE" ] && OPTIMIZE="-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables"
index b8dc3c7..313c7c7 100755 (executable)
@@ -7,12 +7,16 @@ mkdir -p generated
 
 source configure
 
+probecc()
+{
+  ${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $1 -
+}
+
 # Probe for a single config symbol with a "compiles or not" test.
 # Symbol name is first argument, flags second, feed C file to stdin
 probesymbol()
 {
-  ${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $2 - 2>/dev/null
-  [ $? -eq 0 ] && DEFAULT=y || DEFAULT=n
+  probecc $2 2>/dev/null && DEFAULT=y || DEFAULT=n
   rm a.out 2>/dev/null
   echo -e "config $1\n\tbool" || exit 1
   echo -e "\tdefault $DEFAULT\n" || exit 1
@@ -20,6 +24,13 @@ probesymbol()
 
 probeconfig()
 {
+  > generated/cflags
+  # llvm produces its own really stupid warnings about things that aren't wrong,
+  # and although you can turn the warning off, gcc reacts badly to command line
+  # arguments it doesn't understand. So probe.
+  [ -z "$(probecc -Wno-string-plus-int <<< \#warn warn 2>&1 | grep string-plus-int)" ] &&
+    echo -Wno-string-plus-int >> generated/cflags
+
   # Probe for container support on target
   probesymbol TOYBOX_CONTAINER << EOF
     #include <linux/sched.h>
index 56fcc7e..7ebe148 100755 (executable)
@@ -62,6 +62,7 @@ GITHASH="$(git describe --tags --abbrev=12 2>/dev/null)"
 [ ! -z "$GITHASH" ] && GITHASH="-DTOYBOX_VERSION=\"$GITHASH\""
 TOYFILES="$(sed -n 's/^CONFIG_\([^=]*\)=.*/\1/p' "$KCONFIG_CONFIG" | xargs | tr ' [A-Z]' '|[a-z]')"
 TOYFILES="$(egrep -l "TOY[(]($TOYFILES)[ ,]" toys/*/*.c)"
+CFLAGS="$CFLAGS $(cat generated/cflags)"
 BUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE $GITHASH)"
 FILES="$(echo lib/*.c main.c $TOYFILES)"