-q is just plain broken in compat mode, it's easy to fix though.

The second issue is that, if a Makefile as an .END target, that one
will always be run, even in query mode, contrary to .BEGIN.

So let's fix that as well.

Fairly obvious patch

Index: compat.c
===================================================================
RCS file: /cvs/src/usr.bin/make/compat.c,v
retrieving revision 1.88
diff -u -p -r1.88 compat.c
--- compat.c    21 Dec 2019 15:29:25 -0000      1.88
+++ compat.c    5 Jan 2020 13:43:32 -0000
@@ -266,11 +266,12 @@ CompatMake(void *gnp,     /* The node to mak
        }
 }
 
-void
+bool
 Compat_Run(Lst targs)          /* List of target nodes to re-create */
 {
        GNode     *gn = NULL;   /* Current root target */
        int       errors;       /* Number of targets not built due to errors */
+       bool    out_of_date = false;
 
        /* For each entry in the list of targets to create, call CompatMake on
         * it to create the thing. CompatMake will leave the 'built_status'
@@ -291,11 +292,15 @@ Compat_Run(Lst targs)             /* List of target
                else if (gn->built_status == ABORTED) {
                        printf("`%s' not remade because of errors.\n",
                            gn->name);
+                       out_of_date = true;
                        errors++;
+               } else {
+                       out_of_date = true;
                }
        }
 
        /* If the user has defined a .END target, run its commands.  */
-       if (errors == 0)
+       if (errors == 0 && !queryFlag)
                run_gnode(end_node);
+       return out_of_date;
 }
Index: compat.h
===================================================================
RCS file: /cvs/src/usr.bin/make/compat.h,v
retrieving revision 1.3
diff -u -p -r1.3 compat.h
--- compat.h    19 Jul 2010 19:46:43 -0000      1.3
+++ compat.h    5 Jan 2020 13:43:32 -0000
@@ -35,8 +35,9 @@
  *         - friendly variable substitution.
  */
 
-/* Compat_Run(to_create);
- *     Run the actual make engine, to create targets that need to.  */
-extern void Compat_Run(Lst);
+/* out_of_date = Compat_Run(to_create);
+ *     Run the actual make engine, to create targets that need to,
+ *     return true if any target is out of date. */
+extern bool Compat_Run(Lst);
 
 #endif
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/make/main.c,v
retrieving revision 1.123
diff -u -p -r1.123 main.c
--- main.c      22 Apr 2019 18:32:09 -0000      1.123
+++ main.c      5 Jan 2020 13:43:32 -0000
@@ -804,7 +804,7 @@ main(int argc, char **argv)
                if (compatMake)
                        /* Compat_Init will take care of creating all the
                         * targets as well as initializing the module.  */
-                       Compat_Run(&targs);
+                       outOfDate = Compat_Run(&targs);
                else {
                        /* Traverse the graph, checking on all the targets.  */
                        outOfDate = Make_Run(&targs);
Index: make.c
===================================================================
RCS file: /cvs/src/usr.bin/make/make.c,v
retrieving revision 1.76
diff -u -p -r1.76 make.c
--- make.c      21 Dec 2019 15:31:54 -0000      1.76
+++ make.c      5 Jan 2020 13:43:32 -0000
@@ -572,7 +572,8 @@ Make_Run(Lst targs)         /* the initial list
                (void)MakeStartJobs();
        }
 
-       problem = Job_Finish();
+       if (!queryFlag)
+               problem = Job_Finish();
 
        /*
         * Print the final status of each target. E.g. if it wasn't made

Reply via email to