tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Werror.mk (3838B)


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