Bug 1182667 - Changing gcc version detection code
authorMartin Thomson <martin.thomson@gmail.com>
Wed, 19 Aug 2015 16:34:01 -0700
changeset 11532 2df598ffa0a9947c5dfe0dd9eca4f2a7b10a232a
parent 11531 86b762366c25638d6b91578c7c1acd41590dfdc9
child 11533 6cd266575bbd6766d767b9dbaff753989a86e07f
push id699
push usermartin.thomson@gmail.com
push dateWed, 19 Aug 2015 23:34:12 +0000
bugs1182667
Bug 1182667 - Changing gcc version detection code
coreconf/Darwin.mk
coreconf/Linux.mk
--- a/coreconf/Darwin.mk
+++ b/coreconf/Darwin.mk
@@ -76,17 +76,35 @@ endif
 # The meaning of a common is ambiguous.  It may be a true definition:
 #     int x = 0;
 # or it may be a declaration of a symbol defined in another file:
 #     extern int x;
 # Use the -fno-common option to force all commons to become true
 # definitions so that the linker can catch multiply-defined symbols.
 # Also, common symbols are not allowed with Darwin dynamic libraries.
 
-OS_CFLAGS	= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -Wall -fno-common -pipe -DDARWIN -DHAVE_STRERROR -DHAVE_BSD_FLOCK $(DARWIN_SDK_CFLAGS)
+OS_CFLAGS	= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -Wall -Werror -fno-common -pipe -DDARWIN -DHAVE_STRERROR -DHAVE_BSD_FLOCK $(DARWIN_SDK_CFLAGS)
+
+ifeq (clang,$(shell $(CC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q'))
+NSS_HAS_GCC48 = true
+endif
+ifndef NSS_HAS_GCC48
+NSS_HAS_GCC48 := $(shell \
+  [ `$(CC) -dumpversion | cut -f 1 -d . -` -gt 4 -a \
+    `$(CC) -dumpversion | cut -f 2 -d . -` -ge 8 -o \
+    `$(CC) -dumpversion | cut -f 1 -d . -` -ge 5 ] && \
+  echo true || echo false)
+export NSS_HAS_GCC48
+endif
+ifneq (true,$(NSS_HAS_GCC48))
+# Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
+# Here, we disable use of that #pragma and the warnings it suppresses.
+OS_CFLAGS += -DNSS_NO_GCC48 -Wno-unused-variable
+$(warning Unable to find gcc >= 4.8)
+endif
 
 ifdef BUILD_OPT
 ifeq (11,$(ALLOW_OPT_CODE_SIZE)$(OPT_CODE_SIZE))
 	OPTIMIZER       = -Oz
 else
 	OPTIMIZER	= -O2
 endif
 ifdef MOZ_DEBUG_SYMBOLS
--- a/coreconf/Linux.mk
+++ b/coreconf/Linux.mk
@@ -147,37 +147,24 @@ ifdef BUILD_OPT
 # builds, so ignore the resulting errors.
 # See https://llvm.org/bugs/show_bug.cgi?id=20144
 OS_CFLAGS += -Wno-array-bounds -Wno-unevaluated-expression
 endif
 # Clang reports its version as an older gcc, but it's OK
 NSS_HAS_GCC48 = true
 endif
 
-# Check for the existence of gcc 4.8
 ifndef NSS_HAS_GCC48
-define GCC48_TEST =
-#include <stdio.h>\n
-int main() {\n
-fprintf(stderr, \"Found gcc %d.%d\\\n\", __GNUC__, __GNUC_MINOR__);\n
-#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)\n
-  return 1;\n
-#else\n
-  return 0;\n
-#endif\n
-}\n
-endef
-TEST_GCC48 := /tmp/test_gcc48_$(shell echo $$$$)
-NSS_HAS_GCC48 := $(shell echo -e "$(GCC48_TEST)" > $(TEST_GCC48).c && \
-  $(CC) $(C_FLAGS) -o $(TEST_GCC48) $(TEST_GCC48).c && \
-  $(TEST_GCC48) && echo true || echo false; \
-  rm -f $(TEST_GCC48) $(TEST_GCC48).c)
+NSS_HAS_GCC48 := $(shell \
+  [ `$(CC) -dumpversion | cut -f 1 -d . -` -gt 4 -a \
+    `$(CC) -dumpversion | cut -f 2 -d . -` -ge 8 -o \
+    `$(CC) -dumpversion | cut -f 1 -d . -` -ge 5 ] && \
+  echo true || echo false)
 export NSS_HAS_GCC48
 endif
-
 ifneq (true,$(NSS_HAS_GCC48))
 # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
 # Here, we disable use of that #pragma and the warnings it suppresses.
 OS_CFLAGS += -DNSS_NO_GCC48 -Wno-unused-variable
 $(warning Unable to find gcc >= 4.8)
 endif
 
 ifdef USE_PTHREADS