diff --git a/components/bootloader/Makefile.projbuild b/components/bootloader/Makefile.projbuild index 48c09d4816..c8f6e5e62e 100644 --- a/components/bootloader/Makefile.projbuild +++ b/components/bootloader/Makefile.projbuild @@ -17,15 +17,11 @@ BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin $(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) diff --git a/components/expat/Makefile b/components/expat/Makefile index 96b74ce25c..81990aa599 100644 --- a/components/expat/Makefile +++ b/components/expat/Makefile @@ -10,6 +10,6 @@ COMPONENT_ADD_INCLUDEDIRS := port/include include/expat 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 diff --git a/components/lwip/component.mk b/components/lwip/component.mk index a605355d2b..750c1cc0c1 100644 --- a/components/lwip/component.mk +++ b/components/lwip/component.mk @@ -6,6 +6,6 @@ COMPONENT_ADD_INCLUDEDIRS := include/lwip include/lwip/port include/lwip/posix 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 diff --git a/components/mbedtls/Makefile.projbuild b/components/mbedtls/Makefile.projbuild new file mode 100644 index 0000000000..51300efd11 --- /dev/null +++ b/components/mbedtls/Makefile.projbuild @@ -0,0 +1,4 @@ +# Anyone compiling mbedTLS code needs the name of the +# alternative config file +CFLAGS += -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' + diff --git a/components/mbedtls/component.mk b/components/mbedtls/component.mk index ed8f117fff..98838d4d7b 100644 --- a/components/mbedtls/component.mk +++ b/components/mbedtls/component.mk @@ -6,6 +6,4 @@ COMPONENT_ADD_INCLUDEDIRS := port/include include COMPONENT_SRCDIRS := library port -EXTRA_CFLAGS += -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' - include $(IDF_PATH)/make/component_common.mk diff --git a/components/tcpip_adapter/component.mk b/components/tcpip_adapter/component.mk index cb863d1b7d..14596443fb 100755 --- a/components/tcpip_adapter/component.mk +++ b/components/tcpip_adapter/component.mk @@ -2,6 +2,6 @@ # Component Makefile # -EXTRA_CFLAGS := -DLWIP_ESP8266 +CFLAGS += -DLWIP_ESP8266 include $(IDF_PATH)/make/component_common.mk diff --git a/docs/build_system.rst b/docs/build_system.rst index 24381019b5..43055a4787 100644 --- a/docs/build_system.rst +++ b/docs/build_system.rst @@ -60,7 +60,7 @@ influencing the build process of the component as well as the project it's used 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. @@ -76,17 +76,20 @@ Project makefile variables that can be set by the programmer:: 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 @@ -114,6 +117,10 @@ be usable in component or project Makefiles:: 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 @@ -152,10 +159,16 @@ details to add to "menuconfig" for this component. 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 diff --git a/make/common.mk b/make/common.mk index 7f372cc305..4965fa3523 100644 --- a/make/common.mk +++ b/make/common.mk @@ -8,32 +8,6 @@ # 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 diff --git a/make/component_common.mk b/make/component_common.mk index 1a3d9281c8..ebad525a76 100644 --- a/make/component_common.mk +++ b/make/component_common.mk @@ -25,7 +25,7 @@ export COMPONENT_PATH 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)))) @@ -58,7 +58,8 @@ COMPONENT_ADD_LDFLAGS ?= -l$(COMPONENT_NAME) 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)) " @@ -82,9 +83,6 @@ clean: $(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) diff --git a/make/project.mk b/make/project.mk index ca80697cb6..7526774bdb 100644 --- a/make/project.mk +++ b/make/project.mk @@ -133,6 +133,41 @@ export PROJECT_PATH #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) diff --git a/make/project_config.mk b/make/project_config.mk index e39fdac3bb..d2909bb308 100644 --- a/make/project_config.mk +++ b/make/project_config.mk @@ -10,8 +10,6 @@ KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig # 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) diff --git a/tools/kconfig/Makefile b/tools/kconfig/Makefile index b265e9b381..2df04f3f27 100644 --- a/tools/kconfig/Makefile +++ b/tools/kconfig/Makefile @@ -18,6 +18,10 @@ endif # 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