2013-01-04 22:37:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* tools/configure.c
|
|
|
|
*
|
2019-08-05 17:03:12 +02:00
|
|
|
* Copyright (C) 2012, 2017-2019 Gregory Nutt. All rights reserved.
|
2013-01-04 22:37:31 +01:00
|
|
|
* 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>
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
#include <stdint.h>
|
2013-01-04 22:37:31 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2013-01-05 17:07:37 +01:00
|
|
|
#include <dirent.h>
|
2013-01-04 22:37:31 +01:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "cfgparser.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
|
2014-01-04 16:08:14 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
# define strndup(x, y) strdup(x)
|
|
|
|
#endif
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
#define HOST_NOCHANGE 0
|
|
|
|
#define HOST_LINUX 1
|
2017-11-10 00:36:46 +01:00
|
|
|
#define HOST_MACOS 2
|
|
|
|
#define HOST_WINDOWS 3
|
2017-07-10 17:38:45 +02:00
|
|
|
|
|
|
|
#define WINDOWS_NATIVE 1
|
|
|
|
#define WINDOWS_CYGWIN 2
|
2020-10-18 15:28:35 +02:00
|
|
|
#define WINDOWS_MSYS 3
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2019-08-06 18:39:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void show_usage(const char *progname, int exitcode);
|
2020-09-02 20:04:33 +02:00
|
|
|
static void dumpcfgs(void);
|
2019-08-06 18:39:12 +02:00
|
|
|
static void debug(const char *fmt, ...);
|
|
|
|
static void parse_args(int argc, char **argv);
|
2020-03-20 05:08:27 +01:00
|
|
|
static int run_make(const char *arg);
|
2020-08-20 20:32:42 +02:00
|
|
|
static bool filecmp(const char *f1, const char *f2);
|
2019-08-06 18:39:12 +02:00
|
|
|
static bool check_directory(const char *directory);
|
|
|
|
static void verify_directory(const char *directory);
|
|
|
|
static bool verify_optiondir(const char *directory);
|
|
|
|
static bool verify_file(const char *path);
|
|
|
|
static void find_topdir(void);
|
2020-01-16 02:16:14 +01:00
|
|
|
typedef void (*config_callback)(const char *boarddir, const char *archname,
|
|
|
|
const char *chipname, const char *boardname,
|
|
|
|
const char *configname, void *data);
|
2020-03-20 10:40:33 +01:00
|
|
|
static void config_search(const char *boarddir,
|
|
|
|
config_callback callback, void *data);
|
|
|
|
static void archname_callback(const char *boarddir, const char *archname,
|
|
|
|
const char *chipname, const char *boardname,
|
|
|
|
const char *configname, void *data);
|
2020-01-16 02:16:14 +01:00
|
|
|
static void find_archname(void);
|
|
|
|
static void enumerate_callback(const char *boarddir, const char *archname,
|
|
|
|
const char *chipname, const char *boardname,
|
|
|
|
const char *configname, void *data);
|
2019-08-06 18:39:12 +02:00
|
|
|
static void enumerate_configs(void);
|
|
|
|
static void check_configdir(void);
|
|
|
|
static void check_configured(void);
|
|
|
|
static void read_configfile(void);
|
|
|
|
static void read_versionfile(void);
|
|
|
|
static void get_verstring(void);
|
|
|
|
static bool verify_appdir(const char *appdir);
|
|
|
|
static void check_appdir(void);
|
|
|
|
static void check_configuration(void);
|
2020-03-20 10:40:33 +01:00
|
|
|
static void copy_file(const char *srcpath,
|
|
|
|
const char *destpath, mode_t mode);
|
2019-08-06 18:39:12 +02:00
|
|
|
static void substitute(char *str, int ch1, int ch2);
|
|
|
|
static char *double_appdir_backslashes(char *old_appdir);
|
|
|
|
static void copy_optional(void);
|
|
|
|
static void enable_feature(const char *destconfig, const char *varname);
|
|
|
|
static void disable_feature(const char *destconfig, const char *varname);
|
|
|
|
static void set_host(const char *destconfig);
|
|
|
|
static void configure(void);
|
|
|
|
static void refresh(void);
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_WINDOWS_NATIVE
|
|
|
|
static char g_delim = '\\'; /* Delimiter to use when forming paths */
|
|
|
|
static bool g_winpaths = true; /* True: Windows style paths */
|
|
|
|
#else
|
|
|
|
static char g_delim = '/'; /* Delimiter to use when forming paths */
|
|
|
|
static bool g_winpaths = false; /* False: POSIX style paths */
|
|
|
|
#endif
|
|
|
|
static bool g_debug = false; /* Enable debug output */
|
2020-03-19 19:09:45 +01:00
|
|
|
static bool g_enforce = false; /* Enfore distclean */
|
2020-08-20 20:32:42 +02:00
|
|
|
static bool g_distclean = false; /* Distclean if configured */
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2019-08-06 18:39:12 +02:00
|
|
|
static const char *g_appdir = NULL; /* Relative path to the application directory */
|
|
|
|
static const char *g_archdir = NULL; /* Name of architecture subdirectory */
|
2019-08-08 01:25:54 +02:00
|
|
|
static const char *g_chipdir = NULL; /* Name of chip subdirectory */
|
2013-01-04 22:37:31 +01:00
|
|
|
static const char *g_boarddir = NULL; /* Name of board subdirectory */
|
|
|
|
static char *g_configdir = NULL; /* Name of configuration subdirectory */
|
|
|
|
|
|
|
|
static char *g_topdir = NULL; /* Full path to top-level NuttX build directory */
|
2014-07-08 21:12:36 +02:00
|
|
|
static char *g_apppath = NULL; /* Full path to the application directory */
|
2013-01-05 17:07:37 +01:00
|
|
|
static char *g_configtop = NULL; /* Full path to the top-level configuration directory */
|
|
|
|
static char *g_configpath = NULL; /* Full path to the configuration sub-directory */
|
2017-07-11 01:00:54 +02:00
|
|
|
static char *g_scriptspath = NULL; /* Full path to the scripts sub-directory */
|
2013-01-04 22:37:31 +01:00
|
|
|
static char *g_verstring = "0.0"; /* Version String */
|
|
|
|
|
|
|
|
static char *g_srcdefconfig = NULL; /* Source defconfig file */
|
|
|
|
static char *g_srcmakedefs = NULL; /* Source Make.defs file */
|
|
|
|
|
2020-03-20 05:08:27 +01:00
|
|
|
static char **g_makeargv = NULL; /* Arguments pass to make */
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static bool g_winnative = false; /* True: Windows native configuration */
|
2017-10-01 20:45:29 +02:00
|
|
|
static bool g_oldnative = false; /* True: Was Windows native configuration */
|
2013-01-04 22:37:31 +01:00
|
|
|
static bool g_needapppath = true; /* Need to add app path to the .config file */
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
static uint8_t g_host = HOST_NOCHANGE;
|
|
|
|
static uint8_t g_windows = WINDOWS_CYGWIN;
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static char g_buffer[BUFFER_SIZE]; /* Scratch buffer for forming full paths */
|
|
|
|
|
|
|
|
static struct variable_s *g_configvars = NULL;
|
|
|
|
static struct variable_s *g_versionvars = NULL;
|
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
/* Optional configuration files */
|
|
|
|
|
|
|
|
static const char *g_optfiles[] =
|
|
|
|
{
|
2017-06-15 17:59:32 +02:00
|
|
|
".gdbinit",
|
|
|
|
".cproject",
|
|
|
|
".project"
|
2017-06-15 16:24:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define N_OPTFILES (sizeof(g_optfiles) / sizeof(const char *))
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void show_usage(const char *progname, int exitcode)
|
|
|
|
{
|
2020-10-18 15:28:35 +02:00
|
|
|
fprintf(stderr, "\nUSAGE: %s [-d] [-E] [-e] [-b|f] [-L] [-l|m|c|g|n] "
|
2020-03-20 05:08:27 +01:00
|
|
|
"[-a <app-dir>] <board-name>:<config-name> [make-opts]\n",
|
|
|
|
progname);
|
2019-08-06 00:53:39 +02:00
|
|
|
fprintf(stderr, "\nUSAGE: %s [-h]\n", progname);
|
2013-01-04 22:37:31 +01:00
|
|
|
fprintf(stderr, "\nWhere:\n");
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " -d:\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
fprintf(stderr, " Enables debug output\n");
|
2020-08-20 20:32:42 +02:00
|
|
|
fprintf(stderr, " -E:\n");
|
2020-03-19 19:09:45 +01:00
|
|
|
fprintf(stderr, " Enforce distclean if already configured\n");
|
2020-08-20 20:32:42 +02:00
|
|
|
fprintf(stderr, " -e:\n");
|
|
|
|
fprintf(stderr, " Performs distclean if configuration changed\n");
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " -b:\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
#ifdef CONFIG_WINDOWS_NATIVE
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Informs the tool that it should use Windows style\n");
|
|
|
|
fprintf(stderr, " paths like C:\\Program Files instead of POSIX\n");
|
|
|
|
fprintf(stderr, " style paths are used like /usr/local/bin. Windows\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
fprintf(stderr, " style paths are used by default.\n");
|
|
|
|
#else
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Informs the tool that it should use Windows style\n");
|
|
|
|
fprintf(stderr, " paths like C:\\Program Files. By default, POSIX\n");
|
|
|
|
fprintf(stderr, " style paths like /usr/local/bin are used.\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
#endif
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " -f:\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
#ifdef CONFIG_WINDOWS_NATIVE
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Informs the tool that it should use POSIX style\n");
|
|
|
|
fprintf(stderr, " paths like /usr/local/bin. By default, Windows\n");
|
|
|
|
fprintf(stderr, " style paths like C:\\Program Files are used.\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
#else
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Informs the tool that it should use POSIX style\n");
|
|
|
|
fprintf(stderr, " paths like /usr/local/bin instead of Windows\n");
|
|
|
|
fprintf(stderr, " style paths like C:\\Program Files are used.\n");
|
|
|
|
fprintf(stderr, " POSIX style paths are used by default.\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
#endif
|
2020-10-18 15:28:35 +02:00
|
|
|
fprintf(stderr, " [-l|m|c|g|n]\n");
|
2017-11-10 00:36:46 +01:00
|
|
|
fprintf(stderr, " Selects the host environment.\n");
|
|
|
|
fprintf(stderr, " -l Selects the Linux (l) host environment.\n");
|
|
|
|
fprintf(stderr, " -m Selects the macOS (m) host environment.\n");
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " -c Selects the Windows Cygwin (c) environment.\n");
|
|
|
|
fprintf(stderr, " -g Selects the Windows MinGW/MSYS environment.\n");
|
|
|
|
fprintf(stderr, " -n Selects the Windows native (n) environment.\n");
|
2017-11-10 00:36:46 +01:00
|
|
|
fprintf(stderr, " Default: Use host setup in the defconfig file.\n");
|
|
|
|
fprintf(stderr, " Default Windows: Cygwin.\n");
|
2020-09-02 20:04:33 +02:00
|
|
|
fprintf(stderr, " -L:\n");
|
|
|
|
fprintf(stderr, " Lists all available configurations.\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
fprintf(stderr, " -a <app-dir>:\n");
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Informs the configuration tool where the\n");
|
|
|
|
fprintf(stderr, " application build directory. This is a relative\n");
|
|
|
|
fprintf(stderr, " path from the top-level NuttX build directory.\n");
|
|
|
|
fprintf(stderr, " But default, this tool will look in the usual\n");
|
|
|
|
fprintf(stderr, " places to locate the application directory:\n");
|
|
|
|
fprintf(stderr, " ..%capps or\n", g_delim);
|
|
|
|
fprintf(stderr, " ..%capps-xx.yy where xx.yy is the version number.\n",
|
|
|
|
g_delim);
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " <board-name>:\n");
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Identifies the board. This must correspond to a\n");
|
|
|
|
fprintf(stderr, " board directory under nuttx%cboards%c.\n",
|
|
|
|
g_delim, g_delim);
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " <config-name>:\n");
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, " Identifies the specific configuration for the\n");
|
|
|
|
fprintf(stderr, " selected <board-name>. This must correspond to\n");
|
|
|
|
fprintf(stderr, " a sub-directory under the board directory at\n");
|
2019-08-06 00:53:39 +02:00
|
|
|
fprintf(stderr, " under nuttx%cboards%c<board-name>%cconfigs%c.\n",
|
|
|
|
g_delim, g_delim, g_delim, g_delim);
|
2020-03-20 05:08:27 +01:00
|
|
|
fprintf(stderr, " [make-opts]:\n");
|
|
|
|
fprintf(stderr, " Options directly pass to make\n");
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " -h:\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
fprintf(stderr, " Prints this message and exits.\n");
|
|
|
|
exit(exitcode);
|
|
|
|
}
|
|
|
|
|
2020-09-02 20:04:33 +02:00
|
|
|
static void dumpcfgs(void)
|
|
|
|
{
|
|
|
|
find_topdir();
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cboards", g_topdir, g_delim);
|
|
|
|
verify_directory(g_buffer);
|
|
|
|
g_configtop = strdup(g_buffer);
|
|
|
|
enumerate_configs();
|
|
|
|
free(g_configtop);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static void debug(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (g_debug)
|
|
|
|
{
|
|
|
|
va_start(ap, fmt);
|
2020-01-02 17:49:34 +01:00
|
|
|
vprintf(fmt, ap);
|
2013-01-04 22:37:31 +01:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_args(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
/* Parse command line options */
|
|
|
|
|
2020-09-02 20:04:33 +02:00
|
|
|
while ((ch = getopt(argc, argv, "a:bcdEefghLlmnu")) > 0)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case 'a' :
|
|
|
|
g_appdir = optarg;
|
|
|
|
break;
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
case 'b' :
|
2015-05-31 20:42:44 +02:00
|
|
|
g_delim = '\\';
|
|
|
|
g_winpaths = false;
|
2013-01-04 22:37:31 +01:00
|
|
|
break;
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
case 'c' :
|
|
|
|
g_host = HOST_WINDOWS;
|
|
|
|
g_windows = WINDOWS_CYGWIN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd' :
|
|
|
|
g_debug = true;
|
|
|
|
break;
|
|
|
|
|
2020-08-20 20:32:42 +02:00
|
|
|
case 'E' :
|
2020-03-19 19:09:45 +01:00
|
|
|
g_enforce = true;
|
|
|
|
break;
|
|
|
|
|
2020-08-20 20:32:42 +02:00
|
|
|
case 'e' :
|
|
|
|
g_distclean = true;
|
|
|
|
break;
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
case 'f' :
|
2015-05-31 20:42:44 +02:00
|
|
|
g_delim = '/';
|
|
|
|
g_winpaths = true;
|
2013-01-04 22:37:31 +01:00
|
|
|
break;
|
|
|
|
|
2018-05-31 19:53:09 +02:00
|
|
|
case 'g' :
|
|
|
|
g_host = HOST_WINDOWS;
|
|
|
|
g_windows = WINDOWS_MSYS;
|
|
|
|
break;
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
case 'h' :
|
|
|
|
show_usage(argv[0], EXIT_SUCCESS);
|
|
|
|
|
2020-09-02 20:04:33 +02:00
|
|
|
case 'L' :
|
|
|
|
dumpcfgs();
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
case 'l' :
|
|
|
|
g_host = HOST_LINUX;
|
|
|
|
break;
|
|
|
|
|
2017-11-10 00:36:46 +01:00
|
|
|
case 'm' :
|
|
|
|
g_host = HOST_MACOS;
|
|
|
|
break;
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
case 'n' :
|
|
|
|
g_host = HOST_WINDOWS;
|
|
|
|
g_windows = WINDOWS_NATIVE;
|
|
|
|
break;
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
case '?' :
|
|
|
|
fprintf(stderr, "ERROR: Unrecognized option: %c\n", optopt);
|
|
|
|
show_usage(argv[0], EXIT_FAILURE);
|
|
|
|
|
|
|
|
case ':' :
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: Missing option argument, option: %c\n",
|
|
|
|
optopt);
|
2013-01-04 22:37:31 +01:00
|
|
|
show_usage(argv[0], EXIT_FAILURE);
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
default:
|
2013-01-04 22:37:31 +01:00
|
|
|
fprintf(stderr, "ERROR: Unexpected option: %c\n", ch);
|
|
|
|
show_usage(argv[0], EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There should be exactly one argument following the options */
|
|
|
|
|
|
|
|
if (optind >= argc)
|
|
|
|
{
|
2020-01-19 18:22:36 +01:00
|
|
|
fprintf(stderr, "ERROR: Missing <board-name>:<config-name>\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
show_usage(argv[0], EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The required option should be the board directory name and the
|
2019-08-06 00:53:39 +02:00
|
|
|
* configuration directory name separated by ':', '/' or '\'. Any are
|
2013-01-04 22:37:31 +01:00
|
|
|
* acceptable in this context.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_boarddir = argv[optind];
|
|
|
|
optind++;
|
|
|
|
|
2019-08-06 00:53:39 +02:00
|
|
|
ptr = strchr(g_boarddir, ':');
|
|
|
|
if (ptr == NULL)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2019-08-06 00:53:39 +02:00
|
|
|
ptr = strchr(g_boarddir, '/');
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
ptr = strchr(g_boarddir, '\\');
|
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
|
2019-08-06 00:53:39 +02:00
|
|
|
if (ptr == NULL)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2019-08-06 00:53:39 +02:00
|
|
|
fprintf(stderr, "ERROR: Invalid <board-name>:<config-name>\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
show_usage(argv[0], EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr++ = '\0';
|
|
|
|
g_configdir = ptr;
|
|
|
|
|
2020-03-20 05:08:27 +01:00
|
|
|
/* The left arguments will pass to make */
|
|
|
|
|
|
|
|
g_makeargv = &argv[optind];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int run_make(const char *arg)
|
|
|
|
{
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "make %s", arg);
|
2020-03-23 20:15:18 +01:00
|
|
|
|
2020-03-20 05:08:27 +01:00
|
|
|
for (argv = g_makeargv; *argv; argv++)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2020-03-23 20:15:18 +01:00
|
|
|
strncat(g_buffer, " ", BUFFER_SIZE - 1);
|
|
|
|
strncat(g_buffer, *argv, BUFFER_SIZE - 1);
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
2020-03-20 05:08:27 +01:00
|
|
|
|
|
|
|
return system(g_buffer);
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
|
2020-08-20 20:32:42 +02:00
|
|
|
static bool filecmp(const char *f1, const char *f2)
|
|
|
|
{
|
|
|
|
FILE *stream1;
|
|
|
|
FILE *stream2;
|
|
|
|
char ch1;
|
|
|
|
char ch2;
|
|
|
|
|
|
|
|
stream1 = fopen(f1, "r");
|
|
|
|
stream2 = fopen(f2, "r");
|
|
|
|
|
|
|
|
if (stream1 == NULL || stream2 == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ch1 = fgetc(stream1);
|
|
|
|
ch2 = fgetc(stream2);
|
|
|
|
|
|
|
|
if (ch1 != ch2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (ch1 != EOF && ch2 != EOF);
|
|
|
|
|
|
|
|
fclose(stream1);
|
|
|
|
fclose(stream2);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
static bool check_directory(const char *directory)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (stat(directory, &buf) < 0)
|
|
|
|
{
|
|
|
|
debug("stat of %s failed: %s\n", directory, strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISDIR(buf.st_mode))
|
|
|
|
{
|
|
|
|
debug("%s exists but is not a directory\n", directory);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static void verify_directory(const char *directory)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (stat(directory, &buf) < 0)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: stat of %s failed: %s\n",
|
|
|
|
directory, strerror(errno));
|
2013-01-04 22:37:31 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISDIR(buf.st_mode))
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: %s exists but is not a directory\n",
|
|
|
|
directory);
|
2013-01-04 22:37:31 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_optiondir(const char *directory)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (stat(directory, &buf) < 0)
|
|
|
|
{
|
2020-02-23 09:50:23 +01:00
|
|
|
/* It may be okay if the directory does not exist */
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2013-01-05 17:07:37 +01:00
|
|
|
/* It may be okay if the file does not exist */
|
|
|
|
|
|
|
|
int errcode = errno;
|
|
|
|
if (errcode == ENOENT)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
debug("verify_optiondir: stat of %s failed: %s\n",
|
|
|
|
directory, strerror(errno));
|
2013-01-05 17:07:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: stat of %s failed: %s\n",
|
|
|
|
directory, strerror(errno));
|
2013-01-05 17:07:37 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISDIR(buf.st_mode))
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: %s exists but is not a directory\n",
|
|
|
|
directory);
|
2013-01-04 22:37:31 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-05 17:07:37 +01:00
|
|
|
static bool verify_file(const char *path)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (stat(path, &buf) < 0)
|
|
|
|
{
|
|
|
|
/* It may be okay if the file does not exist */
|
|
|
|
|
2013-01-05 17:07:37 +01:00
|
|
|
int errcode = errno;
|
|
|
|
if (errcode == ENOENT)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
debug("verify_file: stat of %s failed: %s\n",
|
|
|
|
path, strerror(errno));
|
2013-01-05 17:07:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: stat of %s failed: %s\n",
|
|
|
|
path, strerror(errno));
|
2013-01-05 17:07:37 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISREG(buf.st_mode))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: %s exists but is not a regular file\n", path);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
static void find_topdir(void)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2017-06-15 16:24:28 +02:00
|
|
|
char *currdir;
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/* Get and verify the top-level NuttX directory */
|
2020-03-20 10:40:33 +01:00
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
/* First get the current directory. We expect this to be either
|
|
|
|
* the nuttx root directory or the tools subdirectory.
|
|
|
|
*/
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
if (getcwd(g_buffer, BUFFER_SIZE) == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: getcwd failed: %s\n", strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
/* Assume that we are in the tools sub-directory and the directory above
|
|
|
|
* is the nuttx root directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
currdir = strdup(g_buffer);
|
2013-01-04 22:37:31 +01:00
|
|
|
g_topdir = strdup(dirname(g_buffer));
|
2017-06-15 16:24:28 +02:00
|
|
|
|
|
|
|
debug("get_topdir: Checking parent directory: %s\n", g_topdir);
|
2013-01-04 22:37:31 +01:00
|
|
|
verify_directory(g_topdir);
|
2017-06-15 16:24:28 +02:00
|
|
|
|
|
|
|
/* Check if the current directory is the nuttx root directory.
|
|
|
|
* If so, then the tools directory should be a sub-directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%ctools", currdir, g_delim);
|
|
|
|
debug("get_topdir: Checking topdir/tools=%s\n", g_buffer);
|
|
|
|
if (check_directory(g_buffer))
|
|
|
|
{
|
|
|
|
/* There is a tools sub-directory under the current directory.
|
|
|
|
* We must have already been in the nuttx root directory. We
|
|
|
|
* will find out for sure in later tests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
free(g_topdir);
|
|
|
|
g_topdir = currdir;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Yes, we are probably in the tools/ sub-directory */
|
|
|
|
|
|
|
|
free(currdir);
|
2020-03-19 19:09:45 +01:00
|
|
|
if (chdir(g_topdir) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Failed to ch to %s\n", g_topdir);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2017-06-15 16:24:28 +02:00
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
static void config_search(const char *boarddir,
|
|
|
|
config_callback callback, void *data)
|
2013-01-05 17:07:37 +01:00
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dp;
|
|
|
|
struct stat buf;
|
|
|
|
char *parent;
|
|
|
|
char *child;
|
|
|
|
|
|
|
|
/* Skip over any leading '/' or '\\'. This happens on the first second
|
|
|
|
* call because the starting boarddir is ""
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (boarddir[0] == g_delim)
|
|
|
|
{
|
|
|
|
boarddir++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the full directory path and open it */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s", g_configtop, g_delim, boarddir);
|
|
|
|
dir = opendir(g_buffer);
|
|
|
|
if (!dir)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Could not open %s: %s\n",
|
|
|
|
g_buffer, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a copy of the path to the directory */
|
|
|
|
|
|
|
|
parent = strdup(g_buffer);
|
|
|
|
|
2019-08-05 21:24:08 +02:00
|
|
|
/* Visit each entry in the directory */
|
2013-01-05 17:07:37 +01:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
while ((dp = readdir(dir)) != NULL)
|
2013-01-05 17:07:37 +01:00
|
|
|
{
|
|
|
|
/* Ignore directory entries that start with '.' */
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a properly terminated copy of d_name (if d_name is long it may
|
2019-08-05 21:24:08 +02:00
|
|
|
* not include a NUL terminator.
|
|
|
|
*/
|
2013-01-05 17:07:37 +01:00
|
|
|
|
|
|
|
child = strndup(dp->d_name, NAME_MAX);
|
|
|
|
|
|
|
|
/* Get the full path to d_name and stat the file/directory */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s", parent, g_delim, child);
|
|
|
|
if (stat(g_buffer, &buf) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: stat of %s failed: %s\n",
|
|
|
|
g_buffer, strerror(errno));
|
|
|
|
free(child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-05 21:24:08 +02:00
|
|
|
/* If it is a directory, then recurse */
|
2013-01-05 17:07:37 +01:00
|
|
|
|
|
|
|
if (S_ISDIR(buf.st_mode))
|
|
|
|
{
|
|
|
|
char *tmppath;
|
2020-03-20 10:40:33 +01:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s",
|
|
|
|
boarddir, g_delim, child);
|
2013-01-05 17:07:37 +01:00
|
|
|
tmppath = strdup(g_buffer);
|
2020-01-16 02:16:14 +01:00
|
|
|
config_search(tmppath, callback, data);
|
2013-01-05 17:07:37 +01:00
|
|
|
free(tmppath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is a regular file named 'defconfig' then we have found a
|
2020-02-23 09:50:23 +01:00
|
|
|
* configuration directory. We could terminate the search in this case
|
2013-01-05 17:07:37 +01:00
|
|
|
* because we do not expect sub-directories within configuration
|
|
|
|
* directories.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (S_ISREG(buf.st_mode) && strcmp("defconfig", child) == 0)
|
|
|
|
{
|
2020-01-16 02:16:14 +01:00
|
|
|
char *archname;
|
|
|
|
char *chipname;
|
2019-08-05 21:24:08 +02:00
|
|
|
char *boardname;
|
|
|
|
char *configname;
|
|
|
|
char *delim;
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
/* Get the board directory near the beginning of the 'boarddir':
|
2019-08-08 01:25:54 +02:00
|
|
|
* <archdir>/<chipdir>/<boarddir>/configs/<configdir>
|
2019-08-06 18:39:12 +02:00
|
|
|
*/
|
2019-08-05 21:24:08 +02:00
|
|
|
|
2019-08-08 01:25:54 +02:00
|
|
|
/* Make a modifiable copy */
|
|
|
|
|
2020-03-23 20:15:18 +01:00
|
|
|
strncpy(g_buffer, boarddir, BUFFER_SIZE - 1);
|
2019-08-08 01:25:54 +02:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
/* Save the <archdir> */
|
|
|
|
|
|
|
|
archname = g_buffer;
|
2019-08-08 01:25:54 +02:00
|
|
|
|
2019-08-06 18:39:12 +02:00
|
|
|
delim = strchr(g_buffer, g_delim);
|
2019-08-05 21:24:08 +02:00
|
|
|
if (delim == NULL)
|
|
|
|
{
|
2019-08-06 18:39:12 +02:00
|
|
|
debug("ERROR: delimiter not found in path: %s\n", boarddir);
|
2019-08-05 21:24:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-16 02:16:14 +01:00
|
|
|
/* Save the <chipdir> */
|
2019-08-05 21:24:08 +02:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
*delim = '\0';
|
|
|
|
chipname = delim + 1;
|
|
|
|
|
|
|
|
delim = strchr(chipname, g_delim);
|
2019-08-06 18:39:12 +02:00
|
|
|
if (delim == NULL)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
debug("ERROR: delimiter not found in path: %s\n",
|
|
|
|
chipname);
|
2019-08-06 18:39:12 +02:00
|
|
|
}
|
|
|
|
else
|
2019-08-05 21:24:08 +02:00
|
|
|
{
|
2019-08-08 01:25:54 +02:00
|
|
|
/* Save the <boardir> */
|
|
|
|
|
|
|
|
*delim = '\0';
|
|
|
|
boardname = delim + 1;
|
|
|
|
|
|
|
|
delim = strchr(boardname, g_delim);
|
2019-08-06 18:39:12 +02:00
|
|
|
if (delim == NULL)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
debug("ERROR: delimiter not found in path: %s\n",
|
|
|
|
boardname);
|
2019-08-06 18:39:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-08 01:25:54 +02:00
|
|
|
/* Save the <configdir> */
|
|
|
|
|
|
|
|
*delim = '\0';
|
|
|
|
delim = strrchr(delim + 1, g_delim);
|
|
|
|
if (delim == NULL)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
debug("ERROR: directory not found in path: %s\n",
|
2019-08-08 01:25:54 +02:00
|
|
|
boardname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
configname = delim + 1;
|
2020-03-20 10:40:33 +01:00
|
|
|
callback(boarddir, archname, chipname,
|
|
|
|
boardname, configname, data);
|
2019-08-08 01:25:54 +02:00
|
|
|
}
|
2019-08-06 18:39:12 +02:00
|
|
|
}
|
2019-08-05 21:24:08 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-05 17:07:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
free(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(parent);
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
static void archname_callback(const char *boarddir, const char *archname,
|
|
|
|
const char *chipname, const char *boardname,
|
|
|
|
const char *configname, void *data)
|
2020-01-16 02:16:14 +01:00
|
|
|
{
|
|
|
|
if (strcmp(g_boarddir, boardname) == 0 &&
|
|
|
|
strcmp(g_configdir, configname) == 0)
|
|
|
|
{
|
|
|
|
g_archdir = strdup(archname);
|
|
|
|
g_chipdir = strdup(chipname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void find_archname(void)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
config_search("", archname_callback, NULL);
|
2020-01-16 02:16:14 +01:00
|
|
|
if (g_archdir == NULL || g_chipdir == NULL)
|
|
|
|
{
|
|
|
|
g_archdir = "unknown";
|
|
|
|
g_chipdir = "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void enumerate_callback(const char *boarddir, const char *archname,
|
|
|
|
const char *chipname, const char *boardname,
|
|
|
|
const char *configname, void *data)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " %s:%s\n", boardname, configname);
|
|
|
|
}
|
|
|
|
|
2013-01-05 17:07:37 +01:00
|
|
|
static void enumerate_configs(void)
|
|
|
|
{
|
2019-08-06 00:53:39 +02:00
|
|
|
fprintf(stderr, "Options for <board-name>:<config-name> include:\n\n");
|
2020-01-16 02:16:14 +01:00
|
|
|
config_search("", enumerate_callback, NULL);
|
2013-01-05 17:07:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static void check_configdir(void)
|
|
|
|
{
|
2019-08-05 17:03:12 +02:00
|
|
|
/* Get the path to the top level configuration directory: boards/ */
|
2013-01-05 17:07:37 +01:00
|
|
|
|
2019-08-05 15:24:57 +02:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cboards", g_topdir, g_delim);
|
2013-01-05 17:07:37 +01:00
|
|
|
debug("check_configdir: Checking configtop=%s\n", g_buffer);
|
|
|
|
|
|
|
|
verify_directory(g_buffer);
|
|
|
|
g_configtop = strdup(g_buffer);
|
|
|
|
|
2019-08-05 17:03:12 +02:00
|
|
|
/* Get and verify the path to the selected configuration:
|
2019-08-08 01:25:54 +02:00
|
|
|
* boards/<archdir>/<chipdir>/<boarddir>/configs/<configdir>
|
2019-08-05 17:03:12 +02:00
|
|
|
*/
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2020-01-16 02:16:14 +01:00
|
|
|
find_archname();
|
|
|
|
|
2019-08-08 01:25:54 +02:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cboards%c%s%c%s%c%s%cconfigs%c%s",
|
|
|
|
g_topdir, g_delim, g_delim, g_archdir, g_delim, g_chipdir,
|
|
|
|
g_delim, g_boarddir, g_delim, g_delim, g_configdir);
|
2013-01-05 17:07:37 +01:00
|
|
|
debug("check_configdir: Checking configpath=%s\n", g_buffer);
|
|
|
|
|
|
|
|
if (!verify_optiondir(g_buffer))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: No configuration at %s\n", g_buffer);
|
2020-09-02 20:04:33 +02:00
|
|
|
fprintf(stderr, "Run tools/configure -L"
|
|
|
|
" to list available configurations.\n");
|
2013-01-05 17:07:37 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
g_configpath = strdup(g_buffer);
|
2017-07-11 01:00:54 +02:00
|
|
|
|
2019-08-05 21:24:08 +02:00
|
|
|
/* Get and verify the path to the scripts directory:
|
2019-08-08 01:25:54 +02:00
|
|
|
* boards/<archdir>/<chipdir>/<boarddir>/scripts
|
2019-08-05 17:03:12 +02:00
|
|
|
*/
|
|
|
|
|
2019-08-08 01:25:54 +02:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cboards%c%s%c%s%c%s%cscripts",
|
2019-08-06 18:39:12 +02:00
|
|
|
g_topdir, g_delim, g_delim, g_archdir, g_delim,
|
2019-08-08 01:25:54 +02:00
|
|
|
g_chipdir, g_delim, g_boarddir, g_delim);
|
2017-07-11 01:00:54 +02:00
|
|
|
debug("check_configdir: Checking scriptspath=%s\n", g_buffer);
|
|
|
|
|
|
|
|
g_scriptspath = NULL;
|
|
|
|
if (verify_optiondir(g_buffer))
|
|
|
|
{
|
|
|
|
g_scriptspath = strdup(g_buffer);
|
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
|
2017-11-10 00:36:46 +01:00
|
|
|
static void check_configured(void)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
/* If we are already configured then there will be a .config and
|
|
|
|
* a Make.defs file in the top-level directory.
|
2017-11-10 00:36:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c.config", g_topdir, g_delim);
|
|
|
|
debug("check_configured: Checking %s\n", g_buffer);
|
2020-08-20 20:32:42 +02:00
|
|
|
|
|
|
|
if (!verify_file(g_buffer))
|
2017-11-10 00:36:46 +01:00
|
|
|
{
|
2020-08-20 20:32:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_enforce)
|
|
|
|
{
|
|
|
|
run_make("distclean");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *defcfgpath = NULL;
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cdefconfig",
|
|
|
|
g_configpath, g_delim);
|
|
|
|
defcfgpath = strdup(g_buffer);
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cdefconfig",
|
|
|
|
g_topdir, g_delim);
|
|
|
|
|
|
|
|
if (filecmp(g_buffer, defcfgpath))
|
2020-03-19 19:09:45 +01:00
|
|
|
{
|
2020-08-20 20:32:42 +02:00
|
|
|
fprintf(stderr, "No configuration change.\n");
|
|
|
|
free(defcfgpath);
|
|
|
|
exit(EXIT_SUCCESS);
|
2020-03-19 19:09:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-20 20:32:42 +02:00
|
|
|
free(defcfgpath);
|
|
|
|
if (g_distclean)
|
|
|
|
{
|
|
|
|
run_make("distclean");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Already configured!\n");
|
|
|
|
fprintf(stderr, "Please 'make distclean' and try again.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2020-03-19 19:09:45 +01:00
|
|
|
}
|
2017-11-10 00:36:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static void read_configfile(void)
|
|
|
|
{
|
|
|
|
FILE *stream;
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cdefconfig", g_configpath, g_delim);
|
|
|
|
stream = fopen(g_buffer, "r");
|
|
|
|
if (!stream)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: failed to open %s for reading: %s\n",
|
|
|
|
g_buffer, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_file(stream, &g_configvars);
|
|
|
|
fclose(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_versionfile(void)
|
|
|
|
{
|
|
|
|
FILE *stream;
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c.version", g_topdir, g_delim);
|
|
|
|
stream = fopen(g_buffer, "r");
|
|
|
|
if (!stream)
|
|
|
|
{
|
|
|
|
/* It may not be an error if there is no .version file */
|
|
|
|
|
|
|
|
debug("Failed to open %s for reading: %s\n",
|
|
|
|
g_buffer, strerror(errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parse_file(stream, &g_versionvars);
|
|
|
|
fclose(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_verstring(void)
|
|
|
|
{
|
|
|
|
struct variable_s *var;
|
|
|
|
|
|
|
|
if (g_versionvars)
|
|
|
|
{
|
|
|
|
var = find_variable("CONFIG_VERSION_STRING", g_versionvars);
|
|
|
|
if (var && var->val)
|
|
|
|
{
|
|
|
|
g_verstring = strdup(var->val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("get_verstring: Version string=%s\n", g_verstring);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_appdir(const char *appdir)
|
|
|
|
{
|
|
|
|
/* Does this directory exist? */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s", g_topdir, g_delim, appdir);
|
|
|
|
debug("verify_appdir: Checking apppath=%s\n", g_buffer);
|
|
|
|
if (verify_optiondir(g_buffer))
|
|
|
|
{
|
|
|
|
/* Yes.. Use this application directory path */
|
|
|
|
|
|
|
|
g_appdir = strdup(appdir);
|
|
|
|
g_apppath = strdup(g_buffer);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("verify_appdir: apppath=%s does not exist\n", g_buffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_appdir(void)
|
|
|
|
{
|
|
|
|
char tmp[16];
|
|
|
|
|
|
|
|
/* Get and verify the full path to the application directory */
|
2020-03-20 10:40:33 +01:00
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/* Was the appdir provided on the command line? */
|
|
|
|
|
|
|
|
debug("check_appdir: Command line appdir=%s\n",
|
|
|
|
g_appdir ? g_appdir : "<null>");
|
|
|
|
|
|
|
|
if (!g_appdir)
|
|
|
|
{
|
2017-10-01 20:45:29 +02:00
|
|
|
/* If no application directory was provided on the command line and we
|
|
|
|
* are switching between a windows native host and some other host then
|
|
|
|
* ignore any path to the apps/ directory in the defconfig file. It
|
|
|
|
* will most certainly not be in a usable form.
|
|
|
|
*/
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2017-10-01 20:45:29 +02:00
|
|
|
if (g_winnative == g_oldnative)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2017-10-01 20:45:29 +02:00
|
|
|
/* No, was the path provided in the configuration? */
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2017-10-01 20:45:29 +02:00
|
|
|
struct variable_s *var =
|
|
|
|
find_variable("CONFIG_APPS_DIR", g_configvars);
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2017-10-01 20:45:29 +02:00
|
|
|
if (var != NULL)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2017-10-01 20:45:29 +02:00
|
|
|
debug("check_appdir: Config file appdir=%s\n",
|
|
|
|
var->val ? var->val : "<null>");
|
|
|
|
|
|
|
|
/* Yes.. does this directory exist? */
|
|
|
|
|
|
|
|
if (var->val && verify_appdir(var->val))
|
|
|
|
{
|
|
|
|
/* We are using the CONFIG_APPS_DIR setting already in the
|
|
|
|
* defconfig file.
|
|
|
|
*/
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2017-10-01 20:45:29 +02:00
|
|
|
g_needapppath = false;
|
|
|
|
return;
|
|
|
|
}
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now try some canned locations */
|
|
|
|
|
|
|
|
/* Try ../apps-xx.yy where xx.yy is the version string */
|
|
|
|
|
2020-01-19 18:22:36 +01:00
|
|
|
snprintf(tmp, 16, "..%capps-%s", g_delim, g_verstring);
|
2013-01-04 22:37:31 +01:00
|
|
|
debug("check_appdir: Try appdir=%s\n", tmp);
|
|
|
|
if (verify_appdir(tmp))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try ../apps with no version */
|
|
|
|
|
|
|
|
snprintf(tmp, 16, "..%capps", g_delim);
|
|
|
|
debug("check_appdir: Try appdir=%s\n", tmp);
|
|
|
|
if (verify_appdir(tmp))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try ../apps-xx.yy where xx.yy are the NuttX version number */
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: Could not find the path to the appdir\n");
|
2013-01-04 22:37:31 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2020-03-20 10:40:33 +01:00
|
|
|
else if (!verify_appdir(g_appdir))
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: Command line path to appdir does not exist\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2013-01-04 22:37:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_configuration(void)
|
|
|
|
{
|
|
|
|
struct variable_s *var;
|
|
|
|
|
|
|
|
/* Check if this is a Windows native configuration */
|
|
|
|
|
|
|
|
var = find_variable("CONFIG_WINDOWS_NATIVE", g_configvars);
|
|
|
|
if (var && var->val && strcmp("y", var->val) == 0)
|
|
|
|
{
|
|
|
|
debug("check_configuration: Windows native configuration\n");
|
2017-10-01 20:45:29 +02:00
|
|
|
g_oldnative = true;
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:45:35 +02:00
|
|
|
/* If we are going to some host other than windows native or to a windows
|
2017-10-01 20:45:29 +02:00
|
|
|
* native host, then don't ignore what is in the defconfig file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_host == HOST_NOCHANGE)
|
|
|
|
{
|
|
|
|
/* Use whatever we found in the configuration file */
|
|
|
|
|
|
|
|
g_winnative = g_oldnative;
|
|
|
|
}
|
|
|
|
else if (g_host == HOST_WINDOWS && g_windows == WINDOWS_NATIVE)
|
|
|
|
{
|
|
|
|
/* The new configuration is windows native */
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
g_winnative = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All configurations must provide a defconfig and Make.defs file */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cdefconfig", g_configpath, g_delim);
|
|
|
|
debug("check_configuration: Checking %s\n", g_buffer);
|
2013-01-05 17:07:37 +01:00
|
|
|
if (!verify_file(g_buffer))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: No configuration in %s\n", g_configpath);
|
|
|
|
fprintf(stderr, " No defconfig file found.\n");
|
2020-09-02 20:04:33 +02:00
|
|
|
fprintf(stderr, "Run tools/configure -L"
|
|
|
|
" to list available configurations.\n");
|
2013-01-05 17:07:37 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
g_srcdefconfig = strdup(g_buffer);
|
2014-01-04 16:08:14 +01:00
|
|
|
|
2017-07-11 01:00:54 +02:00
|
|
|
/* Try the Make.defs file */
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cMake.defs", g_configpath, g_delim);
|
|
|
|
debug("check_configuration: Checking %s\n", g_buffer);
|
2013-01-05 17:07:37 +01:00
|
|
|
if (!verify_file(g_buffer))
|
|
|
|
{
|
2017-07-11 01:00:54 +02:00
|
|
|
/* An alternative location is the scripts/ directory */
|
|
|
|
|
|
|
|
if (g_scriptspath != NULL)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cMake.defs",
|
|
|
|
g_scriptspath, g_delim);
|
2017-07-11 01:00:54 +02:00
|
|
|
debug("check_configuration: Checking %s\n", g_buffer);
|
|
|
|
if (!verify_file(g_buffer))
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: No Make.defs file in %s\n",
|
|
|
|
g_configpath);
|
|
|
|
fprintf(stderr, " No Make.defs file in %s\n",
|
|
|
|
g_scriptspath);
|
2020-09-02 20:04:33 +02:00
|
|
|
fprintf(stderr, "Run tools/configure -L"
|
|
|
|
" to list available configurations.\n");
|
2017-07-11 01:00:54 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: No Make.defs file in %s\n", g_configpath);
|
2020-09-02 20:04:33 +02:00
|
|
|
fprintf(stderr, "Run tools/configure -L"
|
|
|
|
" to list available configurations.\n");
|
2017-07-11 01:00:54 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-01-05 17:07:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
g_srcmakedefs = strdup(g_buffer);
|
|
|
|
}
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
static void copy_file(const char *srcpath,
|
|
|
|
const char *destpath, mode_t mode)
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
|
|
|
int nbytesread;
|
|
|
|
int nbyteswritten;
|
|
|
|
int rdfd;
|
|
|
|
int wrfd;
|
|
|
|
|
|
|
|
/* Open the source file for reading */
|
|
|
|
|
|
|
|
rdfd = open(srcpath, O_RDONLY);
|
|
|
|
if (rdfd < 0)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: Failed to open %s for reading: %s\n",
|
|
|
|
srcpath, strerror(errno));
|
2013-01-04 22:37:31 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
/* Now open the destination for writing */
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
wrfd = open(destpath, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
2013-01-04 22:37:31 +01:00
|
|
|
if (wrfd < 0)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: Failed to open %s for writing: %s\n",
|
|
|
|
destpath, strerror(errno));
|
2013-01-04 22:37:31 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now copy the file */
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
for (; ; )
|
2013-01-04 22:37:31 +01:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nbytesread = read(rdfd, g_buffer, BUFFER_SIZE);
|
|
|
|
if (nbytesread == 0)
|
|
|
|
{
|
|
|
|
/* End of file */
|
|
|
|
|
|
|
|
close(rdfd);
|
|
|
|
close(wrfd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (nbytesread < 0)
|
|
|
|
{
|
|
|
|
/* EINTR is not an error (but will still stop the copy) */
|
|
|
|
|
|
|
|
fprintf(stderr, "ERROR: Read failure: %s\n", strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (nbytesread <= 0);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nbyteswritten = write(wrfd, g_buffer, nbytesread);
|
|
|
|
if (nbyteswritten >= 0)
|
|
|
|
{
|
|
|
|
nbytesread -= nbyteswritten;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* EINTR is not an error (but will still stop the copy) */
|
|
|
|
|
|
|
|
fprintf(stderr, "ERROR: Write failure: %s\n", strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (nbytesread > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void substitute(char *str, int ch1, int ch2)
|
|
|
|
{
|
|
|
|
for (; *str; str++)
|
|
|
|
{
|
|
|
|
if (*str == ch1)
|
|
|
|
{
|
|
|
|
*str = ch2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 23:35:28 +01:00
|
|
|
static char *double_appdir_backslashes(char *old_appdir)
|
|
|
|
{
|
|
|
|
char *new_appdir = NULL;
|
|
|
|
char *p_old = NULL;
|
|
|
|
char *p_new = NULL;
|
|
|
|
int oldlen = 0;
|
|
|
|
int occurrences = 0;
|
|
|
|
int alloclen = 0;
|
|
|
|
|
|
|
|
p_old = old_appdir;
|
|
|
|
while ((p_old = strchr(p_old, '\\')) != NULL)
|
|
|
|
{
|
|
|
|
occurrences++;
|
|
|
|
p_old++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (occurrences != 0)
|
|
|
|
{
|
|
|
|
oldlen = strlen(old_appdir);
|
|
|
|
alloclen = oldlen + occurrences + sizeof((char) '\0');
|
|
|
|
new_appdir = malloc(alloclen);
|
|
|
|
|
|
|
|
if (new_appdir != NULL)
|
|
|
|
{
|
|
|
|
p_old = old_appdir;
|
|
|
|
p_new = new_appdir;
|
|
|
|
while (oldlen)
|
|
|
|
{
|
|
|
|
if (*p_old != '\\')
|
|
|
|
{
|
|
|
|
*p_new++ = *p_old;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p_new++ = '\\';
|
|
|
|
*p_new++ = '\\';
|
|
|
|
}
|
|
|
|
|
|
|
|
++p_old;
|
|
|
|
--oldlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p_new = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_appdir = strdup(old_appdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_appdir;
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
static void copy_optional(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < N_OPTFILES; i++)
|
|
|
|
{
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s",
|
|
|
|
g_configpath, g_delim, g_optfiles[i]);
|
|
|
|
|
|
|
|
if (verify_file(g_buffer))
|
|
|
|
{
|
|
|
|
char *optsrc = strdup(g_buffer);
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s",
|
|
|
|
g_topdir, g_delim, g_optfiles[i]);
|
2017-06-15 16:24:28 +02:00
|
|
|
|
|
|
|
debug("copy_optional: Copying from %s to %s\n", optsrc, g_buffer);
|
|
|
|
copy_file(optsrc, g_buffer, 0644);
|
|
|
|
|
|
|
|
free(optsrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
static void enable_feature(const char *destconfig, const char *varname)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE,
|
2017-07-13 02:48:11 +02:00
|
|
|
"kconfig-tweak --file %s --enable %s",
|
2017-07-10 17:38:45 +02:00
|
|
|
destconfig, varname);
|
|
|
|
|
|
|
|
ret = system(g_buffer);
|
|
|
|
|
|
|
|
#ifdef WEXITSTATUS
|
|
|
|
if (ret < 0 || WEXITSTATUS(ret) != 0)
|
|
|
|
#else
|
|
|
|
if (ret < 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Failed to enable %s\n", varname);
|
|
|
|
fprintf(stderr, " command: %s\n", g_buffer);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_feature(const char *destconfig, const char *varname)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE,
|
|
|
|
"kconfig-tweak --file %s --disable %s",
|
|
|
|
destconfig, varname);
|
|
|
|
|
|
|
|
ret = system(g_buffer);
|
|
|
|
|
|
|
|
#ifdef WEXITSTATUS
|
|
|
|
if (ret < 0 || WEXITSTATUS(ret) != 0)
|
|
|
|
#else
|
|
|
|
if (ret < 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Failed to disable %s\n", varname);
|
|
|
|
fprintf(stderr, " command: %s\n", g_buffer);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Select the host build development environment */
|
|
|
|
|
|
|
|
static void set_host(const char *destconfig)
|
|
|
|
{
|
2017-11-10 16:39:06 +01:00
|
|
|
switch (g_host)
|
2017-07-10 17:38:45 +02:00
|
|
|
{
|
2017-11-10 16:39:06 +01:00
|
|
|
case HOST_LINUX:
|
2017-07-10 17:38:45 +02:00
|
|
|
{
|
2017-11-10 16:39:06 +01:00
|
|
|
printf(" Select the Linux host\n");
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
enable_feature(destconfig, "CONFIG_HOST_LINUX");
|
|
|
|
disable_feature(destconfig, "CONFIG_HOST_WINDOWS");
|
2018-06-01 21:25:50 +02:00
|
|
|
disable_feature(destconfig, "CONFIG_HOST_MACOS");
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_MSYS");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_OTHER");
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
enable_feature(destconfig, "CONFIG_SIM_X8664_SYSTEMV");
|
|
|
|
disable_feature(destconfig, "CONFIG_SIM_X8664_MICROSOFT");
|
|
|
|
}
|
|
|
|
break;
|
2017-11-10 00:36:46 +01:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
case HOST_MACOS:
|
|
|
|
{
|
2020-01-19 18:22:36 +01:00
|
|
|
printf(" Select the macOS host\n");
|
2017-11-10 00:36:46 +01:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
disable_feature(destconfig, "CONFIG_HOST_LINUX");
|
|
|
|
disable_feature(destconfig, "CONFIG_HOST_WINDOWS");
|
2018-06-01 21:25:50 +02:00
|
|
|
enable_feature(destconfig, "CONFIG_HOST_MACOS");
|
2017-11-10 00:36:46 +01:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_MSYS");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_OTHER");
|
2017-11-10 00:36:46 +01:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
enable_feature(destconfig, "CONFIG_SIM_X8664_SYSTEMV");
|
|
|
|
disable_feature(destconfig, "CONFIG_SIM_X8664_MICROSOFT");
|
|
|
|
}
|
|
|
|
break;
|
2017-11-10 00:36:46 +01:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
case HOST_WINDOWS:
|
|
|
|
{
|
|
|
|
enable_feature(destconfig, "CONFIG_HOST_WINDOWS");
|
|
|
|
disable_feature(destconfig, "CONFIG_HOST_LINUX");
|
2018-06-01 21:25:50 +02:00
|
|
|
disable_feature(destconfig, "CONFIG_HOST_MACOS");
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_OTHER");
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
enable_feature(destconfig, "CONFIG_SIM_X8664_MICROSOFT");
|
|
|
|
disable_feature(destconfig, "CONFIG_SIM_X8664_SYSTEMV");
|
2017-07-10 17:38:45 +02:00
|
|
|
|
2017-11-10 16:39:06 +01:00
|
|
|
switch (g_windows)
|
2017-07-10 17:38:45 +02:00
|
|
|
{
|
2017-11-10 16:39:06 +01:00
|
|
|
case WINDOWS_CYGWIN:
|
|
|
|
printf(" Select Windows/Cygwin host\n");
|
|
|
|
enable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN");
|
2018-05-31 19:53:09 +02:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_MSYS");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINDOWS_MSYS:
|
2020-01-19 18:22:36 +01:00
|
|
|
printf(" Select Windows/MSYS host\n");
|
2018-05-31 19:53:09 +02:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN");
|
|
|
|
enable_feature(destconfig, "CONFIG_WINDOWS_MSYS");
|
2017-11-10 16:39:06 +01:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINDOWS_NATIVE:
|
|
|
|
printf(" Select Windows native host\n");
|
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN");
|
2018-05-31 19:53:09 +02:00
|
|
|
disable_feature(destconfig, "CONFIG_WINDOWS_MSYS");
|
2017-11-10 16:39:06 +01:00
|
|
|
enable_feature(destconfig, "CONFIG_WINDOWS_NATIVE");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: Unrecognized windows configuration: %d\n",
|
|
|
|
g_windows);
|
|
|
|
exit(EXIT_FAILURE);
|
2017-07-10 17:38:45 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-10 16:39:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HOST_NOCHANGE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr, "ERROR: Unrecognized host configuration: %d\n",
|
|
|
|
g_host);
|
2017-11-10 16:39:06 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2017-07-10 17:38:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
static void configure(void)
|
|
|
|
{
|
|
|
|
char *destconfig;
|
|
|
|
|
2020-08-20 20:32:42 +02:00
|
|
|
/* Copy the defconfig to toplevel */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cdefconfig", g_topdir, g_delim);
|
|
|
|
copy_file(g_srcdefconfig, g_buffer, 0644);
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/* Copy the defconfig file as .config */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%c.config", g_topdir, g_delim);
|
|
|
|
destconfig = strdup(g_buffer);
|
|
|
|
debug("configure: Copying from %s to %s\n", g_srcdefconfig, destconfig);
|
2013-01-05 14:19:53 +01:00
|
|
|
copy_file(g_srcdefconfig, destconfig, 0644);
|
2013-01-04 22:37:31 +01:00
|
|
|
|
|
|
|
/* Copy the Make.defs file as Make.defs */
|
|
|
|
|
|
|
|
snprintf(g_buffer, BUFFER_SIZE, "%s%cMake.defs", g_topdir, g_delim);
|
|
|
|
debug("configure: Copying from %s to %s\n", g_srcmakedefs, g_buffer);
|
2013-01-05 14:19:53 +01:00
|
|
|
copy_file(g_srcmakedefs, g_buffer, 0644);
|
2013-01-04 22:37:31 +01:00
|
|
|
|
2017-06-15 16:24:28 +02:00
|
|
|
/* Copy optional files */
|
|
|
|
|
|
|
|
copy_optional();
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
/* Select the host build development environment */
|
|
|
|
|
|
|
|
set_host(destconfig);
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
/* 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
|
2013-01-04 22:37:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_needapppath)
|
|
|
|
{
|
|
|
|
FILE *stream;
|
|
|
|
char *appdir = strdup(g_appdir);
|
|
|
|
|
2020-03-20 10:40:33 +01:00
|
|
|
/* One complexity is if we are using Windows paths, but the
|
|
|
|
* configuration needs POSIX paths (or vice versa).
|
2013-01-04 22:37:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_winpaths != g_winnative)
|
|
|
|
{
|
|
|
|
/* Not the same */
|
|
|
|
|
|
|
|
if (g_winpaths)
|
|
|
|
{
|
2020-07-17 15:37:49 +02:00
|
|
|
/* Using Windows paths, but the configuration wants POSIX
|
|
|
|
* paths.
|
|
|
|
*/
|
2013-01-04 22:37:31 +01:00
|
|
|
|
|
|
|
substitute(appdir, '\\', '/');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-17 15:37:49 +02:00
|
|
|
/* Using POSIX paths, but the configuration wants Windows
|
|
|
|
* paths.
|
|
|
|
*/
|
2013-01-04 22:37:31 +01:00
|
|
|
|
|
|
|
substitute(appdir, '/', '\\');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 23:35:28 +01:00
|
|
|
/* Looks like prebuilt winnative kconfig-conf interprets "..\apps" as
|
|
|
|
* "..apps" (possibly '\a' as escape-sequence) so expand winnative path
|
|
|
|
* to double-backslashed variant "..\\apps".
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_winnative)
|
|
|
|
{
|
|
|
|
char *tmp_appdir = double_appdir_backslashes(appdir);
|
|
|
|
if (NULL == tmp_appdir)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: Failed to double appdir backslashes\n");
|
2018-11-05 23:35:28 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(appdir);
|
|
|
|
appdir = tmp_appdir;
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/* Open the file for appending */
|
2014-01-04 16:08:14 +01:00
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
stream = fopen(destconfig, "a");
|
|
|
|
if (!stream)
|
|
|
|
{
|
2020-03-20 10:40:33 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: Failed to open %s for append mode mode: %s\n",
|
2013-01-04 22:37:31 +01:00
|
|
|
destconfig, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stream, "\n# Application configuration\n\n");
|
|
|
|
fprintf(stream, "CONFIG_APPS_DIR=\"%s\"\n", appdir);
|
|
|
|
fclose(stream);
|
|
|
|
free(appdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(destconfig);
|
|
|
|
}
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
static void refresh(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2018-11-05 23:35:28 +01:00
|
|
|
printf(" Refreshing...\n");
|
2017-10-01 23:41:59 +02:00
|
|
|
fflush(stdout);
|
|
|
|
|
2020-03-21 11:14:41 +01:00
|
|
|
ret = run_make("olddefconfig");
|
2017-10-01 23:41:59 +02:00
|
|
|
putchar('\n');
|
|
|
|
|
2017-07-10 17:38:45 +02:00
|
|
|
#ifdef WEXITSTATUS
|
|
|
|
if (ret < 0 || WEXITSTATUS(ret) != 0)
|
|
|
|
#else
|
|
|
|
if (ret < 0)
|
|
|
|
#endif
|
|
|
|
{
|
2020-02-23 09:50:23 +01:00
|
|
|
fprintf(stderr, "ERROR: Failed to refresh configurations\n");
|
2017-07-10 17:38:45 +02:00
|
|
|
fprintf(stderr, " kconfig-conf --olddefconfig Kconfig\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:37:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
|
|
{
|
|
|
|
debug("main: Checking arguments\n");
|
|
|
|
parse_args(argc, argv);
|
|
|
|
|
2020-10-19 06:09:06 +02:00
|
|
|
debug("main: Checking NuttX Directories\n");
|
2017-06-15 16:24:28 +02:00
|
|
|
find_topdir();
|
2013-01-04 22:37:31 +01:00
|
|
|
check_configdir();
|
2017-11-10 00:36:46 +01:00
|
|
|
check_configured();
|
2013-01-04 22:37:31 +01:00
|
|
|
|
|
|
|
debug("main: Reading the configuration/version files\n");
|
|
|
|
read_configfile();
|
|
|
|
read_versionfile();
|
|
|
|
get_verstring();
|
|
|
|
|
|
|
|
debug("main: Checking Configuration Directory\n");
|
|
|
|
check_configuration();
|
|
|
|
|
|
|
|
debug("main: Checking Application Directories\n");
|
|
|
|
check_appdir();
|
|
|
|
debug("main: Using apppath=%s\n", g_apppath ? g_apppath : "<null>");
|
|
|
|
|
|
|
|
debug("main: Configuring\n");
|
|
|
|
configure();
|
2017-07-10 17:38:45 +02:00
|
|
|
|
|
|
|
debug("main: Refresh configuration\n");
|
|
|
|
refresh();
|
2013-01-04 22:37:31 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|