I'm not able to reproduce the issue here... I have cloned esp-idf-template and added "CFLAGS := -DFOO=1" line above "include" line in main/component.mk.
Here's a part of build log:
Code: Select all
xtensa-esp32-elf-gcc -DFOO=1 -DESP_PLATFORM -I /Volumes/ESPTools/esp-idf-template/main/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/bt/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/driver/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/esp32/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/expat/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/expat/include/expat -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/freertos/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/json/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/json/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/log/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/lwip/include/lwip -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/lwip/include/lwip/port -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/lwip/include/lwip/posix -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/mbedtls/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/mbedtls/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/newlib/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/newlib/platform_include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/nghttp/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/nghttp/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/nvs_flash/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/openssl/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/spi_flash/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/tcpip_adapter/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/vfs/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/xtensa-debug-module/include -I /Volumes/ESPTools/esp-idf-template/build/include -I. -c /Volumes/ESPTools/esp-idf-template/main/./main.c -o main.o
Note that -DFOO=1 was added, but all other flags which came from the build system were removed. So it's better to add "CFLAGS += -DFOO=1" instead.
Code: Select all
xtensa-esp32-elf-gcc -std=gnu99 -Og -ggdb -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -MMD -MP -Wall -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DFOO=1 -DESP_PLATFORM -I /Volumes/ESPTools/esp-idf-template/main/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/bt/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/driver/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/esp32/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/expat/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/expat/include/expat -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/freertos/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/json/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/json/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/log/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/lwip/include/lwip -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/lwip/include/lwip/port -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/lwip/include/lwip/posix -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/mbedtls/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/mbedtls/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/newlib/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/newlib/platform_include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/nghttp/port/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/nghttp/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/nvs_flash/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/openssl/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/spi_flash/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/tcpip_adapter/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/vfs/include -I /Users/igrokhotkov/e/ESPTools/esp32-sdkng/components/xtensa-debug-module/include -I /Volumes/ESPTools/esp-idf-template/build/include -I. -c /Volumes/ESPTools/esp-idf-template/main/./main.c -o main.o
Now "-DFOO=1" is present after all other defines which came from the build system.
Note that the build system may not detect the change to makefile to rebuild all .c files... So you may need to run "make main-clean main-build" to rebuild the component to see extra CFLAGS taking effect.