Makefile tweaking:
authorBernd Petrovitsch <bernd@firmix.at>
Tue, 1 May 2007 21:36:50 +0000 (21:36 +0000)
committerBernd Petrovitsch <bernd@firmix.at>
Tue, 1 May 2007 21:36:50 +0000 (21:36 +0000)
- gcc accepts different warnings on different versions. In an ideal world gcc could
  compare numbers to check for versions. Since make doesn't do this, we have now a shell scripts
  which kills not understand warnings.
- gather the -W options for CFLAGS in the WARNINGS variable so that we can pass them
  to the above script and on sub-makes.
- and pass said WARNINGS variable actually down
- if we have a default CC variable is is not empty, so the "?=" operator doesn't
  work that well.

Makefile
Makefile.inc
gcc-warnings [new file with mode: 0644]

index 1d53bf3..8974596 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@
 # to the project. For more information see the website or contact
 # the copyright holders.
 #
-# $Id: Makefile,v 1.83 2007/04/22 21:33:33 bernd67 Exp $
+# $Id: Makefile,v 1.84 2007/05/01 21:36:50 bernd67 Exp $
 
 VERS =         0.5.1pre
 
@@ -44,7 +44,7 @@ include Makefile.inc
 
 CFLAGS +=      -DVERSION=\"$(VERS)\"
 
-MAKECMD = $(MAKE) OS=$(OS)
+MAKECMD = $(MAKE) OS="$(OS)" WARNINGS="$(WARNINGS)"
 
 LIBS +=                $(OS_LIB_DYNLOAD)
 
index 2704b13..8f61c32 100644 (file)
@@ -1,6 +1,10 @@
 # programs
 CCACHE ?=       $(shell sh -c "type -path ccache")
+ifeq ($(origin CC),default)
+CC =           $(CCACHE) gcc
+else
 CC ?=          $(CCACHE) gcc
+endif
 STRIP ?=       strip
 BISON ?=       bison
 FLEX ?=                flex
@@ -18,34 +22,34 @@ EXENAME ?= olsrd
 
 INCLUDES =     -Isrc -I$(TOPDIR)/src 
 
-GCC_VERSION := $(shell v=$$($(CC) -dumpversion); echo $${v//./ })
-
 # add gcc warnings and optimizations if CFLAGS not set
 ifndef CFLAGS
-CFLAGS +=      -Wall
+ifndef WARNINGS
+WARNINGS +=    -Wall
 # gcc-3.3.5 on Debian sarge doesn't know the following warnings
-ifneq ("$(GCC_VERSION)","3 3 5")
-CFLAGS +=      -Wextra
-CFLAGS +=      -Wold-style-definition
-CFLAGS +=      -Wdeclaration-after-statement
+WARNINGS +=    -Wextra
+WARNINGS +=    -Wold-style-definition
+WARNINGS +=    -Wdeclaration-after-statement
+WARNINGS +=    -Wmissing-prototypes
+WARNINGS +=    -Wstrict-prototypes
+WARNINGS +=    -Wmissing-declarations
+WARNINGS +=    -Wsign-compare
+WARNINGS +=    -Waggregate-return
+WARNINGS +=    -Wmissing-noreturn
+WARNINGS +=    -Wmissing-format-attribute
+WARNINGS +=    -Wno-multichar
+WARNINGS +=    -Wno-deprecated-declarations
+#WARNINGS +=   -Wredundant-decls
+WARNINGS +=    -Wnested-externs
+#WARNINGS +=   -Wunreachable-code
+WARNINGS +=    -Winline
+WARNINGS +=    -Wdisabled-optimization
+WARNINGS +=    -Werror
+WARNINGS :=    $(shell CC="$(CC)" $(TOPDIR)/gcc-warnings $(WARNINGS))
 endif
-CFLAGS +=      -Wmissing-prototypes
-CFLAGS +=      -Wstrict-prototypes
-CFLAGS +=      -Wmissing-declarations
-CFLAGS +=      -Wsign-compare
-CFLAGS +=      -Waggregate-return
-CFLAGS +=      -Wmissing-noreturn
-CFLAGS +=      -Wmissing-format-attribute
-CFLAGS +=      -Wno-multichar
-CFLAGS +=      -Wno-deprecated-declarations
-#CFLAGS +=     -Wredundant-decls
-CFLAGS +=      -Wnested-externs
-#CFLAGS +=     -Wunreachable-code
-CFLAGS +=      -Winline
-CFLAGS +=      -Wdisabled-optimization
+CFLAGS +=      $(WARNINGS)
 CFLAGS +=      -O2
 CFLAGS +=      -g
-#CFLAGS +=     -Werror
 endif
 
 ifdef OLSRD_PLUGIN
diff --git a/gcc-warnings b/gcc-warnings
new file mode 100644 (file)
index 0000000..7475f84
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash --norc
+#
+# We expect warning options for gcc as argumenst and return the ones which are accepted
+# by the given gcc.
+#
+# $Id: gcc-warnings,v 1.1 2007/05/01 21:36:50 bernd67 Exp $
+
+set -ue
+#set -vx
+
+OPTS=""
+for param; do
+    case "$param" in
+    -W?*) OPTS="$OPTS $param";;
+    *)    echo "Ignoring $param" >&2
+    esac
+done
+
+while read error; do 
+    case "$error" in
+    *error:\ unrecognized\ option*) opt="${error#*\`}"
+                                    opt="${opt%\'*}"
+                                    OPTS="${OPTS//$opt/}"
+                                    ;;
+    esac
+done < <(cat <<EOF | $CC $OPTS -E - 2>&1 >/dev/null
+    int main(void) {
+        return 0;
+    }
+    EOF)
+echo $OPTS
+exit 0