1ifneq ($(O),) 2ifeq ($(origin O), command line) 3 dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),) 4 ABSOLUTE_O := $(shell cd $(O) ; pwd) 5 OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/) 6 COMMAND_O := O=$(ABSOLUTE_O) 7ifeq ($(objtree),) 8 objtree := $(O) 9endif 10endif 11endif 12 13# check that the output directory actually exists 14ifneq ($(OUTPUT),) 15OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd) 16$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) 17endif 18 19# 20# Include saner warnings here, which can catch bugs: 21# 22EXTRA_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 35EXTRA_WARNINGS += -Wstrict-prototypes 36EXTRA_WARNINGS += -Wswitch-default 37EXTRA_WARNINGS += -Wswitch-enum 38EXTRA_WARNINGS += -Wundef 39EXTRA_WARNINGS += -Wwrite-strings 40EXTRA_WARNINGS += -Wformat 41 42ifneq ($(CC), clang) 43EXTRA_WARNINGS += -Wstrict-aliasing=3 44endif 45 46ifneq ($(findstring $(MAKEFLAGS), w),w) 47PRINT_DIR = --no-print-directory 48else 49NO_SUBDIR = : 50endif 51 52ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4 53ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),) 54 silent=1 55endif 56else # make-3.8x 57ifneq ($(filter s% -s%,$(MAKEFLAGS)),) 58 silent=1 59endif 60endif 61 62# 63# Define a callable command for descending to a new directory 64# 65# Call by doing: $(call descend,directory[,target]) 66# 67descend = \ 68 +mkdir -p $(OUTPUT)$(1) && \ 69 $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2) 70 71QUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir 72QUIET_SUBDIR1 = 73 74ifneq ($(silent),1) 75 ifneq ($(V),1) 76 QUIET_CC = @echo ' CC '$@; 77 QUIET_CC_FPIC = @echo ' CC FPIC '$@; 78 QUIET_AR = @echo ' AR '$@; 79 QUIET_LINK = @echo ' LINK '$@; 80 QUIET_MKDIR = @echo ' MKDIR '$@; 81 QUIET_GEN = @echo ' GEN '$@; 82 QUIET_SUBDIR0 = +@subdir= 83 QUIET_SUBDIR1 = ;$(NO_SUBDIR) \ 84 echo ' SUBDIR '$$subdir; \ 85 $(MAKE) $(PRINT_DIR) -C $$subdir 86 QUIET_FLEX = @echo ' FLEX '$@; 87 QUIET_BISON = @echo ' BISON '$@; 88 89 descend = \ 90 +@echo ' DESCEND '$(1); \ 91 mkdir -p $(OUTPUT)$(1) && \ 92 $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) $(2) 93 94 QUIET_CLEAN = @printf ' CLEAN %s\n' $1; 95 QUIET_INSTALL = @printf ' INSTALL %s\n' $1; 96 endif 97endif 98