tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

make: Check_Cwd_av handle -C or remove?



I added the Check_Cwd_av logic at least 10 years ago, to avoid the need
to fix lots of makefiles which didn't work with MAKEOBJDIRPREFIX.

I suspect the need for it has passed.
Building with separate obj trees (via MAKEOBJDIRPREFIX etc), seems
almost universal now.
Perhaps it is time to retire this check or perhaps disable it by
default?

Anyway, the patch below teaches it to spot 'make -C somewhere' as the
equivalent of 'cd somewhere && make'.
I limited the check of make args to some small number, since I at least
tend to make -C one of the 1st args, and it is rare
that an extra 'cd ${.CURDIR}' will do harm.
Setting MAKE_CHECK_CWD_ARGS to 0 would check them all.

--sjg

Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.203
diff -u -p -r1.203 main.c
--- main.c      31 Aug 2012 07:00:36 -0000      1.203
+++ main.c      18 Jan 2013 17:58:02 -0000
@@ -1406,6 +1406,11 @@ found:
  */
 static int  Check_Cwd_Off = 0;
 
+/* Limit the number of args to make we check for -C */
+#ifndef MAKE_CHECK_CWD_ARGS
+# define MAKE_CHECK_CWD_ARGS 8
+#endif
+
 static char *
 Check_Cwd_av(int ac, char **av, int copy)
 {
@@ -1413,6 +1418,8 @@ Check_Cwd_av(int ac, char **av, int copy
     static char *cur_dir = NULL;
     char **mp;
     char *cp;
+    char *is_make;
+    int check_args;
     int is_cmd, next_cmd;
     int i;
     int n;
@@ -1453,7 +1460,8 @@ Check_Cwd_av(int ac, char **av, int copy
         return NULL;
     }
 
-    
+    is_make = NULL;
+    check_args = MAKE_CHECK_CWD_ARGS;
     next_cmd = 1;
     for (i = 0; i < ac; ++i) {
        is_cmd = next_cmd;
@@ -1461,9 +1469,13 @@ Check_Cwd_av(int ac, char **av, int copy
        n = strlen(av[i]);
        cp = &(av[i])[n - 1];
        if (strspn(av[i], "|&;") == (size_t)n) {
+           if (is_make)
+               break;
            next_cmd = 1;
            continue;
        } else if (*cp == ';' || *cp == '&' || *cp == '|' || *cp == ')') {
+           if (is_make)
+               break;
            next_cmd = 1;
            if (copy) {
                do {
@@ -1507,16 +1519,33 @@ Check_Cwd_av(int ac, char **av, int copy
            for (mp = make; *mp != NULL; ++mp) {
                n = strlen(*mp);
                if (strcmp(cp, *mp) == 0) {
-                   if (DEBUG(CWD))
-                       fprintf(debug_file, " %s == '%s', chdir(%s)\n",
-                           cp, *mp, cur_dir);
-                   return cur_dir;
+                   is_make = *mp;
+                   break;
                }
            }
+       } else if (is_make) {
+           /* looking at args to make */
+           if (strcmp("-C", cp) == 0) {
+               if (DEBUG(CWD))
+                   fprintf(debug_file, " == cd, done.\n");
+               return NULL;
+           }
+           if (MAKE_CHECK_CWD_ARGS > 0 && check_args-- <= 0) {
+               /* -C is usually one of the first args? give up now */
+               if (DEBUG(CWD))
+                   fprintf(debug_file, "\n");
+               break;
+           }
        }
        if (DEBUG(CWD))
            fprintf(debug_file, "\n");
     }
+    if (is_make) {
+       if (DEBUG(CWD))
+           fprintf(debug_file, "cmd == '%s', chdir(%s)\n",
+                   is_make, cur_dir);
+       return cur_dir;
+    }
     return NULL;
 }
 


Home | Main Index | Thread Index | Old Index