From ef1eb97660814aaca64bd32464c034b6867c972c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Jul 2017 09:38:45 -0600 Subject: [PATCH] Update configure.sh, configure.bat, configure.c: With compressed format, part of the installation requires that we run 'make olddefconfig' to restore the uncompressed defconfig format. Also, while I was at it, I also added options to select host platform on configure command line. --- tools/configure.bat | 65 +++++++------ tools/configure.c | 224 ++++++++++++++++++++++++++++++++++++++++---- tools/configure.sh | 95 +++++++++++++++++-- 3 files changed, 330 insertions(+), 54 deletions(-) diff --git a/tools/configure.bat b/tools/configure.bat index 7dc9ca116c9..95416f10b18 100755 --- a/tools/configure.bat +++ b/tools/configure.bat @@ -2,7 +2,7 @@ rem tools/configure.bat rem -rem Copyright (C) 2012 Gregory Nutt. All rights reserved. +rem Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved. rem Author: Gregory Nutt rem rem Redistribution and use in source and binary forms, with or without @@ -36,33 +36,38 @@ rem rem Parse command line arguments set debug= -set fmt=-w +set fmt=-b set posix= set help= set appdir= set config= +set hostopt= :ArgLoop if "%1"=="" goto :NoConfig if "%1"=="-h" goto :ShowUsage if "%1"=="-d" goto :SetDebug -if "%1"=="-w" goto :SetWindows -if "%1"=="-l" goto :SetPosix +if "%1"=="-f" goto :SetFormat +if "%1"=="-b" goto :SetFormat +if "%1"=="-l" goto :SetHostOption +if "%1"=="-c" goto :SetHostOption +if "%1"=="-u" goto :SetHostOption +if "%1"=="-n" goto :SetHostOption if "%1"=="-a" goto :SetAppDir set config=%1 goto EndOfLoop :SetDebug -set debug=-d +set debug=%1 goto :NextArg -:SetWindows -set fmt=-w +:SetFormat +set fmt=%1 goto :NextArg -:SetWindows -set fmt=-l +:SetHostOption +set hostopt=%1 goto :NextArg :SetAppDir @@ -89,7 +94,7 @@ if errorlevel 1 ( ) :HaveConfigureExe -configure.exe %debug% %fmt% %appdir% %config% +configure.exe %debug% %fmt% %hostopt% %appdir% %config% if errorlevel 1 echo configure.exe failed goto End @@ -97,8 +102,29 @@ goto End echo Missing ^/^ argument :ShowUsage -echo USAGE: %0 [-d] [-w] [-l] [-h] [-a ^] ^\^ +echo USAGE: %0 [-d] [-b|f] [-a ^] ^\^ +echo %0 [-h] echo\nWhere: +echo -d: +echo Enables debug output +echo -b: +echo Informs the tool that it should use Windows style paths like C:\\Program Files +echo instead of POSIX style paths are used like /usr/local/bin. Windows +echo style paths are used by default. +echo -f: +echo Informs the tool that it should use POSIX style paths like /usr/local/bin. +echo By default, Windows style paths like C:\\Program Files are used. +echo -l selects the Linux (l) host environment. The [-c^|u^|n] options +echo select one of the Windows environments. Default: Use host setup +echo in the defconfig file +echo [-c^|u^|n] selects the Windows host and a Windows environment: Cygwin (c), +echo Ubuntu under Windows 10 (u), or Windows native (n). Default Cygwin +echo -a ^: +echo Informs the configuration tool where the application build +echo directory. This is a relative path from the top-level NuttX +echo build directory. But default, this tool will look in the usual +echo places to try to locate the application directory: ../apps or +echo ../apps-xx.yy where xx.yy is the NuttX version number. echo ^: echo Identifies the board. This must correspond to a board directory echo under nuttx/configs/. @@ -106,22 +132,7 @@ echo ^: echo Identifies the specific configuratin for the selected ^. echo This must correspond to a sub-directory under the board directory at echo under nuttx/configs/^/. -echo ^<-d^>: -echo Enables debug output -echo ^<-w^>: -echo Informs the tool that it should use Windows style paths like C:\\Program Files -echo instead of POSIX style paths are used like /usr/local/bin. Windows -echo style paths are used by default. -echo ^<-l^>: -echo Informs the tool that it should use POSIX style paths like /usr/local/bin. -echo By default, Windows style paths like C:\\Program Files are used. -echo -a ^: -echo Informs the configuration tool where the application build -echo directory. This is a relative path from the top-level NuttX -echo build directory. But default, this tool will look in the usual -echo places to try to locate the application directory: ../apps or -echo ../apps-xx.yy where xx.yy is the NuttX version number. -echo ^<-h^>: +echo -h: echo Prints this message and exits. :End diff --git a/tools/configure.c b/tools/configure.c index 80c3b3d5cfa..f27224e4295 100644 --- a/tools/configure.c +++ b/tools/configure.c @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -62,6 +63,14 @@ # define strndup(x, y) strdup(x) #endif +#define HOST_NOCHANGE 0 +#define HOST_LINUX 1 +#define HOST_WINDOWS 2 + +#define WINDOWS_NATIVE 1 +#define WINDOWS_CYGWIN 2 +#define WINDOWS_UBUNTU 3 + /**************************************************************************** * Private Data ****************************************************************************/ @@ -91,6 +100,9 @@ static char *g_srcmakedefs = NULL; /* Source Make.defs file */ static bool g_winnative = false; /* True: Windows native configuration */ static bool g_needapppath = true; /* Need to add app path to the .config file */ +static uint8_t g_host = HOST_NOCHANGE; +static uint8_t g_windows = WINDOWS_CYGWIN; + static char g_buffer[BUFFER_SIZE]; /* Scratch buffer for forming full paths */ static struct variable_s *g_configvars = NULL; @@ -113,18 +125,12 @@ static const char *g_optfiles[] = static void show_usage(const char *progname, int exitcode) { - fprintf(stderr, "\nUSAGE: %s [-d] [-w] [-l] [-h] [-a ] [%c]\n", progname, g_delim); + fprintf(stderr, "\nUSAGE: %s [-d] [-b] [-f] [-l|c|u|n] [-a ] [%c]\n", progname, g_delim); + fprintf(stderr, "\nUSAGE: %s [-h]\n\n", progname); fprintf(stderr, "\nWhere:\n"); - fprintf(stderr, " :\n"); - fprintf(stderr, " Identifies the board. This must correspond to a board directory\n"); - fprintf(stderr, " under nuttx%cconfigs%c.\n", g_delim, g_delim); - fprintf(stderr, " :\n"); - fprintf(stderr, " Identifies the specific configuration for the selected .\n"); - fprintf(stderr, " This must correspond to a sub-directory under the board directory at\n"); - fprintf(stderr, " under nuttx%cconfigs%c%c.\n", g_delim, g_delim, g_delim); - fprintf(stderr, " <-d>:\n"); + fprintf(stderr, " -d:\n"); fprintf(stderr, " Enables debug output\n"); - fprintf(stderr, " <-w>:\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"); fprintf(stderr, " instead of POSIX style paths are used like /usr/local/bin. Windows\n"); @@ -133,7 +139,7 @@ static void show_usage(const char *progname, int exitcode) fprintf(stderr, " Informs the tool that it should use Windows style paths like C:\\Program Files.\n"); fprintf(stderr, " By default, POSIX style paths like /usr/local/bin are used.\n"); #endif - fprintf(stderr, " <-l>:\n"); + fprintf(stderr, " -f:\n"); #ifdef CONFIG_WINDOWS_NATIVE fprintf(stderr, " Informs the tool that it should use POSIX style paths like /usr/local/bin.\n"); fprintf(stderr, " By default, Windows style paths like C:\\Program Files are used.\n"); @@ -142,13 +148,27 @@ static void show_usage(const char *progname, int exitcode) fprintf(stderr, " instead of Windows style paths like C:\\Program Files are used. POSIX\n"); fprintf(stderr, " style paths are used by default.\n"); #endif + fprintf(stderr, " -l:\n"); + fprintf(stderr, " Selects the Linux (l) host environment. The [-c|u|n] options\n"); + fprintf(stderr, " select one of the Windows environments. Default: Use host setup\n"); + fprintf(stderr, " in the defconfig file\n"); + fprintf(stderr, " [-c|u|n]\n"); + fprintf(stderr, " Selects the Windows host and a Windows host environment: Cygwin (c),\n"); + fprintf(stderr, " Ubuntu under Windows 10 (u), or Windows native (n). Default Cygwin\n"); fprintf(stderr, " -a :\n"); fprintf(stderr, " Informs the configuration tool where the application build\n"); fprintf(stderr, " directory. This is a relative path from the top-level NuttX\n"); fprintf(stderr, " build directory. But default, this tool will look in the usual\n"); fprintf(stderr, " places to try to locate the application directory: ..%capps or\n", g_delim); fprintf(stderr, " ..%capps-xx.yy where xx.yy is the NuttX version number.\n", g_delim); - fprintf(stderr, " <-h>:\n"); + fprintf(stderr, " :\n"); + fprintf(stderr, " Identifies the board. This must correspond to a board directory\n"); + fprintf(stderr, " under nuttx%cconfigs%c.\n", g_delim, g_delim); + fprintf(stderr, " :\n"); + fprintf(stderr, " Identifies the specific configuration for the selected .\n"); + fprintf(stderr, " This must correspond to a sub-directory under the board directory at\n"); + fprintf(stderr, " under nuttx%cconfigs%c%c.\n", g_delim, g_delim, g_delim); + fprintf(stderr, " -h:\n"); fprintf(stderr, " Prints this message and exits.\n"); exit(exitcode); } @@ -174,7 +194,7 @@ static void parse_args(int argc, char **argv) g_debug = false; - while ((ch = getopt(argc, argv, ":a:dwlh")) > 0) + while ((ch = getopt(argc, argv, ":a:bcdfhlnu")) > 0) { switch (ch) { @@ -182,16 +202,21 @@ static void parse_args(int argc, char **argv) g_appdir = optarg; break; - case 'd' : - g_debug = true; - break; - - case 'w' : + case 'b' : g_delim = '\\'; g_winpaths = false; break; - case 'l' : + case 'c' : + g_host = HOST_WINDOWS; + g_windows = WINDOWS_CYGWIN; + break; + + case 'd' : + g_debug = true; + break; + + case 'f' : g_delim = '/'; g_winpaths = true; break; @@ -199,6 +224,20 @@ static void parse_args(int argc, char **argv) case 'h' : show_usage(argv[0], EXIT_SUCCESS); + case 'l' : + g_host = HOST_LINUX; + break; + + case 'n' : + g_host = HOST_WINDOWS; + g_windows = WINDOWS_NATIVE; + break; + + case 'u' : + g_host = HOST_WINDOWS; + g_windows = WINDOWS_UBUNTU; + break; + case '?' : fprintf(stderr, "ERROR: Unrecognized option: %c\n", optopt); show_usage(argv[0], EXIT_FAILURE); @@ -801,6 +840,123 @@ static void copy_optional(void) } } +static void enable_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 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) +{ + if (g_host != HOST_NOCHANGE) + { + if (g_host == HOST_LINUX) + { + printf(" Select the Linux host\n"); + + enable_feature(destconfig, "CONFIG_HOST_LINUX"); + disable_feature(destconfig, "CONFIG_HOST_WINDOWS"); + + disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE"); + disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN"); + disable_feature(destconfig, "CONFIG_WINDOWS_UBUNTU"); + disable_feature(destconfig, "CONFIG_WINDOWS_MSYS"); + disable_feature(destconfig, "CONFIG_WINDOWS_OTHER"); + + enable_feature(destconfig, "CONFIG_SIM_X8664_SYSTEMV"); + disable_feature(destconfig, "CONFIG_SIM_X8664_MICROSOFT"); + disable_feature(destconfig, "CONFIG_SIM_M32"); + } + else if (g_host == HOST_WINDOWS) + { + enable_feature(destconfig, "CONFIG_HOST_WINDOWS"); + disable_feature(destconfig, "CONFIG_HOST_LINUX"); + + disable_feature(destconfig, "CONFIG_WINDOWS_MSYS"); + disable_feature(destconfig, "CONFIG_WINDOWS_OTHER"); + + enable_feature(destconfig, "CONFIG_SIM_X8664_MICROSOFT"); + disable_feature(destconfig, "CONFIG_SIM_X8664_SYSTEMV"); + + disable_feature(destconfig, "CONFIG_SIM_M32"); + + switch (g_windows) + { + case WINDOWS_CYGWIN: + printf(" Select Windows/Cygwin host\n"); + enable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN"); + disable_feature(destconfig, "CONFIG_WINDOWS_UBUNTU"); + disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE"); + break; + + case WINDOWS_UBUNTU: + printf(" Select Ubuntu for Windows 10 host\n"); + disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN"); + enable_feature(destconfig, "CONFIG_WINDOWS_UBUNTU"); + disable_feature(destconfig, "CONFIG_WINDOWS_NATIVE"); + break; + + case WINDOWS_NATIVE: + printf(" Select Windows native host\n"); + disable_feature(destconfig, "CONFIG_WINDOWS_CYGWIN"); + disable_feature(destconfig, "CONFIG_WINDOWS_UBUNTU"); + enable_feature(destconfig, "CONFIG_WINDOWS_NATIVE"); + break; + + default: + fprintf(stderr, "ERROR: Unrecognized windows configuration: %d\n", + g_windows); + exit(EXIT_FAILURE); + } + } + else + { + fprintf(stderr, "ERROR: Unrecognized host configuration: %d\n", g_host); + exit(EXIT_FAILURE); + } + } +} + static void configure(void) { char *destconfig; @@ -822,6 +978,10 @@ static void configure(void) copy_optional(); + /* Select the host build development environment */ + + set_host(destconfig); + /* 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 @@ -873,6 +1033,29 @@ static void configure(void) free(destconfig); } +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); + } + + ret = system("make olddefconfig"); +#ifdef WEXITSTATUS + if (ret < 0 || WEXITSTATUS(ret) != 0) +#else + if (ret < 0) +#endif + { + fprintf(stderr, "ERROR: Failed to refresh configuations\n"); + fprintf(stderr, " kconfig-conf --olddefconfig Kconfig\n"); + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -900,5 +1083,8 @@ int main(int argc, char **argv, char **envp) debug("main: Configuring\n"); configure(); + + debug("main: Refresh configuration\n"); + refresh(); return EXIT_SUCCESS; } diff --git a/tools/configure.sh b/tools/configure.sh index 1cae32ae734..e9949048243 100755 --- a/tools/configure.sh +++ b/tools/configure.sh @@ -36,12 +36,18 @@ WD=`test -d ${0%/*} && cd ${0%/*}; pwd` TOPDIR="${WD}/.." USAGE=" -USAGE: ${0} [-d] [-a ] / +USAGE: ${0} [-d] [-l|c|u|n] [-a ] / Where: + -l selects the Linux (l) host environment. The [-c|u|n] options + select one of the Windows environments. Default: Use host setup + in the defconfig file + [-c|u|n] selects the Windows host and a Windows environment: Cygwin (c), + Ubuntu under Windows 10 (u), or Windows native (n). Default Cygwin is the name of the board in the configs directory is the name of the board configuration sub-directory - is the path to the apps/ directory, relative to the nuttx directory + is the path to the apps/ directory, relative to the nuttx + directory " @@ -57,9 +63,19 @@ OPTFILES="\ unset boardconfig unset appdir +unset host +unset wenv while [ ! -z "$1" ]; do case "$1" in + -a ) + shift + appdir=$1 + ;; + -c ) + host=windows + wenv=cygwin + ;; -d ) set -x ;; @@ -67,9 +83,16 @@ while [ ! -z "$1" ]; do echo "$USAGE" exit 0 ;; - -a ) - shift - appdir=$1 + -l ) + host=linux + ;; + -n ) + host=windows + wenv=native + ;; + -u ) + host=windows + wenv=ubuntu ;; *) if [ ! -z "${boardconfig}" ]; then @@ -129,6 +152,12 @@ if [ ! -r "${src_config}" ]; then exit 6 fi +if [ -r ${dest_config} ]; then + echo "Already configured!" + echo "Do 'make distclean' and try again." + exit 7 +fi + # Extract values needed from the defconfig file. We need: # (1) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a # native Windows @@ -185,6 +214,7 @@ fi # Okay... Everything looks good. Setup the configuration +echo " Copy files" install -m 644 "${src_makedefs}" "${dest_makedefs}" || \ { echo "Failed to copy \"${src_makedefs}\"" ; exit 7 ; } install -m 644 "${src_config}" "${dest_config}" || \ @@ -206,12 +236,61 @@ if [ "X${defappdir}" = "Xy" ]; then sed -e "/^CONFIG_APPS_DIR/d" "${dest_config}" > "${dest_config}-temp" mv "${dest_config}-temp" "${dest_config}" - echo "" >> "${dest_config}" - echo "# Application configuration" >> "${dest_config}" - echo "" >> "${dest_config}" if [ "X${winnative}" = "Xy" ]; then echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${dest_config}" else echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${dest_config}" fi fi + +if [ ! -z "$host" ]; then + sed -i -e "/CONFIG_HOST_OSX/d" ${dest_config} + sed -i -e "/CONFIG_HOST_OTHER/d" ${dest_config} + + if [ "$host" == "linux" ]; then + echo " Select CONFIG_HOST_LINUX=y" + + sed -i -e "/CONFIG_HOST_WINDOWS/d" ${dest_config} + sed -i -e "/CONFIG_SIM_X8664_MICROSOFT/d" ${dest_config} + sed -i -e "/CONFIG_SIM_M32/d" ${dest_config} + echo "CONFIG_HOST_LINUX=y" >> "${dest_config}" + echo "CONFIG_SIM_X8664_SYSTEMV=y" >> "${dest_config}" + +else + echo " Select CONFIG_HOST_WINDOWS=y" + + sed -i -e "/CONFIG_HOST_LINUX/d" ${dest_config} + sed -i -e "/CONFIG_WINDOWS_MSYS/d" ${dest_config} + sed -i -e "/CONFIG_WINDOWS_OTHER/d" ${dest_config} + sed -i -e "/CONFIG_SIM_X8664_SYSTEMV/d" ${dest_config} + echo "CONFIG_HOST_WINDOWS=y" >> "${dest_config}" + echo "CONFIG_SIM_X8664_MICROSOFT=y" >> "${dest_config}" + + if [ "X$wenv" == "Xcygwin" ]; then + echo " Select CONFIG_WINDOWS_CYGWIN=y" + + sed -i -e "/CONFIG_WINDOWS_UBUNTU/d" ${dest_config} + sed -i -e "/CONFIG_WINDOWS_NATIVE/d" ${dest_config} + echo "CONFIG_WINDOWS_CYGWIN=y" >> "${dest_config}" + else + sed -i -e "/CONFIG_WINDOWS_CYGWIN/d" ${dest_config} + if [ "X$wenv" == "Xubuntu" ]; then + echo " Select CONFIG_WINDOWS_UBUNTU=y" + + sed -i -e "/CONFIG_WINDOWS_UBUNTU/d" ${dest_config} + echo "CONFIG_WINDOWS_UBUNTU=y" >> "${dest_config}" + else + echo " Select CONFIG_WINDOWS_NATIVE=y" + + sed -i -e "/CONFIG_WINDOWS_NATIVE/d" ${dest_config} + echo "CONFIG_WINDOWS_NATIVE=y" >> "${dest_config}" + fi + fi + fi +fi + +# The saved defconfig files are all in compressed format and must be +# reconstitued before they can be used. + +echo " Refreshing..." +make olddefconfig 1>/dev/null 2>&1