@@ -131,39 +131,65 @@ ifndef COMPONENT_DIRS
131
131
EXTRA_COMPONENT_DIRS ?=
132
132
COMPONENT_DIRS := $(PROJECT_PATH ) /components $(EXTRA_COMPONENT_DIRS ) $(IDF_PATH ) /components $(PROJECT_PATH ) /main
133
133
endif
134
+ # Make sure that every directory in the list is an absolute path without trailing slash.
135
+ # This is necessary to split COMPONENT_DIRS into SINGLE_COMPONENT_DIRS and MULTI_COMPONENT_DIRS below.
136
+ COMPONENT_DIRS := $(foreach cd,$(COMPONENT_DIRS ) ,$(abspath $(cd ) ) )
134
137
export COMPONENT_DIRS
135
138
136
139
ifdef SRCDIRS
137
140
$(warning SRCDIRS variable is deprecated. These paths can be added to EXTRA_COMPONENT_DIRS or COMPONENT_DIRS instead.)
138
141
COMPONENT_DIRS += $(abspath $(SRCDIRS ) )
139
142
endif
140
143
141
- # The project Makefile can define a list of components, but if it does not do this we just take all available components
142
- # in the component dirs. A component is COMPONENT_DIRS directory, or immediate subdirectory,
144
+ # List of component directories, i.e. directories which contain a component.mk file
145
+ SINGLE_COMPONENT_DIRS := $(abspath $(dir $(dir $(foreach cd,$(COMPONENT_DIRS ) ,\
146
+ $(wildcard $(cd ) /component.mk) ) ) ) )
147
+
148
+ # List of components directories, i.e. directories which may contain components
149
+ MULTI_COMPONENT_DIRS := $(filter-out $(SINGLE_COMPONENT_DIRS ) ,$(COMPONENT_DIRS ) )
150
+
151
+ # The project Makefile can define a list of components, but if it does not do this
152
+ # we just take all available components in the component dirs.
153
+ # A component is COMPONENT_DIRS directory, or immediate subdirectory,
143
154
# which contains a component.mk file.
144
155
#
145
156
# Use the "make list-components" target to debug this step.
146
157
ifndef COMPONENTS
147
158
# Find all component names. The component names are the same as the
148
159
# directories they're in, so /bla/components/mycomponent/component.mk -> mycomponent.
149
- COMPONENTS := $(dir $(foreach cd,$(COMPONENT_DIRS ) , \
150
- $(wildcard $(cd ) /* /component.mk) $(wildcard $(cd ) /component.mk) \
151
- ) )
160
+ # We need to do this for MULTI_COMPONENT_DIRS only, since SINGLE_COMPONENT_DIRS
161
+ # are already known to contain component.mk.
162
+ COMPONENTS := $(dir $(foreach cd,$(MULTI_COMPONENT_DIRS ) ,$(wildcard $(cd ) /* /component.mk) ) ) \
163
+ $(SINGLE_COMPONENT_DIRS )
152
164
COMPONENTS := $(sort $(foreach comp,$(COMPONENTS ) ,$(lastword $(subst /, ,$(comp ) ) ) ) )
153
165
endif
154
- # After a full manifest of component names is determined, subtract the ones explicitly omitted by the project Makefile.
166
+ # After a full manifest of component names is determined, subtract the ones explicitly
167
+ # omitted by the project Makefile.
168
+ EXCLUDE_COMPONENTS ?=
155
169
ifdef EXCLUDE_COMPONENTS
156
- COMPONENTS := $(filter-out $(EXCLUDE_COMPONENTS ) , $(COMPONENTS ) )
170
+ COMPONENTS := $(filter-out $(subst ",,$(EXCLUDE_COMPONENTS ) ) , $(COMPONENTS ) )
171
+ # to keep syntax highlighters happy: "))
157
172
endif
158
173
export COMPONENTS
159
174
160
175
# Resolve all of COMPONENTS into absolute paths in COMPONENT_PATHS.
176
+ # For each entry in COMPONENT_DIRS:
177
+ # - either this is directory with multiple components, in which case check that
178
+ # a subdirectory with component name exists, and it contains a component.mk file.
179
+ # - or, this is a directory of a single component, in which case the name of this
180
+ # directory has to match the component name
161
181
#
162
182
# If a component name exists in multiple COMPONENT_DIRS, we take the first match.
163
183
#
164
184
# NOTE: These paths must be generated WITHOUT a trailing / so we
165
185
# can use $(notdir x) to get the component name.
166
- COMPONENT_PATHS := $(foreach comp,$(COMPONENTS ) ,$(firstword $(foreach cd,$(COMPONENT_DIRS ) ,$(wildcard $(dir $(cd ) )$(comp ) $(cd ) /$(comp ) ) ) ) )
186
+ COMPONENT_PATHS := $(foreach comp,$(COMPONENTS ) ,\
187
+ $(firstword $(foreach cd,$(COMPONENT_DIRS ) ,\
188
+ $(if $(findstring $(cd ) ,$(MULTI_COMPONENT_DIRS ) ) ,\
189
+ $(abspath $(dir $(wildcard $(cd ) /$(comp ) /component.mk) ) ) ,) \
190
+ $(if $(findstring $(cd ) ,$(SINGLE_COMPONENT_DIRS ) ) ,\
191
+ $(if $(filter $(comp ) ,$(notdir $(cd ) ) ) ,$(cd ) ,) ,) \
192
+ ) ) )
167
193
export COMPONENT_PATHS
168
194
169
195
TEST_COMPONENTS ?=
0 commit comments