tech-toolchain archive

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

introduce OBJMACHINE_ARCH



I would like to keep multiple object directories like obj.evbarm-armeh and
evbarm-earmeh etc. Unfortunately this is difficult to do now. Here's a patch
that cleans up the existing code and add this feature:

christos

Index: usr.bin/make/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.251
diff -u -u -r1.251 main.c
--- usr.bin/make/main.c	26 Aug 2016 23:28:39 -0000	1.251
+++ usr.bin/make/main.c	6 Dec 2016 22:37:34 -0000
@@ -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,19 @@
 	 * 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-%s", _PATH_OBJDIR, machine, machine_arch) &&
+	    !Main_SetObjdir("%s.%s", _PATH_OBJDIR, machine) &&
+	    !Main_SetObjdir(_PATH_OBJDIR))
+		(void)Main_SetObjdir("%s%s", _PATH_OBJDIRPREFIX, curdir);
 
 	/*
 	 * Initialize archive, target and suffix modules in preparation for
Index: usr.bin/make/make.h
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.h,v
retrieving revision 1.101
diff -u -u -r1.101 make.h
--- usr.bin/make/make.h	26 Aug 2016 23:28:39 -0000	1.101
+++ usr.bin/make/make.h	6 Dec 2016 22:37:34 -0000
@@ -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 *);
Index: usr.bin/make/parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.215
diff -u -u -r1.215 parse.c
--- usr.bin/make/parse.c	26 Aug 2016 23:28:39 -0000	1.215
+++ usr.bin/make/parse.c	6 Dec 2016 22:37:34 -0000
@@ -1651,7 +1651,7 @@
 		    Suff_SetNull(line);
 		    break;
 		case ExObjdir:
-		    Main_SetObjdir(line);
+		    Main_SetObjdir("%s", line);
 		    break;
 		default:
 		    break;
Index: share/mk/bsd.obj.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.obj.mk,v
retrieving revision 1.49
diff -u -u -r1.49 bsd.obj.mk
--- share/mk/bsd.obj.mk	25 Jan 2010 00:43:00 -0000	1.49
+++ share/mk/bsd.obj.mk	6 Dec 2016 22:37:34 -0000
@@ -37,10 +37,11 @@
 .else
 PAWD?=		/bin/pwd
 
-__objdir=	obj${OBJMACHINE:D.${MACHINE}}
+__objdirsuffix=${OBJMACHINE:D.${MACHINE}${OBJMACHINE_ARCH:D-${MACHINE_ARCH}}}
+__objdir=	obj${__objdirsuffix}
 
-__usrobjdir=	${BSDOBJDIR}${USR_OBJMACHINE:D.${MACHINE}}
-__usrobjdirpf=	${USR_OBJMACHINE:D:U${OBJMACHINE:D.${MACHINE}}}
+__usrobjdir=	${BSDOBJDIR}${USR_OBJMACHINE:D${__objdirsuffix}}
+__usrobjdirpf=	${USR_OBJMACHINE:D:U${OBJMACHINE:D${_objdirsuffix}}}
 
 .if defined(BUILDID)
 __objdir:=	${__objdir}.${BUILDID}


Home | Main Index | Thread Index | Old Index