How to config makefile with subfolder

panjikuai
Posts: 4
Joined: Tue Feb 28, 2017 7:03 am

How to config makefile with subfolder

Postby panjikuai » Tue Mar 07, 2017 12:57 pm

Hi support team,

Firstly I'm not familiar with linux makefile, in esp-idf SDK example, all the example are based on one main.c file, if I want to pass the compiling, I need to put all of the c files into the same path as that of the main.c located; actually in real application ,we need sub folders to manage different function modules , for example:
in the folder: /workspace/esp-idf-template/main: may includes:
main.c
iot_sdk
------src
---mqqt.c
---smartconfig.c
------inc
---mqtt.h
---smartconfig.h
if I assign the file structure above, how to set the configure file: such as component.mk and others.

It would be helpful for real application development.

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

Re: How to config makefile with subfolder

Postby ESP_Angus » Tue Mar 07, 2017 11:16 pm

By default, the component.mk file will pick up all source files (.c, .cpp, .S) in the same directory, and add an "include" directory to the search path. You can override this behaviour as described in the documentation.

For your example you posted, a component.mk in the same directory as main.c would look something like

Code: Select all

COMPONENT_SRCDIRS = . iot_sdk/src/
COMPONENT_ADD_INCLUDEDIRS = iot_sdk/inc
In this example the "main" component contains all of these source files. However, you may want to structure your code in a different way to this so that your project also contains multiple components. The "Example Project" in the docs gives an example of an alternative layout: http://esp-idf.readthedocs.io/en/latest ... le-project

Who is online

Users browsing this forum: No registered users and 138 guests