]> granicus.if.org Git - esp-idf/commitdiff
Build system: Allow components to add to the global CFLAGS via Makefile.projbuild
authorAngus Gratton <angus@espressif.com>
Fri, 9 Sep 2016 00:14:38 +0000 (10:14 +1000)
committerAngus Gratton <angus@espressif.com>
Fri, 9 Sep 2016 01:08:19 +0000 (11:08 +1000)
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.

12 files changed:
components/bootloader/Makefile.projbuild
components/expat/Makefile
components/lwip/component.mk
components/mbedtls/Makefile.projbuild [new file with mode: 0644]
components/mbedtls/component.mk
components/tcpip_adapter/component.mk
docs/build_system.rst
make/common.mk
make/component_common.mk
make/project.mk
make/project_config.mk
tools/kconfig/Makefile

index 48c09d4816e08e84b6ae89c4d45b18c6f69ed991..c8f6e5e62eb95cc72c86bb06380d9bfdc6a77c4a 100644 (file)
@@ -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)
 
index 96b74ce25c6f986eb3b8d985e14164211870b988..81990aa599a700b15ba73c62d5f40bf23fc0063d 100644 (file)
@@ -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
index a605355d2b192c93fc3ab1115f52cb7becb1a415..750c1cc0c1faecc8bbab8059d538dcb6ef066a8e 100644 (file)
@@ -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 (file)
index 0000000..51300ef
--- /dev/null
@@ -0,0 +1,4 @@
+# Anyone compiling mbedTLS code needs the name of the
+# alternative config file
+CFLAGS += -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"'
+
index ed8f117fff93f80438e707cd1105143c030dd37b..98838d4d7b36a32c32ee27e821ed2d03b2f074ae 100644 (file)
@@ -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
index cb863d1b7dea976a029424cf8cfc5f674aa1eb0e..14596443fbf9e6417b169a3bcc797c77abf93c77 100755 (executable)
@@ -2,6 +2,6 @@
 # Component Makefile
 #
 
-EXTRA_CFLAGS := -DLWIP_ESP8266
+CFLAGS += -DLWIP_ESP8266
 
 include $(IDF_PATH)/make/component_common.mk
index 24381019b551c412eda69dbe006d2f899120089f..43055a4787c88b8fd62800ebc34ef04470147a59 100644 (file)
@@ -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
index 7f372cc3051be550a2b317817fed644c503afbe3..4965fa3523fa128e3672634fcad72ef18c40a3a9 100644 (file)
@@ -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
index 1a3d9281c8ee5c15a669964dbaa947615293a76c..ebad525a76036957d410f3d07ae339c60459054d 100644 (file)
@@ -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)
 
index ca80697cb6dc44d7df44416d6ea1fec91c8f00be..7526774bdb3e314d35130e3b9e02d7c580fdec86 100644 (file)
@@ -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)
index e39fdac3bbeb3438086a69882cfdcafd39a21d59..d2909bb308ebd8c0be9a5aa6308f5f2b559654dd 100644 (file)
@@ -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)
 
index b265e9b3819c99f4470a921792001d59c93fd85f..2df04f3f2713fa16945396aa31ad91c1fcead224 100644 (file)
@@ -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