Index: /trunk/src/kmk/Makefile.kmk
===================================================================
--- /trunk/src/kmk/Makefile.kmk	(revision 3213)
+++ /trunk/src/kmk/Makefile.kmk	(revision 3214)
@@ -106,4 +106,6 @@
 	kmkbuiltin/kbuild_protection.c \
 	kmkbuiltin/common-env-and-cwd-opt.c \
+	kmkbuiltin/getopt_r.c \
+	kmkbuiltin/getopt1_r.c \
 	getopt.c \
 	getopt1.c \
Index: /trunk/src/kmk/kmkbuiltin/install.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/install.c	(revision 3213)
+++ /trunk/src/kmk/kmkbuiltin/install.c	(revision 3214)
@@ -47,4 +47,5 @@
 #endif
 
+#define FAKES_NO_GETOPT_H
 #include "config.h"
 #ifndef _MSC_VER
@@ -79,5 +80,5 @@
 # include <process.h>
 #endif
-#include "getopt.h"
+#include "getopt_r.h"
 #ifdef __sun__
 # include "solfakes.h"
@@ -175,4 +176,5 @@
 {
 	INSTALLINSTANCE This;
+	struct getopt_state_r gos;
 	struct stat from_sb, to_sb;
 	mode_t *set;
@@ -203,16 +205,11 @@
 	This.dos2unix = 0;
 
-	/* reset getopt and set progname. */
-	opterr = 1;
-	optarg = NULL;
-	optopt = 0;
-	optind = 0; /* init */
-
 	iflags = 0;
 	group = owner = NULL;
-	while ((ch = getopt_long(argc, argv, "B:bCcdf:g:Mm:o:pSsv", long_options, NULL)) != -1)
+	getopt_initialize_r(&gos, argc, argv, "B:bCcdf:g:Mm:o:pSsv", long_options, envp, pCtx);
+	while ((ch = getopt_long_r(&gos, NULL)) != -1)
 		switch(ch) {
 		case 'B':
-			This.suffix = optarg;
+			This.suffix = gos.optarg;
 			/* FALLTHROUGH */
 		case 'b':
@@ -239,5 +236,5 @@
 			break;
 		case 'g':
-			group = optarg;
+			group = gos.optarg;
 			break;
 		case 'M':
@@ -245,6 +242,6 @@
 			break;
                 case 'm':
-			if (!(set = bsd_setmode(optarg)))
-				return errx(pCtx, EX_USAGE, "invalid file mode: %s", optarg);
+			if (!(set = bsd_setmode(gos.optarg)))
+				return errx(pCtx, EX_USAGE, "invalid file mode: %s", gos.optarg);
 			This.mode = bsd_getmode(set, 0);
 			free(set);
@@ -252,5 +249,5 @@
 			break;
 		case 'o':
-			owner = optarg;
+			owner = gos.optarg;
 			break;
 		case 'p':
@@ -293,6 +290,6 @@
 			return usage(pCtx, 1);
 		}
-	argc -= optind;
-	argv += optind;
+	argc -= gos.optind;
+	argv += gos.optind;
 
 	/* some options make no sense when creating directories */
