From 491477aeac01cc9d82035cacc52984875f000f0a Mon Sep 17 00:00:00 2001
From: shelarcy <shelarcy@capella.freemail.ne.jp>
Date: Sat, 21 May 2005 11:23:18 +0000
Subject: [PATCH] fix examples to run process /bin/date well : System.Process
 uses cmd or command.com shell on Windows, doen't use Cygwin or MSYS shell

---
 Makefile                                                   | 2 ++
 configure                                                  | 5 ++++-
 configure.ac                                               | 3 ++-
 examples/makewith/io/{TestIO.conf => TestIO.conf.in}       | 7 ++++++-
 examples/makewith/unsafeio/{Unsafe.conf => Unsafe.conf.in} | 4 ++++
 5 files changed, 18 insertions(+), 3 deletions(-)
 rename examples/makewith/io/{TestIO.conf => TestIO.conf.in} (60%)
 rename examples/makewith/unsafeio/{Unsafe.conf => Unsafe.conf.in} (73%)

diff --git a/Makefile b/Makefile
index 85ae2ba..3213001 100644
--- a/Makefile
+++ b/Makefile
@@ -79,6 +79,8 @@ clean:
 	find examples -name '*.o' -exec rm {} \;
 	find examples -name '*.core' -exec rm {} \;
 	find examples -name 'package.conf' -exec rm {} \;
+	rm -f examples/makewith/io/TestIO.conf
+	rm -f examples/makewith/unsafeio/Unsafe.conf
 	rm -rf examples/hmake/lib-plugs/plugs
 	rm -rf examples/hmake/one-shot/runplugs
 	rm -f EvalHaskell.h
diff --git a/configure b/configure
index 341450c..0478047 100644
--- a/configure
+++ b/configure
@@ -3036,7 +3036,8 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 
 
-                    ac_config_files="$ac_config_files config.mk config.h"
+# System.Process uses cmd or command.com shell on Windows, doen't use Cygwin or MSYS shell
+                                        ac_config_files="$ac_config_files config.mk config.h examples/makewith/io/TestIO.conf examples/makewith/unsafeio/Unsafe.conf"
 
 
 cat >confcache <<\_ACEOF
@@ -3592,6 +3593,8 @@ do
   # Handling of arguments.
   "config.mk" ) CONFIG_FILES="$CONFIG_FILES config.mk" ;;
   "config.h" ) CONFIG_FILES="$CONFIG_FILES config.h" ;;
+  "examples/makewith/io/TestIO.conf" ) CONFIG_FILES="$CONFIG_FILES examples/makewith/io/TestIO.conf" ;;
+  "examples/makewith/unsafeio/Unsafe.conf" ) CONFIG_FILES="$CONFIG_FILES examples/makewith/unsafeio/Unsafe.conf" ;;
   *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
    { (exit 1); exit 1; }; };;
diff --git a/configure.ac b/configure.ac
index 4b97a97..eb60996 100644
--- a/configure.ac
+++ b/configure.ac
@@ -218,7 +218,8 @@ AC_SUBST(SYMS)
 
 AC_PROG_INSTALL
 
-AC_CONFIG_FILES(config.mk config.h)
+# System.Process uses cmd or command.com shell on Windows, doen't use Cygwin or MSYS shell
+AC_CONFIG_FILES(config.mk config.h examples/makewith/io/TestIO.conf examples/makewith/unsafeio/Unsafe.conf)
 
 AC_OUTPUT
 
diff --git a/examples/makewith/io/TestIO.conf b/examples/makewith/io/TestIO.conf.in
similarity index 60%
rename from examples/makewith/io/TestIO.conf
rename to examples/makewith/io/TestIO.conf.in
index 530a0e1..2d78a08 100644
--- a/examples/makewith/io/TestIO.conf
+++ b/examples/makewith/io/TestIO.conf.in
@@ -13,5 +13,10 @@ resource = testio { field = date }
 -- call a shell command , returning it's output
 --
 date :: IO String
-date = do (_,out,_,_) <- catch (runInteractiveCommand "/bin/date") (\_->error "popen failed")
+date = do
+#if !defined(CYGWIN) || !defined(__MINGW32__)
+          (_,out,_,_) <- catch (runInteractiveCommand "/bin/date") (\_->error "popen failed")
+#else
+          (_,out,_,_) <- catch (runInteractiveCommand "@PREFIX@/../../bin/date") (\_->error "popen failed")
+#endif
           hGetLine out
diff --git a/examples/makewith/unsafeio/Unsafe.conf b/examples/makewith/unsafeio/Unsafe.conf.in
similarity index 73%
rename from examples/makewith/unsafeio/Unsafe.conf
rename to examples/makewith/unsafeio/Unsafe.conf.in
index 14bdc8b..2e51794 100644
--- a/examples/makewith/unsafeio/Unsafe.conf
+++ b/examples/makewith/unsafeio/Unsafe.conf.in
@@ -10,7 +10,11 @@ resource = unsafe { field = date }
 -- illustrates the use of the devil's work
 date :: String
 date = unsafePerformIO $ do
+#if !defined(CYGWIN) || !defined(__MINGW32__)
             (_,outh,_,proc) <- runInteractiveProcess "date" [] Nothing Nothing		
+#else
+            (_,outh,_,proc) <- runInteractiveProcess "@PREFIX@/../../bin/date" [] Nothing Nothing		
+#endif
     	    waitForProcess proc
             s <- hGetContents outh
             return s