commit 743a9b26faf8cdf8458db1b00e7c9494f0ca9e5a
parent 8db691ec62143bac4b0f6522b5fa63a6895045a3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 24 Oct 2024 21:55:31 +0200
make: Enable debug output as soon as possible
As command line options are enabled only after reading the makefiles
very useful debug information was lost until the command line was
parsed.
Diffstat:
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/cmd/scc-make/main.c b/src/cmd/scc-make/main.c
@@ -139,15 +139,21 @@ appendmakeflags(char *text)
free(t);
}
+static int
+hasargs(int c)
+{
+ return c == 'f' || c == 'j';
+}
+
static void
parseflag(int flag, char **args, char ***argv)
{
- char *arg;
+ if (hasargs(flag))
+ getarg(args, argv);
switch (flag) {
case 'j':
case 'f':
- getarg(args, argv);
break;
case 'e':
eflag = 1;
@@ -280,7 +286,7 @@ parsemakefiles(char **argv)
hasmake = 0;
for ( ; *argv && **argv == '-'; ++argv) {
for (s = *argv; c = *s; ++s) {
- if (c == 'f' || c == 'j')
+ if (hasargs(c))
arg = getarg(&s, &argv);
if (c == 'f') {
@@ -301,6 +307,28 @@ parsemakefiles(char **argv)
return;
}
+/*
+ * We want to enable debug as earlier as possible,
+ * if we wait until we read the Makefiles then
+ * we are going to lose to much debug information.
+ */
+static void
+enadebug(char *argv[])
+{
+ int c;
+ char *p;
+
+ for ( ; *argv && **argv == '-'; ++argv) {
+ p = *argv;
+ for (++p; c = *p; ++p) {
+ if (hasargs(c))
+ getarg(&p, &argv);
+ if (c == 'd')
+ dflag = 1;
+ }
+ }
+}
+
int
main(int argc, char *argv[])
{
@@ -313,6 +341,7 @@ main(int argc, char *argv[])
arg0 = *argv++;
+ enadebug(argv);
inject(defaults);
parsemakefiles(argv);
parsemakeflags();