From 272bdc0d6e84fed24baea20d6279f0f4344caa99 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Jul 2018 10:42:15 -0600 Subject: [PATCH] apps Makesystem: Fix an error when building apps/ withtout nuttx/, using only the NuttX export package only and assuming that the nuttx/ directory in not even present. In this case, the problem fixed where the apps/Make.defs file was selecting tools from the /tools directory which does not exist because TOPDIR=apps/import. Instead, for this build case, I have not thought of any option but to duplicate scripts as necessary in the apps/tools directory. Also added a top-level target to compile the symbol table. Misc fixes: quoting in scripts, some errors in script syntax. --- Make.defs | 40 ++++++++++++++++++++++++++++++---------- Makefile | 5 ++++- import/Make.defs | 7 ++++--- import/Makefile | 6 +++--- tools/mksymtab.sh | 8 +++++++- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Make.defs b/Make.defs index 415ea09fc..282b6e7e4 100644 --- a/Make.defs +++ b/Make.defs @@ -57,28 +57,49 @@ endef endif # Tools +# +# In a normal build, tools will reside in the nuttx/tools sub-directory and +# TOPDIR will refer to that nuttx/ directory. This, however, is not the +# case when building apps/ with a NuttX export directory; there is no +# apps/import/tools directory. In that case copies of the NuttX tools in +# the apps/tools directory are used. + +DELIM ?= $(strip /) +ifneq (,$(wildcard $(TOPDIR)$(DELIM)tools)) + TOOLDIR = $(TOPDIR)$(DELIM)tools +else + TOOLDIR = $(APPDIR)$(DELIM)tools +endif ifeq ($(DIRLINK),) ifeq ($(CONFIG_WINDOWS_NATIVE),y) - DIRLINK = $(TOPDIR)\tools\link.bat - DIRUNLINK = $(TOPDIR)\tools\unlink.bat + DIRLINK = $(TOOLDIR)$(DELIM)link.bat + DIRUNLINK = $(TOOLDIR)$(DELIM)unlink.bat else ifeq ($(CONFIG_WINDOWS_MSYS),y) - DIRLINK = $(TOPDIR)$(DELIM)tools$(DELIM)copydir.sh - DIRUNLINK = $(TOPDIR)$(DELIM)tools$(DELIM)unlink.sh + DIRLINK = $(TOOLDIR)$(DELIM)copydir.sh + DIRUNLINK = $(TOOLDIR)$(DELIM)unlink.sh else - DIRUNLINK = $(TOPDIR)/tools/unlink.sh + DIRUNLINK = $(TOOLDIR)$(DELIM)unlink.sh ifeq ($(WINTOOL),y) - DIRLINK = $(TOPDIR)/tools/copydir.sh + DIRLINK = $(TOOLDIR)$(DELIM)copydir.sh else - DIRLINK = $(TOPDIR)/tools/link.sh + DIRLINK = $(TOOLDIR)$(DELIM)link.sh endif endif endif ifeq ($(CONFIG_WINDOWS_NATIVE),y) - MKKCONFIG = $(APPDIR)\tools\mkkconfig.bat + MKKCONFIG = $(APPDIR)$(DELIM)tools$(DELIM)mkkconfig.bat else - MKKCONFIG = $(APPDIR)/tools/mkkconfig.sh + MKKCONFIG = $(APPDIR)$(DELIM)tools$(DELIM)mkkconfig.sh +endif + +ifeq ($(INCDIR),) +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + INCDIR = $(TOOLDIR)$(DELIM)incdir.bat +else + INCDIR = $(TOOLDIR)$(DELIM)incdir.sh +endif endif ifeq ($(WINTOOL),y) @@ -89,4 +110,3 @@ endif CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(APPDIR)$(DELIM)include"} CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(APPDIR)$(DELIM)include"} - diff --git a/Makefile b/Makefile index 3adfa7ca4..cec62c3d3 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ BIN = libapps$(LIBEXT) # Build targets all: $(BIN) -.PHONY: import install dirlinks context context_serialize clean_context context_rest .depdirs preconfig depend clean distclean +.PHONY: import symtab install dirlinks context context_serialize clean_context context_rest .depdirs preconfig depend clean distclean .PRECIOUS: libapps$(LIBEXT) define MAKE_template @@ -108,6 +108,9 @@ install: $(BIN_DIR) .install .import: $(BIN) install +symtab: + $(call MAKE_template,import,symtab) + import: $(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import" diff --git a/import/Make.defs b/import/Make.defs index 1480d4a66..6960eb296 100644 --- a/import/Make.defs +++ b/import/Make.defs @@ -186,10 +186,10 @@ AFLAGS = $(CFLAGS) -D__ASSEMBLY__ ifeq ($(WINTOOL),y) # Windows-native toolchains - LDLIBPATH = -L "${shell cygpath -w $(APPDIR)}" -L "${shell cygpath -w $(TOPDIR)$(DELIM)staging}" + LDLIBPATH = -L "${shell cygpath -w $(APPDIR)}" -L "${shell cygpath -w $(TOPDIR)$(DELIM)libs}" else # Linux/Cygwin-native toolchain - LDLIBPATH = -L $(APPDIR) -L $(TOPDIR)$(DELIM)staging + LDLIBPATH = -L $(APPDIR) -L $(TOPDIR)$(DELIM)libs endif LDLIBS = -lapps -lnuttx @@ -199,7 +199,7 @@ LDLIBS = -lapps -lnuttx LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name 2>/dev/null}" ifneq ($(LIBGCC),) - LDLIBPATH += -L ${shell dirname $(LIBGCC)} + LDLIBPATH += -L "${shell dirname $(LIBGCC)}" LDLIBS += -lgcc endif @@ -211,3 +211,4 @@ ifeq ($(WINTOOL),y) else LDELFFLAGS += -T $(TOPDIR)/scripts/gnu-elf.ld endif + diff --git a/import/Makefile b/import/Makefile index bf2560de9..75806ad96 100644 --- a/import/Makefile +++ b/import/Makefile @@ -41,9 +41,9 @@ SUBDIRS = arch build include libs startup tmp FILES = .config System.map User.map -ifeq (,$(wildcard ./symtab.c)) +ifneq (,$(wildcard ./symtab.c)) define MKSYMTAB - $(Q) $(MAKE) -f Makefile.symtab $1 + $(Q) $(MAKE) -f Makefile.symtab $1 TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" endef else define MKSYMTAB @@ -51,7 +51,7 @@ endef endif all: symtab -.PHONY: context depend clean distclean +.PHONY: symtab context depend clean distclean .PRECIOUS: ../libapps$(LIBEXT) symtab: diff --git a/tools/mksymtab.sh b/tools/mksymtab.sh index 105cd5f4e..24b2e419a 100755 --- a/tools/mksymtab.sh +++ b/tools/mksymtab.sh @@ -78,7 +78,13 @@ rm -f $outfile # Extract all of the undefined symbols from the ELF files and create a # list of sorted, unique undefined variable names. -varlist=`find ${dir} -executable -type f | xargs nm | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` +execlist=`find ${dir} -executable -type f` +for exec in ${execlist}; do + nm $exec | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 >>_tmplist.dat +done + +varlist `cat _tmplist | sort - | uniq -` +rm -f _tmplist # Now output the symbol table as a structure in a C source file. All # undefined symbols are declared as void* types. If the toolchain does