Update tools/configure.c to same functionality as configure.sh. Add an array of optional file names. Currently, .gdbinit is the only optional file but other things like IDE-specific project files might need to be copied as well.

This commit is contained in:
Gregory Nutt 2017-06-15 08:24:28 -06:00
parent d958cec7a4
commit fe5b3a58e4
2 changed files with 107 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* tools/configure.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -96,6 +96,15 @@ static char g_buffer[BUFFER_SIZE]; /* Scratch buffer for forming full p
static struct variable_s *g_configvars = NULL;
static struct variable_s *g_versionvars = NULL;
/* Optional configuration files */
static const char *g_optfiles[] =
{
".gdbinit"
};
#define N_OPTFILES (sizeof(g_optfiles) / sizeof(const char *))
/****************************************************************************
* Private Functions
****************************************************************************/
@ -240,6 +249,25 @@ static void parse_args(int argc, char **argv)
}
}
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;
}
static void verify_directory(const char *directory)
{
struct stat buf;
@ -319,9 +347,14 @@ static bool verify_file(const char *path)
return true;
}
static void get_topdir(void)
static void find_topdir(void)
{
char *currdir;
/* Get and verify the top-level NuttX directory */
/* First get the current directory. We expect this to be either
* the nuttx root directory or the tools subdirectory.
*/
if (getcwd(g_buffer, BUFFER_SIZE) == NULL)
{
@ -329,9 +362,38 @@ static void get_topdir(void)
exit(EXIT_FAILURE);
}
/* Assume that we are in the tools sub-directory and the directory above
* is the nuttx root directory.
*/
currdir = strdup(g_buffer);
g_topdir = strdup(dirname(g_buffer));
debug("get_topdir: Checking topdir=%s\n", g_topdir);
debug("get_topdir: Checking parent directory: %s\n", g_topdir);
verify_directory(g_topdir);
/* 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);
}
}
static void config_search(const char *boarddir)
@ -714,6 +776,29 @@ static void substitute(char *str, int ch1, int ch2)
}
}
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);
snprintf(g_buffer, BUFFER_SIZE, "%s%c.config", g_topdir, g_delim);
debug("copy_optional: Copying from %s to %s\n", optsrc, g_buffer);
copy_file(optsrc, g_buffer, 0644);
free(optsrc);
}
}
}
static void configure(void)
{
char *destconfig;
@ -731,6 +816,10 @@ static void configure(void)
debug("configure: Copying from %s to %s\n", g_srcmakedefs, g_buffer);
copy_file(g_srcmakedefs, g_buffer, 0644);
/* Copy optional files */
copy_optional();
/* 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
@ -792,7 +881,7 @@ int main(int argc, char **argv, char **envp)
parse_args(argc, argv);
debug("main: Checking Nuttx Directories\n");
get_topdir();
find_topdir();
check_configdir();
debug("main: Reading the configuration/version files\n");

View File

@ -1,7 +1,7 @@
#!/bin/bash
# configure.sh
#
# Copyright (C) 2007, 2008, 2011, 2015 Gregory Nutt. All rights reserved.
# Copyright (C) 2007, 2008, 2011, 2015, 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -45,6 +45,12 @@ Where:
"
# A list of optional files that may be installed
OPTFILES="\
.gdbinit
"
# Parse command arguments
unset boardconfig
@ -88,6 +94,7 @@ fi
configpath=${TOPDIR}/configs/${boardconfig}
if [ ! -d "${configpath}" ]; then
# Try direct path for convenience.
configpath=${TOPDIR}/${boardconfig}
if [ ! -d "${configpath}" ]; then
echo "Directory ${configpath} does not exist. Options are:"
@ -180,7 +187,12 @@ install -m 644 "${src_makedefs}" "${dest_makedefs}" || \
{ echo "Failed to copy \"${src_makedefs}\"" ; exit 7 ; }
install -m 644 "${src_config}" "${dest_config}" || \
{ echo "Failed to copy \"${src_config}\"" ; exit 9 ; }
test -f "${configpath}/.gdbinit" && install "${configpath}/.gdbinit" "${TOPDIR}/"
# Install any optional files
for opt in ${OPTFILES}; do
test -f "${configpath}/${opt}" && install "${configpath}/${opt}" "${TOPDIR}/"
done
# 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