From 720055740313044a597240a941e26a15459fcadd Mon Sep 17 00:00:00 2001
From: Christopher Faylor <me@cgf.cx>
Date: Mon, 26 Aug 2002 04:30:11 +0000
Subject: [PATCH] * Makefile.in (cygcheck.exe): Make a -mno-cygwin program. *
 cygrun.c (main): Export CYGWIN=ntsec unless otherwise set. * shared.cc
 (shared_name): Only add build date to shared name when *testing*.

---
 winsup/cygwin/ChangeLog   |  8 ++++++++
 winsup/cygwin/Makefile.in |  9 ++++++--
 winsup/cygwin/cygrun.c    | 43 +++++++++++++++++++++++++--------------
 winsup/cygwin/shared.cc   |  2 +-
 4 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 083ed3143..e908c27d1 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+2002-08-26  Christopher Faylor  <cgf@redhat.com>
+
+	* Makefile.in (cygcheck.exe): Make a -mno-cygwin program.
+	* cygrun.c (main): Export CYGWIN=ntsec unless otherwise set.
+
+	* shared.cc (shared_name): Only add build date to shared name when
+	*testing*.
+
 2002-08-24  Christopher Faylor  <cgf@redhat.com>
 
 	* Makefile.in (DLL_IMPORTS): Move libuuid.a and libshell32.a to list
diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 1d62664c5..b4f110316 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -270,6 +270,7 @@ new-$(LIB_NAME): $(LIB_NAME)
 	$(DLLTOOL) --as=$(AS) --dllname new-$(DLL_NAME) --def $(DEF_FILE) --output-lib new-templib.a
 	$(AR) rcv new-templib.a $(LIBCOS)
 	mv new-templib.a new-$(LIB_NAME)
+	$(RANLIB) $@
 
 dll_ofiles: $(DLL_OFILES)
 
@@ -314,9 +315,12 @@ winver_stamp: mkvers.sh include/cygwin/version.h winver.rc $(DLL_OFILES)
 malloc.o: malloc.cc
 	$(COMPILE_CXX) -fomit-frame-pointer -o $@ $<
 
-cygrun.exe : cygrun.o -lgcc $(LIB_NAME) $(w32api_lib)/libuser32.a \
+cygrun.o: cygrun.c
+	$(CC) $(MINGW_CFLAGS) -o $@ -c $<
+
+cygrun.exe : cygrun.o -lgcc $(w32api_lib)/libuser32.a \
 	     $(w32api_lib)/libshell32.a $(w32api_lib)/libkernel32.a
-	$(CC) -nodefaultlibs -o $@ $^
+	$(CC) -mno-cygwin -o $@ $^
 
 cygserver_transport_outside.o: cygserver_transport.cc
 	$(COMPILE_CXX) -D__OUTSIDE_CYGWIN__ -o $@ $<
@@ -343,6 +347,7 @@ cygserver.exe: cygserver.o cygserver_shm.o cygserver_transport_outside.o cygserv
 #endif
 
 -lgcc:
+	:
 
 #
 
diff --git a/winsup/cygwin/cygrun.c b/winsup/cygwin/cygrun.c
index 6380bf818..94b0c399f 100644
--- a/winsup/cygwin/cygrun.c
+++ b/winsup/cygwin/cygrun.c
@@ -1,6 +1,6 @@
 /* cygrun.c: testsuite support program
 
-   Copyright 1999, 2000, 2001 Red Hat, Inc.
+   Copyright 1999, 2000, 2001, 2002 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -18,34 +18,47 @@ details. */
 #include <stdlib.h>
 
 int
-main(int argc, char **argv)
+main (int argc, char **argv)
 {
   STARTUPINFO sa;
   PROCESS_INFORMATION pi;
   DWORD ec = 1;
+  char *p;
 
   if (argc < 2)
     {
-      fprintf(stderr, "Usage: cygrun [program]\n");
+      fprintf (stderr, "Usage: cygrun [program]\n");
       exit (0);
     }
 
-  putenv("CYGWIN_TESTING=1");
-  SetEnvironmentVariable("CYGWIN_TESTING", "1");
-
-  memset(&sa, 0, sizeof(sa));
-  memset(&pi, 0, sizeof(pi));
-  if (!CreateProcess(0, argv[1], 0, 0, 1, 0, 0, 0, &sa, &pi))
+  SetEnvironmentVariable ("CYGWIN_TESTING", "1");
+  if ((p = getenv ("CYGWIN")) == NULL || (strstr (p, "ntsec") == NULL))
     {
-      fprintf(stderr, "CreateProcess %s failed\n", argv[1]);
-      exit(1);
+      char buf[4096];
+      if (!p)
+	p[0] = '\0';
+      else
+	{
+	  strcat (buf, p);
+	  strcat (buf, " ");
+	}
+      strcat(buf, "ntsec");
+      SetEnvironmentVariable ("CYGWIN", buf);
     }
 
-  WaitForSingleObject(pi.hProcess, INFINITE);
+  memset (&sa, 0, sizeof (sa));
+  memset (&pi, 0, sizeof (pi));
+  if (!CreateProcess (0, argv[1], 0, 0, 1, 0, 0, 0, &sa, &pi))
+    {
+      fprintf (stderr, "CreateProcess %s failed\n", argv[1]);
+      exit (1);
+    }
 
-  GetExitCodeProcess(pi.hProcess, &ec);
+  WaitForSingleObject (pi.hProcess, INFINITE);
 
-  CloseHandle(pi.hProcess);
-  CloseHandle(pi.hThread);
+  GetExitCodeProcess (pi.hProcess, &ec);
+
+  CloseHandle (pi.hProcess);
+  CloseHandle (pi.hThread);
   return ec;
 }
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 7585d6364..b6d15f3b3 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -38,7 +38,7 @@ shared_name (const char *str, int num)
   extern bool _cygwin_testing;
 
   __small_sprintf (buf, "%s.%s.%d", cygwin_version.shared_id, str, num);
-  if (!_cygwin_testing)
+  if (_cygwin_testing)
     strcat (buf, cygwin_version.dll_build_date);
   return buf;
 }