From b8d3f120253a47d2f3de5e69fb884a76bac8c278 Mon Sep 17 00:00:00 2001
From: tg <tg@mirbsd.org>
Date: Mon, 17 Dec 2012 21:55:06 +0000
Subject: [PATCH] =?UTF-8?q?merge/genericise=20RT=E2=80=99s=20port=20to=20M?=
 =?UTF-8?q?inix-vmd?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Build.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 sh.h     | 12 ++++++++++--
 2 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/Build.sh b/Build.sh
index d4610e0..03ff00d 100644
--- a/Build.sh
+++ b/Build.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.598 2012/12/05 19:38:05 tg Exp $'
+srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.599 2012/12/17 21:55:04 tg Exp $'
 #-
 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
 #		2011, 2012
@@ -270,7 +270,21 @@ ac_header() {
 	echo "/* NeXTstep bug workaround */" >x
 	for i
 	do
-		echo "#include <$i>" >>x
+		case $i in
+		_time)
+			echo '#if HAVE_BOTH_TIME_H' >>x
+			echo '#include <sys/time.h>' >>x
+			echo '#include <time.h>' >>x
+			echo '#elif HAVE_SYS_TIME_H' >>x
+			echo '#include <sys/time.h>' >>x
+			echo '#elif HAVE_TIME_H' >>x
+			echo '#include <time.h>' >>x
+			echo '#endif' >>x
+			;;
+		*)
+			echo "#include <$i>" >>x
+			;;
+		esac
 	done
 	echo "#include <$hf>" >>x
 	echo 'int main(void) { return (0); }' >>x
@@ -604,6 +618,19 @@ LynxOS)
 	;;
 MidnightBSD)
 	;;
+Minix-vmd)
+	#XXX @RT: really?
+	add_cppflags -DMKSH__NO_SETEUGID
+	add_cppflags -DMKSH_UNEMPLOYED
+	add_cppflags -DMKSH_CONSERVATIVE_FDS
+	#XXX added from Minix3; RT didn't use this, why?
+	add_cppflags -DMKSH_NO_LIMITS
+	#XXX why the deviation from Minix3?
+	add_cppflags -D_MINIX_SOURCE
+	#XXX two copied from Minix3
+	oldish_ed=no-stderr-ed		# no /bin/ed, maybe see below
+	: ${HAVE_SETLOCALE_CTYPE=0}
+	;;
 Minix3)
 	add_cppflags -DMKSH_UNEMPLOYED
 	add_cppflags -DMKSH_CONSERVATIVE_FDS
@@ -1364,11 +1391,21 @@ ac_ifcpp 'ifdef MKSH_CONSERVATIVE_FDS' isset_MKSH_CONSERVATIVE_FDS '' \
 #
 # Environment: headers
 #
+ac_header sys/time.h sys/types.h
+ac_header time.h sys/types.h
+test "11" = "$HAVE_SYS_TIME_H$HAVE_TIME_H" || HAVE_BOTH_TIME_H=0
+ac_test both_time_h '' 'whether <sys/time.h> and <time.h> can both be included' <<-'EOF'
+	#include <sys/types.h>
+	#include <sys/time.h>
+	#include <time.h>
+	int main(void) { struct tm tm; return ((int)sizeof(tm)); }
+EOF
 ac_header sys/bsdtypes.h
 ac_header sys/file.h sys/types.h
 ac_header sys/mkdev.h sys/types.h
 ac_header sys/mman.h sys/types.h
 ac_header sys/param.h
+ac_header sys/resource.h sys/types.h _time
 ac_header sys/select.h sys/types.h
 ac_header sys/sysmacros.h
 ac_header bstring.h
@@ -1430,8 +1467,17 @@ EOF
 
 ac_test rlim_t <<-'EOF'
 	#include <sys/types.h>
+	#if HAVE_BOTH_TIME_H
 	#include <sys/time.h>
+	#include <time.h>
+	#elif HAVE_SYS_TIME_H
+	#include <sys/time.h>
+	#elif HAVE_TIME_H
+	#include <time.h>
+	#endif
+	#if HAVE_SYS_RESOURCE_H
 	#include <sys/resource.h>
+	#endif
 	#include <unistd.h>
 	int main(void) { return ((int)(rlim_t)0); }
 EOF
@@ -1482,7 +1528,7 @@ else
 		#define EXTERN
 		#define MKSH_INCLUDES_ONLY
 		#include "sh.h"
-		__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.598 2012/12/05 19:38:05 tg Exp $");
+		__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.599 2012/12/17 21:55:04 tg Exp $");
 		int main(void) { printf("Hello, World!\n"); return (0); }
 EOF
 	case $cm in
@@ -1641,7 +1687,14 @@ EOF
 
 ac_test select <<-'EOF'
 	#include <sys/types.h>
+	#if HAVE_BOTH_TIME_H
 	#include <sys/time.h>
+	#include <time.h>
+	#elif HAVE_SYS_TIME_H
+	#include <sys/time.h>
+	#elif HAVE_TIME_H
+	#include <time.h>
+	#endif
 	#if HAVE_SYS_BSDTYPES_H
 	#include <sys/bsdtypes.h>
 	#endif
diff --git a/sh.h b/sh.h
index b207a1b..0d1395e 100644
--- a/sh.h
+++ b/sh.h
@@ -38,7 +38,14 @@
 #include <sys/param.h>
 #endif
 #include <sys/types.h>
+#if HAVE_BOTH_TIME_H
 #include <sys/time.h>
+#include <time.h>
+#elif HAVE_SYS_TIME_H
+#include <sys/time.h>
+#elif HAVE_TIME_H
+#include <time.h>
+#endif
 #include <sys/ioctl.h>
 #if HAVE_SYS_SYSMACROS_H
 #include <sys/sysmacros.h>
@@ -49,7 +56,9 @@
 #if HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
+#if HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
+#endif
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <dirent.h>
@@ -85,7 +94,6 @@
 /* shudder… */
 #include <termio.h>
 #endif
-#include <time.h>
 #if HAVE_ULIMIT_H
 #include <ulimit.h>
 #endif
@@ -152,7 +160,7 @@
 #endif
 
 #ifdef EXTERN
-__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.615 2012/12/07 23:46:38 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.616 2012/12/17 21:55:06 tg Exp $");
 #endif
 #define MKSH_VERSION "R41 2012/12/07"