
If neither TARGET_BIG_ENDIAN or TARGET_LITTLE_ENDIAN are defined,
default to native compilation.

FIXME: This only checks for variable definition (i.e. via environment), not
for command-line assignment parameters.

--- a/src/usr.bin/make/main.c
+++ b/src/usr.bin/make/main.c
@@ -61,6 +61,7 @@
  *			the .MFLAGS target.
  */
 
+#include <sys/endian.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -881,6 +882,7 @@
 	const char *machine;
 	const char *machine_arch;
 	const char *machine_cpu;
+	int machine_endian_little;
 	Boolean outOfDate = TRUE;	/* FALSE if all targets up to date */
 	const char *p;
 	const char *pathp;
@@ -1014,6 +1016,16 @@
 	Var_SetGlobal("MACHINE", machine);
 	Var_SetGlobal("MACHINE_ARCH", machine_arch);
 	Var_SetGlobal("MACHINE_CPU", machine_cpu);
+	if (!Var_Exists("TARGET_BIG_ENDIAN", VAR_GLOBAL) && !Var_Exists("TARGET_LITTLE_ENDIAN", VAR_GLOBAL)) {
+		/*
+		 * If neither TARGET_BIG_ENDIAN or TARGET_LITTLE_ENDIAN are defined,
+		 * default to native compilation.
+		 */
+		if (_BYTE_ORDER == _LITTLE_ENDIAN)
+			Var_SetGlobal("TARGET_LITTLE_ENDIAN", "true");
+		else
+			Var_SetGlobal("TARGET_BIG_ENDIAN", "true");
+	}
 #ifdef MAKE_VERSION
 	Var_SetGlobal("MAKE_VERSION", MAKE_VERSION);
 #endif
