LEFT | RIGHT |
1 # | 1 # |
2 # This Source Code Form is subject to the terms of the Mozilla Public | 2 # This Source Code Form is subject to the terms of the Mozilla Public |
3 # License, v. 2.0. If a copy of the MPL was not distributed with this | 3 # License, v. 2.0. If a copy of the MPL was not distributed with this |
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
5 | 5 |
6 # This sets warning flags for unix-like operating systems. | 6 # This sets WARNING_CFLAGS for gcc-like compilers. |
| 7 |
| 8 ifndef CC_IS_GCC |
| 9 CC_IS_GCC := $(shell $(CC) -x c -E -Wall -Werror /dev/null >/dev/null 2>&1 &&
echo 1) |
| 10 # Export CC_IS_GCC to save a shell invocation when recursing. |
| 11 export CC_IS_GCC |
| 12 endif |
7 | 13 |
8 ifndef CC_NAME | 14 ifndef CC_NAME |
9 CC_NAME := $(shell $(CC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q') | 15 ifeq (1,$(CC_IS_GCC)) |
| 16 CC_NAME := $(shell $(CC) -? 2>&1 >/dev/null | sed -e 's/:.*//;1q') |
| 17 else |
| 18 CC_NAME := $(notdir $(CC)) |
| 19 endif |
| 20 # Export CC_NAME to save a shell invocation when recursing. |
10 export CC_NAME | 21 export CC_NAME |
11 endif | 22 endif |
12 | 23 |
13 ifndef CC_VERSION | 24 ifndef GCC_VERSION |
14 CC_VERSION := $(subst ., ,$(shell $(CC) -dumpversion)) | 25 ifeq (1,$(CC_IS_GCC)) |
15 export CC_VERSION | 26 GCC_VERSION := $(subst ., ,$(shell $(CC) -dumpversion || echo x.x.x)) |
| 27 # Export GCC_VERSION to save a shell invocation when recursing. |
| 28 export GCC_VERSION |
| 29 endif |
16 endif | 30 endif |
17 | 31 |
18 ifndef WARNING_CFLAGS | 32 ifndef WARNING_CFLAGS |
19 # This tests to see if enabling the warning is possible before | 33 ifneq (1,$(CC_IS_GCC)) |
20 # setting an option to disable it. | 34 WARNING_CFLAGS = $(NULL) |
21 disable_warning = $(shell $(CC) -x c -E -Werror -W$(1) /dev/null >/dev/null 2>
&1 && echo -Wno-$(1)) | 35 else |
| 36 # This tests to see if enabling the warning is possible before |
| 37 # setting an option to disable it. |
| 38 disable_warning = $(shell $(CC) -x c -E -Werror -W$(1) /dev/null >/dev/null
2>&1 && echo -Wno-$(1)) |
22 | 39 |
23 WARNING_CFLAGS = -Wall | 40 WARNING_CFLAGS = -Wall |
24 ifeq ($(CC_NAME),clang) | 41 ifeq ($(CC_NAME),clang) |
25 # -Qunused-arguments : clang objects to arguments that it doesn't understand | 42 # -Qunused-arguments : clang objects to arguments that it doesn't understa
nd |
26 # and fixing this would require rearchitecture | 43 # and fixing this would require rearchitecture |
27 WARNING_CFLAGS += -Qunused-arguments | 44 WARNING_CFLAGS += -Qunused-arguments |
28 # -Wno-parentheses-equality : because clang warns about macro expansions | 45 # -Wno-parentheses-equality : because clang warns about macro expansions |
29 WARNING_CFLAGS += $(call disable_warning,parentheses-equality) | 46 WARNING_CFLAGS += $(call disable_warning,parentheses-equality) |
30 ifdef BUILD_OPT | 47 ifdef BUILD_OPT |
31 # clang is unable to handle glib's expansion of strcmp and similar for opt
imized | 48 # clang is unable to handle glib's expansion of strcmp and similar for o
ptimized |
32 # builds, so ignore the resulting errors. | 49 # builds, so ignore the resulting errors. |
33 # See https://llvm.org/bugs/show_bug.cgi?id=20144 | 50 # See https://llvm.org/bugs/show_bug.cgi?id=20144 |
34 WARNING_CFLAGS += $(call disable_warning,array-bounds) | 51 WARNING_CFLAGS += $(call disable_warning,array-bounds) |
35 WARNING_CFLAGS += $(call disable_warning,unevaluated-expression) | 52 WARNING_CFLAGS += $(call disable_warning,unevaluated-expression) |
36 endif | 53 endif |
37 endif # if clang | 54 endif # if clang |
38 | 55 |
39 ifndef NSS_ENABLE_WERROR | 56 ifndef NSS_ENABLE_WERROR |
40 ifeq ($(OS_TARGET),Android) | 57 ifeq ($(OS_TARGET),Android) |
41 # Android lollipop generates the following warning: | 58 # Android lollipop generates the following warning: |
42 # error: call to 'sprintf' declared with attribute warning: | 59 # error: call to 'sprintf' declared with attribute warning: |
43 # sprintf is often misused; please use snprintf [-Werror] | 60 # sprintf is often misused; please use snprintf [-Werror] |
44 # So, just suppress -Werror entirely on Android | 61 # So, just suppress -Werror entirely on Android |
45 NSS_ENABLE_WERROR = 0 | 62 NSS_ENABLE_WERROR = 0 |
46 $(warning OS_TARGET is Android, disabling -Werror) | 63 $(warning OS_TARGET is Android, disabling -Werror) |
47 else | |
48 ifeq ($(CC_NAME),clang) | |
49 # Clang reports its version as an older gcc, but it's OK | |
50 NSS_ENABLE_WERROR = 1 | |
51 else | 64 else |
52 ifneq (,$(filter 4.8 4.9,$(word 1,$(CC_VERSION)).$(word 2,$(CC_VERSION))
)) | 65 ifeq ($(CC_NAME),clang) |
| 66 # Clang reports its version as an older gcc, but it's OK |
53 NSS_ENABLE_WERROR = 1 | 67 NSS_ENABLE_WERROR = 1 |
54 endif | 68 else ifeq ($(CC_NAME),gcc) |
55 ifeq (,$(filter 0 1 2 3 4,$(word 1,$(CC_VERSION)))) | 69 ifneq (,$(filter 4.8 4.9,$(word 1,$(GCC_VERSION)).$(word 2,$(GCC_VERSI
ON)))) |
56 NSS_ENABLE_WERROR = 1 | 70 NSS_ENABLE_WERROR = 1 |
| 71 endif |
| 72 ifeq (,$(filter 0 1 2 3 4,$(word 1,$(GCC_VERSION)))) |
| 73 NSS_ENABLE_WERROR = 1 |
| 74 endif |
57 endif | 75 endif |
58 ifndef NSS_ENABLE_WERROR | 76 ifndef NSS_ENABLE_WERROR |
59 $(warning Unable to find gcc 4.8 or greater, disabling -Werror) | 77 $(warning Unable to find gcc 4.8 or greater, disabling -Werror) |
60 NSS_ENABLE_WERROR = 0 | 78 NSS_ENABLE_WERROR = 0 |
61 endif | 79 endif |
62 endif | 80 endif |
| 81 endif #ndef NSS_ENABLE_WERROR |
| 82 |
| 83 ifeq ($(NSS_ENABLE_WERROR),1) |
| 84 WARNING_CFLAGS += -Werror |
| 85 else |
| 86 # Old versions of gcc (< 4.8) don't support #pragma diagnostic in function
s. |
| 87 # Use this to disable use of that #pragma and the warnings it suppresses. |
| 88 WARNING_CFLAGS += -DNSS_NO_GCC48 |
63 endif | 89 endif |
64 endif #ndef NSS_ENABLE_WERROR | |
65 | |
66 ifeq ($(NSS_ENABLE_WERROR),1) | |
67 WARNING_CFLAGS += -Werror | |
68 else | |
69 # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions. | |
70 # Use this to disable use of that #pragma and the warnings it suppresses. | |
71 WARNING_CFLAGS += -DNSS_NO_GCC48 | |
72 endif | 90 endif |
73 export WARNING_CFLAGS | 91 export WARNING_CFLAGS |
74 endif # ndef WARNING_CFLAGS | 92 endif # ndef WARNING_CFLAGS |
LEFT | RIGHT |