Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make We must delay setting .CURDIR and .OBJDIR until...



details:   https://anonhg.NetBSD.org/src/rev/9aee2399b91f
branches:  trunk
changeset: 747309:9aee2399b91f
user:      sjg <sjg%NetBSD.org@localhost>
date:      Wed Sep 09 17:09:49 2009 +0000

description:
We must delay setting .CURDIR and .OBJDIR until after MainParseArgs()
in case -C is used - in which case we should also ignore $PWD.

diffstat:

 usr.bin/make/main.c |  135 ++++++++++++++++++++++++++-------------------------
 1 files changed, 70 insertions(+), 65 deletions(-)

diffs (205 lines):

diff -r a530365d7397 -r 9aee2399b91f usr.bin/make/main.c
--- a/usr.bin/make/main.c       Wed Sep 09 11:47:24 2009 +0000
+++ b/usr.bin/make/main.c       Wed Sep 09 17:09:49 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.173 2009/09/08 17:29:20 sjg Exp $   */
+/*     $NetBSD: main.c,v 1.174 2009/09/09 17:09:49 sjg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.173 2009/09/08 17:29:20 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.174 2009/09/09 17:09:49 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.173 2009/09/08 17:29:20 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.174 2009/09/09 17:09:49 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -180,6 +180,7 @@
 static int             ReadMakefile(const void *, const void *);
 static void            usage(void);
 
+static Boolean         ignorePWD;      /* if we use -C, PWD is meaningless */
 static char curdir[MAXPATHLEN + 1];    /* startup directory */
 static char objdir[MAXPATHLEN + 1];    /* where we chdir'ed to */
 char *progname;                                /* the program name */
@@ -392,6 +393,7 @@
                                              strerror(errno));
                                exit(1);
                        }
+                       ignorePWD = TRUE;
                        break;
                case 'D':
                        if (argvalue == NULL || argvalue[0] == 0) goto noarg;
@@ -759,40 +761,6 @@
                }
        }
 #endif
-       /*
-        * Find where we are and take care of PWD for the automounter...
-        * All this code is so that we know where we are when we start up
-        * on a different machine with pmake.
-        */
-       if (getcwd(curdir, MAXPATHLEN) == NULL) {
-               (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
-               exit(2);
-       }
-
-       if (stat(curdir, &sa) == -1) {
-           (void)fprintf(stderr, "%s: %s: %s.\n",
-                progname, curdir, strerror(errno));
-           exit(2);
-       }
-
-       /*
-        * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX
-        * since the value of curdir can very depending on how we got
-        * here.  Ie sitting at a shell prompt (shell that provides $PWD)
-        * or via subdir.mk in which case its likely a shell which does
-        * not provide it.
-        * So, to stop it breaking this case only, we ignore PWD if
-        * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
-        */
-       if ((pwd = getenv("PWD")) != NULL && getenv("MAKEOBJDIRPREFIX") == NULL) {
-               const char *makeobjdir = getenv("MAKEOBJDIR");
-
-               if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
-                       if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino &&
-                           sa.st_dev == sb.st_dev)
-                               (void)strncpy(curdir, pwd, MAXPATHLEN);
-               }
-       }
 
        /*
         * Get the name of this type of MACHINE from utsname
@@ -836,7 +804,6 @@
         */
        Var_Init();             /* Initialize the lists of variables for
                                 * parsing arguments */
-       Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);
        Var_Set("MACHINE", machine, VAR_GLOBAL, 0);
        Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0);
 #ifdef MAKE_VERSION
@@ -844,32 +811,6 @@
 #endif
        Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */
 
-       /*
-        * Find the .OBJDIR.  If MAKEOBJDIRPREFIX, or failing that,
-        * MAKEOBJDIR is set in the environment, try only that value
-        * and fall back to .CURDIR if it does not exist.
-        *
-        * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
-        * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
-        * of these paths exist, just use .CURDIR.
-        */
-       Dir_Init(curdir);
-       (void)Main_SetObjdir(curdir);
-
-       if ((path = getenv("MAKEOBJDIRPREFIX")) != NULL) {
-               (void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
-               (void)Main_SetObjdir(mdpath);
-       } else if ((path = getenv("MAKEOBJDIR")) != NULL) {
-               (void)Main_SetObjdir(path);
-       } else {
-               (void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
-               if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {
-                       (void)snprintf(mdpath, MAXPATHLEN, "%s%s", 
-                                       _PATH_OBJDIRPREFIX, curdir);
-                       (void)Main_SetObjdir(mdpath);
-               }
-       }
-
        create = Lst_Init(FALSE);
        makefiles = Lst_Init(FALSE);
        printVars = FALSE;
@@ -889,7 +830,7 @@
        maxJobs = DEFMAXLOCAL;          /* Set default local max concurrency */
        maxJobTokens = maxJobs;
        compatMake = FALSE;             /* No compat mode */
-
+       ignorePWD = FALSE;
 
        /*
         * Initialize the parsing, directory and variable modules to prepare
@@ -943,6 +884,70 @@
        MainParseArgs(argc, argv);
 
        /*
+        * Find where we are (now) and take care of PWD for the automounter...
+        * All this code is so that we know where we are when we start up
+        * on a different machine with pmake.
+        */
+       if (getcwd(curdir, MAXPATHLEN) == NULL) {
+               (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
+               exit(2);
+       }
+
+       if (stat(curdir, &sa) == -1) {
+           (void)fprintf(stderr, "%s: %s: %s.\n",
+                progname, curdir, strerror(errno));
+           exit(2);
+       }
+
+       /*
+        * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX
+        * since the value of curdir can vary depending on how we got
+        * here.  Ie sitting at a shell prompt (shell that provides $PWD)
+        * or via subdir.mk in which case its likely a shell which does
+        * not provide it.
+        * So, to stop it breaking this case only, we ignore PWD if
+        * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
+        */
+       if (!ignorePWD &&
+           (pwd = getenv("PWD")) != NULL &&
+           getenv("MAKEOBJDIRPREFIX") == NULL) {
+               const char *makeobjdir = getenv("MAKEOBJDIR");
+
+               if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
+                       if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino &&
+                           sa.st_dev == sb.st_dev)
+                               (void)strncpy(curdir, pwd, MAXPATHLEN);
+               }
+       }
+       Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);
+
+       /*
+        * Find the .OBJDIR.  If MAKEOBJDIRPREFIX, or failing that,
+        * MAKEOBJDIR is set in the environment, try only that value
+        * and fall back to .CURDIR if it does not exist.
+        *
+        * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
+        * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
+        * of these paths exist, just use .CURDIR.
+        */
+       Dir_Init(curdir);
+       (void)Main_SetObjdir(curdir);
+
+       if ((path = getenv("MAKEOBJDIRPREFIX")) != NULL) {
+               (void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
+               (void)Main_SetObjdir(mdpath);
+       } else if ((path = getenv("MAKEOBJDIR")) != NULL) {
+               (void)Main_SetObjdir(path);
+       } else {
+               (void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
+               if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {
+                       (void)snprintf(mdpath, MAXPATHLEN, "%s%s", 
+                                       _PATH_OBJDIRPREFIX, curdir);
+                       (void)Main_SetObjdir(mdpath);
+               }
+       }
+
+       /*
         * Be compatible if user did not specify -j and did not explicitly
         * turned compatibility on
         */



Home | Main Index | Thread Index | Old Index