1
0
Fork 0
forked from nuttx/nuttx-update

support building external code into the OS, similar to how "external" apps work

This works by having the build system look for nuttx/external/Kconfig
to determine whether this directory is present or not. nuttx/external
is gitignored in order to be added by the final user but not to be
commited into the repo. Tipically this will by a symbolic link, just like
apps/external.

Inside external/ a Makefile should be placed with the same structure
than any nuttx/ subdirectory (eg: nuttx/drivers/). The
nuttx/external/Kconfig will be sourced and any options defined there will
appear at the bottom of menuconfig (unless options are conditioned on
menus, in which case they will appear accordingly).

The purpose is to allow arch/board independent code, which for any
reason is not to be upstreamed (propietary, not relevant for mainline,
testing, etc), to be built into the OS during OS building stage. This
way the user does not need to fork the NuttX repo to do so. This feature
complements well with external apps and custom board support.
This commit is contained in:
Matias N 2020-09-14 16:51:31 -03:00 committed by Xiang Xiao
parent 166242c171
commit 9ce4de634d
11 changed files with 73 additions and 14 deletions

1
.external-dummy/Kconfig Normal file
View file

@ -0,0 +1 @@
# This is supposed to be empty

View file

@ -0,0 +1,2 @@
This directory exists to hold an empty Kconfig which is used
when no nuttx/external is present.

1
.gitignore vendored
View file

@ -46,3 +46,4 @@
core core
Make*.dep Make*.dep
uImage uImage
/external

12
Kconfig
View file

@ -1826,3 +1826,15 @@ endmenu
menu "Application Configuration" menu "Application Configuration"
source "$APPSDIR/Kconfig" source "$APPSDIR/Kconfig"
endmenu endmenu
# Support optionally including external code
# into the OS build. EXTERNALDIR will be used
# to either point to 'nuttx/external' or
# 'nuttx/.external-dummy', if 'nuttx/external'
# does not contain a Kconfig file
config EXTERNALDIR
string
option env="EXTERNALDIR"
source "$EXTERNALDIR/Kconfig"

View file

@ -72,6 +72,11 @@ endif
KERNDEPDIRS += sched drivers boards $(ARCH_SRC) KERNDEPDIRS += sched drivers boards $(ARCH_SRC)
KERNDEPDIRS += fs binfmt KERNDEPDIRS += fs binfmt
ifeq ($(EXTERNALDIR),external)
KERNDEPDIRS += external
endif
CONTEXTDIRS = boards fs $(APPDIR) CONTEXTDIRS = boards fs $(APPDIR)
CLEANDIRS += pass1 CLEANDIRS += pass1

View file

@ -48,6 +48,12 @@ USERLIBS =
NUTTXLIBS += staging$(DELIM)libdrivers$(LIBEXT) NUTTXLIBS += staging$(DELIM)libdrivers$(LIBEXT)
# External code support
ifeq ($(EXTERNALDIR),external)
NUTTXLIBS += staging$(DELIM)libexternal$(LIBEXT)
endif
# Add libraries for board support # Add libraries for board support
NUTTXLIBS += staging$(DELIM)libboards$(LIBEXT) NUTTXLIBS += staging$(DELIM)libboards$(LIBEXT)

View file

@ -47,6 +47,12 @@ USERLIBS =
NUTTXLIBS += staging$(DELIM)libdrivers$(LIBEXT) NUTTXLIBS += staging$(DELIM)libdrivers$(LIBEXT)
# External code support
ifeq ($(EXTERNALDIR),external)
NUTTXLIBS += staging$(DELIM)libexternal$(LIBEXT)
endif
# Add libraries for board support # Add libraries for board support
NUTTXLIBS += staging$(DELIM)libboards$(LIBEXT) NUTTXLIBS += staging$(DELIM)libboards$(LIBEXT)

View file

@ -106,6 +106,12 @@ drivers$(DELIM)libdrivers$(LIBEXT): pass2dep
staging$(DELIM)libdrivers$(LIBEXT): drivers$(DELIM)libdrivers$(LIBEXT) staging$(DELIM)libdrivers$(LIBEXT): drivers$(DELIM)libdrivers$(LIBEXT)
$(Q) $(call INSTALL_LIB,$<,$@) $(Q) $(call INSTALL_LIB,$<,$@)
external$(DELIM)libexternal$(LIBEXT): pass2dep
$(Q) $(MAKE) -C external libexternal$(LIBEXT) EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)"
staging$(DELIM)libexternal$(LIBEXT): external$(DELIM)libexternal$(LIBEXT)
$(Q) $(call INSTALL_LIB,$<,$@)
binfmt$(DELIM)libbinfmt$(LIBEXT): pass2dep binfmt$(DELIM)libbinfmt$(LIBEXT): pass2dep
$(Q) $(MAKE) -C binfmt libbinfmt$(LIBEXT) EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)" $(Q) $(MAKE) -C binfmt libbinfmt$(LIBEXT) EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)"

View file

@ -63,6 +63,13 @@ CONFIG_APPS_DIR = ../apps
endif endif
APPDIR := $(realpath ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi}) APPDIR := $(realpath ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi})
# External code support
# If external/ contains a Kconfig, we define the EXTERNALDIR variable to 'external'
# so that main Kconfig can find it. Otherwise, we redirect it to a dummy Kconfig
# This is due to kconfig inability to do conditional inclusion.
EXTERNALDIR := $(shell if [ -r $(TOPDIR)/external/Kconfig ]; then echo 'external'; else echo '.external-dummy'; fi)
# CONTEXTDIRS include directories that have special, one-time pre-build # CONTEXTDIRS include directories that have special, one-time pre-build
# requirements. Normally this includes things like auto-generation of # requirements. Normally this includes things like auto-generation of
# configuration specific files or creation of configurable symbolic links # configuration specific files or creation of configurable symbolic links
@ -455,28 +462,28 @@ pass2dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT)
# file in the NuttX tools GIT repository for additional information. # file in the NuttX tools GIT repository for additional information.
config: apps_preconfig config: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf Kconfig
oldconfig: apps_preconfig oldconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf --oldconfig Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf --oldconfig Kconfig
olddefconfig: apps_preconfig olddefconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf --olddefconfig Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf --olddefconfig Kconfig
menuconfig: apps_preconfig menuconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-mconf Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-mconf Kconfig
nconfig: apps_preconfig nconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-nconf Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-nconf Kconfig
qconfig: apps_preconfig qconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-qconf Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-qconf Kconfig
gconfig: apps_preconfig gconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-gconf Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-gconf Kconfig
savedefconfig: apps_preconfig savedefconfig: apps_preconfig
$(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf --savedefconfig defconfig.tmp Kconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf --savedefconfig defconfig.tmp Kconfig
$(Q) sed -i -e "/CONFIG_APPS_DIR=/d" defconfig.tmp $(Q) sed -i -e "/CONFIG_APPS_DIR=/d" defconfig.tmp
$(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp $(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp
$(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp; true $(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp; true

View file

@ -48,6 +48,13 @@ CONFIG_APPS_DIR = ..\apps
endif endif
APPDIR := $(realpath ${shell if exist "$(CONFIG_APPS_DIR)\Makefile" echo $(CONFIG_APPS_DIR)}) APPDIR := $(realpath ${shell if exist "$(CONFIG_APPS_DIR)\Makefile" echo $(CONFIG_APPS_DIR)})
# External code support
# If external/ contains a Kconfig, we define the EXTERNALDIR variable to 'external'
# so that main Kconfig can find it. Otherwise, we redirect it to a dummy Kconfig
# This is due to kconfig inability to do conditional inclusion.
EXTERNALDIR := $(shell if [ -r $(TOPDIR)\external\Kconfig ]; then echo 'external'; else echo '.external-dummy'; fi)
# CONTEXTDIRS include directories that have special, one-time pre-build # CONTEXTDIRS include directories that have special, one-time pre-build
# requirements. Normally this includes things like auto-generation of # requirements. Normally this includes things like auto-generation of
# configuration specific files or creation of configurable symbolic links # configuration specific files or creation of configurable symbolic links
@ -411,22 +418,22 @@ pass2dep: context tools\mkdeps$(HOSTEXEEXT)
# misc\tools\README.txt for additional information. # misc\tools\README.txt for additional information.
config: apps_preconfig config: apps_preconfig
$(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf Kconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& set EXTERNALDIR=$(EXTERNALDIR)& kconfig-conf Kconfig
oldconfig: apps_preconfig oldconfig: apps_preconfig
$(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf --oldconfig Kconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& set EXTERNALDIR=$(EXTERNALDIR)& kconfig-conf --oldconfig Kconfig
olddefconfig: apps_preconfig olddefconfig: apps_preconfig
$(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf --olddefconfig Kconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& set EXTERNALDIR=$(EXTERNALDIR)& kconfig-conf --olddefconfig Kconfig
menuconfig: configenv apps_preconfig menuconfig: configenv apps_preconfig
$(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-mconf Kconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& set EXTERNALDIR=$(EXTERNALDIR)& kconfig-mconf Kconfig
nconfig: apps_preconfig nconfig: apps_preconfig
$(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-nconf Kconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& set EXTERNALDIR=$(EXTERNALDIR)& kconfig-nconf Kconfig
savedefconfig: apps_preconfig savedefconfig: apps_preconfig
$(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf --savedefconfig defconfig.tmp Kconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& set EXTERNALDIR=$(EXTERNALDIR)& kconfig-conf --savedefconfig defconfig.tmp Kconfig
$(Q) sed -i -e "/CONFIG_APPS_DIR=/d" defconfig.tmp $(Q) sed -i -e "/CONFIG_APPS_DIR=/d" defconfig.tmp
$(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp $(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp
-$(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp -$(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp

View file

@ -48,6 +48,12 @@ USERLIBS =
NUTTXLIBS += staging$(DELIM)libdrivers$(LIBEXT) NUTTXLIBS += staging$(DELIM)libdrivers$(LIBEXT)
# External code support
ifeq ($(EXTERNALDIR),external)
NUTTXLIBS += staging$(DELIM)libexternal$(LIBEXT)
endif
# Add libraries for board support # Add libraries for board support
NUTTXLIBS += staging$(DELIM)libboards$(LIBEXT) NUTTXLIBS += staging$(DELIM)libboards$(LIBEXT)