tech-toolchain archive

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

Re: make: ensure ${.MAKE} works



In article <20100413210259.C93981C7053%bad.crufty.net@localhost>,
Simon J. Gerraty <sjg%crufty.net@localhost> wrote:
>
>This came up in a recent thread.
>
>Anyone object?

realpath(3) is not guaranteed to return an absolute path name if it is not
given one (although in the NetBSD implementation it does).

The test should just be:

        if (argv[0][0] != '/')

instead of the strchr and the comparison.

On the standard realpath(3) implementations it is a no-op. Perhaps
adding a test afterwards:

        if (*p1 != '/') {
            char cwd[MAXPATHLEN];
            snprintf(p1 = mdpath, "%s/%s", getcwd(cwd, sizeof(cwd)), argv[0]);
    }

or before doing the realpath() call?

Wish we had working $ORIGIN...

christos

>
>--------------------8<--------------------
>If argv[0] contains '/' but is not an absolute path,
>use realpath() to resolve it for setting .MAKE
>
>Index: main.c
>===================================================================
>RCS file: /cvsroot/src/usr.bin/make/main.c,v
>retrieving revision 1.177
>diff -u -p -r1.177 main.c
>--- main.c     8 Apr 2010 17:41:29 -0000       1.177
>+++ main.c     13 Apr 2010 20:59:35 -0000
>@@ -895,8 +895,14 @@ main(int argc, char **argv)
>        *      MFLAGS also gets initialized empty, for compatibility.
>        */
>       Parse_Init();
>-      Var_Set("MAKE", argv[0], VAR_GLOBAL, 0);
>-      Var_Set(".MAKE", argv[0], VAR_GLOBAL, 0);
>+      if ((p1 = strchr(argv[0], '/')) && p1 != argv[0]) {
>+              /* resolve to an absolute path */
>+              p1 = realpath(argv[0], mdpath);
>+      }
>+      if (!p1)
>+              p1 = argv[0];
>+      Var_Set("MAKE", p1, VAR_GLOBAL, 0);
>+      Var_Set(".MAKE", p1, VAR_GLOBAL, 0);
>       Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0);
>       Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
>       Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
>
>





Home | Main Index | Thread Index | Old Index