Augment files in /make/ with notices (apache-2.0)
[apeos.git] / make / common.mk
blobcfac01c9b00ed61f4dd61b97cc302ff72293cb46
1 # Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
3 # Functionality common to both top-level project makefile (project.mk)
4 # and component makefiles (component_wrapper.mk)
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # Include project config makefile, if it exists.
20 # (Note that we only rebuild this makefile automatically for some
21 # targets, see project_config.mk for details.)
22 SDKCONFIG_MAKEFILE ?= $(abspath $(BUILD_DIR_BASE)/include/config/auto.conf)
23 -include $(SDKCONFIG_MAKEFILE)
24 export SDKCONFIG_MAKEFILE # sub-makes (like bootloader) will reuse this path
26 # BATCH_BUILD flag disables interactive terminal features, defaults to verbose build
27 ifdef BATCH_BUILD
28 V ?= 1
29 endif
31 #Handling of V=1/VERBOSE=1 flag
33 # if V=1, $(summary) does nothing and $(details) will echo extra details
34 # if V is unset or not 1, $(summary) echoes a summary and $(details) does nothing
35 VERBOSE ?=
36 V ?= $(VERBOSE)
37 ifeq ("$(V)","1")
38 summary := @true
39 details := @echo
40 else
41 summary := @echo
42 details := @true
44 # disable echoing of commands, directory names
45 MAKEFLAGS += --silent
46 endif # $(V)==1
48 ifdef CONFIG_MAKE_WARN_UNDEFINED_VARIABLES
49 MAKEFLAGS += --warn-undefined-variables
50 endif
52 # General make utilities
54 # convenience variable for printing an 80 asterisk wide separator line
55 SEPARATOR:="*******************************************************************************"
57 # macro to remove quotes from an argument, ie $(call dequote,$(CONFIG_BLAH))
58 define dequote
59 $(subst ",,$(1))
60 endef
61 # " comment kept here to keep syntax highlighting happy
64 # macro to keep an absolute path as-is, but resolve a relative path
65 # against a particular parent directory
67 # $(1) path to resolve
68 # $(2) directory to resolve non-absolute path against
70 # Path and directory don't have to exist (definition of a "relative
71 # path" is one that doesn't start with /)
73 # $(2) can contain a trailing forward slash or not, result will not
74 # double any path slashes.
76 # example $(call resolvepath,$(CONFIG_PATH),$(CONFIG_DIR))
77 define resolvepath
78 $(foreach dir,$(1),$(if $(filter /%,$(dir)),$(dir),$(subst //,/,$(2)/$(dir))))
79 endef
82 # macro to include a target only if it's on the list of targets that make
83 # was invoked with
85 # This allows you to have something like an "order-only phony prerequisite",
86 # ie a prerequisite that determines an order phony targets have to run in.
88 # Because normal order-only prerequisites don't work with phony targets.
90 # example $(call prereq_if_explicit,erase_flash)
91 define prereq_if_explicit
92 $(filter $(1),$(MAKECMDGOALS))
93 endef
95 # macro to kill duplicate items in a list without messing up the sort order of the list.
96 # Will only keep the unique items; if there are non-unique items in the list, it will remove
97 # the later recurring ones so only the first one remains.
98 # Copied from http://stackoverflow.com/questions/16144115/makefile-remove-duplicate-words-without-sorting
99 define uniq
100 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
101 endef