Including source in subdirectory tree - had a working solution, now I've broken it :)

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Including source in subdirectory tree - had a working solution, now I've broken it :)

Postby jcsbanks » Tue Aug 14, 2018 4:49 pm

I have a component with a number of subdirectories, and they are only going to grow in number.

Initially I had to use the first line (now commented) in this component.mk, but after some searching came up with the second line to find the subdirectories and add them to COMPONENT_SRCDIRS, and didn't really understand why it worked but it did :)

Unfortunately now moving to another computer, I cannot get the lower line to work despite the same tree structure and get undefined references. The msys32 installation is about 6 months newer if that matters.

Anyone know how to include a whole subdirectory tree in the source directories?

This component.mk is at the same level as the directory "src", so I want to include everything inside there automagically.

Code: Select all

#
# Main component makefile.
#
# This Makefile can be left empty. By default, it will take the sources in the 
# src/ directory, compile them and link them into lib(subdirectory_name).a 
# in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
#COMPONENT_SRCDIRS			:=  src/SeedKey src/SeedKey/MED17/1.1 src/SeedKey/MED17/8.3
COMPONENT_SRCDIRS			:=  . $(notdir $(shell find -L $(COMPONENT_PATH) -maxdepth 1 -mindepth 1 -type d))

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Including source in subdirectory tree - had a working solution, now I've broken it :)

Postby ESP_Angus » Tue Aug 14, 2018 11:56 pm

Hi jcsbanks,

I think you probably don't want the "-maxdepth 1" argument to find, this will cause "find" to list top-level directories only and not recurse any deeper.

A tip which is useful for debugging Makefiles, you can add a line like this at the bottom of your component.mk:

Code: Select all

$(warning COMPONENT_SRCDIRS=$(COMPONENT_SRCDIRS))
And each time this file is expanded a warning will be printed on stderr, which you can then use to debug the values which are being returned by the shell command.

BTW, I don't know your full situation but usually if you have a large number of source directories in a component the recommended approach in ESP-IDF is to refactor this into multiple components, each with distinct functionality.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: Including source in subdirectory tree - had a working solution, now I've broken it :)

Postby jcsbanks » Wed Aug 15, 2018 10:21 am

Thanks @ESP_Angus.

Code: Select all

COMPONENT_SRCDIRS			:=  $(shell find $(COMPONENT_PATH)/src -type d -printf 'src/%P ')
Result:

Code: Select all

COMPONENT_SRCDIRS=src/ src/SeedKey src/SeedKey/MED17 src/SeedKey/MED17/1.1 src/SeedKey/MED17/8.3
The C++ project being brought in by a colleague has source spread through a tree like this. This makes it work.

Who is online

Users browsing this forum: No registered users and 106 guests