aboutsummaryrefslogtreecommitdiff
path: root/nuttx/tools
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/tools')
-rw-r--r--nuttx/tools/Config.mk157
-rw-r--r--nuttx/tools/Makefile.export12
-rw-r--r--nuttx/tools/Makefile.host112
-rw-r--r--nuttx/tools/README.txt111
-rw-r--r--nuttx/tools/b16.c121
-rw-r--r--nuttx/tools/cfgparser.c2
-rwxr-xr-xnuttx/tools/configure.sh92
-rwxr-xr-xnuttx/tools/copydir.bat102
-rwxr-xr-xnuttx/tools/copydir.sh (renamed from nuttx/tools/winlink.sh)2
-rw-r--r--nuttx/tools/define.bat178
-rwxr-xr-xnuttx/tools/define.sh8
-rwxr-xr-xnuttx/tools/incdir.bat165
-rwxr-xr-xnuttx/tools/incdir.sh40
-rwxr-xr-xnuttx/tools/link.bat89
-rw-r--r--nuttx/tools/mkconfig.c2
-rw-r--r--nuttx/tools/mkdeps.bat173
-rw-r--r--nuttx/tools/mkdeps.c721
-rwxr-xr-xnuttx/tools/mkdeps.sh2
-rwxr-xr-xnuttx/tools/mkromfsimg.sh2
-rw-r--r--nuttx/tools/mksymtab.c2
-rwxr-xr-xnuttx/tools/unlink.bat71
21 files changed, 2076 insertions, 88 deletions
diff --git a/nuttx/tools/Config.mk b/nuttx/tools/Config.mk
index 3a82a1937..9ac93e7d0 100644
--- a/nuttx/tools/Config.mk
+++ b/nuttx/tools/Config.mk
@@ -2,7 +2,12 @@
# Config.mk
# Global build rules and macros.
#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
# Author: Richard Cochran
+# Gregory Nutt <gnutt@nuttx.org>
+#
+# This file (along with $(TOPDIR)/.config) must be included by every
+# configuration-specific Make.defs file.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -40,33 +45,177 @@ CONFIG_ARCH := $(patsubst "%",%,$(strip $(CONFIG_ARCH)))
CONFIG_ARCH_CHIP := $(patsubst "%",%,$(strip $(CONFIG_ARCH_CHIP)))
CONFIG_ARCH_BOARD := $(patsubst "%",%,$(strip $(CONFIG_ARCH_BOARD)))
-# Default build rules.
+# Some defaults just to prohibit some bad behavior if for some reason they
+# are not defined
+
+OBJEXT ?= .o
+LIBEXT ?= .a
+
+# DELIM - Path segment delimiter character
+#
+# Depends on this settings defined in board-specific defconfig file installed
+# at $(TOPDIR)/.config:
+#
+# CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ DELIM = $(strip \)
+else
+ DELIM = $(strip /)
+endif
+
+# INCDIR - Convert a list of directory paths to a list of compiler include
+# directirves
+# Example: CFFLAGS += ${shell $(INCDIR) [options] "compiler" "dir1" "dir2" "dir2" ...}
+#
+# Note that the compiler string and each directory path string must quoted if
+# they contain spaces or any other characters that might get mangled by the
+# shell
+#
+# Depends on this setting passed as a make commaond line definition from the
+# toplevel Makefile:
+#
+# TOPDIR - The path to the the top level NuttX directory in the form
+# appropriate for the current build environment
+#
+# Depends on this settings defined in board-specific defconfig file installed
+# at $(TOPDIR)/.config:
+#
+# CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ INCDIR = "$(TOPDIR)\tools\incdir.bat"
+else
+ INCDIR = "$(TOPDIR)/tools/incdir.sh"
+endif
+
+# PREPROCESS - Default macro to run the C pre-processor
+# Example: $(call PREPROCESS, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CPP - The command to invoke the C pre-processor
+# CPPFLAGS - Options to pass to the C pre-processor
define PREPROCESS
@echo "CPP: $1->$2"
$(Q) $(CPP) $(CPPFLAGS) $1 -o $2
endef
+# COMPILE - Default macro to compile one C file
+# Example: $(call COMPILE, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CC - The command to invoke the C compiler
+# CFLAGS - Options to pass to the C compiler
+
define COMPILE
@echo "CC: $1"
$(Q) $(CC) -c $(CFLAGS) $1 -o $2
endef
+# COMPILEXX - Default macro to compile one C++ file
+# Example: $(call COMPILEXX, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CXX - The command to invoke the C++ compiler
+# CXXFLAGS - Options to pass to the C++ compiler
+
define COMPILEXX
@echo "CXX: $1"
$(Q) $(CXX) -c $(CXXFLAGS) $1 -o $2
endef
+# ASSEMBLE - Default macro to assemble one assembly language file
+# Example: $(call ASSEMBLE, in-file, out-file)
+#
+# NOTE that the most common toolchain, GCC, uses the compiler to assemble
+# files because this has the advantage of running the C Pre-Processor against
+# the assembly language files. This is not possible with other toolchains;
+# platforms using those other tools should define AS and over-ride this
+# definition in order to use the assembler directly.
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CC - By default, the C compiler is used to compile assembly language
+# files
+# AFLAGS - Options to pass to the C+compiler
+
define ASSEMBLE
@echo "AS: $1"
$(Q) $(CC) -c $(AFLAGS) $1 -o $2
endef
+# ARCHIVE - Add a list of files to an archive
+# Example: $(call ARCHIVE, archive-file, "file1 file2 file3 ...")
+#
+# Note: The fileN strings may not contain spaces or characters that may be
+# interpreted strangely by the shell
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# AR - The command to invoke the archiver (includes any options)
+#
+# Depends on this settings defined in board-specific defconfig file installed
+# at $(TOPDIR)/.config:
+#
+# CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define ARCHIVE
+ @echo AR: $2
+ $(Q) $(AR) $1 $(2)
+endef
+else
define ARCHIVE
- echo "AR: $2"; \
- $(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
+ @echo "AR: $2"
+ $(Q) $(AR) $1 $(2) || { echo "$(AR) $1 FAILED!" ; exit 1 ; }
endef
+endif
+# DELFILE - Delete one file
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define DELFILE
+ $(Q) if exist $1 (del /f /q $1)
+endef
+else
+define DELFILE
+ $(Q) rm -f $1
+endef
+endif
+
+# DELDIR - Delect one directory
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define DELDIR
+ $(Q) if exist $1 (rmdir /q /s $1)
+endef
+else
+define DELDIR
+ $(Q) rm -rf $1
+endef
+endif
+
+# CLEAN - Default clean target
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define CLEAN
+ $(Q) if exist *$(OBJEXT) (del /f /q *$(OBJEXT))
+ $(Q) if exist *$(LIBEXT) (del /f /q *$(LIBEXT))
+ $(Q) if exist *~ (del /f /q *~)
+ $(Q) if exist (del /f /q .*.swp)
+endef
+else
define CLEAN
- $(Q) rm -f *.o *.a
+ $(Q) rm -f *$(OBJEXT) *$(LIBEXT) *~ .*.swp
endef
+endif
+ \ No newline at end of file
diff --git a/nuttx/tools/Makefile.export b/nuttx/tools/Makefile.export
index ce4842187..002cb526b 100644
--- a/nuttx/tools/Makefile.export
+++ b/nuttx/tools/Makefile.export
@@ -37,10 +37,16 @@ include $(TOPDIR)/.config
include $(EXPORTDIR)/Make.defs
ifdef ARCHSCRIPT
-LDPATH = ${shell echo "$(ARCHSCRIPT)" | sed -e "s/^-T[ ]*//g"}
+ifeq ($(WINTOOL),y)
+LDPATH = ${shell cygpath -u $(patsubst -T,,$(ARCHSCRIPT))}
+else
+LDPATH = $(patsubst -T,,$(ARCHSCRIPT))
+endif
+
LDNAME = ${shell basename ${LDPATH}}
LDDIR = ${shell dirname ${LDPATH}}
endif
+
ARCHSUBDIR = "arch/$(CONFIG_ARCH)/src"
ARCHDIR ="$(TOPDIR)/$(ARCHSUBDIR)"
@@ -61,7 +67,7 @@ endif
@echo "ARCHCFLAGS=\"$(ARCHCFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "ARCHCXXFLAGS=\"$(ARCHCXXFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "CROSSDEV=\"$(CROSSDEV)\"" >> $(EXPORTDIR)/makeinfo.sh
- @chmod 755 $(EXPORTDIR)/makeinfo.sh
+ $(Q) chmod 755 $(EXPORTDIR)/makeinfo.sh
clean:
- @rm -f $(EXPORTDIR)/makeinfo.sh
+ $(Q) rm -f $(EXPORTDIR)/makeinfo.sh
diff --git a/nuttx/tools/Makefile.host b/nuttx/tools/Makefile.host
index 33b7aaab2..4a46901e6 100644
--- a/nuttx/tools/Makefile.host
+++ b/nuttx/tools/Makefile.host
@@ -33,45 +33,119 @@
#
############################################################################
-all: mkconfig mkversion mksyscall bdf-converter
-default: mkconfig mksyscall
+TOPDIR ?= ${shell pwd}/..
+-include $(TOPDIR)/Make.defs
+include ${TOPDIR}/tools/Config.mk
+
+# strtok_r is used in some tools, but does not seem to be available in
+# the MinGW environment.
+
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ HOSTCFLAGS += -D HAVE_STRTOK_C
+endif
+
+all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \
+ mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) mksymtab$(HOSTEXEEXT) \
+ mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT)
+default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT)
+
+ifdef HOSTEXEEXT
+.PHONY: b16 bdf-converter cmpconfig clean mkconfig mkdeps mksymtab \
+ mksyscall mkversion
+else
.PHONY: clean
+endif
-# Add CFLAGS=-g on the make command line build debug versions
+# Add HOSTCFLAGS=-g on the make command line build debug versions
-CFLAGS = -O2 -Wall -I.
+HOSTCFLAGS ?= -O2 -Wall -I.
+HOSTCC ?= gcc
+
+# b16 - Fixed precision math converstion tool
+
+b16$(HOSTEXEEXT): b16.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o b16$(HOSTEXEEXT) b16.c
+
+ifdef HOSTEXEEXT
+b16: b16$(HOSTEXEEXT)
+endif
# mkconfig - Convert a .config file into a C config.h file
-mkconfig: mkconfig.c cfgparser.c
- @gcc $(CFLAGS) -o mkconfig mkconfig.c cfgparser.c
+mkconfig$(HOSTEXEEXT): mkconfig.c cfgparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mkconfig$(HOSTEXEEXT) mkconfig.c cfgparser.c
+
+ifdef HOSTEXEEXT
+mkconfig: mkconfig$(HOSTEXEEXT)
+endif
# cmpconfig - Compare the contents of two configuration files
-cmpconfig: cmpconfig.c
- @gcc $(CFLAGS) -o cmpconfig cmpconfig.c
+cmpconfig$(HOSTEXEEXT): cmpconfig.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cmpconfig$(HOSTEXEEXT) cmpconfig.c
+
+ifdef HOSTEXEEXT
+cmpconfig: cmpconfig$(HOSTEXEEXT)
+endif
# mkversion - Convert a .version file into a C version.h file
-mkversion: mkconfig.c cfgparser.c
- @gcc $(CFLAGS) -o mkversion mkversion.c cfgparser.c
+mkversion$(HOSTEXEEXT): mkconfig.c cfgparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mkversion$(HOSTEXEEXT) mkversion.c cfgparser.c
+
+ifdef HOSTEXEEXT
+mkversion: mkversion$(HOSTEXEEXT)
+endif
# mksyscall - Convert a CSV file into syscall stubs and proxies
-mksyscall: mksyscall.c csvparser.c
- @gcc $(CFLAGS) -o mksyscall mksyscall.c csvparser.c
+mksyscall$(HOSTEXEEXT): mksyscall.c csvparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mksyscall$(HOSTEXEEXT) mksyscall.c csvparser.c
+
+ifdef HOSTEXEEXT
+mksyscall: mksyscall$(HOSTEXEEXT)
+endif
# mksymtab - Convert a CSV file into a symbol table
-mksymtab: mksymtab.c csvparser.c
- @gcc $(CFLAGS) -o mksymtab mksymtab.c csvparser.c
+mksymtab$(HOSTEXEEXT): mksymtab.c csvparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mksymtab$(HOSTEXEEXT) mksymtab.c csvparser.c
+
+ifdef HOSTEXEEXT
+mksymtab: mksymtab$(HOSTEXEEXT)
+endif
# bdf-converter - Converts a BDF font to the NuttX font format
-bdf-converter: bdf-converter.c
- @gcc $(CFLAGS) -o bdf-converter bdf-converter.c
+bdf-converter$(HOSTEXEEXT): bdf-converter.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o bdf-converter$(HOSTEXEEXT) bdf-converter.c
+
+ifdef HOSTEXEEXT
+bdf-converter: bdf-converter$(HOSTEXEEXT)
+endif
+
+# Create dependencies for a list of files
+
+mkdeps$(HOSTEXEEXT): mkdeps.c csvparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mkdeps$(HOSTEXEEXT) mkdeps.c
+
+ifdef HOSTEXEEXT
+mkdeps: mkdeps$(HOSTEXEEXT)
+endif
clean:
- @rm -f *.o *.a *~ .*.swp
- @rm -f mkconfig mksyscall mkversion bdf-converter
- @rm -f mkconfig.exe mksyscall.exe mkversion.exe bdf-converter.exe
+ $(call DELFILE, mkdeps)
+ $(call DELFILE, mkdeps.exe)
+ $(call DELFILE, mkconfig)
+ $(call DELFILE, mkconfig.exe)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, mksyscall)
+ $(call DELFILE, mksyscall.exe)
+ $(call DELFILE, mkversion)
+ $(call DELFILE, mkversion.exe)
+ $(call DELFILE, bdf-converter)
+ $(call DELFILE, bdf-converter.exe)
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) rm -rf *.dSYM
+endif
+ $(call CLEAN)
diff --git a/nuttx/tools/README.txt b/nuttx/tools/README.txt
index 5d52eaeff..2b9ac61f4 100644
--- a/nuttx/tools/README.txt
+++ b/nuttx/tools/README.txt
@@ -1,5 +1,5 @@
tools/README.txt
-^^^^^^^^^^^^^^^^
+================
This README file addresses the contents of the NuttX tools/ directory.
@@ -8,22 +8,38 @@ that are necessary parts of the the NuttX build system. These files
include:
README.txt
+----------
- This file
+ This file!
+
+Config.mk
+---------
+
+ This file contains common definitions used by many configureation files.
+ This file (along with <nuttx>/.config) must be included at the top of
+ each configuration-specific Make.defs file like:
+
+ -include $(TOPDIR)/.config
+ include $(TOPDIR)/tools/Config.mk
+
+ Subsequent logic within the configuration-specific Make.defs file may then
+ override these default definitions as necessary.
configure.sh
+------------
This is a bash script that is used to configure NuttX for a given
target board. See configs/README.txt or Documentation/NuttxPortingGuide.html
for a description of how to configure NuttX with this script.
discover.py
+-----------
Example script for discovering devices in the local network.
It is the counter part to apps/netutils/discover
-
mkconfig.c, cfgparser.c, and cfgparser.h
+----------------------------------------
These are Cs file that are used to build mkconfig program. The mkconfig
program is used during the initial NuttX build.
@@ -38,11 +54,13 @@ mkconfig.c, cfgparser.c, and cfgparser.h
NuttX configuration that can be included by C files.
cmdconfig.c
+-----------
This C file can be used to build a utility for comparing two NuttX
configuration files.
mkexport.sh and Makefile.export
+-------------------------------
These implement part of the top-level Makefile's 'export' target. That
target will bundle up all of the NuttX libraries, header files, and the
@@ -51,6 +69,7 @@ mkexport.sh and Makefile.export
options from the top-level Make.defs file.
mkfsdata.pl
+-----------
This perl script is used to build the "fake" file system and CGI support
as needed for the apps/netutils/webserver. It is currently used only
@@ -61,6 +80,7 @@ mkfsdata.pl
by Adam Dunkels. uIP has a license that is compatible with NuttX.
mkversion.c, cfgparser.c, and cfgparser.h
+-----------------------------------------
This is C file that is used to build mkversion program. The mkversion
program is used during the initial NuttX build.
@@ -74,6 +94,7 @@ mkversion.c, cfgparser.c, and cfgparser.h
version.h provides version information that can be included by C files.
mksyscall.c, cvsparser.c, and cvsparser.h
+-----------------------------------------
This is a C file that is used to build mksyscall program. The mksyscall
program is used during the initial NuttX build by the logic in the top-
@@ -96,6 +117,7 @@ mksyscall.c, cvsparser.c, and cvsparser.h
stub files as output. See syscall/README.txt for additonal information.
mksymtab.c, cvsparser.c, and cvsparser.h
+----------------------------------------
This is a C file that is used to build symbol tables from common-separated
value (CSV) files. This tool is not used during the NuttX build, but
@@ -116,10 +138,12 @@ mksymtab.c, cvsparser.c, and cvsparser.h
./mksymtab.exe tmp.csv tmp.c
pic32mx
+-------
This directory contains build tools used only for PIC32MX platforms
bdf-convert.c
+-------------
This C file is used to build the bdf-converter program. The bdf-converter
program be used to convert fonts in Bitmap Distribution Format (BDF)
@@ -255,6 +279,7 @@ bdf-convert.c
};
Makefile.host
+-------------
This is the makefile that is used to make the mkconfig program from
the mkconfig.c C file, the cmpconfig program from cmpconfig.c C file
@@ -265,20 +290,25 @@ Makefile.host
make -f Makefile.host <program>
mkromfsimg.sh
+-------------
This script may be used to automate the generate of a ROMFS file system
image. It accepts an rcS script "template" and generates and image that
may be mounted under /etc in the NuttX pseudo file system.
mkdeps.sh
+mkdeps.bat
+mkdeps.c
mknulldeps.sh
+-------------
NuttX uses the GCC compilers capabilities to create Makefile dependencies.
The bash script mkdeps.sh is used to run GCC in order to create the
dependencies. If a NuttX configuration uses the GCC toolchain, its Make.defs
file (see configs/README.txt) will include a line like:
- MKDEP = $(TOPDIR)/tools/mkdeps.sh
+ MKDEP = $(TOPDIR)/tools/mkdeps.sh, or
+ MKDEP = $(TOPDIR)/tools/mkdeps[.exe] (See NOTE below)
If the NuttX configuration does not use a GCC compatible toolchain, then
it cannot use the dependencies and instead it uses mknulldeps.sh:
@@ -287,23 +317,64 @@ mknulldeps.sh
The mknulldeps.sh is a stub script that does essentially nothing.
+ NOTE: The mk*deps.* files are undergoing change. mkdeps.sh is a bash
+ script that produces dependencies well for POSIX style hosts (e..g.,
+ Linux and Cygwin). It does not work well for mixed environments with
+ a Windows toolchain running in a POSIX style environemnt (hence, the
+ mknulldeps.sh script). And, of course, cannot be used in a Windows
+ nativ environment.
+
+ [mkdeps.sh does have an option, --winpath, that purports to convert
+ the dependencies generated by a Windows toolchain to POSIX format.
+ However, that is not being used and mostly likely does not cover
+ all of the conversion cases.]
+
+ mkdeps.bat is a simple port of the bash script to run in a Windows
+ command shell. However, it does not work well either because some
+ of the common CFLAGS use characters like '=' which are transformed
+ by the CMD.exe shell.
+
+ mkdeps.c generates mkdeps (on Linux) or mkdeps.exe (on Windows).
+ However, this verison is still under-development. It works well in
+ the all POSIX environment or in the all Windows environment but also
+ does not work well in mixed POSIX environment with a Windows toolchain.
+ In that case, there are still issues with the conversion of things like
+ 'c:\Program Files' to 'c:program files' by bash. Those issues may,
+ eventually be solvable but for now continue to use mknulldeps.sh in
+ that mixed environment.
+
define.sh
+define.bat
+---------
Different compilers have different conventions for specifying pre-
processor definitions on the compiler command line. This bash
script allows the build system to create create command line definitions
without concern for the particular compiler in use.
+ The define.bat script is a counterpart for use in the native Windows
+ build.
+
incdir.sh
+incdir.bat
+---------
Different compilers have different conventions for specifying lists
- of include file paths on the the compiler command line. This bash
- script allows the build system to create include file paths without
+ of include file paths on the the compiler command line. This incdir.sh
+ bash script allows the build system to create include file paths without
concern for the particular compiler in use.
+ The incdir.bat script is a counterpart for use in the native Windows
+ build. However, there is currently only one compiler supported in
+ that context: MinGW-GCC.
+
link.sh
-winlink.sh
+link.bat
+copydir.sh
+copydir.bat
unlink.sh
+unlink.bat
+----------
Different file system have different capabilities for symbolic links.
Some windows file systems have no native support for symbolic links.
@@ -322,30 +393,40 @@ unlink.sh
default. link.sh is a bash script that performs a normal, Linux-style
symbolic link; unlink.sh is a do-it-all unlinking script.
- But if you are building under cygwin using a Windows native toolchain,
- then you will need something like the following in you Make.defs file:
+ But if you are building under cygwin using a Windows native toolchain
+ within a POSIX framework (such as Cygwin), then you will need something
+ like the following in you Make.defs file:
- DIRLINK = $(TOPDIR)/tools/winlink.sh
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
DIRUNLINK = (TOPDIR)/tools/unlink.sh
- winlink.sh will copy the whole directory instead of linking it.
+ copydir.sh will copy the whole directory instead of linking it.
+
+ Finally, if you are running in a pure native Windows environment with
+ a CMD.exe shell, then you will need something like this:
+
+ DIRLINK = $(TOPDIR)/tools/copydir.bat
+ DIRUNLINK = (TOPDIR)/tools/unlink.bat
- NOTE: I have been told that some NuttX users have been able to build
- successfully using the GnuWin32 tools and modifying the link.sh
- script so that it uses the NTFS mklink command. But I have never
- tried that
+ Note that this will copy directories. ;ink.bat might also be used in
+ this case. link.bat will attempt to create a symbolic link using the
+ NTFS mklink.exe command instead of copying files. That logic, however,
+ has not been verified as of this writing.
mkimage.sh
+----------
The creates a downloadable image as needed with the rrload bootloader.
indent.sh
+---------
This script can be used to indent .c and .h files in a manner similar
to my coding NuttX coding style. It doesn't do a really good job,
however (see the comments at the top of the indent.sh file).
zipme.sh
+--------
I use this script to create the nuttx-xx.yy.tar.gz tarballs for
release on SourceForge. It is handy because it also does the
diff --git a/nuttx/tools/b16.c b/nuttx/tools/b16.c
new file mode 100644
index 000000000..66d581ffa
--- /dev/null
+++ b/nuttx/tools/b16.c
@@ -0,0 +1,121 @@
+/****************************************************************************
+ * tools/b16.c
+ *
+ * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void show_usage(const char *progname)
+{
+ fprintf(stderr, "\nUSAGE: %s <b16_t>|<float>\n", progname);
+ fprintf(stderr, "\nWhere:\n");
+ fprintf(stderr, " <b16_t>:\n");
+ fprintf(stderr, " A b16 fixed precision value in hexadecimal form: E.g., 0x00010000\n");
+ fprintf(stderr, " Any value begininning with '0' will assumed by be hexadecimal format\n");
+ fprintf(stderr, " <float>:\n");
+ fprintf(stderr, " A floating value in standard form: E.g., 5.1\n");
+ exit(EXIT_FAILURE);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ double fvalue;
+ unsigned long ulvalue;
+ long lvalue;
+ const char *str;
+ char *endptr;
+
+ /* There must be exactly one argument */
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "\nExpected a single argument\n");
+ show_usage(argv[0]);
+ }
+ str = argv[1];
+
+ /* If the value begins with a zero, we will assume that it is a hexadecimal
+ * representation.
+ */
+
+ if (str[0] == '0')
+ {
+ endptr = NULL;
+ ulvalue = strtoul(str, &endptr, 16);
+ if (!endptr || *endptr != '\0')
+ {
+ fprintf(stderr, "\nHexadecimal argument not fully converted\n");
+ show_usage(argv[0]);
+ }
+
+ if (ulvalue >= 0x80000000)
+ {
+ lvalue = ~ulvalue + 1;
+ }
+ else
+ {
+ lvalue = ulvalue;
+ }
+
+ fvalue = ((double)lvalue) / 65536.0;
+ printf("0x%08lx -> %10.5f\n", ulvalue, fvalue);
+ }
+ else
+ {
+ endptr = NULL;
+ fvalue = strtod(str, &endptr);
+ if (!endptr || *endptr != '\0')
+ {
+ fprintf(stderr, "\nFloating point argument not fully converted\n");
+ show_usage(argv[0]);
+ }
+
+ lvalue = 65536.0 * fvalue;
+ printf("%10.5f -> 0x%08lx\n", fvalue, lvalue);
+ }
+
+ return 0;
+}
diff --git a/nuttx/tools/cfgparser.c b/nuttx/tools/cfgparser.c
index b1f189f6f..1a35f7857 100644
--- a/nuttx/tools/cfgparser.c
+++ b/nuttx/tools/cfgparser.c
@@ -2,7 +2,7 @@
* tools/cfgpaser.c
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <>
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/nuttx/tools/configure.sh b/nuttx/tools/configure.sh
index 3b68fe3f6..ffa997178 100755
--- a/nuttx/tools/configure.sh
+++ b/nuttx/tools/configure.sh
@@ -100,32 +100,54 @@ if [ ! -d "${configpath}" ]; then
exit 3
fi
-if [ ! -r "${configpath}/Make.defs" ]; then
- echo "File \"${configpath}/Make.defs\" does not exist"
+src_makedefs="${configpath}/Make.defs"
+dest_makedefs="${TOPDIR}/Make.defs"
+
+if [ ! -r "${src_makedefs}" ]; then
+ echo "File \"${src_makedefs}\" does not exist"
exit 4
fi
-if [ ! -r "${configpath}/setenv.sh" ]; then
- echo "File \"${configpath}/setenv.sh\" does not exist"
- exit 5
+src_setenv="${configpath}/setenv.sh"
+unset have_setenv
+
+if [ -r "${src_setenv}" ]; then
+ dest_setenv=${TOPDIR}/setenv.sh
+ have_setenv=y
+else
+ src_setenv="${configpath}/setenv.bat"
+ if [ -r "${src_setenv}" ]; then
+ dest_setenv=${TOPDIR}/setenv.bat
+ have_setenv=y
+ else
+ unset src_setenv
+ fi
fi
-if [ ! -r "${configpath}/defconfig" ]; then
- echo "File \"${configpath}/defconfig\" does not exist"
+src_config="${configpath}/defconfig"
+tmp_config="${TOPDIR}/.configX"
+dest_config="${TOPDIR}/.config"
+
+if [ ! -r "${src_config}" ]; then
+ echo "File \"${src_config}\" does not exist"
exit 6
fi
# Extract values needed from the defconfig file. We need:
# (1) The CONFIG_NUTTX_NEWCONFIG setting to know if this is a "new" style
-# configuration, and
-# (2) The CONFIG_APPS_DIR to see if there is a configured location for the
-# application directory.
+# configuration,
+# (2) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a
+# native Windows (meaning that we want setenv.bat vs setenv.sh and we need
+# to use backslashes in the CONFIG_APPS_DIR setting).
+# (3) The CONFIG_APPS_DIR setting to see if there is a configured location for the
+# application directory. This can be overridden from the command line.
-newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${configpath}/defconfig" | cut -d'=' -f2`
+newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${src_config}" | cut -d'=' -f2`
+winnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2`
defappdir=y
if [ -z "${appdir}" ]; then
- quoted=`grep "^CONFIG_APPS_DIR=" "${configpath}/defconfig" | cut -d'=' -f2`
+ quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2`
if [ ! -z "${appdir}" ]; then
appdir=`echo ${quoted} | sed -e "s/\"//g"`
defappdir=n
@@ -157,34 +179,45 @@ if [ -z "${appdir}" ]; then
fi
fi
+# For checking the apps dir path, we need a POSIX version of the relative path.
+
+posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'`
+winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\/g'`
+
# If appsdir was provided (or discovered) then make sure that the apps/
# directory exists
-if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${appdir}" ]; then
- echo "Directory \"${TOPDIR}/${appdir}\" does not exist"
+if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${posappdir}" ]; then
+ echo "Directory \"${TOPDIR}/${posappdir}\" does not exist"
exit 7
fi
# Okay... Everything looks good. Setup the configuration
-install -C "${configpath}/Make.defs" "${TOPDIR}/." || \
- { echo "Failed to copy ${configpath}/Make.defs" ; exit 7 ; }
-install -C "${configpath}/setenv.sh" "${TOPDIR}/." || \
- { echo "Failed to copy ${configpath}/setenv.sh" ; exit 8 ; }
-chmod 755 "${TOPDIR}/setenv.sh"
-install -C "${configpath}/defconfig" "${TOPDIR}/.configX" || \
- { echo "Failed to copy ${configpath}/defconfig" ; exit 9 ; }
+install "${src_makedefs}" "${dest_makedefs}" || \
+ { echo "Failed to copy \"${src_makedefs}\"" ; exit 7 ; }
+if [ "X${have_setenv}" = "Xy" ]; then
+ install "${src_setenv}" "${dest_setenv}" || \
+ { echo "Failed to copy ${src_setenv}" ; exit 8 ; }
+ chmod 755 "${dest_setenv}"
+fi
+install "${src_config}" "${tmp_config}" || \
+ { echo "Failed to copy \"${src_config}\"" ; exit 9 ; }
# If we did not use the CONFIG_APPS_DIR that was in the defconfig config file,
# then append the correct application information to the tail of the .config
# file
if [ "X${defappdir}" = "Xy" ]; then
- sed -i -e "/^CONFIG_APPS_DIR/d" "${TOPDIR}/.configX"
- echo "" >> "${TOPDIR}/.configX"
- echo "# Application configuration" >> "${TOPDIR}/.configX"
- echo "" >> "${TOPDIR}/.configX"
- echo "CONFIG_APPS_DIR=\"$appdir\"" >> "${TOPDIR}/.configX"
+ sed -i -e "/^CONFIG_APPS_DIR/d" "${tmp_config}"
+ echo "" >> "${tmp_config}"
+ echo "# Application configuration" >> "${tmp_config}"
+ echo "" >> "${tmp_config}"
+ if [ "X${winnative}" = "Xy" ]; then
+ echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${tmp_config}"
+ else
+ echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${tmp_config}"
+ fi
fi
# Copy appconfig file. The appconfig file will be copied to ${appdir}/.config
@@ -195,7 +228,7 @@ if [ ! -z "${appdir}" -a "X${newconfig}" != "Xy" ]; then
if [ ! -r "${configpath}/appconfig" ]; then
echo "NOTE: No readable appconfig file found in ${configpath}"
else
- install -C "${configpath}/appconfig" "${TOPDIR}/${appdir}/.config" || \
+ install "${configpath}/appconfig" "${TOPDIR}/${posappdir}/.config" || \
{ echo "Failed to copy ${configpath}/appconfig" ; exit 10 ; }
fi
fi
@@ -203,6 +236,5 @@ fi
# install the final .configX only if it differs from any existing
# .config file.
-install -C "${TOPDIR}/.configX" "${TOPDIR}/.config"
-rm -f "${TOPDIR}/.configX"
-
+install "${tmp_config}" "${dest_config}"
+rm -f "${tmp_config}"
diff --git a/nuttx/tools/copydir.bat b/nuttx/tools/copydir.bat
new file mode 100755
index 000000000..2857c415f
--- /dev/null
+++ b/nuttx/tools/copydir.bat
@@ -0,0 +1,102 @@
+@echo off
+
+rem tools/copydir.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+rem
+rem NuttX uses symbolic links to configure platform-specific directories into
+rem the build system. This works great except for when a Windows native
+rem toolchain is used in a Cygwin environment. In that case, symbolic
+rem links do not work correctly when accessed from the Windows native toolchain;
+rem rather, just look link files with the extension .lnk
+rem
+rem In this environment, the build system will work around this using this script
+rem as a replacement for the 'ln' command. This scrpt will simply copy the
+rem directory into the expected positiion.
+rem
+
+set src=%1
+set dest=%2
+
+rem Verify that arguments were provided
+
+if "%src%"=="" goto :MissingSrc
+if "%dest%"=="" goto :MissingDest
+goto CheckSrc
+
+:MissingSrc
+
+echo Missing ^<src^> and ^<dest^> arguments
+goto :ShowUsage
+
+:MissingDest
+
+echo Missing ^<dest^> arguments
+goto :ShowUsage
+
+rem Verify that a directory exists at the source path
+
+:CheckSrc
+
+if exist %src% goto :CheckDest
+
+echo No directory at %src%
+goto :ShowUsage
+
+:CheckDest
+
+rem If something already exists at the destination path, remove it
+
+if not exist %dest% goto :CopyDir
+
+rmdir /q /s %dest%
+if errorlevel 1 (
+ echo Failed to remove existing object at %dest%
+ goto :ShowUsage
+)
+
+rem Copy the directory
+
+:CopyDir
+
+xcopy %src% %dest% /c /q /s /e /y /i
+echo FAKELNK > %dest%\.fakelnk
+goto :End
+
+:ShowUsage
+echo USAGE: %0 ^<src^> ^<dest^>
+echo Where:
+echo ^<src^> is the source directory to be copied
+echo ^<dest^> is the destination directory to be created
+
+:End
diff --git a/nuttx/tools/winlink.sh b/nuttx/tools/copydir.sh
index f79eda2bd..5d9f79002 100755
--- a/nuttx/tools/winlink.sh
+++ b/nuttx/tools/copydir.sh
@@ -1,6 +1,6 @@
#!/bin/bash
############################################################################
-# tools/winlink.sh
+# tools/copydir.sh
#
# Copyright (C) 2008 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/tools/define.bat b/nuttx/tools/define.bat
new file mode 100644
index 000000000..13d29ac31
--- /dev/null
+++ b/nuttx/tools/define.bat
@@ -0,0 +1,178 @@
+@echo off
+
+rem tools/define.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+
+rem Handle command line options
+rem [-h] <compiler-path> <def1> [-val <val1>] [<def2> [-val <val2>] [<def3> [-val <val3>] ...]]
+rem [-w] [-d] ignored for compatibility with define.sh
+
+set progname=%0
+
+:ArgLoop
+if "%1"=="-d" goto :NextArg
+if "%1"=="-w" goto :NextArg
+if "%1"=="-h" goto :ShowUsage
+
+goto :CheckCompilerPath
+
+:NextArg
+shift
+goto :ArgLoop
+
+:CheckCompilerPath
+
+if "%1"=="" (
+ echo Missing compiler path
+ goto :ShowUsage
+)
+
+set ccpath=%1
+shift
+
+set compiler=
+for /F %%i in ("%ccpath%") do set compiler=%%~ni
+
+if "%1"=="" (
+ echo Missing definition list
+ goto :ShowUsage
+)
+
+rem Check for some well known, non-GCC Windows native tools that require
+rem a special output format as well as special paths
+
+:GetFormat
+set fmt=std
+if "%compiler%"=="ez8cc" goto :SetZdsFormt
+if "%compiler%"=="zneocc" goto :SetZdsFormt
+if "%compiler%"=="ez80cc" goto :SetZdsFormt
+goto :ProcessDefinitions
+
+:SetZdsFormt
+set fmt=zds
+
+rem Now process each directory in the directory list
+
+:ProcessDefinitions
+set response=
+
+:DefinitionLoop
+if "%1"=="" goto :Done
+
+set varname=%1
+shift
+
+rem Handle the output depending on if there is a value for the variable or not
+
+if "%1"=="-val" goto :GetValue
+
+rem Handle the output using the selected format
+
+:NoValue
+if "%fmt%"=="zds" goto :NoValueZDS
+
+:NoValueStandard
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-D%varname%
+ goto :DefinitionLoop
+)
+
+set response=%response% -D%varname%
+goto :DefinitionLoop
+
+:NoValueZDS
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-define:%varname%
+ goto :DefinitionLoop
+)
+
+set response=%response% -define:%varname%
+goto :DefinitionLoop
+
+rem Get value following the variable name
+
+:GetValue
+shift
+set varvalue=%1
+shift
+
+rem Handle the output using the selected format
+
+if "%fmt%"=="zds" goto :ValueZDS
+
+:ValueStandard
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-D%varname%=%varvalue%
+ goto :DefinitionLoop
+)
+
+set response=%response% -D%varname%=%varvalue%
+goto :DefinitionLoop
+
+:ValueZds
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-define:%varname%=%varvalue%
+ goto :DefinitionLoop
+)
+
+set response=%response% -define:%varname%=%varvalue%
+goto :DefinitionLoop
+
+:Done
+echo %response%
+goto :End
+
+:ShowUsage
+echo %progname% is a tool for flexible generation of command line pre-processor
+echo definitions arguments for a variety of diffent ccpaths in a variety of
+echo compilation environments"
+echo USAGE:%progname% [-h] ^<compiler-path^> [-val ^<^val1^>] [^<def2^> [-val ^<val2^>] [^<def3^> [-val ^<val3^>] ...]]
+echo Where:"
+echo ^<compiler-path^>
+echo The full path to your ccpath
+echo ^<def1^> ^<def2^> ^<def3^> ...
+echo A list of pre-preprocesser variable names to be defined.
+echo [-val ^<val1^>] [-val ^<val2^>] [-val ^<val3^>] ...
+echo optional values to be assigned to each pre-processor variable.
+echo If not supplied, the variable will be defined with no explicit value.
+echo -h
+echo Show this text and exit
+
+:End
diff --git a/nuttx/tools/define.sh b/nuttx/tools/define.sh
index c53cb92a8..dc982cc64 100755
--- a/nuttx/tools/define.sh
+++ b/nuttx/tools/define.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# tools/define.sh
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,7 @@
progname=$0
wintool=n
-usage="USAGE: $progname [-w] [-d] [-l] [-h] <compiler-path> <def1>[=val1] [<def2>[=val2] [<def3>[=val3] ...]]"
+usage="USAGE: $progname [-w] [-d] [-h] <compiler-path> <def1>[=val1] [<def2>[=val2] [<def3>[=val3] ...]]"
advice="Try '$progname -h' for more information"
while [ ! -z "$1" ]; do
@@ -60,7 +60,7 @@ while [ ! -z "$1" ]; do
echo " <compiler-path>"
echo " The full path to your compiler"
echo " <def1> <def2> [<def3> ..."
- echo " A list of pre-preprocesser variable names to be defind."
+ echo " A list of pre-preprocesser variable names to be defined."
echo " [=val1] [=val2] [=val3]"
echo " optional values to be assigned to each pre-processor variable."
echo " If not supplied, the variable will be defined with no explicit value."
@@ -164,7 +164,7 @@ else
fmt=std
fi
-# Now process each directory in the directory list
+# Now process each definition in the definition list
unset response
for vardef in $varlist; do
diff --git a/nuttx/tools/incdir.bat b/nuttx/tools/incdir.bat
new file mode 100755
index 000000000..f7383fc9a
--- /dev/null
+++ b/nuttx/tools/incdir.bat
@@ -0,0 +1,165 @@
+@echo off
+
+rem tools/incdir.sh
+rem
+rem Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+rem Handle command line options
+
+set progname=%0
+set pathtype=user
+
+:ArgLoop
+
+rem [-d] [-w] [-s] [-h]. [-w] and [-d] Ignored for compatibility with incdir.sh
+
+if "%1"=="-d" goto :NextArg
+if "%1"=="-w" goto :NextArg
+if "%1"=="-h" goto :Usage
+
+if "%1"=="-s" (
+ set pathtype=system
+ goto :NextArg
+)
+
+goto :CheckCompiler
+
+:NextArg
+shift
+goto :ArgLoop
+
+:CheckCompiler
+if "%1"=="" (
+ echo ERROR: Missing compiler name
+ goto :Usage
+)
+
+set ccpath=%1
+shift
+
+set compiler=
+for /F %%i in ("%ccpath%") do set compiler=%%~ni
+
+if "%1"=="" (
+ echo ERROR: Missing directory paths
+ goto :Usage
+)
+
+rem Check for some well known, non-GCC Windows native tools that require
+rem a special output format as well as special paths
+
+:GetFormat
+set fmt=std
+if "%compiler%"=="ez8cc" goto :SetZdsFormt
+if "%compiler%"=="zneocc" goto :SetZdsFormt
+if "%compiler%"=="ez80cc" goto :SetZdsFormt
+goto :GeneratePaths
+
+:SetZdsFormt
+set fmt=zds
+
+rem Generate the compiler include path directives.
+
+:GeneratePaths
+set response=
+
+:DirLoop
+if "%1" == "" (
+ echo %response%
+ goto :End
+)
+
+if not exist %1 (
+ echo ERROR: Path %1 does not exist
+ goto :Usage
+)
+
+if "%fmt%"=="zds" goto :GenerateZdsPath
+if "%response%"=="" goto :FirstStdPath
+if "%pathtype%"=="system" goto :NextStdSystemPath
+
+set response=%response% -I "%1"
+goto :EndOfDirLoop
+
+:NextStdSystemPath
+
+set response=%response% -isystem "%1"
+goto :EndOfDirLoop
+
+:FirstStdPath
+
+if "%pathtype%"=="system" goto :FirstStdSystemPath
+set response=-I "%1"
+goto :EndOfDirLoop
+
+:FirstStdSystemPath
+
+set response=-isystem "%1"
+goto :EndOfDirLoop
+
+:GenerateZdsPath
+
+if "%response%"=="" goto :FirstZdsPath
+set response=%response%;%1
+goto :EndOfDirLoop
+
+:FirstZdsPath
+
+if "%pathtype%"=="system" goto :FirstZdsSystemPath
+set response=-usrinc:%1
+goto :EndOfDirLoop
+
+:FirstZdsSystemPath
+
+set response=-stdinc:%1
+
+:EndOfDirLoop
+shift
+goto :DirLoop
+
+:Usage
+echo %progname% is a tool for flexible generation of include path arguments for a
+echo variety of different compilers in a variety of compilation environments
+echo USAGE: %progname% [-w] [-d] [-s] [-h] ^<compiler-path^> ^<dir1^> [^<dir2^> [^<dir3^> ...]]
+echo Where:
+echo ^<compiler-path^>
+echo The full path to your compiler
+echo ^<dir1^> [^<dir2^> [^<dir3^> ...]]
+echo A list of include directories
+echo -w, -d
+echo For compatibility with incdir.sh (ignored)
+echo -s
+echo Generate standard, system header file paths instead of normal user
+echo header file paths.
+echo -h
+echo Shows this help text and exits.
+:End
diff --git a/nuttx/tools/incdir.sh b/nuttx/tools/incdir.sh
index be6a1d07a..145bfe9bb 100755
--- a/nuttx/tools/incdir.sh
+++ b/nuttx/tools/incdir.sh
@@ -36,6 +36,7 @@
progname=$0
wintool=n
+pathtype=user
usage="USAGE: $progname [-w] [-d] [-h] <compiler-path> <dir1> [<dir2> [<dir3> ...]]"
advice="Try '$progname -h' for more information"
@@ -47,6 +48,9 @@ while [ ! -z "$1" ]; do
-w )
wintool=y
;;
+ -s )
+ pathtype=system
+ ;;
-h )
echo "$progname is a tool for flexible generation of include path arguments for a"
echo "variety of different compilers in a variety of compilation environments"
@@ -61,8 +65,14 @@ while [ ! -z "$1" ]; do
echo " -w"
echo " The compiler is a Windows native tool and requires Windows"
echo " style pathnames like C:\\Program Files"
+ echo " -s"
+ echo " Generate standard, system header file paths instead of normal user"
+ echo " header file paths."
echo " -d"
echo " Enable script debug"
+ echo " -h"
+ echo " Shows this help text and exits."
+ exit 0
;;
* )
break;
@@ -155,11 +165,27 @@ exefile=`basename "$compiler"`
# a special output format as well as special paths
if [ "X$exefile" = "Xez8cc.exe" -o "X$exefile" = "Xzneocc.exe" -o "X$exefile" = "Xez80cc.exe" ]; then
- fmt=userinc
+ fmt=zds
else
fmt=std
fi
+# Select system or user header file path command line option
+
+if [ "X$fmt" = "Xzds" ]; then
+ if [ "X$pathtype" = "Xsystem" ]; then
+ cmdarg=-stdinc:
+ else
+ cmdarg=-usrinc:
+ fi
+else
+ if [ "X$pathtype" = "Xsystem" ]; then
+ cmdarg=-isystem
+ else
+ cmdarg=-I
+ fi
+fi
+
# Now process each directory in the directory list
unset response
@@ -183,26 +209,26 @@ for dir in $dirlist; do
# Handle the output using the selected format
- if [ "X$fmt" = "Xuserinc" ]; then
+ if [ "X$fmt" = "Xzds" ]; then
# Treat the first directory differently
if [ -z "$response" ]; then
- response="-usrinc:'"$path
+ response="${cmdarg}'"${path}
else
- response=$response":$path"
+ response=${response}";${path}"
fi
else
# Treat the first directory differently
if [ -z "$response" ]; then
- response=-I\"$path\"
+ response="${cmdarg} \"$path\""
else
- response=$response" -I\"$path\""
+ response="${response} ${cmdarg} \"$path\""
fi
fi
done
-if [ "X$fmt" = "Xuserinc" ]; then
+if [ "X$fmt" = "Xzds" ]; then
response=$response"'"
fi
diff --git a/nuttx/tools/link.bat b/nuttx/tools/link.bat
new file mode 100755
index 000000000..434574ee3
--- /dev/null
+++ b/nuttx/tools/link.bat
@@ -0,0 +1,89 @@
+@echo off
+
+rem tools/link.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+set src=%1
+set link=%2
+
+rem Verify that arguments were provided
+
+if "%src%"=="" goto :MissingSrc
+if "%link%"=="" goto :MissingLink
+goto CheckSrc
+
+:MissingSrc
+
+echo Missing ^<src^> and ^<link^> arguments
+goto :ShowUsage
+
+:MissingLink
+
+echo Missing ^<link^> arguments
+goto :ShowUsage
+
+rem Verify that a directory exists at the source path
+
+:CheckSrc
+
+if exist %src% goto :CheckLink
+
+echo No directory at %src%
+goto :ShowUsage
+
+:CheckLink
+
+rem If something already exists at the destination path, remove it
+
+if not exist %link% goto :MkLink
+
+rmdir /q /s %link%
+if errorlevel 1 (
+ echo Failed to remove existing object at %link%
+ goto :ShowUsage
+)
+
+rem Copy the directory
+
+:MkLink
+
+/user:administrator mklink /d %src% %link%
+goto :End
+
+:ShowUsage
+echo USAGE: %0 ^<src^> ^<link^>
+echo Where:
+echo ^<src^> is the source directory to be linked
+echo ^<link^> is the link to be created
+
+:End
diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c
index 2d2fff5c5..3e55f5097 100644
--- a/nuttx/tools/mkconfig.c
+++ b/nuttx/tools/mkconfig.c
@@ -116,7 +116,7 @@ int main(int argc, char **argv, char **envp)
printf(" * configured (at present, NXFLAT is the only supported binary.\n");
printf(" * format).\n");
printf(" */\n\n");
- printf("#if !defined(CONFIG_NXFLAT)\n");
+ printf("#if !defined(CONFIG_NXFLAT) && !defined(CONFIG_ELF)\n");
printf("# undef CONFIG_BINFMT_DISABLE\n");
printf("# define CONFIG_BINFMT_DISABLE 1\n");
printf("#endif\n\n");
diff --git a/nuttx/tools/mkdeps.bat b/nuttx/tools/mkdeps.bat
new file mode 100644
index 000000000..23aab0b71
--- /dev/null
+++ b/nuttx/tools/mkdeps.bat
@@ -0,0 +1,173 @@
+@echo off
+
+rem tools/mkdeps.sh
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+
+rem Accumulate CFLAGS up to "--"
+
+set cc=
+set cflags=
+set altpath=
+set files=
+set args=
+set debug=n
+
+:Loop
+if "%1"=="" goto Continue
+
+if "%1"=="--" (
+ set cc=%cflags%
+ set cflags=%args%
+ set args=
+ goto NextParm
+)
+
+if "%1"=="--dep-path" (
+ if "%args%"=="" (
+ set altpath=%altpath% %2
+ ) else (
+ set args=%args% %2
+ )
+ shift
+ goto NextParm
+)
+
+if "%1"=="--dep-debug" (
+rem @echo on
+ set debug=y
+ goto NextParm
+)
+
+if "%1"=="--help" goto Usage
+
+if "%args%"=="" (
+ set args=%1
+) else (
+ set args=%args% %1
+)
+
+:NextParm
+shift
+goto Loop
+:Continue
+
+set files=%args%
+
+if "%debug%"=="y" (
+ echo cc=%cc%
+ echo cflags=%cflags%
+ echo files=%files%
+ echo altpath=%altpath%
+)
+
+rem Now check if we have everything
+
+if "%cc%"=="" (
+ echo ERROR: No compiler specified
+ goto Usage
+)
+
+if "%files%"=="" (
+ rem Don't report an error -- this happens normally in some configurations
+ echo # No files specified for dependency generataion
+ goto End
+)
+
+rem Then get the dependencies for each file
+
+if "%altpath%"=="" goto NoPaths
+for %%G in (%files%) do (
+ set fullpath=
+ set file=%%G
+ call :Checkpaths
+ if "%debug%"=="y" echo %file%: fullpath=%fullpath%
+ if "%fullpath%"=="" goto :NoFile
+ if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath%
+ %cc% -M %cflags% %fullpath% || goto DepFail
+)
+goto :End
+
+:NoPaths
+for %%G in (%files%) do (
+ set fullpath=
+ set file=%%G
+ call :CheckFile %%G
+)
+goto :End
+
+:CheckFile
+if "%debug%"=="y" echo Checkfile: Checking %file%
+if not exist %file% goto :NoFile
+set fullpath=%file%
+ if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath%
+%cc% -M %cflags% %fullpath% || goto DepFail
+goto :EOF
+
+:CheckPaths
+for %%H in (%altpath%) do (
+ set tmppath=%%H\%file%
+ if "%debug%"=="y" echo Checkfile: Checking %tmppath%
+ if exist %tmppath% (
+ set fullpath=%tmppath%
+ goto :EOF
+ )
+)
+goto :EOF
+
+:NoFile
+echo ERROR: No readable file at %file%
+goto Usage
+
+:DepFail
+echo ERROR: Failed to created dependencies for %file%
+
+:Usage
+echo Usage: mkdeps [OPTIONS] CC -- CFLAGS -- file [file [file...]]
+echo Where:
+echo CC
+echo A variable number of arguments that define how to execute the compiler
+echo CFLAGS
+echo The compiler compilation flags
+echo file
+echo One or more C files whose dependencies will be checked. Each file is expected
+echo to reside in the current directory unless --dep-path is provided on the command line
+echo And [OPTIONS] include:
+echo --dep-debug
+echo Enable script debug
+echo --dep-path ^<path^>
+echo Do not look in the current directory for the file. Instead, look in <path> to see
+echo if the file resides there. --dep-path may be used multiple times to specify
+echo multiple alternative location
+echo --help
+echo Shows this message and exits
+
+:End
diff --git a/nuttx/tools/mkdeps.c b/nuttx/tools/mkdeps.c
new file mode 100644
index 000000000..64d81cbd7
--- /dev/null
+++ b/nuttx/tools/mkdeps.c
@@ -0,0 +1,721 @@
+/****************************************************************************
+ * tools/mkdeps.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/stat.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_BUFFER (4096)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+enum slashmode_e
+{
+ MODE_FSLASH = 0,
+ MODE_BSLASH = 1,
+ MODE_DBLBACK = 2
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char *g_cc = NULL;
+static char *g_cflags = NULL;
+static char *g_files = NULL;
+static char *g_altpath = NULL;
+static int g_debug = 0;
+static bool g_winnative = false;
+#ifdef HAVE_WINPATH
+static bool g_winpath = false;
+static char *g_topdir = NULL;
+#endif
+
+static char g_command[MAX_BUFFER];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+ /* MinGW does not seem to provide strtok_r */
+
+#ifndef HAVE_STRTOK_R
+static char *MY_strtok_r(char *str, const char *delim, char **saveptr)
+{
+ char *pbegin;
+ char *pend = NULL;
+
+ /* Decide if we are starting a new string or continuing from
+ * the point we left off.
+ */
+
+ if (str)
+ {
+ pbegin = str;
+ }
+ else if (saveptr && *saveptr)
+ {
+ pbegin = *saveptr;
+ }
+ else
+ {
+ return NULL;
+ }
+
+ /* Find the beginning of the next token */
+
+ for (;
+ *pbegin && strchr(delim, *pbegin) != NULL;
+ pbegin++);
+
+ /* If we are at the end of the string with nothing
+ * but delimiters found, then return NULL.
+ */
+
+ if (!*pbegin)
+ {
+ return NULL;
+ }
+
+ /* Find the end of the token */
+
+ for (pend = pbegin + 1;
+ *pend && strchr(delim, *pend) == NULL;
+ pend++);
+
+ /* pend either points to the end of the string or to
+ * the first delimiter after the string.
+ */
+
+ if (*pend)
+ {
+ /* Turn the delimiter into a null terminator */
+
+ *pend++ = '\0';
+ }
+
+ /* Save the pointer where we left off and return the
+ * beginning of the token.
+ */
+
+ if (saveptr)
+ {
+ *saveptr = pend;
+ }
+ return pbegin;
+}
+
+#define strtok_r MY_strtok_r
+#endif
+
+static void append(char **base, char *str)
+{
+ char *oldbase;
+ char *newbase;
+ int alloclen;
+
+ oldbase = *base;
+ if (!oldbase)
+ {
+ newbase = strdup(str);
+ if (!newbase)
+ {
+ fprintf(stderr, "ERROR: Failed to strdup %s\n", str);
+ exit(EXIT_FAILURE);
+ }
+ }
+ else
+ {
+ alloclen = strlen(oldbase) + strlen(str) + 2;
+ newbase = (char *)malloc(alloclen);
+ if (!newbase)
+ {
+ fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
+ exit(EXIT_FAILURE);
+ }
+
+ snprintf(newbase, alloclen, "%s %s\n", oldbase, str);
+ free(oldbase);
+ }
+
+ *base = newbase;
+}
+
+static void show_usage(const char *progname, const char *msg, int exitcode)
+{
+ if (msg)
+ {
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%s:\n", msg);
+ }
+
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%s [OPTIONS] CC -- CFLAGS -- file [file [file...]]\n",
+ progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Where:\n");
+ fprintf(stderr, " CC\n");
+ fprintf(stderr, " A variable number of arguments that define how to execute the compiler\n");
+ fprintf(stderr, " CFLAGS\n");
+ fprintf(stderr, " The compiler compilation flags\n");
+ fprintf(stderr, " file\n");
+ fprintf(stderr, " One or more C files whose dependencies will be checked. Each file is expected\n");
+ fprintf(stderr, " to reside in the current directory unless --dep-path is provided on the command line\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "And [OPTIONS] include:\n");
+ fprintf(stderr, " --dep-debug\n");
+ fprintf(stderr, " Enable script debug\n");
+ fprintf(stderr, " --dep-path <path>\n");
+ fprintf(stderr, " Do not look in the current directory for the file. Instead, look in <path> to see\n");
+ fprintf(stderr, " if the file resides there. --dep-path may be used multiple times to specify\n");
+ fprintf(stderr, " multiple alternative location\n");
+ fprintf(stderr, " --winnative\n");
+ fprintf(stderr, " By default, a POSIX-style environment is assumed (e.g., Linux, Cygwin, etc.) This option is\n");
+ fprintf(stderr, " inform the tool that is working in a pure Windows native environment.\n");
+#ifdef HAVE_WINPATH
+ fprintf(stderr, " --winpaths <TOPDIR>\n");
+ fprintf(stderr, " This option is useful when using a Windows native toolchain in a POSIX environment (such\n");
+ fprintf(stderr, " such as Cygwin). In this case, will CC generates dependency lists using Windows paths\n");
+ fprintf(stderr, " (e.g., C:\\blablah\\blabla). This switch instructs the script to use 'cygpath' to convert\n");
+ fprintf(stderr, " the Windows paths to Cygwin POSIXE paths.\n");
+#endif
+ fprintf(stderr, " --help\n");
+ fprintf(stderr, " Shows this message and exits\n");
+ exit(exitcode);
+}
+
+static void parse_args(int argc, char **argv)
+{
+ char *args = NULL;
+ int argidx;
+
+ /* Accumulate CFLAGS up to "--" */
+
+ for (argidx = 1; argidx < argc; argidx++)
+ {
+ if (strcmp(argv[argidx], "--") == 0)
+ {
+ g_cc = g_cflags;
+ g_cflags = args;
+ args = NULL;
+ }
+ else if (strcmp(argv[argidx], "--dep-debug") == 0)
+ {
+ g_debug++;
+ }
+ else if (strcmp(argv[argidx], "--dep-path") == 0)
+ {
+ argidx++;
+ if (argidx >= argc)
+ {
+ show_usage(argv[0], "ERROR: Missing argument to --dep-path", EXIT_FAILURE);
+ }
+
+ if (args)
+ {
+ append(&args, argv[argidx]);
+ }
+ else
+ {
+ append(&g_altpath, argv[argidx]);
+ }
+ }
+ else if (strcmp(argv[argidx], "--winnative") == 0)
+ {
+ g_winnative = true;
+ }
+#ifdef HAVE_WINPATH
+ else if (strcmp(argv[argidx], "--winpath") == 0)
+ {
+ g_winpath = true;
+ if (g_topdir)
+ {
+ free(g_topdir);
+ }
+
+ argidx++;
+ if (argidx >= argc)
+ {
+ show_usage(argv[0], "ERROR: Missing argument to --winpath", EXIT_FAILURE);
+ }
+
+ g_topdir = strdup(argv[argidx]);
+ }
+#endif
+ else if (strcmp(argv[argidx], "--help") == 0)
+ {
+ show_usage(argv[0], NULL, EXIT_SUCCESS);
+ }
+ else
+ {
+ append(&args, argv[argidx]);
+ }
+ }
+
+ /* The final thing accumulated is the list of files */
+
+ g_files = args;
+
+ /* If no paths were specified, then look in the current directory only */
+
+ if (!g_altpath)
+ {
+ g_altpath = strdup(".");
+ }
+
+ if (g_debug)
+ {
+ fprintf(stderr, "SELECTIONS\n");
+ fprintf(stderr, " CC : [%s]\n", g_cc ? g_cc : "(None)");
+ fprintf(stderr, " CFLAGS : [%s]\n", g_cflags ? g_cflags : "(None)");
+ fprintf(stderr, " FILES : [%s]\n", g_files ? g_files : "(None)");
+ fprintf(stderr, " PATHS : [%s]\n", g_altpath ? g_altpath : "(None)");
+#ifdef HAVE_WINPATH
+ fprintf(stderr, " Windows Paths : [%s]\n", g_winpath ? "TRUE" : "FALSE");
+ if (g_winpath)
+ {
+ fprintf(stderr, " TOPDIR : [%s]\n", g_topdir);
+ }
+#endif
+ fprintf(stderr, " Windows Native : [%s]\n", g_winnative ? "TRUE" : "FALSE");
+ }
+
+ /* Check for required paramters */
+
+ if (!g_cc)
+ {
+ show_usage(argv[0], "ERROR: No compiler specified", EXIT_FAILURE);
+ }
+
+ if (!g_files)
+ {
+ /* Don't report an error -- this happens normally in some configurations */
+
+ printf("# No files specified for dependency generataion\n");
+ exit(EXIT_SUCCESS);
+ }
+
+#ifdef HAVE_WINPATH
+ if (g_winnative && g_winpath)
+ {
+ show_usage(argv[0], "ERROR: Both --winnative and --winpapth makes no sense", EXIT_FAILURE);
+ }
+#endif
+}
+
+static void do_dependency(const char *file, char separator)
+{
+ static const char moption[] = " -M ";
+ struct stat buf;
+ char *alloc;
+ char *altpath;
+ char *path;
+ char *lasts;
+ int cmdlen;
+ int pathlen;
+ int filelen;
+ int totallen;
+ int ret;
+
+ /* Copy the compiler into the command buffer */
+
+ cmdlen = strlen(g_cc);
+ if (cmdlen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Compiler string is too long [%d/%d]: %s\n",
+ cmdlen, MAX_BUFFER, g_cc);
+ exit(EXIT_FAILURE);
+ }
+
+ strcpy(g_command, g_cc);
+
+ /* Copy " -M " */
+
+ cmdlen += strlen(moption);
+ if (cmdlen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Option string is too long [%d/%d]: %s\n",
+ cmdlen, MAX_BUFFER, moption);
+ exit(EXIT_FAILURE);
+ }
+
+ strcat(g_command, moption);
+
+ /* Copy the CFLAGS into the command buffer */
+
+ cmdlen += strlen(g_cflags);
+ if (cmdlen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: CFLAG string is too long [%d/%d]: %s\n",
+ cmdlen, MAX_BUFFER, g_cflags);
+ exit(EXIT_FAILURE);
+ }
+
+ strcat(g_command, g_cflags);
+
+ /* Add a space */
+
+ g_command[cmdlen] = ' ';
+ cmdlen++;
+ g_command[cmdlen] = '\0';
+
+ /* Make a copy of g_altpath. We need to do this because at least the version
+ * of strtok_r above does modifie it.
+ */
+
+ alloc = strdup(g_altpath);
+ if (!alloc)
+ {
+ fprintf(stderr, "ERROR: Failed to strdup paths\n");
+ exit(EXIT_FAILURE);
+ }
+
+ altpath = alloc;
+
+ /* Try each path. This loop will continue until each path has been tried
+ * (failure) or until stat() finds the file
+ */
+
+ while ((path = strtok_r(altpath, " ", &lasts)) != NULL)
+ {
+ /* Create a full path to the file */
+
+ pathlen = strlen(path);
+ totallen = cmdlen + pathlen;
+ if (totallen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Path is too long [%d/%d]: %s\n",
+ totallen, MAX_BUFFER, path);
+ exit(EXIT_FAILURE);
+ }
+
+ strcpy(&g_command[cmdlen], path);
+
+ if (g_command[totallen] != '\0')
+ {
+ fprintf(stderr, "ERROR: Missing NUL terminator\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (g_command[totallen-1] != separator)
+ {
+ g_command[totallen] = separator;
+ g_command[totallen+1] = '\0';
+ pathlen++;
+ totallen++;
+ }
+
+ filelen = strlen(file);
+ totallen += filelen;
+ if (totallen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Path+file is too long [%d/%d]\n",
+ totallen, MAX_BUFFER);
+ exit(EXIT_FAILURE);
+ }
+
+ strcat(g_command, file);
+
+ /* Check that a file actually exists at this path */
+
+ if (g_debug)
+ {
+ fprintf(stderr, "Trying path=%s file=%s fullpath=%s\n",
+ path, file, &g_command[cmdlen]);
+ }
+
+ ret = stat(&g_command[cmdlen], &buf);
+ if (ret < 0)
+ {
+ altpath = NULL;
+ continue;
+ }
+
+ if (!S_ISREG(buf.st_mode))
+ {
+ fprintf(stderr, "ERROR: File %s exists but is not a regular file\n",
+ &g_command[cmdlen]);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Okay.. we have. Create the dependency. One a failure to start the
+ * compiler, system() will return -1; Otherwise, the returned value
+ * from the compiler is in WEXITSTATUS(ret).
+ */
+
+ ret = system(g_command);
+#ifdef WEXITSTATUS
+ if (ret < 0 || WEXITSTATUS(ret) != 0)
+ {
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: system failed: %s\n", strerror(errno));
+ }
+ else
+ {
+ fprintf(stderr, "ERROR: %s failed: %d\n", g_cc, WEXITSTATUS(ret));
+ }
+
+ fprintf(stderr, " command: %s\n", g_command);
+ exit(EXIT_FAILURE);
+ }
+#else
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: system failed: %s\n", strerror(errno));
+ fprintf(stderr, " command: %s\n", g_command);
+ exit(EXIT_FAILURE);
+ }
+#endif
+
+ /* We don't really know that the command succeeded... Let's assume that it did */
+
+ free(alloc);
+ return;
+ }
+
+ printf("# ERROR: File \"%s\" not found at any location\n", file);
+ exit(EXIT_FAILURE);
+}
+
+/* Convert a Cygwin path to a Windows path */
+
+#ifdef HAVE_WINPATH
+static char *cywin2windows(const char *str, const char *append, enum slashmode_e mode)
+{
+ static const char cygdrive[] = "/cydrive";
+ const char *src = src;
+ char *dest;
+ char *newpath;
+ char *allocpath = NULL;
+ int srclen = strlen(str);
+ int alloclen = 0;
+ int drive = 0;
+ int lastchar;
+
+ /* Skip any leading whitespace */
+
+ while (isspace(*str)) str++;
+
+ /* Were we asked to append something? */
+
+ if (append)
+ {
+ char *tmp;
+
+ alloclen = sizeof(str) + sizeof(append) + 1;
+ allocpath = (char *)malloc(alloclen);
+ if (!allocpath)
+ {
+ fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
+ exit(EXIT_FAILURE);
+ }
+
+ snprintf(allocpath, alloclen, "%s/%s", str, append);
+ }
+
+ /* Looking for path of the form /cygdrive/c/bla/bla/bla */
+
+ if (strcasecmp(src, cygdrive) == 0)
+ {
+ int cygsize = sizeof(cygdrive);
+ if (src[cygsize] == '/')
+ {
+ cygsize++;
+ srclen -= cygsize;
+ src += cygsize;
+
+ if (srclen <= 0)
+ {
+ fprintf(stderr, "ERROR: Unhandled path: \"%s\"\n", str);
+ exit(EXIT_FAILURE);
+ }
+
+ drive = toupper(*src);
+ if (drive < 'A' || drive > 'Z')
+ {
+ fprintf(stderr, "ERROR: Drive charager: \"%s\"\n", str);
+ exit(EXIT_FAILURE);
+ }
+
+ srclen--;
+ src++;
+ alloclen = 2;
+ }
+ }
+
+ /* Determine the size of the new path */
+
+ alloclen += sizeof(src) + 1;
+ if (mode == MODE_DBLBACK)
+ {
+ const char *tmpptr;
+ for (tmpptr = src; *tmpptr; tmpptr++)
+ {
+ if (*tmpptr == '/') alloclen++;
+ }
+ }
+
+ /* Allocate memory for the new path */
+
+ newpath = (char *)malloc(alloclen);
+ if (!newpath)
+ {
+ fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
+ exit(EXIT_FAILURE);
+ }
+
+ dest = newpath;
+
+ /* Copy the drive character */
+
+ if (drive)
+ {
+ *dest++ = drive;
+ *dest++ = ':';
+ }
+
+ /* Copy each character from the source, making modifications for foward
+ * slashes as required.
+ */
+
+ lastchar = '\0';
+ for (; *src; src++)
+ {
+ if (mode != MODE_FSLASH && *src == '/')
+ {
+ if (lastchar != '/')
+ {
+ *dest++ = '\\';
+ if (mode == MODE_DBLBACK)
+ {
+ *dest++ = '\\';
+ }
+ }
+ }
+ else
+ {
+ *dest++ = *src;
+ }
+
+ lastchar = *src;
+ }
+
+ *dest++ = '\0';
+ if (allocpath)
+ {
+ free(allocpath);
+ }
+ return dest;
+}
+#endif
+
+#ifdef HAVE_WINPATH
+static void do_winpath(char *file)
+{
+ /* The file is in POSIX format. CC expects Windows format to generate the
+ * dependencies, but GNU make expect the resulting dependencies to be back
+ * in POSIX format. What a mess!
+ */
+
+ char *path = cywin2windows(g_topdir, file, MODE_FSLASH);
+
+ /* Then get the dependency and perform conversions on it to make it
+ * palatable to the Cygwin make.
+ */
+#warning "Missing logic"
+
+ free(path);
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ char *lasts;
+ char *files;
+ char *file;
+
+ /* Parse command line parameters */
+
+ parse_args(argc, argv);
+
+ /* Then generate dependencies for each path on the command line. NOTE
+ * strtok_r will clobber the files list. But that is okay because we are
+ * only going to traverse it once.
+ */
+
+ files = g_files;
+ while ((file = strtok_r(files, " ", &lasts)) != NULL)
+ {
+ /* Check if we need to do path conversions for a Windows-natvie tool
+ * being using in a POSIX/Cygwin environment.
+ */
+
+#ifdef HAVE_WINPATH
+ if (g_winpath)
+ {
+ do_winpath(file);
+ }
+ else
+#endif
+ {
+ do_dependency(file, g_winnative ? '\\' : '/');
+ }
+
+ files = NULL;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/nuttx/tools/mkdeps.sh b/nuttx/tools/mkdeps.sh
index d8984e553..42397012b 100755
--- a/nuttx/tools/mkdeps.sh
+++ b/nuttx/tools/mkdeps.sh
@@ -2,7 +2,7 @@
############################################################################
# tools/mkdeps.sh
#
-# Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
diff --git a/nuttx/tools/mkromfsimg.sh b/nuttx/tools/mkromfsimg.sh
index b77411980..8811f1953 100755
--- a/nuttx/tools/mkromfsimg.sh
+++ b/nuttx/tools/mkromfsimg.sh
@@ -233,7 +233,7 @@ mkdir -p $workingdir || { echo "Failed to created the new $workingdir"; exit 1;
# Create the rcS file from the rcS.template
if [ ! -r $rcstemplate ]; then
- echo "$rcstemplete does not exist"
+ echo "$rcstemplate does not exist"
rmdir $workingdir
exit 1
fi
diff --git a/nuttx/tools/mksymtab.c b/nuttx/tools/mksymtab.c
index c5a46a92b..e401812c0 100644
--- a/nuttx/tools/mksymtab.c
+++ b/nuttx/tools/mksymtab.c
@@ -222,7 +222,7 @@ int main(int argc, char **argv, char **envp)
fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", symtab);
fprintf(outstream, "#include <nuttx/config.h>\n");
- fprintf(outstream, "#include <nuttx/symtab.h>\n\n");
+ fprintf(outstream, "#include <nuttx/binfmt/symtab.h>\n\n");
/* Output all of the require header files */
diff --git a/nuttx/tools/unlink.bat b/nuttx/tools/unlink.bat
new file mode 100755
index 000000000..25e83bb9f
--- /dev/null
+++ b/nuttx/tools/unlink.bat
@@ -0,0 +1,71 @@
+@echo off
+
+rem tools/unlink.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+rem Verify that arguments were provided
+
+set link=%1
+if "%link%"=="" goto :MissingArgument
+
+rem Check if something already exists at the link path
+
+if exist "%link%" goto :LinkExists
+
+echo %link% does not exist
+goto :ShowUsage
+
+rem %link% make be a symbolic link or it may be a copied director (with
+rem a .fakelnk file in it). It really does not matter which: We do the
+rem same thing in either case
+
+:LinkExists
+
+rmdir /q /s %link%
+if errorlevel 1 (
+ echo Failed to remove existing object at %link%
+ goto :ShowUsage
+)
+
+goto :End
+
+:MissingArgument
+
+echo Missing Argument
+
+:ShowUsage
+echo USAGE: %0 ^<link^>
+echo Where:
+echo ^<link^> is the linked (or copied) directory to be removed
+
+:End