Subject: Re: make: MACHINE vs. MACHINE_ARCH
To: NetBSD-current Users <current-users@NetBSD.ORG>
From: Curt Sampson <cjs@portal.ca>
List: current-users
Date: 12/22/1996 19:40:27
Ok, here's my proposal. The following patch to make does this:

* Remove use of MACHINE in the source entirely, so that it's not
compiled in if defined. At runtime we always use the uname value,
unless overridden by the environment variable.
* Still use a compiled in MACHINE_ARCH, but let the environment
override it.
* Define HOST_MACHINE and HOST_MACHINE_ARCH, identical to the above,
except that they are not overridden by environment variables. This
is for future use by cross-compilation environments.

This should not affect anything that we do now. However, I'm going
to run with it for a while and do some builds on various systems.
If nobody voices any objections or alternative plans before the
end of the week, I'll commit it.

cjs

Curt Sampson    cjs@portal.ca		Info at http://www.portal.ca/
Internet Portal Services, Inc.	
Vancouver, BC   (604) 257-9400		De gustibus, aut bene aut nihil.


Index: main.c
===================================================================
RCS file: /usr2/CVSRoot/netbsd/src/usr.bin/make/main.c,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -u -r1.1.1.4 -r1.2
--- main.c	1996/11/11 00:05:47	1.1.1.4
+++ main.c	1996/12/23 02:40:05	1.2
@@ -85,9 +85,7 @@
 #include <sys/resource.h>
 #include <sys/signal.h>
 #include <sys/stat.h>
-#ifndef MACHINE
 #include <sys/utsname.h>
-#endif
 #include <sys/wait.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -440,10 +438,13 @@
 	char obpath[MAXPATHLEN + 1];
 	char cdpath[MAXPATHLEN + 1];
     	char *machine = getenv("MACHINE");
+	char *machine_arch = getenv("MACHINE_ARCH");
+	char *host_machine = NULL;
 	Lst sysMkPath;			/* Path of sys.mk */
 	char *cp = NULL, *start;
 					/* avoid faults on read-only strings */
 	static char syspath[] = _PATH_DEFSYSPATH;
+	struct utsname utsname;
 
 #ifdef RLIMIT_NOFILE
 	/*
@@ -486,22 +487,25 @@
 	 * so we can share an executable for similar machines.
 	 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
 	 *
-	 * Note that while MACHINE is decided at run-time,
-	 * MACHINE_ARCH is always known at compile time.
+	 * MACHINE is decided at run time. The default value of
+	 * MACHINE_ARCH must be known at compile time, but the
+	 * environment can override this at run time.
+	 * HOST_MACHINE is taken from the system at run time.
+	 * HOST_MACHINE_ARCH must be known at compile time.
 	 */
+	if (uname(&utsname) == -1) {
+		perror("make: uname");
+		exit(2);
+	}
+	host_machine = utsname.machine;
     	if (!machine) {
-#ifndef MACHINE
-	    struct utsname utsname;
-
-	    if (uname(&utsname) == -1) {
-		    perror("make: uname");
-		    exit(2);
-	    }
 	    machine = utsname.machine;
-#else
-	    machine = MACHINE;
-#endif
 	}
+#ifdef MACHINE_ARCH
+	if (!machine_arch) {
+	    machine_arch = MACHINE_ARCH;
+	}
+#endif
 
 	/*
 	 * If the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory
@@ -594,8 +598,11 @@
 	Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
 	Var_Set("MFLAGS", "", VAR_GLOBAL);
 	Var_Set("MACHINE", machine, VAR_GLOBAL);
+	if (machine_arch)
+	    Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
+	Var_Set("HOST_MACHINE", host_machine, VAR_GLOBAL);
 #ifdef MACHINE_ARCH
-	Var_Set("MACHINE_ARCH", MACHINE_ARCH, VAR_GLOBAL);
+	Var_Set("HOST_MACHINE_ARCH", MACHINE_ARCH, VAR_GLOBAL);
 #endif
 
 	/*