Module Name: src
Committed By: christos
Date: Wed Dec 7 15:00:46 UTC 2016
Modified Files:
src/usr.bin/make: main.c make.h parse.c
Log Message:
Refactor and simplify objdir setting code.
To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/usr.bin/make/main.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/make/make.h
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/make/parse.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.251 src/usr.bin/make/main.c:1.252
--- src/usr.bin/make/main.c:1.251 Fri Aug 26 19:28:39 2016
+++ src/usr.bin/make/main.c Wed Dec 7 10:00:46 2016
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
#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 @@ Main_ParseArgLine(const char *line)
}
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 @@ Main_SetObjdir(const char *path)
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 @@ main(int argc, char **argv)
* 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
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.101 src/usr.bin/make/make.h:1.102
--- src/usr.bin/make/make.h:1.101 Fri Aug 26 19:28:39 2016
+++ src/usr.bin/make/make.h Wed Dec 7 10:00:46 2016
@@ -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 @@ char * Check_Cwd_Cmd(const char *);
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 *);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.215 src/usr.bin/make/parse.c:1.216
--- src/usr.bin/make/parse.c:1.215 Fri Aug 26 19:28:39 2016
+++ src/usr.bin/make/parse.c Wed Dec 7 10:00:46 2016
@@ -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 @@ ParseDoDependency(char *line)
Suff_SetNull(line);
break;
case ExObjdir:
- Main_SetObjdir(line);
+ Main_SetObjdir("%s", line);
break;
default:
break;