1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 29e4a6648SBorislav Petkovifneq ($(O),) 3bf35182fSDavid Howellsifeq ($(origin O), command line) 4028568d8SMasahiro Yamada dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),) 5028568d8SMasahiro Yamada ABSOLUTE_O := $(shell cd $(O) ; pwd) 6bf35182fSDavid Howells OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/) 7c883122aSSteven Rostedt COMMAND_O := O=$(ABSOLUTE_O) 8bf35182fSDavid Howellsifeq ($(objtree),) 9bf35182fSDavid Howells objtree := $(O) 10bf35182fSDavid Howellsendif 1198d89bfdSBorislav Petkovendif 129e4a6648SBorislav Petkovendif 1398d89bfdSBorislav Petkov 1498d89bfdSBorislav Petkov# check that the output directory actually exists 159e4a6648SBorislav Petkovifneq ($(OUTPUT),) 1616f8259cSBjørn ForsmanOUTDIR := $(shell cd $(OUTPUT) && pwd) 1798d89bfdSBorislav Petkov$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) 1898d89bfdSBorislav Petkovendif 1998d89bfdSBorislav Petkov 2098d89bfdSBorislav Petkov# 2198d89bfdSBorislav Petkov# Include saner warnings here, which can catch bugs: 2298d89bfdSBorislav Petkov# 23d8caf3ebSBorislav PetkovEXTRA_WARNINGS := -Wbad-function-cast 24d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wdeclaration-after-statement 25d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wformat-security 26d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wformat-y2k 27d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Winit-self 28d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wmissing-declarations 29d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wmissing-prototypes 30d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wnested-externs 31d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wno-system-headers 32d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wold-style-definition 33d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wpacked 34d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wredundant-decls 35d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wshadow 36d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wstrict-prototypes 37d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wswitch-default 38d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wswitch-enum 39d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wundef 40d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wwrite-strings 41d8caf3ebSBorislav PetkovEXTRA_WARNINGS += -Wformat 4298d89bfdSBorislav Petkov 433866058eSDavid Carrillo-CisnerosCC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) 443866058eSDavid Carrillo-Cisneros 45*7ed1c190SMartin Kelly# Makefiles suck: This macro sets a default value of $(2) for the 46*7ed1c190SMartin Kelly# variable named by $(1), unless the variable has been set by 47*7ed1c190SMartin Kelly# environment or command line. This is necessary for CC and AR 48*7ed1c190SMartin Kelly# because make sets default values, so the simpler ?= approach 49*7ed1c190SMartin Kelly# won't work as expected. 50*7ed1c190SMartin Kellydefine allow-override 51*7ed1c190SMartin Kelly $(if $(or $(findstring environment,$(origin $(1))),\ 52*7ed1c190SMartin Kelly $(findstring command line,$(origin $(1)))),,\ 53*7ed1c190SMartin Kelly $(eval $(1) = $(2))) 54*7ed1c190SMartin Kellyendef 55*7ed1c190SMartin Kelly 56*7ed1c190SMartin Kelly# Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. 57*7ed1c190SMartin Kelly$(call allow-override,CC,$(CROSS_COMPILE)gcc) 58*7ed1c190SMartin Kelly$(call allow-override,AR,$(CROSS_COMPILE)ar) 59*7ed1c190SMartin Kelly$(call allow-override,LD,$(CROSS_COMPILE)ld) 60*7ed1c190SMartin Kelly$(call allow-override,CXX,$(CROSS_COMPILE)g++) 61*7ed1c190SMartin Kelly$(call allow-override,STRIP,$(CROSS_COMPILE)strip) 62*7ed1c190SMartin Kelly 633866058eSDavid Carrillo-Cisnerosifeq ($(CC_NO_CLANG), 1) 64093b75efSArnaldo Carvalho de MeloEXTRA_WARNINGS += -Wstrict-aliasing=3 65093b75efSArnaldo Carvalho de Meloendif 66093b75efSArnaldo Carvalho de Melo 673337e682SArnaldo Carvalho de Melo# Hack to avoid type-punned warnings on old systems such as RHEL5: 683337e682SArnaldo Carvalho de Melo# We should be changing CFLAGS and checking gcc version, but this 693337e682SArnaldo Carvalho de Melo# will do for now and keep the above -Wstrict-aliasing=3 in place 703337e682SArnaldo Carvalho de Melo# in newer systems. 713337e682SArnaldo Carvalho de Melo# Needed for the __raw_cmpxchg in tools/arch/x86/include/asm/cmpxchg.h 723337e682SArnaldo Carvalho de Meloifneq ($(filter 3.%,$(MAKE_VERSION)),) # make-3 733337e682SArnaldo Carvalho de MeloEXTRA_WARNINGS += -fno-strict-aliasing 743337e682SArnaldo Carvalho de Meloendif 753337e682SArnaldo Carvalho de Melo 7698d89bfdSBorislav Petkovifneq ($(findstring $(MAKEFLAGS), w),w) 7798d89bfdSBorislav PetkovPRINT_DIR = --no-print-directory 7898d89bfdSBorislav Petkovelse 7998d89bfdSBorislav PetkovNO_SUBDIR = : 8098d89bfdSBorislav Petkovendif 8198d89bfdSBorislav Petkov 826f0fa58eSMasahiro Yamadaifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) 83e572d088SJosh Poimboeuf silent=1 84e572d088SJosh Poimboeufendif 85e572d088SJosh Poimboeuf 86ca9dfc6cSDavid Howells# 87ca9dfc6cSDavid Howells# Define a callable command for descending to a new directory 88ca9dfc6cSDavid Howells# 89ca9dfc6cSDavid Howells# Call by doing: $(call descend,directory[,target]) 90ca9dfc6cSDavid Howells# 91ca9dfc6cSDavid Howellsdescend = \ 92bf35182fSDavid Howells +mkdir -p $(OUTPUT)$(1) && \ 932b73f65dSDavid Howells $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2) 94ca9dfc6cSDavid Howells 95bf35182fSDavid HowellsQUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir 9698d89bfdSBorislav PetkovQUIET_SUBDIR1 = 9798d89bfdSBorislav Petkov 98e572d088SJosh Poimboeufifneq ($(silent),1) 995125bc22SRobert Richter ifneq ($(V),1) 10065fb0992SIngo Molnar QUIET_CC = @echo ' CC '$@; 101bdebbacdSJiri Olsa QUIET_CC_FPIC = @echo ' CC FPIC '$@; 10265fb0992SIngo Molnar QUIET_AR = @echo ' AR '$@; 10365fb0992SIngo Molnar QUIET_LINK = @echo ' LINK '$@; 10465fb0992SIngo Molnar QUIET_MKDIR = @echo ' MKDIR '$@; 10565fb0992SIngo Molnar QUIET_GEN = @echo ' GEN '$@; 10698d89bfdSBorislav Petkov QUIET_SUBDIR0 = +@subdir= 10765fb0992SIngo Molnar QUIET_SUBDIR1 = ;$(NO_SUBDIR) \ 10865fb0992SIngo Molnar echo ' SUBDIR '$$subdir; \ 10998d89bfdSBorislav Petkov $(MAKE) $(PRINT_DIR) -C $$subdir 11065fb0992SIngo Molnar QUIET_FLEX = @echo ' FLEX '$@; 11165fb0992SIngo Molnar QUIET_BISON = @echo ' BISON '$@; 112bf35182fSDavid Howells 113bf35182fSDavid Howells descend = \ 11465fb0992SIngo Molnar +@echo ' DESCEND '$(1); \ 115bf35182fSDavid Howells mkdir -p $(OUTPUT)$(1) && \ 1162b73f65dSDavid Howells $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2) 117b7248defSJiri Olsa 118b7248defSJiri Olsa QUIET_CLEAN = @printf ' CLEAN %s\n' $1; 119b7248defSJiri Olsa QUIET_INSTALL = @printf ' INSTALL %s\n' $1; 120d3244248SQuentin Monnet QUIET_UNINST = @printf ' UNINST %s\n' $1; 12198d89bfdSBorislav Petkov endif 12298d89bfdSBorislav Petkovendif 123