Used by mbedTLS to set MBEDTLS_CONFIG_FILE in all components.
This change sets CFLAGS/etc at the project level and then exports those
variables for components, rather than setting them independently each time
a component Makefile is invoked.
$(BOOTLOADER_BIN): $(COMPONENT_PATH)/src/sdkconfig
$(Q) PROJECT_PATH= \
- LDFLAGS= \
- CFLAGS= \
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src MAKEFLAGS= V=$(V) TARGET_BIN_LAYOUT="$(BOOTLOADER_TARGET_BIN_LAYOUT)" $(BOOTLOADER_BIN)
bootloader-clean:
$(Q) PROJECT_PATH= \
- LDFLAGS= \
- CFLAGS= \
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src app-clean MAKEFLAGS= V=$(V)
COMPONENT_SRCDIRS := library port
-EXTRA_CFLAGS := -Wno-error=address -Waddress -DHAVE_EXPAT_CONFIG_H
+CFLAGS += -Wno-error=address -Waddress -DHAVE_EXPAT_CONFIG_H
include $(IDF_PATH)/make/component.mk
COMPONENT_SRCDIRS := api apps/sntp apps core/ipv4 core/ipv6 core netif port/freertos port/netif port
-EXTRA_CFLAGS := -Wno-error=address -Waddress -DLWIP_ESP8266
+CFLAGS += -Wno-error=address -Waddress -DLWIP_ESP8266
include $(IDF_PATH)/make/component_common.mk
--- /dev/null
+# Anyone compiling mbedTLS code needs the name of the
+# alternative config file
+CFLAGS += -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"'
+
COMPONENT_SRCDIRS := library port
-EXTRA_CFLAGS += -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"'
-
include $(IDF_PATH)/make/component_common.mk
# Component Makefile
#
-EXTRA_CFLAGS := -DLWIP_ESP8266
+CFLAGS += -DLWIP_ESP8266
include $(IDF_PATH)/make/component_common.mk
in. Components may also include a Kconfig file defining the compile-time options that are
settable by means of the menu system.
-Project makefile variables that can be set by the programmer::
+Project Makefile variables that can be set by the programmer::
PROJECT_NAME: Mandatory. Name for the project
BUILD_DIR_BASE: Set the directory where all objects/libraries/binaries end up in.
include directories that are passed to the compilation pass of all components and
they do not have a Kconfig option.
-Component makefile variables that can be set by the programmer::
+Component-specific component.mk variables that can be set by the programmer::
COMPONENT_ADD_INCLUDEDIRS: Relative path to include directories to be added to
- the entire project
+ the entire project. If an include directory is only needed to compile this
+ specific component, don't add it here.
COMPONENT_PRIV_INCLUDEDIRS: Relative path to include directories that are only used
- when compiling this specific component
+ when compiling this specific component.
COMPONENT_DEPENDS: Names of any components that need to be compiled before this component.
- COMPONENT_ADD_LDFLAGS: Ld flags to add for this project. Defaults to -l$(COMPONENT_NAME).
+ COMPONENT_ADD_LDFLAGS: LD flags to add for the entire project. Defaults to -l$(COMPONENT_NAME).
Add libraries etc in the current directory as $(abspath libwhatever.a)
- COMPONENT_EXTRA_INCLUDES: Any extra include paths. These will be prefixed with '-I' and
- passed to the compiler; please put absolute paths here.
+ COMPONENT_EXTRA_INCLUDES: Any extra include paths used when compiling the component's
+ source files. These will be prefixed with '-I' and passed to the compiler.
+ Similar to COMPONENT_PRIV_INCLUDEDIRS, but these paths are passed as-is instead of
+ expanded relative to the component directory.
COMPONENT_SRCDIRS: Relative directories to look in for sources. Defaults to '.', the current
directory (the root of the component) only. Use this to specify any subdirectories. Note
that specifying this overwrites the default action of compiling everything in the
COMPONENTS: Name of the components to be included
CONFIG_*: All values set by 'make menuconfig' have corresponding Makefile variables.
+Inside your component's component.mk makefile, you can override or add to these variables
+as necessary. The changes are isolated from other components (see Makefile.projbuild below
+if you want to share these changes with all other components.)
+
For components, there also are these defines::
COMPONENT_PATH: Absolute path to the root of the source tree of the component we're
Makefile.projbuild
------------------
-For components that have parts that need to be run when building of the
-project is done, you can create a file called Makefile.projbuild in the
-component root directory. This file will be included in the main
-Makefile.
+For components that have parts that need to be evaluated in the top-level
+project context, you can create a file called Makefile.projbuild in the
+component root directory. These files is included into the project's
+top-level Makefile.
+
+For example, if your component needs to add to CFLAGS for the entire
+project (not just for its own source files) then you can set
+``CFLAGS +=`` in Makefile.projbuild. Note that this isn't necessary for
+adding include directories to the project, you can set
+``COMPONENT_ADD_INCLUDEDIRS`` (see above) in the component.mk.
KConfig.projbuild
# see project_config.mk for details.)
-include $(PROJECT_PATH)/build/include/config/auto.conf
-ifeq ("$(LDFLAGS)","")
-LDFLAGS = -nostdlib \
- -L$(IDF_PATH)/lib \
- -L$(IDF_PATH)/ld \
- $(addprefix -L$(BUILD_DIR_BASE)/,$(COMPONENTS) $(SRCDIRS)) \
- -u call_user_start_cpu0 \
- -Wl,--gc-sections \
- -Wl,-static \
- -Wl,--start-group \
- $(COMPONENT_LDFLAGS) \
- -lgcc \
- -Wl,--end-group
-endif
-
-ifeq ("$(CFLAGS)","")
-CFLAGS = -DESP_PLATFORM -Og -std=gnu99 -g3 \
- -Wpointer-arith -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable \
- -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -Wall -ffunction-sections -fdata-sections $(EXTRA_CFLAGS)
-endif
-
-ifeq ("$(CXXFLAGS)","")
-CXXFLAGS = -DESP_PLATFORM -Og -std=gnu++11 -g3 \
- -Wpointer-arith -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable \
- -Wl,-EL -nostdlib -mlongcalls -Wall -ffunction-sections -fdata-sections $(EXTRA_CFLAGS) -fno-exceptions
-endif
-
#Handling of V=1/VERBOSE=1 flag
#
# if V=1, $(summary) does nothing and $(details) will echo extra details
include $(IDF_PATH)/make/common.mk
-#Some of these options are overridable by the components Makefile.
+#Some of these options are overridable by the component's component.mk Makefile
#Name of the component
COMPONENT_NAME ?= $(lastword $(subst /, ,$(realpath $(COMPONENT_PATH))))
OWN_INCLUDES:=$(abspath $(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS) $(COMPONENT_PRIV_INCLUDEDIRS)))
COMPONENT_INCLUDES := $(OWN_INCLUDES) $(filter-out $(OWN_INCLUDES),$(COMPONENT_INCLUDES))
-#This target is used to collect variable values from inside the main makefile
+#This target is used to collect variable values from inside project.mk
+# see project.mk GetVariable macro for details.
get_variable:
@echo "$(GET_VARIABLE)=$(call $(GET_VARIABLE)) "
$(Q) rm -f $(COMPONENT_LIBRARY) $(COMPONENT_OBJS) $(COMPONENT_OBJS:.o=.d) $(COMPONENT_EXTRA_CLEAN)
endif
-#Also generate dependency files
-CFLAGS+=-MMD -MP
-CXXFLAGS+=-MMD -MP
#Include all dependency files already generated
-include $(COMPONENT_OBJS:.o=.d)
#Include functionality common to both project & component
-include $(IDF_PATH)/make/common.mk
+# Set default LDFLAGS
+
+LDFLAGS ?= -nostdlib \
+ -L$(IDF_PATH)/lib \
+ -L$(IDF_PATH)/ld \
+ $(addprefix -L$(BUILD_DIR_BASE)/,$(COMPONENTS) $(SRCDIRS)) \
+ -u call_user_start_cpu0 \
+ -Wl,--gc-sections \
+ -Wl,-static \
+ -Wl,--start-group \
+ $(COMPONENT_LDFLAGS) \
+ -lgcc \
+ -Wl,--end-group \
+ -Wl,-EL
+
+# Set default CPPFLAGS, CFLAGS, CXXFLAGS
+#
+# These are exported so that components can use them when compiling.
+#
+# If you need your component to add CFLAGS/etc for it's own source compilation only, set CFLAGS += in your component's Makefile.
+#
+# If you need your component to add CFLAGS/etc globally for all source
+# files, set CFLAGS += in your component's Makefile.projbuild
+
+# CPPFLAGS used by an compile pass that uses the C preprocessor
+CPPFLAGS = -DESP_PLATFORM -Og -g3 -Wpointer-arith -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wall -ffunction-sections -fdata-sections -mlongcalls -nostdlib -MMD -MP
+
+# C flags use by C only
+CFLAGS = $(CPPFLAGS) -std=gnu99 -g3 -fno-inline-functions
+
+# CXXFLAGS uses by C++ only
+CXXFLAGS = $(CPPFLAGS) -Og -std=gnu++11 -g3 -fno-exceptions
+
+export CFLAGS CPPFLAGS CXXFLAGS
+
#Set host compiler and binutils
HOSTCC := $(CC)
HOSTLD := $(LD)
# clear MAKEFLAGS as the menuconfig makefile uses implicit compile rules
$(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf:
MAKEFLAGS="" \
- CFLAGS="" \
- LDFLAGS="" \
CC=$(HOSTCC) LD=$(HOSTLD) \
$(MAKE) -C $(KCONFIG_TOOL_DIR)
# We need this, in case the user has it in its environment
unexport CONFIG_
+# Unset some environment variables set in the project environment
+CFLAGS :=
+CPPFLAGS :=
+LDFLAGS :=
default: mconf conf