kconfig: Allow out of tree building, build under cmake build directory

This commit is contained in:
Angus Gratton 2018-02-06 18:03:41 +08:00 committed by Angus Gratton
parent cb99531d15
commit 7eaf2f4bdb
2 changed files with 33 additions and 16 deletions

View File

@ -1,7 +1,7 @@
include(ExternalProject) include(ExternalProject)
macro(kconfig_set_variables) macro(kconfig_set_variables)
set(MCONF ${IDF_PATH}/tools/kconfig/mconf) set(MCONF kconfig_bin/mconf)
set_default(SDKCONFIG ${PROJECT_PATH}/sdkconfig) set_default(SDKCONFIG ${PROJECT_PATH}/sdkconfig)
set(SDKCONFIG_HEADER ${CMAKE_BINARY_DIR}/sdkconfig.h) set(SDKCONFIG_HEADER ${CMAKE_BINARY_DIR}/sdkconfig.h)
@ -10,19 +10,20 @@ macro(kconfig_set_variables)
set(ROOT_KCONFIG ${IDF_PATH}/Kconfig) set(ROOT_KCONFIG ${IDF_PATH}/Kconfig)
endmacro() endmacro()
# Use the existing Makefile to build mconf when needed # Use the existing Makefile to build mconf (out of tree) when needed
# #
# TODO: replace this with something more Windows-friendly # TODO: Find a solution on Windows
ExternalProject_Add(mconf ExternalProject_Add(mconf
SOURCE_DIR ${IDF_PATH}/tools/kconfig SOURCE_DIR ${IDF_PATH}/tools/kconfig
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_IN_SOURCE 1 BINARY_DIR "kconfig_bin"
BUILD_COMMAND make mconf BUILD_COMMAND make -f ${IDF_PATH}/tools/kconfig/Makefile mconf
BUILD_BYPRODUCTS ${MCONF} BUILD_BYPRODUCTS "kconfig_bin" ${MCONF}
INSTALL_COMMAND "" INSTALL_COMMAND ""
EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_ALL 1
) )
# Find all Kconfig files for all components # Find all Kconfig files for all components
function(kconfig_process_config) function(kconfig_process_config)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/config") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/config")
@ -65,7 +66,7 @@ function(kconfig_process_config)
"COMPONENT_KCONFIGS=${kconfigs}" "COMPONENT_KCONFIGS=${kconfigs}"
"COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}" "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
"KCONFIG_CONFIG=${SDKCONFIG}" "KCONFIG_CONFIG=${SDKCONFIG}"
${IDF_PATH}/tools/kconfig/mconf ${ROOT_KCONFIG} ${MCONF} ${ROOT_KCONFIG}
VERBATIM VERBATIM
USES_TERMINAL) USES_TERMINAL)

View File

@ -2,6 +2,10 @@
# Kernel configuration targets # Kernel configuration targets
# These targets are used from top-level makefile # These targets are used from top-level makefile
# SRCDIR is kconfig source dir, allows for out-of-tree builds
# if building in tree, SRCDIR==build dir
SRCDIR := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
PHONY += xconfig gconfig menuconfig config silentoldconfig \ PHONY += xconfig gconfig menuconfig config silentoldconfig \
localmodconfig localyesconfig clean localmodconfig localyesconfig clean
@ -156,13 +160,22 @@ help:
@echo ' tinyconfig - Configure the tiniest possible kernel' @echo ' tinyconfig - Configure the tiniest possible kernel'
# lxdialog stuff # lxdialog stuff
check-lxdialog := lxdialog/check-lxdialog.sh check-lxdialog := $(SRCDIR)/lxdialog/check-lxdialog.sh
# Use recursively expanded variables so we do not call gcc unless # Use recursively expanded variables so we do not call gcc unless
# we really need to do so. (Do not call gcc as part of make mrproper) # we really need to do so. (Do not call gcc as part of make mrproper)
CFLAGS += $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) \ CFLAGS += $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) \
-DLOCALE -MD -DLOCALE -MD
%.o: $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
lxdialog/%.o: $(SRCDIR)/lxdialog/%.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o: %.c
$(CC) -I $(SRCDIR) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
# =========================================================================== # ===========================================================================
# Shared Makefile for the various kconfig executables: # Shared Makefile for the various kconfig executables:
# conf: Used for defconfig, oldconfig and related targets # conf: Used for defconfig, oldconfig and related targets
@ -199,9 +212,12 @@ clean-files += $(all-objs) $(all-deps) conf mconf
# Check that we have the required ncurses stuff installed for lxdialog (menuconfig) # Check that we have the required ncurses stuff installed for lxdialog (menuconfig)
PHONY += dochecklxdialog PHONY += dochecklxdialog
$(addprefix ,$(lxdialog)): dochecklxdialog $(addprefix ,$(lxdialog)): dochecklxdialog
dochecklxdialog: dochecklxdialog: lxdialog
$(CONFIG_SHELL) $(check-lxdialog) -check $(CC) $(CFLAGS) $(LOADLIBES_mconf) $(CONFIG_SHELL) $(check-lxdialog) -check $(CC) $(CFLAGS) $(LOADLIBES_mconf)
lxdialog:
mkdir -p lxdialog
always := dochecklxdialog always := dochecklxdialog
# Add environment specific flags # Add environment specific flags
@ -308,7 +324,7 @@ gconf.glade.h: gconf.glade
gconf.glade gconf.glade
mconf: $(mconf-objs) mconf: lxdialog $(mconf-objs)
$(CC) -o $@ $(mconf-objs) $(LOADLIBES_mconf) $(CC) -o $@ $(mconf-objs) $(LOADLIBES_mconf)
conf: $(conf-objs) conf: $(conf-objs)
@ -316,15 +332,15 @@ conf: $(conf-objs)
zconf.tab.c: zconf.lex.c zconf.tab.c: zconf.lex.c
zconf.lex.c: zconf.l zconf.lex.c: $(SRCDIR)/zconf.l
flex -L -P zconf -o zconf.lex.c zconf.l flex -L -P zconf -o zconf.lex.c $<
zconf.hash.c: zconf.gperf zconf.hash.c: $(SRCDIR)/zconf.gperf
# strip CRs on Windows systems where gperf will otherwise barf on them # strip CRs on Windows systems where gperf will otherwise barf on them
sed -E "s/\\x0D$$//" zconf.gperf | gperf -t --output-file zconf.hash.c -a -C -E -g -k '1,3,$$' -p -t sed -E "s/\\x0D$$//" $< | gperf -t --output-file zconf.hash.c -a -C -E -g -k '1,3,$$' -p -t
zconf.tab.c: zconf.y zconf.tab.c: $(SRCDIR)/zconf.y
bison -t -l -p zconf -o zconf.tab.c zconf.y bison -t -l -p zconf -o zconf.tab.c $<
clean: clean:
rm -f $(clean-files) rm -f $(clean-files)