diff --git a/ChangeLog b/ChangeLog index 58ee7eef19..dcb13526e1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11292,4 +11292,7 @@ (2016-01-09). * arch/avr/include/debug.h: Add an AVR-specific header file used when the AVR MEMX pointer is used. From Dimitri Kloper (2016-01-09). + * tools/cnvwindeps.c: Add a tool that will convert paths in + dependencies generated by a Windows compiler so that they can be + used with the Cygwin make (2016-01-09). diff --git a/arch b/arch index 3fbe4f51dc..4570fe271a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 3fbe4f51dc531070c93821018a342cfb5d8a6c02 +Subproject commit 4570fe271a034ae7aa23e579064f90c75594f985 diff --git a/configs b/configs index a8e9be00f9..6fb104206e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a8e9be00f98fe4abe13ad2703637f00c516d7d7d +Subproject commit 6fb104206eed94cba309bb827d59780e3d24f002 diff --git a/tools/Makefile.host b/tools/Makefile.host index 1f9f0027d0..3cc0080261 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -63,7 +63,7 @@ endif all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \ configure$(HOSTEXEEXT) mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \ mksymtab$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) \ - nxstyle$(HOSTEXEEXT) + cnvwindeps$(HOSTEXEEXT) nxstyle$(HOSTEXEEXT) default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) ifdef HOSTEXEEXT @@ -153,7 +153,7 @@ ifdef HOSTEXEEXT bdf-converter: bdf-converter$(HOSTEXEEXT) endif -# nxsytle - Check a file for compliance to NuttX coding style +# nxstyle - Check a file for compliance to NuttX coding style nxstyle$(HOSTEXEEXT): nxstyle.c $(Q) $(HOSTCC) $(HOSTCFLAGS) -o nxstyle$(HOSTEXEEXT) nxstyle.c @@ -162,6 +162,16 @@ ifdef HOSTEXEEXT nxstyle: nxstyle$(HOSTEXEEXT) endif +# cnvwindeps - Convert dependences generated by a Windows native toolchain +# for use in a Cygwin/POSIX build environment + +cnvwindeps$(HOSTEXEEXT): cnvwindeps.c + $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cnvwindeps$(HOSTEXEEXT) cnvwindeps.c + +ifdef HOSTEXEEXT +cnvwindeps: cnvwindeps$(HOSTEXEEXT) +endif + # Create dependencies for a list of files mkdeps$(HOSTEXEEXT): mkdeps.c csvparser.c diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c new file mode 100644 index 0000000000..c390e6f778 --- /dev/null +++ b/tools/cnvwindeps.c @@ -0,0 +1,266 @@ +/**************************************************************************** + * tools/cnvwindeps.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MAX_LINE 1024 +#define MAX_PATH 1024 + +/**************************************************************************** + * Global Data + ****************************************************************************/ + +static unsigned long g_lineno; +static char g_line[MAX_LINE]; +static char g_dequoted[MAX_PATH]; +static char g_posix[MAX_PATH]; +static const char g_cygpath[] = "/usr/bin/cygpath"; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static char *skip_spaces(char *ptr) +{ + while (*ptr && isspace((int)*ptr)) ptr++; + return ptr; +} + +static char *find_spaces(char *ptr) +{ + bool quoted = false; + + while (*ptr) + { + if (ptr[0] == '\\' && isspace((int)ptr[1])) + { + quoted = true; + ptr++; + } + else if (!quoted && isspace((int)*ptr)) + { + break; + } + else + { + quoted = false; + ptr++; + } + } + + return ptr; +} + +static bool dequote_path(const char *winpath) +{ + char *dest = g_dequoted; + const char *src = winpath; + int len = 0; + bool quoted = false; + + while (*src && len < MAX_PATH) + { + if (src[0] != '\\' || (src[1] != ' ' && src[1] != '(' && src[1] != ')')) + { + *dest++ = *src; + len++; + } + else + { + quoted = true; + } + + src++; + } + + if (*src || len >= MAX_PATH) + { + fprintf(stderr, "%lu: Line truncated\n", g_lineno); + exit(EXIT_FAILURE); + } + + *dest = '\0'; + return quoted; +} + +static bool convert_path(const char *winpath) +{ + ssize_t size; + ssize_t ret; + bool quoted; + + quoted = dequote_path(winpath); + + size = cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, g_dequoted, NULL, 0); + if (size > MAX_PATH) + { + fprintf(stderr, "%lu: POSIX path too long: %lu\n", + g_lineno, (unsigned long)size); + exit(EXIT_FAILURE); + } + + ret = cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, g_dequoted, g_posix, MAX_PATH); + if (ret < 0) + { + fprintf(stderr, "%lu: cygwin_conv_path '%s' failed: %s\n", + g_lineno, g_dequoted, strerror(errno)); + exit(EXIT_FAILURE); + } + + return quoted; +} + +static void show_usage(const char *progname) +{ + fprintf(stderr, "USAGE: %s \n", progname); + exit(EXIT_FAILURE); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv, char **envp) +{ + char *path; + char *next; + FILE *stream; + bool begin; + bool quoted; + + if (argc != 2) + { + fprintf(stderr, "Unexpected number of arguments\n"); + show_usage(argv[0]); + } + + stream = fopen(argv[1], "r"); + if (!stream) + { + fprintf(stderr, "open %s failed: %s\n", argv[1], strerror(errno)); + exit(EXIT_FAILURE); + } + + begin = true; + g_lineno = 0; + + while (fgets(g_line, MAX_LINE, stream) != NULL) + { + g_lineno++; + next = g_line; + + for (; ; ) + { + if (begin) + { + path = skip_spaces(next); + next = strchr(path, ':'); + if (!next) + { + fprintf(stderr, "%lu: Expected semicolon\n", g_lineno); + exit(EXIT_FAILURE); + } + + if (*next != '\0') + { + *next++ = '\0'; + } + + quoted = convert_path(path); + if (quoted) + { + printf("\"%s\":", g_posix); + } + else + { + printf("%s:", g_posix); + } + + begin = false; + } + else + { + path = skip_spaces(next); + next = find_spaces(path); + + if (path[0] == '\\') + { + break; + } + else if (strcmp(path, "") == 0) + { + printf("\n\n"); + begin = true; + break; + } + else + { + if (*next != '\0') + { + *next++ = '\0'; + } + + quoted = convert_path(path); + if (quoted) + { + printf(" \\\n\t\"%s\"", g_posix); + } + else + { + printf(" \\\n\t%s", g_posix); + } + } + } + } + } + + fclose(stream); + return 0; +}