Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Refactor and simplify objdir setting code.



details:   https://anonhg.NetBSD.org/src/rev/945becdf2354
branches:  trunk
changeset: 349337:945becdf2354
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Dec 07 15:00:46 2016 +0000

description:
Refactor and simplify objdir setting code.

diffstat:

 usr.bin/make/main.c  |  58 +++++++++++++++++++++++++++++----------------------
 usr.bin/make/make.h  |   4 +-
 usr.bin/make/parse.c |   8 +++---
 3 files changed, 39 insertions(+), 31 deletions(-)

diffs (165 lines):

diff -r 61fd127ac37b -r 945becdf2354 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Wed Dec 07 11:27:18 2016 +0000
+++ b/usr.bin/make/main.c       Wed Dec 07 15:00:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.251 2016/08/26 23:28:39 dholland Exp $      */
+/*     $NetBSD: main.c,v 1.252 2016/12/07 15:00:46 christos Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.251 2016/08/26 23:28:39 dholland Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.252 2016/12/07 15:00:46 christos 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.251 2016/08/26 23:28:39 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.252 2016/12/07 15:00:46 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -681,18 +681,24 @@
 }
 
 Boolean
-Main_SetObjdir(const char *path)
+Main_SetObjdir(const char *fmt, ...)
 {
        struct stat sb;
-       char *p = NULL;
-       char buf[MAXPATHLEN + 1];
+       char *p, *path;
+       char buf[MAXPATHLEN + 1], pbuf[MAXPATHLEN + 1];
        Boolean rc = FALSE;
+       va_list ap;
+
+       va_start(ap, fmt);
+       vsnprintf(path = pbuf, MAXPATHLEN, fmt, ap);
+       va_end(ap);
 
        /* expand variable substitutions */
        if (strchr(path, '$') != 0) {
                snprintf(buf, MAXPATHLEN, "%s", path);
                path = p = Var_Subst(NULL, buf, VAR_GLOBAL, VARF_WANTRES);
-       }
+       } else
+               p = NULL;
 
        if (path[0] != '/') {
                snprintf(buf, MAXPATHLEN, "%s/%s", curdir, path);
@@ -719,6 +725,18 @@
        return rc;
 }
 
+static Boolean
+Main_SetVarObjdir(const char *var)
+{
+       char *p1, *path;
+       if ((path = Var_Value(var, VAR_CMD, &p1)) == NULL)
+               return FALSE;
+
+       (void)Main_SetObjdir("%s%s", path, curdir);
+       free(p1);
+       return TRUE;
+}
+
 /*-
  * ReadAllMakefiles --
  *     wrapper around ReadMakefile() to read all.
@@ -1095,28 +1113,18 @@
         * 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
+        * Otherwise, try _PATH_OBJDIR.MACHINE-MACHINE_ARCH, _PATH_OBJDIR.MACHINE,
+        * and * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
         * of these paths exist, just use .CURDIR.
         */
        Dir_Init(curdir);
-       (void)Main_SetObjdir(curdir);
+       (void)Main_SetObjdir("%s", curdir);
 
-       if ((path = Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &p1)) != NULL) {
-               (void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
-               (void)Main_SetObjdir(mdpath);
-               free(p1);
-       } else if ((path = Var_Value("MAKEOBJDIR", VAR_CMD, &p1)) != NULL) {
-               (void)Main_SetObjdir(path);
-               free(p1);
-       } 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);
-               }
-       }
+       if (!Main_SetVarObjdir("MAKEOBJDIRPREFIX") &&
+           !Main_SetVarObjdir("MAKEOBJDIR") &&
+           !Main_SetObjdir("%s.%s", _PATH_OBJDIR, machine) &&
+           !Main_SetObjdir("%s", _PATH_OBJDIR))
+               (void)Main_SetObjdir("%s%s", _PATH_OBJDIRPREFIX, curdir);
 
        /*
         * Initialize archive, target and suffix modules in preparation for
diff -r 61fd127ac37b -r 945becdf2354 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Wed Dec 07 11:27:18 2016 +0000
+++ b/usr.bin/make/make.h       Wed Dec 07 15:00:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.101 2016/08/26 23:28:39 dholland Exp $      */
+/*     $NetBSD: make.h,v 1.102 2016/12/07 15:00:46 christos Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -488,7 +488,7 @@
 void Check_Cwd(const char **);
 void PrintOnError(GNode *, const char *);
 void Main_ExportMAKEFLAGS(Boolean);
-Boolean Main_SetObjdir(const char *);
+Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 int mkTempFile(const char *, char **);
 int str2Lst_Append(Lst, char *, const char *);
 int cached_lstat(const char *, void *);
diff -r 61fd127ac37b -r 945becdf2354 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Wed Dec 07 11:27:18 2016 +0000
+++ b/usr.bin/make/parse.c      Wed Dec 07 15:00:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.215 2016/08/26 23:28:39 dholland Exp $     */
+/*     $NetBSD: parse.c,v 1.216 2016/12/07 15:00:46 christos Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.215 2016/08/26 23:28:39 dholland Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.216 2016/12/07 15:00:46 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.215 2016/08/26 23:28:39 dholland Exp $");
+__RCSID("$NetBSD: parse.c,v 1.216 2016/12/07 15:00:46 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1651,7 +1651,7 @@
                    Suff_SetNull(line);
                    break;
                case ExObjdir:
-                   Main_SetObjdir(line);
+                   Main_SetObjdir("%s", line);
                    break;
                default:
                    break;



Home | Main Index | Thread Index | Old Index