diff --git a/Application.mk b/Application.mk index ba3b7f7c4..b4c9a8965 100644 --- a/Application.mk +++ b/Application.mk @@ -89,9 +89,16 @@ $(MAINOBJ): %$(OBJEXT): %.c $(call COMPILE, $<, $@) endif +ifeq ($(LOADABLE),y) +.built: $(OBJS) + $(call ELFLD, $(APPNAME)_main, $(OBJS), $(APPNAME)) + $(Q) mkdir -p $(BIN_DIR) + $(Q) install $(APPNAME) $(BIN_DIR)$(DELIM)$(APPNAME) +else .built: $(OBJS) $(call ARCHIVE, $(BIN), $(OBJS)) $(Q) touch $@ +endif ifeq ($(CONFIG_BUILD_KERNEL),y) $(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) diff --git a/Make.defs b/Make.defs index a63ec82eb..482f503c7 100644 --- a/Make.defs +++ b/Make.defs @@ -56,6 +56,33 @@ define REGISTER endef endif +# COMPILE - a macro to compile a loadable app in C + +ifeq ($(LOADABLE),y) +define COMPILE + @echo "CC) $1" + $(Q) $(CC) -c $(CELFFLAGS) -DLOADABLE_APP $1 -o $2 +endef +endif + +# COMPILEXX - a macro to compile a loadable app in C++ + +ifeq ($(LOADABLE),y) +define COMPILEXX + @echo "CXX: $1" + $(Q) $(CXX) -c $(CXXELFFLAGS) -DLOADABLE_APP $1 -o $2 +endef +endif + +# ELFLD - a macro to link loadable app +# Example: $(call ELFLD, entry point, in-file(s), out-file) + +define ELFLD + @echo "LD: $3" + $(Q) $(LD) $(LDELFFLAGS) $2 -o $3 + $(Q) chmod +x $3 +endef + # Tools # # In a normal build, tools will reside in the nuttx/tools sub-directory and diff --git a/Makefile b/Makefile index 1111668cd..3287054fe 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,11 @@ BIN_DIR = $(APPDIR)$(DELIM)bin BIN = libapps$(LIBEXT) +# Symbol table for loadable apps. + +SYMTABSRC = $(APPDIR)$(DELIM)symtab_apps.c +SYMTABOBJ = $(APPDIR)$(DELIM)symtab_apps.o + # Build targets all: $(BIN) @@ -97,7 +102,15 @@ $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),depend)) $(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),clean))) $(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) -$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) +make_symbols: +ifeq ($(CONFIG_EXAMPLES_NSH_SYMTAB),y) + mkdir -p $(BIN_DIR) + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BIN_DIR) $(SYMTABSRC) + $(call COMPILE, $(SYMTABSRC), $(SYMTABOBJ)) + $(call ARCHIVE, $(APPDIR)$(DELIM)$(BIN), $(SYMTABOBJ)) +endif + +$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) make_symbols .install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install) @@ -143,6 +156,7 @@ clean_context: $(Q) $(MAKE) -C platform clean_context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean) + $(call DELFILE, $(SYMTABSRC)) $(call DELFILE, $(BIN)) $(call DELFILE, Kconfig) $(call DELDIR, $(BIN_DIR)) @@ -164,6 +178,7 @@ else ) endif $(call DELFILE, .depend) + $(call DELFILE, $(SYMTABSRC)) $(call DELFILE, $(BIN)) $(call DELFILE, Kconfig) $(call DELDIR, $(BIN_DIR)) diff --git a/examples/hello/Kconfig b/examples/hello/Kconfig index cd74a901d..ae46e5918 100644 --- a/examples/hello/Kconfig +++ b/examples/hello/Kconfig @@ -4,7 +4,7 @@ # config EXAMPLES_HELLO - bool "\"Hello, World!\" example" + tristate "\"Hello, World!\" example" default n ---help--- Enable the \"Hello, World!\" example diff --git a/examples/hello/Make.defs b/examples/hello/Make.defs index cc176e18e..c01a50ae5 100644 --- a/examples/hello/Make.defs +++ b/examples/hello/Make.defs @@ -34,6 +34,6 @@ # ############################################################################ -ifeq ($(CONFIG_EXAMPLES_HELLO),y) +ifneq ($(CONFIG_EXAMPLES_HELLO),) CONFIGURED_APPS += examples/hello endif diff --git a/examples/hello/Makefile b/examples/hello/Makefile index 3133b33fb..f7b1c0cf9 100644 --- a/examples/hello/Makefile +++ b/examples/hello/Makefile @@ -41,8 +41,13 @@ CONFIG_EXAMPLES_HELLO_PRIORITY ?= SCHED_PRIORITY_DEFAULT CONFIG_EXAMPLES_HELLO_STACKSIZE ?= 2048 APPNAME = hello -PRIORITY = $(CONFIG_EXAMPLES_HELLO_PRIORITY) + +ifeq ($(CONFIG_EXAMPLES_HELLO),m) +LOADABLE = y +else +PRIORITY = $(CONFIG_EXAMPLES_HELLO_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_HELLO_STACKSIZE) +endif # Hello, World! Example diff --git a/examples/hello/hello_main.c b/examples/hello/hello_main.c index b3fe8778c..8a3d5bcec 100644 --- a/examples/hello/hello_main.c +++ b/examples/hello/hello_main.c @@ -48,7 +48,7 @@ * hello_main ****************************************************************************/ -#ifdef CONFIG_BUILD_KERNEL +#if defined (CONFIG_BUILD_KERNEL) || defined (LOADABLE_APP) int main(int argc, FAR char *argv[]) #else int hello_main(int argc, char *argv[]) diff --git a/examples/helloxx/Kconfig b/examples/helloxx/Kconfig index 1a8bcd738..78432547b 100644 --- a/examples/helloxx/Kconfig +++ b/examples/helloxx/Kconfig @@ -4,7 +4,7 @@ # config EXAMPLES_HELLOXX - bool "\"Hello, World!\" C++ example" + tristate "\"Hello, World!\" C++ example" default n depends on HAVE_CXX ---help--- diff --git a/examples/helloxx/Make.defs b/examples/helloxx/Make.defs index 18a28d637..63a9256ed 100644 --- a/examples/helloxx/Make.defs +++ b/examples/helloxx/Make.defs @@ -34,6 +34,6 @@ # ############################################################################ -ifeq ($(CONFIG_EXAMPLES_HELLOXX),y) +ifneq ($(CONFIG_EXAMPLES_HELLOXX),) CONFIGURED_APPS += examples/helloxx endif diff --git a/examples/helloxx/Makefile b/examples/helloxx/Makefile index 64b9b32d7..fe69e14ee 100644 --- a/examples/helloxx/Makefile +++ b/examples/helloxx/Makefile @@ -48,7 +48,12 @@ PROGNAME = $(CONFIG_EXAMPLES_HELLOXX_PROGNAME) # helloxx built-in application info APPNAME = helloxx + +ifeq ($(CONFIG_EXAMPLES_HELLOXX),m) +LOADABLE = y +else PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = 2048 +endif include $(APPDIR)/Application.mk diff --git a/examples/helloxx/helloxx_main.cxx b/examples/helloxx/helloxx_main.cxx index 0a2896e77..62991d34d 100644 --- a/examples/helloxx/helloxx_main.cxx +++ b/examples/helloxx/helloxx_main.cxx @@ -127,7 +127,7 @@ static CHelloWorld g_HelloWorld; extern "C" { -#ifdef CONFIG_BUILD_KERNEL +#if defined (CONFIG_BUILD_KERNEL) || defined (LOADABLE_APP) int main(int argc, FAR char *argv[]) #else int helloxx_main(int argc, char *argv[]) diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 90a5ffeeb..2bc75dd2e 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -182,6 +182,7 @@ config NSH_BUILTIN_APPS config NSH_FILE_APPS bool "Enable execution of program files" + option modules default n depends on LIBC_EXECFUNCS ---help---