Bug 1211568 - Improve performance of build, r=glandium
authorMartin Thomson <martin.thomson@gmail.com>
Fri, 30 Oct 2015 08:03:44 +0900
changeset 11702 b9bdca563fbaaaa8f8c93ba0a786574f6169b07c
parent 11701 1db1054bbb97490b4c83b589094d8c47045cc935
child 11703 c82113e56943d914fa3454c208c65a7a2955c689
push id841
push usermartin.thomson@gmail.com
push dateFri, 06 Nov 2015 00:10:15 +0000
reviewersglandium
bugs1211568
Bug 1211568 - Improve performance of build, r=glandium
coreconf/Darwin.mk
coreconf/Linux.mk
coreconf/Werror.mk
--- a/coreconf/Darwin.mk
+++ b/coreconf/Darwin.mk
@@ -1,14 +1,15 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include $(CORE_DEPTH)/coreconf/UNIX.mk
+include $(CORE_DEPTH)/coreconf/Werror.mk
 
 DEFAULT_COMPILER = gcc
 
 CC		= gcc
 CCC		= g++
 RANLIB		= ranlib
 
 ifndef CPU_ARCH
@@ -76,54 +77,17 @@ 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)
-
-# This tests to see if enabling the warning is possible before
-# setting an option to disable it.
-disable_warning=$(shell $(CC) -x c -E -Werror -W$(1) /dev/null >/dev/null 2>&1 && echo -Wno-$(1)) 
-
-COMPILER_NAME = $(shell $(CC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q')
-ifeq ($(COMPILER_NAME),clang)
-  # -Qunused-arguments : clang objects to arguments that it doesn't understand
-  #    and fixing this would require rearchitecture
-  OS_CFLAGS += -Qunused-arguments
-  # -Wno-parentheses-equality : because clang warns about macro expansions
-  OS_CFLAGS += $(call disable_warning,parentheses-equality)
-endif
-
-ifndef NSS_ENABLE_WERROR
-  ifeq ($(COMPILER_NAME),clang)
-    NSS_ENABLE_WERROR = 1
-  else
-    NSS_ENABLE_WERROR := $(shell \
-    [ `$(CC) -dumpversion | cut -f 1 -d . -` -eq 4 -a \
-      `$(CC) -dumpversion | cut -f 2 -d . -` -ge 8 -o \
-      `$(CC) -dumpversion | cut -f 1 -d . -` -ge 5 ] && \
-      echo 1 || echo 0)
-    ifneq ($(NSS_ENABLE_WERROR),1)
-      $(warning Unable to find gcc >= 4.8 disabling -Werror)
-    endif
-  endif
-  export NSS_ENABLE_WERROR
-endif
-
-ifeq ($(NSS_ENABLE_WERROR),1)
-  OS_CFLAGS += -Werror
-else
-  # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
-  # Use this to disable use of that #pragma and the warnings it suppresses.
-  OS_CFLAGS += -DNSS_NO_GCC48
-endif
+OS_CFLAGS	= $(DSO_CFLAGS) $(OS_REL_CFLAGS) $(WARNING_CFLAGS) -fno-common -pipe -DDARWIN -DHAVE_STRERROR -DHAVE_BSD_FLOCK $(DARWIN_SDK_CFLAGS)
 
 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
@@ -1,14 +1,15 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include $(CORE_DEPTH)/coreconf/UNIX.mk
+include $(CORE_DEPTH)/coreconf/Werror.mk
 
 #
 # The default implementation strategy for Linux is now pthreads
 #
 ifneq ($(OS_TARGET),Android)
 	USE_PTHREADS = 1
 endif
 
@@ -127,80 +128,26 @@ ifdef MOZ_DEBUG_SYMBOLS
 		OPTIMIZER += $(MOZ_DEBUG_FLAGS)
 	else
 		OPTIMIZER += -gdwarf-2
 	endif
 endif
 endif
 
 ifndef COMPILER_TAG
-COMPILER_TAG = _$(shell $(CC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q')
-CCC_COMPILER_TAG = _$(shell $(CCC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q')
+COMPILER_TAG := _$(CC_NAME)
 endif
 
 ifeq ($(USE_PTHREADS),1)
 OS_PTHREAD = -lpthread 
 endif
 
-OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) $(ARCHFLAG) -Wall -pipe -ffunction-sections -fdata-sections -DLINUX -Dlinux -DHAVE_STRERROR
+OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) $(ARCHFLAG) $(WARNING_CFLAGS) -pipe -ffunction-sections -fdata-sections -DLINUX -Dlinux -DHAVE_STRERROR
 OS_LIBS			= $(OS_PTHREAD) -ldl -lc
 
-# This tests to see if enabling the warning is possible before
-# setting an option to disable it.
-disable_warning=$(shell $(CC) -x c -E -Werror -W$(1) /dev/null >/dev/null 2>&1 && echo -Wno-$(1))
-
-ifeq ($(COMPILER_TAG),_clang)
-  # -Qunused-arguments : clang objects to arguments that it doesn't understand
-  #    and fixing this would require rearchitecture
-  OS_CFLAGS += -Qunused-arguments
-  # -Wno-parentheses-equality : because clang warns about macro expansions
-  OS_CFLAGS += $(call disable_warning,parentheses-equality)
-  ifdef BUILD_OPT
-    # clang is unable to handle glib's expansion of strcmp and similar for optimized
-    # builds, so ignore the resulting errors.
-    # See https://llvm.org/bugs/show_bug.cgi?id=20144
-    OS_CFLAGS += $(call disable_warning,array-bounds)
-    OS_CFLAGS += $(call disable_warning,unevaluated-expression)
-  endif
-endif
-
-ifndef NSS_ENABLE_WERROR
-  ifneq ($(OS_TARGET),Android)
-    # Android lollipop generates the following warning:
-    # error: call to 'sprintf' declared with attribute warning:
-    #   sprintf is often misused; please use snprintf [-Werror]
-    # So, just suppress -Werror entirely on Android
-    NSS_ENABLE_WERROR = 0
-    $(warning !!! OS_TARGET is Android, disabling -Werror)
-  else
-    ifeq ($(COMPILER_TAG),_clang)
-      # Clang reports its version as an older gcc, but it's OK
-      NSS_ENABLE_WERROR = 1
-    else
-      NSS_ENABLE_WERROR := $(shell \
-        [ `$(CC) -dumpversion | cut -f 1 -d . -` -eq 4 -a \
-          `$(CC) -dumpversion | cut -f 2 -d . -` -ge 8 -o \
-          `$(CC) -dumpversion | cut -f 1 -d . -` -ge 5 ] && \
-        echo 1 || echo 0)
-      ifneq ($(NSS_ENABLE_WERROR),1)
-        $(warning !!! Unable to find gcc 4.8 or greater, disabling -Werror)
-      endif
-    endif
-  endif
-  export NSS_ENABLE_WERROR
-endif
-
-ifeq (1,$(NSS_ENABLE_WERROR))
-  OS_CFLAGS += -Werror
-else
-  # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
-  # Use this to disable use of that #pragma and the warnings it suppresses.
-  OS_CFLAGS += -DNSS_NO_GCC48
-endif
-
 ifdef USE_PTHREADS
 	DEFINES		+= -D_REENTRANT
 endif
 
 ARCH			= linux
 
 DSO_CFLAGS		= -fPIC
 DSO_LDOPTS		= -shared $(ARCHFLAG) -Wl,--gc-sections
new file mode 100644
--- /dev/null
+++ b/coreconf/Werror.mk
@@ -0,0 +1,70 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This sets warning flags for unix-like operating systems.
+
+ifndef CC_NAME
+  CC_NAME := $(shell $(CC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q')
+  export CC_NAME
+endif
+
+ifndef WARNING_CFLAGS
+  # This tests to see if enabling the warning is possible before
+  # setting an option to disable it.
+  disable_warning = $(shell $(CC) -x c -E -Werror -W$(1) /dev/null >/dev/null 2>&1 && echo -Wno-$(1))
+
+  WARNING_CFLAGS = -Wall
+  ifeq ($(CC_NAME),clang)
+    # -Qunused-arguments : clang objects to arguments that it doesn't understand
+    #    and fixing this would require rearchitecture
+    WARNING_CFLAGS += -Qunused-arguments
+    # -Wno-parentheses-equality : because clang warns about macro expansions
+    OS_CFLAGS += $(call disable_warning,parentheses-equality)
+    ifdef BUILD_OPT
+      # clang is unable to handle glib's expansion of strcmp and similar for optimized
+      # builds, so ignore the resulting errors.
+      # See https://llvm.org/bugs/show_bug.cgi?id=20144
+      WARNING_CFLAGS += $(call disable_warning,array-bounds)
+      WARNING_CFLAGS += $(call disable_warning,unevaluated-expression)
+    endif
+  endif # if clang
+
+  ifndef NSS_ENABLE_WERROR
+    ifeq ($(OS_TARGET),Android)
+      # Android lollipop generates the following warning:
+      # error: call to 'sprintf' declared with attribute warning:
+      #   sprintf is often misused; please use snprintf [-Werror]
+      # So, just suppress -Werror entirely on Android
+      NSS_ENABLE_WERROR = 0
+      $(warning OS_TARGET is Android, disabling -Werror)
+    else
+      ifeq ($(CC_NAME),clang)
+        # Clang reports its version as an older gcc, but it's OK
+        NSS_ENABLE_WERROR = 1
+      else
+        CC_VERSION := $(subst ., ,$(shell $(CC) -dumpversion))
+        ifneq (,$(filter 4.8 4.9,$(word 1,$(CC_VERSION)).$(word 2,$(CC_VERSION))))
+          NSS_ENABLE_WERROR = 1
+        endif
+        ifeq (,$(filter 0 1 2 3 4,$(word 1,$(CC_VERSION))))
+          NSS_ENABLE_WERROR = 1
+        endif
+        ifndef NSS_ENABLE_WERROR
+          $(warning Unable to find gcc 4.8 or greater, disabling -Werror)
+          NSS_ENABLE_WERROR = 0
+        endif
+      endif
+    endif
+  endif #ndef NSS_ENABLE_WERROR
+
+  ifeq ($(NSS_ENABLE_WERROR),1)
+    WARNING_CFLAGS += -Werror
+  else
+    # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
+    # Use this to disable use of that #pragma and the warnings it suppresses.
+    WARNING_CFLAGS += -DNSS_NO_GCC48
+  endif
+  export WARNING_CFLAGS
+endif # ndef WARNING_CFLAGS