From a54a492dd217ac49b6bc90a411db5f62aad512b8 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 20 Mar 2020 12:08:27 +0800 Subject: [PATCH] tools/configure.sh: Support passing options to make Signed-off-by: Xiang Xiao Change-Id: I6c928ac4574721aacb87be27c979ca8ae146a4ce --- tools/README.txt | 3 ++- tools/configure.c | 38 ++++++++++++++++++++++++++++---------- tools/configure.sh | 15 ++++++--------- tools/sethost.sh | 29 ++++++++++++----------------- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/tools/README.txt b/tools/README.txt index fcf4b75464..dfee90fbb5 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -940,13 +940,14 @@ sethost.sh $ ./sethost.sh -h - USAGE: ./sethost.sh [-l|m|c|u|g|n] + USAGE: ./sethost.sh [-l|m|c|u|g|n] [make-opts] ./sethost.sh -h Where: -l|m|c|u|g|n selects Linux (l), macOS (m), Cygwin (c), Ubuntu under Windows 10 (u), MSYS/MSYS2 (g) or Windows native (n). Default Linux + make-opts directly pass to make -h will show this help test and terminate simhostroute.sh diff --git a/tools/configure.c b/tools/configure.c index d35b84b591..c66f49344e 100644 --- a/tools/configure.c +++ b/tools/configure.c @@ -80,6 +80,7 @@ static void show_usage(const char *progname, int exitcode); static void debug(const char *fmt, ...); static void parse_args(int argc, char **argv); +static int run_make(const char *arg); static bool check_directory(const char *directory); static void verify_directory(const char *directory); static bool verify_optiondir(const char *directory); @@ -147,6 +148,8 @@ 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 */ +static char **g_makeargv = NULL; /* Arguments pass to make */ + static bool g_winnative = false; /* True: Windows native configuration */ static bool g_oldnative = false; /* True: Was Windows native configuration */ static bool g_needapppath = true; /* Need to add app path to the .config file */ @@ -177,7 +180,8 @@ static const char *g_optfiles[] = static void show_usage(const char *progname, int exitcode) { fprintf(stderr, "\nUSAGE: %s [-d] [-e] [-b|f] [-l|m|c|u|g|n] " - "[-a ] :\n", progname); + "[-a ] : [make-opts]\n", + progname); fprintf(stderr, "\nUSAGE: %s [-h]\n", progname); fprintf(stderr, "\nWhere:\n"); fprintf(stderr, " -d:\n"); @@ -235,6 +239,8 @@ static void show_usage(const char *progname, int exitcode) fprintf(stderr, " a sub-directory under the board directory at\n"); fprintf(stderr, " under nuttx%cboards%c%cconfigs%c.\n", g_delim, g_delim, g_delim, g_delim); + fprintf(stderr, " [make-opts]:\n"); + fprintf(stderr, " Options directly pass to make\n"); fprintf(stderr, " -h:\n"); fprintf(stderr, " Prints this message and exits.\n"); exit(exitcode); @@ -368,11 +374,23 @@ static void parse_args(int argc, char **argv) *ptr++ = '\0'; g_configdir = ptr; - if (optind < argc) + /* 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); + for (argv = g_makeargv; *argv; argv++) { - fprintf(stderr, "ERROR: Unexpected garbage at the end of the line\n"); - show_usage(argv[0], EXIT_FAILURE); + strncat(g_buffer, " ", BUFFER_SIZE); + strncat(g_buffer, *argv, BUFFER_SIZE); } + + return system(g_buffer); } static bool check_directory(const char *directory) @@ -789,14 +807,14 @@ static void check_configured(void) { if (g_debug) { - system("make distclean V=1"); + run_make("distclean V=1"); } else { #ifdef WIN32 - system("make distclean"); + run_make("distclean"); #else - system("make distclean 1>/dev/null"); + run_make("distclean 1>/dev/null"); #endif } } @@ -1456,14 +1474,14 @@ static void refresh(void) if (g_debug) { - ret = system("make olddefconfig V=1"); + ret = run_make("olddefconfig V=1"); } else { #ifdef WIN32 - ret = system("make olddefconfig"); + ret = run_make("olddefconfig"); #else - ret = system("make olddefconfig 1>/dev/null"); + ret = run_make("olddefconfig 1>/dev/null"); #endif } diff --git a/tools/configure.sh b/tools/configure.sh index 5a653d8cb3..aa016771a6 100755 --- a/tools/configure.sh +++ b/tools/configure.sh @@ -37,7 +37,7 @@ WD=`test -d ${0%/*} && cd ${0%/*}; pwd` TOPDIR="${WD}/.." USAGE=" -USAGE: ${0} [-d] [-e] [-l|m|c|u|g|n] [-a ] : +USAGE: ${0} [-d] [-e] [-l|m|c|u|g|n] [-a ] : [make-opts] Where: -d enables script debug output @@ -54,6 +54,7 @@ Where: directory is the name of the board in the boards directory configs/ is the name of the board configuration sub-directory + make-opts directly pass to make " @@ -99,13 +100,9 @@ while [ ! -z "$1" ]; do exit 0 ;; *) - if [ ! -z "${boardconfig}" ]; then - echo "" - echo " defined twice" - echo "$USAGE" - exit 1 - fi boardconfig=$1 + shift + break ;; esac shift @@ -181,7 +178,7 @@ if [ -r ${dest_config} ]; then fi if [ "X${enforce}" = "Xy" ]; then - make -C ${TOPDIR} distclean + make -C ${TOPDIR} distclean $* else echo "Already configured!" echo "Do 'make distclean' and try again." @@ -293,4 +290,4 @@ fi # The saved defconfig files are all in compressed format and must be # reconstitued before they can be used. -${TOPDIR}/tools/sethost.sh $debug $host +${TOPDIR}/tools/sethost.sh $debug $host $* diff --git a/tools/sethost.sh b/tools/sethost.sh index 2d2bd18b67..af4aa4c37c 100755 --- a/tools/sethost.sh +++ b/tools/sethost.sh @@ -39,7 +39,7 @@ wenv= function showusage { echo "" - echo "USAGE: $progname -d [-l|m|c|u|g|n]" + echo "USAGE: $progname -d [-l|m|c|u|g|n] [make-opts]" echo " $progname -h" echo "" echo "Where:" @@ -47,6 +47,7 @@ function showusage { echo " -l|m|c|u|g|n selects Linux (l), macOS (m), Cygwin (c)," echo " Ubuntu under Windows 10 (u), MSYS/MSYS2 (g)" echo " or Windows native (n). Default Linux" + echo " make-opts directly pass to make" echo " -h will show this help test and terminate" exit 1 } @@ -84,7 +85,7 @@ while [ ! -z "$1" ]; do showusage ;; * ) - break; + break ;; esac shift @@ -116,23 +117,18 @@ if [ -z "$host" ]; then esac fi -if [ ! -z "$1" ]; then - echo "ERROR: Garbage at the end of line" - showusage -fi - WD=`test -d ${0%/*} && cd ${0%/*}; pwd` cd $WD if [ -x sethost.sh ]; then - nuttx=$PWD/.. + cd .. +fi + +if [ -x tools/sethost.sh ]; then + nuttx=$PWD else - if [ -x tools/sethost.sh ]; then - nuttx=$PWD - else - echo "This script must be execute in nuttx/ or nutts/tools directories" - exit 1 - fi + echo "This script must be execute in nuttx/ or nutts/tools directories" + exit 1 fi if [ ! -r $nuttx/.config ]; then @@ -220,9 +216,8 @@ fi sed -i -e "/CONFIG_HOST_OTHER/d" $nuttx/.config echo " Refreshing..." -cd $nuttx || { echo "ERROR: failed to cd to $nuttx"; exit 1; } if [ "X${debug}" = "Xy" ]; then - make olddefconfig V=1 || { echo "ERROR: failed to refresh"; exit 1; } + make olddefconfig $* V=1 || { echo "ERROR: failed to refresh"; exit 1; } else - make olddefconfig 1>/dev/null || { echo "ERROR: failed to refresh"; exit 1; } + make olddefconfig $* 1>/dev/null || { echo "ERROR: failed to refresh"; exit 1; } fi