.. _esp-idf-template: https://github.com/espressif/esp-idf-template
.. _GNU Make Manual: https://www.gnu.org/software/make/manual/make.html
.. _[_f1]: Actually, some components in esp-idf are "pure configuration" components that don't have a component.mk file, only a Makefile.projbuild and/or Kconfig.projbuild file. However, these components are unusual and most components have a component.mk file.
+
+
+Custom sdkconfig defaults
+-------------------------
+
+For example projects or other projects where you don't want to specify a full sdkconfig configuration, but you do want to override some key values from the esp-idf defaults, it is possible to create a file ``sdkconfig.defaults`` in the project directory. This file will be used when running ``make defconfig``, or creating a new config from scratch.
+
+To override the name of this file, set the ``SDKCONFIG_DEFAULTS`` environment variable.
+
PROJECT_NAME := ble_adv
include $(IDF_PATH)/make/project.mk
-
-# Copy some defaults into the sdkconfig by default
-# so BT stack is enabled
-sdkconfig: sdkconfig.defaults
- $(Q) cp $< $@
-
-menuconfig: sdkconfig
-defconfig: sdkconfig
COMPONENT_ADD_INCLUDEDIRS := components/include
include $(IDF_PATH)/make/project.mk
-
-# Copy some defaults into the sdkconfig by default
-# so BT stack is enabled
-sdkconfig: sdkconfig.defaults
- $(Q) cp $< $@
-
-menuconfig: sdkconfig
-defconfig: sdkconfig
COMPONENT_ADD_INCLUDEDIRS := components/include
include $(IDF_PATH)/make/project.mk
-
-# Copy some defaults into the sdkconfig by default
-# so BT stack is enabled
-sdkconfig: sdkconfig.defaults
- $(Q) cp $< $@
-
-menuconfig: sdkconfig
-defconfig: sdkconfig
COMPONENT_ADD_INCLUDEDIRS := components/include
include $(IDF_PATH)/make/project.mk
-
-# Copy some defaults into the sdkconfig by default
-# so BT stack is enabled
-sdkconfig: sdkconfig.defaults
- $(Q) cp $< $@
-
-menuconfig: sdkconfig
-defconfig: sdkconfig
+++ /dev/null
-# Some sdkconfig parameters overriden from the defaults for this example,
-# This file is in git but will be overwritten with the autogenerated file
-# the first time "menuconfig" is run (changes ignored by git).
-CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
-CONFIG_PARTITION_TABLE_TWO_OTA=y
--- /dev/null
+# Default sdkconfig parameters to use the OTA
+# partition table layout, with a 4MB flash size
+CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
+CONFIG_PARTITION_TABLE_TWO_OTA=y
# unless it's overriden (happens for bootloader)
SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig
+# SDKCONFIG_DEFAULTS is an optional file containing default
+# overrides (usually used for esp-idf examples)
+SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults
+
# reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
$(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf:
MAKEFLAGS=$(ORIGINAL_MAKEFLAGS) CC=$(HOSTCC) LD=$(HOSTLD) \
COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \
COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)"
-menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig
+menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig | defconfig
$(summary) MENUCONFIG
$(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig
ifeq ("$(wildcard $(SDKCONFIG))","")
ifeq ("$(call prereq_if_explicit,defconfig)","")
-# if not configuration is present and defconfig is not a target, run makeconfig
-$(SDKCONFIG): menuconfig
+# if not configuration is present and defconfig is not a target, run defconfig then menuconfig
+$(SDKCONFIG): defconfig menuconfig
else
+# otherwise, just defconfig
$(SDKCONFIG): defconfig
endif
endif
+$(wildcard $(PROJECT_PATH)/sdkconfig.defaults): | menuconfig defconfig
+ cp $< $@
+
+# defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
defconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(BUILD_DIR_BASE)
$(summary) DEFCONFIG
+ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
+ cp $(SDKCONFIG_DEFAULTS) $(SDKCONFIG)
+endif
mkdir -p $(BUILD_DIR_BASE)/include/config
$(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --olddefconfig $(IDF_PATH)/Kconfig