blob: 1e8b6116ba3c4ee03e137b737b84aaa26d133b94 [file] [log] [blame]
Borislav Petkov9e4a6642013-02-20 16:32:29 +01001ifneq ($(O),)
David Howellsbf351822012-11-05 21:02:08 +00002ifeq ($(origin O), command line)
Masahiro Yamada028568d2017-10-02 17:07:28 +09003 dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
4 ABSOLUTE_O := $(shell cd $(O) ; pwd)
David Howellsbf351822012-11-05 21:02:08 +00005 OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
Steven Rostedtc8831222012-08-13 10:23:02 -04006 COMMAND_O := O=$(ABSOLUTE_O)
David Howellsbf351822012-11-05 21:02:08 +00007ifeq ($(objtree),)
8 objtree := $(O)
9endif
Borislav Petkov98d89bf2012-04-11 18:36:14 +020010endif
Borislav Petkov9e4a6642013-02-20 16:32:29 +010011endif
Borislav Petkov98d89bf2012-04-11 18:36:14 +020012
Borislav Petkov98d89bf2012-04-11 18:36:14 +020013# check that the output directory actually exists
Borislav Petkov9e4a6642013-02-20 16:32:29 +010014ifneq ($(OUTPUT),)
Masahiro Yamada028568d2017-10-02 17:07:28 +090015OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
Borislav Petkov98d89bf2012-04-11 18:36:14 +020016$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
17endif
18
19#
20# Include saner warnings here, which can catch bugs:
21#
Borislav Petkovd8caf3e2012-04-11 18:36:15 +020022EXTRA_WARNINGS := -Wbad-function-cast
23EXTRA_WARNINGS += -Wdeclaration-after-statement
24EXTRA_WARNINGS += -Wformat-security
25EXTRA_WARNINGS += -Wformat-y2k
26EXTRA_WARNINGS += -Winit-self
27EXTRA_WARNINGS += -Wmissing-declarations
28EXTRA_WARNINGS += -Wmissing-prototypes
29EXTRA_WARNINGS += -Wnested-externs
30EXTRA_WARNINGS += -Wno-system-headers
31EXTRA_WARNINGS += -Wold-style-definition
32EXTRA_WARNINGS += -Wpacked
33EXTRA_WARNINGS += -Wredundant-decls
34EXTRA_WARNINGS += -Wshadow
Borislav Petkovd8caf3e2012-04-11 18:36:15 +020035EXTRA_WARNINGS += -Wstrict-prototypes
36EXTRA_WARNINGS += -Wswitch-default
37EXTRA_WARNINGS += -Wswitch-enum
38EXTRA_WARNINGS += -Wundef
39EXTRA_WARNINGS += -Wwrite-strings
40EXTRA_WARNINGS += -Wformat
Borislav Petkov98d89bf2012-04-11 18:36:14 +020041
David Carrillo-Cisneros38660582017-08-27 00:54:40 -070042CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
43
44ifeq ($(CC_NO_CLANG), 1)
Arnaldo Carvalho de Melo093b75e2017-02-14 10:34:35 -030045EXTRA_WARNINGS += -Wstrict-aliasing=3
46endif
47
Arnaldo Carvalho de Melo3337e682017-02-22 16:54:53 -030048# Hack to avoid type-punned warnings on old systems such as RHEL5:
49# We should be changing CFLAGS and checking gcc version, but this
50# will do for now and keep the above -Wstrict-aliasing=3 in place
51# in newer systems.
52# Needed for the __raw_cmpxchg in tools/arch/x86/include/asm/cmpxchg.h
53ifneq ($(filter 3.%,$(MAKE_VERSION)),) # make-3
54EXTRA_WARNINGS += -fno-strict-aliasing
55endif
56
Borislav Petkov98d89bf2012-04-11 18:36:14 +020057ifneq ($(findstring $(MAKEFLAGS), w),w)
58PRINT_DIR = --no-print-directory
59else
60NO_SUBDIR = :
61endif
62
Masahiro Yamada6f0fa582017-05-19 20:42:30 +090063ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
Josh Poimboeufe572d082017-01-18 22:16:55 -060064 silent=1
65endif
Josh Poimboeufe572d082017-01-18 22:16:55 -060066
David Howellsca9dfc62012-11-05 15:15:24 +000067#
68# Define a callable command for descending to a new directory
69#
70# Call by doing: $(call descend,directory[,target])
71#
72descend = \
David Howellsbf351822012-11-05 21:02:08 +000073 +mkdir -p $(OUTPUT)$(1) && \
David Howells2b73f652012-11-13 14:14:38 -030074 $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2)
David Howellsca9dfc62012-11-05 15:15:24 +000075
David Howellsbf351822012-11-05 21:02:08 +000076QUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
Borislav Petkov98d89bf2012-04-11 18:36:14 +020077QUIET_SUBDIR1 =
78
Josh Poimboeufe572d082017-01-18 22:16:55 -060079ifneq ($(silent),1)
Ingo Molnar65fb0992013-10-09 11:49:27 +020080 ifneq ($(V),1)
81 QUIET_CC = @echo ' CC '$@;
Jiri Olsabdebbac2013-12-19 14:42:03 +010082 QUIET_CC_FPIC = @echo ' CC FPIC '$@;
Ingo Molnar65fb0992013-10-09 11:49:27 +020083 QUIET_AR = @echo ' AR '$@;
84 QUIET_LINK = @echo ' LINK '$@;
85 QUIET_MKDIR = @echo ' MKDIR '$@;
86 QUIET_GEN = @echo ' GEN '$@;
Borislav Petkov98d89bf2012-04-11 18:36:14 +020087 QUIET_SUBDIR0 = +@subdir=
Ingo Molnar65fb0992013-10-09 11:49:27 +020088 QUIET_SUBDIR1 = ;$(NO_SUBDIR) \
89 echo ' SUBDIR '$$subdir; \
Borislav Petkov98d89bf2012-04-11 18:36:14 +020090 $(MAKE) $(PRINT_DIR) -C $$subdir
Ingo Molnar65fb0992013-10-09 11:49:27 +020091 QUIET_FLEX = @echo ' FLEX '$@;
92 QUIET_BISON = @echo ' BISON '$@;
David Howellsbf351822012-11-05 21:02:08 +000093
94 descend = \
Ingo Molnar65fb0992013-10-09 11:49:27 +020095 +@echo ' DESCEND '$(1); \
David Howellsbf351822012-11-05 21:02:08 +000096 mkdir -p $(OUTPUT)$(1) && \
David Howells2b73f652012-11-13 14:14:38 -030097 $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2)
Jiri Olsab7248de2013-12-19 14:42:00 +010098
99 QUIET_CLEAN = @printf ' CLEAN %s\n' $1;
100 QUIET_INSTALL = @printf ' INSTALL %s\n' $1;
Ingo Molnar65fb0992013-10-09 11:49:27 +0200101 endif
Borislav Petkov98d89bf2012-04-11 18:36:14 +0200102endif