Makefile.include 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # SPDX-License-Identifier: GPL-2.0
  2. ifneq ($(O),)
  3. ifeq ($(origin O), command line)
  4. dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
  5. ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
  6. OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
  7. COMMAND_O := O=$(ABSOLUTE_O)
  8. ifeq ($(objtree),)
  9. objtree := $(O)
  10. endif
  11. endif
  12. endif
  13. # check that the output directory actually exists
  14. ifneq ($(OUTPUT),)
  15. OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
  16. $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
  17. endif
  18. #
  19. # Include saner warnings here, which can catch bugs:
  20. #
  21. EXTRA_WARNINGS := -Wbad-function-cast
  22. EXTRA_WARNINGS += -Wdeclaration-after-statement
  23. EXTRA_WARNINGS += -Wformat-security
  24. EXTRA_WARNINGS += -Wformat-y2k
  25. EXTRA_WARNINGS += -Winit-self
  26. EXTRA_WARNINGS += -Wmissing-declarations
  27. EXTRA_WARNINGS += -Wmissing-prototypes
  28. EXTRA_WARNINGS += -Wnested-externs
  29. EXTRA_WARNINGS += -Wno-system-headers
  30. EXTRA_WARNINGS += -Wold-style-definition
  31. EXTRA_WARNINGS += -Wpacked
  32. EXTRA_WARNINGS += -Wredundant-decls
  33. EXTRA_WARNINGS += -Wshadow
  34. EXTRA_WARNINGS += -Wstrict-prototypes
  35. EXTRA_WARNINGS += -Wswitch-default
  36. EXTRA_WARNINGS += -Wswitch-enum
  37. EXTRA_WARNINGS += -Wundef
  38. EXTRA_WARNINGS += -Wwrite-strings
  39. EXTRA_WARNINGS += -Wformat
  40. CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
  41. # Makefiles suck: This macro sets a default value of $(2) for the
  42. # variable named by $(1), unless the variable has been set by
  43. # environment or command line. This is necessary for CC and AR
  44. # because make sets default values, so the simpler ?= approach
  45. # won't work as expected.
  46. define allow-override
  47. $(if $(or $(findstring environment,$(origin $(1))),\
  48. $(findstring command line,$(origin $(1)))),,\
  49. $(eval $(1) = $(2)))
  50. endef
  51. # Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix.
  52. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
  53. $(call allow-override,AR,$(CROSS_COMPILE)ar)
  54. $(call allow-override,LD,$(CROSS_COMPILE)ld)
  55. $(call allow-override,CXX,$(CROSS_COMPILE)g++)
  56. $(call allow-override,STRIP,$(CROSS_COMPILE)strip)
  57. ifeq ($(CC_NO_CLANG), 1)
  58. EXTRA_WARNINGS += -Wstrict-aliasing=3
  59. endif
  60. # Hack to avoid type-punned warnings on old systems such as RHEL5:
  61. # We should be changing CFLAGS and checking gcc version, but this
  62. # will do for now and keep the above -Wstrict-aliasing=3 in place
  63. # in newer systems.
  64. # Needed for the __raw_cmpxchg in tools/arch/x86/include/asm/cmpxchg.h
  65. ifneq ($(filter 3.%,$(MAKE_VERSION)),) # make-3
  66. EXTRA_WARNINGS += -fno-strict-aliasing
  67. endif
  68. ifneq ($(findstring $(MAKEFLAGS), w),w)
  69. PRINT_DIR = --no-print-directory
  70. else
  71. NO_SUBDIR = :
  72. endif
  73. ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
  74. silent=1
  75. endif
  76. #
  77. # Define a callable command for descending to a new directory
  78. #
  79. # Call by doing: $(call descend,directory[,target])
  80. #
  81. descend = \
  82. +mkdir -p $(OUTPUT)$(1) && \
  83. $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2)
  84. QUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
  85. QUIET_SUBDIR1 =
  86. ifneq ($(silent),1)
  87. ifneq ($(V),1)
  88. QUIET_CC = @echo ' CC '$@;
  89. QUIET_CC_FPIC = @echo ' CC FPIC '$@;
  90. QUIET_AR = @echo ' AR '$@;
  91. QUIET_LINK = @echo ' LINK '$@;
  92. QUIET_MKDIR = @echo ' MKDIR '$@;
  93. QUIET_GEN = @echo ' GEN '$@;
  94. QUIET_SUBDIR0 = +@subdir=
  95. QUIET_SUBDIR1 = ;$(NO_SUBDIR) \
  96. echo ' SUBDIR '$$subdir; \
  97. $(MAKE) $(PRINT_DIR) -C $$subdir
  98. QUIET_FLEX = @echo ' FLEX '$@;
  99. QUIET_BISON = @echo ' BISON '$@;
  100. descend = \
  101. +@echo ' DESCEND '$(1); \
  102. mkdir -p $(OUTPUT)$(1) && \
  103. $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2)
  104. QUIET_CLEAN = @printf ' CLEAN %s\n' $1;
  105. QUIET_INSTALL = @printf ' INSTALL %s\n' $1;
  106. endif
  107. endif
  108. pound := \#