This is an automated email from the ASF dual-hosted git repository.

davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c4ea4e976db36ac247209b2f7d139951c4c01494
Author: Xiang Xiao <[email protected]>
AuthorDate: Fri Mar 20 02:09:45 2020 +0800

    tools/configure.sh: Add -e option to invoke distclean if already configured
    
    Signed-off-by: Xiang Xiao <[email protected]>
    Change-Id: I19eddc3d4e6650eace2482c3cce8fbb07aadc04b
---
 tools/Makefile.unix |  1 +
 tools/Makefile.win  |  1 +
 tools/configure.c   | 58 ++++++++++++++++++++++++++++++++---------------------
 tools/configure.sh  | 26 +++++++++++++++++++-----
 4 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/tools/Makefile.unix b/tools/Makefile.unix
index 1c4ee2d..ffc89aa 100644
--- a/tools/Makefile.unix
+++ b/tools/Makefile.unix
@@ -648,6 +648,7 @@ endif
        $(call DELFILE, include/nuttx/config.h)
        $(call DELFILE, include/nuttx/version.h)
        $(call DELFILE, Make.defs)
+       $(call DELFILE, defconfig)
        $(call DELFILE, .config)
        $(call DELFILE, .config.old)
        $(call DELFILE, .gdbinit)
diff --git a/tools/Makefile.win b/tools/Makefile.win
index 7193907..4453cfa 100644
--- a/tools/Makefile.win
+++ b/tools/Makefile.win
@@ -626,6 +626,7 @@ ifeq ($(CONFIG_BUILD_2PASS),y)
        $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean
 endif
        $(call DELFILE, Make.defs)
+       $(call DELFILE, defconfig)
        $(call DELFILE, .config)
        $(call DELFILE, .config.old)
        $(call DELDIR, include\arch\board)
diff --git a/tools/configure.c b/tools/configure.c
index 1698ffd..f1a50eb 100644
--- a/tools/configure.c
+++ b/tools/configure.c
@@ -127,6 +127,7 @@ static char        g_delim         = '/';   /* Delimiter to 
use when forming pat
 static bool        g_winpaths      = false; /* False: POSIX style paths */
 #endif
 static bool        g_debug         = false; /* Enable debug output */
+static bool        g_enforce       = false; /* Enfore distclean */
 
 static const char *g_appdir        = NULL;  /* Relative path to the 
application directory */
 static const char *g_archdir       = NULL;  /* Name of architecture 
subdirectory */
@@ -173,11 +174,13 @@ static const char *g_optfiles[] =
 
 static void show_usage(const char *progname, int exitcode)
 {
-  fprintf(stderr, "\nUSAGE: %s  [-d] [-b] [-f] [-l|m|c|u|g|n] [-a <app-dir>] 
<board-name>:<config-name>\n", progname);
+  fprintf(stderr, "\nUSAGE: %s  [-d] [-e] [-b|f] [-l|m|c|u|g|n] [-a <app-dir>] 
<board-name>:<config-name>\n", progname);
   fprintf(stderr, "\nUSAGE: %s  [-h]\n", progname);
   fprintf(stderr, "\nWhere:\n");
   fprintf(stderr, "  -d:\n");
   fprintf(stderr, "    Enables debug output\n");
+  fprintf(stderr, "  -e:\n");
+  fprintf(stderr, "    Enforce distclean if already configured\n");
   fprintf(stderr, "  -b:\n");
 #ifdef CONFIG_WINDOWS_NATIVE
   fprintf(stderr, "    Informs the tool that it should use Windows style paths 
like C:\\Program Files\n");
@@ -246,7 +249,7 @@ static void parse_args(int argc, char **argv)
 
   g_debug = false;
 
-  while ((ch = getopt(argc, argv, "a:bcdfghlmnu")) > 0)
+  while ((ch = getopt(argc, argv, "a:bcdefghlmnu")) > 0)
     {
       switch (ch)
         {
@@ -268,6 +271,10 @@ static void parse_args(int argc, char **argv)
             g_debug = true;
             break;
 
+          case 'e' :
+            g_enforce = true;
+            break;
+
           case 'f' :
              g_delim = '/';
              g_winpaths = true;
@@ -499,6 +506,11 @@ static void find_topdir(void)
       /* Yes, we are probably in the tools/ sub-directory */
 
       free(currdir);
+      if (chdir(g_topdir) < 0)
+        {
+          fprintf(stderr, "ERROR: Failed to ch to %s\n", g_topdir);
+          exit(EXIT_FAILURE);
+        }
     }
 }
 
@@ -747,20 +759,27 @@ static void check_configured(void)
   debug("check_configured: Checking %s\n", g_buffer);
   if (verify_file(g_buffer))
     {
-      fprintf(stderr, "ERROR: Found %s... Already configured\n", g_buffer);
-      fprintf(stderr, "       Please 'make distclean' and try again\n");
-      exit(EXIT_FAILURE);
-    }
-
-  /* Try the Make.defs file */
-
-  snprintf(g_buffer, BUFFER_SIZE, "%s%cMake.defs", g_topdir, g_delim);
-  debug("check_configuration: Checking %s\n", g_buffer);
-  if (verify_file(g_buffer))
-    {
-      fprintf(stderr, "ERROR: Found %s... Already configured\n", g_buffer);
-      fprintf(stderr, "       Please 'make distclean' and try again\n");
-      exit(EXIT_FAILURE);
+      if (g_enforce)
+        {
+          if (g_debug)
+            {
+              system("make distclean V=1");
+            }
+          else
+            {
+        #ifdef WIN32
+              system("make distclean");
+        #else
+              system("make distclean 1>/dev/null");
+        #endif
+            }
+        }
+      else
+        {
+          fprintf(stderr, "ERROR: Found %s... Already configured\n", g_buffer);
+          fprintf(stderr, "       Please 'make distclean' and try again\n");
+          exit(EXIT_FAILURE);
+        }
     }
 }
 
@@ -1397,13 +1416,6 @@ static void refresh(void)
 {
   int ret;
 
-  ret = chdir(g_topdir);
-  if (ret < 0)
-    {
-      fprintf(stderr, "ERROR: Failed to ch to %s\n", g_topdir);
-      exit(EXIT_FAILURE);
-    }
-
   printf("  Refreshing...\n");
   fflush(stdout);
 
diff --git a/tools/configure.sh b/tools/configure.sh
index 87ca985..5a653d8 100755
--- a/tools/configure.sh
+++ b/tools/configure.sh
@@ -37,10 +37,11 @@ WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
 TOPDIR="${WD}/.."
 USAGE="
 
-USAGE: ${0} [-d] [-l|m|c|u|g|n] [-a <app-dir>] <board-name>:<config-name>
+USAGE: ${0} [-d] [-e] [-l|m|c|u|g|n] [-a <app-dir>] <board-name>:<config-name>
 
 Where:
   -d enables script debug output
+  -e enforce distclean if already configured
   -l selects the Linux (l) host environment.
   -m selects the macOS (m) host environment.
   -c selects the Windows host and Cygwin (c) environment.
@@ -71,6 +72,7 @@ unset winnative
 unset appdir
 unset host
 unset debug
+unset enforce
 
 while [ ! -z "$1" ]; do
   case "$1" in
@@ -88,7 +90,9 @@ while [ ! -z "$1" ]; do
     ;;
   -d )
     debug=-d
-    set -x
+    ;;
+  -e )
+    enforce=y
     ;;
   -h )
     echo "$USAGE"
@@ -163,6 +167,7 @@ fi
 
 src_config=${configpath}/defconfig
 dest_config="${TOPDIR}/.config"
+backup_config="${TOPDIR}/defconfig"
 
 if [ ! -r ${src_config} ]; then
   echo "File ${src_config} does not exist"
@@ -170,9 +175,18 @@ if [ ! -r ${src_config} ]; then
 fi
 
 if [ -r ${dest_config} ]; then
-  echo "Already configured!"
-  echo "Do 'make distclean' and try again."
-  exit 6
+  if cmp -s ${src_config} ${backup_config}; then
+    echo "No configuration change."
+    exit 0
+  fi
+
+  if [ "X${enforce}" = "Xy" ]; then
+    make -C ${TOPDIR} distclean
+  else
+    echo "Already configured!"
+    echo "Do 'make distclean' and try again."
+    exit 6
+  fi
 fi
 
 # Extract values needed from the defconfig file.  We need:
@@ -250,6 +264,8 @@ install -m 644 ${src_makedefs} "${dest_makedefs}" || \
   { echo "Failed to copy ${src_makedefs}" ; exit 8 ; }
 install -m 644 ${src_config} "${dest_config}" || \
   { echo "Failed to copy ${src_config}" ; exit 9 ; }
+install -m 644 ${src_config} "${backup_config}" || \
+  { echo "Failed to backup ${src_config}" ; exit 10 ; }
 
 # Install any optional files
 

Reply via email to