summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorDmitry Goncharov <dgoncharov@users.sf.net>2023-04-02 10:50:17 -0400
committerPaul Smith <psmith@gnu.org>2023-04-02 11:12:11 -0400
commitcd46baab90296a75e03c73ad5c1f6f5bc3eb6cb3 (patch)
tree904138f41717618eb5cfda0c1f2d3062dea0f0d8 /src/main.c
parent54b3202f8da0761c7d5a3410313f0a32eb63ef8b (diff)
downloadmake-git-cd46baab90296a75e03c73ad5c1f6f5bc3eb6cb3.tar.gz
[SV 63856] Implement .WAIT on the command line
* src/main.c (handle_non_switch_argument): Return 1 if arg is .WAIT. (decode_switches): Set wait_here for a goal that follows .WAIT. * src/remake.c (update_goal_chain): Honor wait_here for a command line goal. Don't allow double-colon targets to continue if .WAIT is given for one of them. * tests/scripts/targets/WAIT: Add .WAIT tests.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 8587de61..7b8e91cf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2975,15 +2975,17 @@ init_switches (void)
}
-/* Non-option argument. It might be a variable definition. */
-static void
+/* Non-option argument. It might be a variable definition.
+ Returns 1 if the argument we read was .WAIT, else 0.
+ */
+static unsigned int
handle_non_switch_argument (const char *arg, enum variable_origin origin)
{
struct variable *v;
if (arg[0] == '-' && arg[1] == '\0')
/* Ignore plain '-' for compatibility. */
- return;
+ return 0;
#if MK_OS_VMS
{
@@ -3036,7 +3038,12 @@ handle_non_switch_argument (const char *arg, enum variable_origin origin)
Enter it as a file and add it to the dep chain of goals.
Check ARG[0] because if the top makefile resets MAKEOVERRIDES
then ARG points to an empty string in the submake. */
- struct file *f = enter_file (strcache_add (expand_command_line_file (arg)));
+ struct file *f;
+
+ if (strcmp (arg, ".WAIT") == 0)
+ return 1;
+
+ f = enter_file (strcache_add (expand_command_line_file (arg)));
f->cmd_target = 1;
if (goals == 0)
@@ -3077,6 +3084,7 @@ handle_non_switch_argument (const char *arg, enum variable_origin origin)
define_variable_cname ("MAKECMDGOALS", value, o_default, 0);
}
}
+ return 0;
}
/* Called if the makefile resets the MAKEFLAGS variable. */
@@ -3098,6 +3106,7 @@ decode_switches (int argc, const char **argv, enum variable_origin origin)
struct command_switch *cs;
struct stringlist *sl;
int c;
+ unsigned int found_wait = 0;
/* getopt does most of the parsing for us.
First, get its vectors set up. */
@@ -3120,15 +3129,22 @@ decode_switches (int argc, const char **argv, enum variable_origin origin)
if (c == EOF)
/* End of arguments, or "--" marker seen. */
break;
- else if (c == 1)
- /* An argument not starting with a dash. */
- handle_non_switch_argument (coptarg, origin);
else if (c == '?')
/* Bad option. We will print a usage message and die later.
But continue to parse the other options so the user can
see all he did wrong. */
bad = 1;
+ else if (c == 1)
+ {
+ /* An argument not starting with a dash. */
+ const unsigned int prior_found_wait = found_wait;
+ found_wait = handle_non_switch_argument (coptarg, origin);
+ if (prior_found_wait && lastgoal)
+ /* If the argument before this was .WAIT, wait here. */
+ lastgoal->wait_here = 1;
+ }
else
+ /* An option starting with a dash. */
for (cs = switches; cs->c != '\0'; ++cs)
if (cs->c == c)
{
@@ -3320,7 +3336,12 @@ decode_switches (int argc, const char **argv, enum variable_origin origin)
to be returned in order, this only happens when there is a "--"
argument to prevent later arguments from being options. */
while (optind < argc)
- handle_non_switch_argument (argv[optind++], origin);
+ {
+ const int prior_found_wait = found_wait;
+ found_wait = handle_non_switch_argument (argv[optind++], origin);
+ if (prior_found_wait && lastgoal)
+ lastgoal->wait_here = 1;
+ }
if (bad && origin == o_command)
print_usage (bad);