commit 4b8f21398beae9be4143f5d8be8c6a55a7b492b1
Author: dprunier <dominique.prunier@watch4net.com>
Date:   Mon Mar 5 13:44:54 2012

    use static pthreads

diff --git a/win/MinGW.mak b/win/MinGW.mak
index 5ba397a..b3ba174 100755
--- a/win/MinGW.mak
+++ b/win/MinGW.mak
@@ -11,7 +11,7 @@ OPT=-g -O0
 #OPT=-O5
 INC=-I . -I ../src -I pthreads/$(CHOST)/include
 DEF=-DFASTBIT_MAX_WAIT_TIME=3 -DWITHOUT_FASTBIT_CONFIG_H
-LIB=-Lpthreads/$(CHOST)/lib -lpthread -lm
+LIB=-Lpthreads/$(CHOST)/lib -lpthread -lm -lws2_32
 TESTDIR=tmp
 
 CCFLAGS=$(DEF) $(INC) $(OPT)
@@ -84,7 +84,8 @@ OBJ =  parth3d.o parth3da.o parth3db.o parth3dw.o \
  resource.o \
  rids.o \
  utilidor.o \
- util.o
+ util.o \
+ static_pthread_init.o
 
 #
 all: ibis ardea rara thula tcapi
@@ -155,18 +156,27 @@ clean:
 clean-all: clean
 	$(RM) Debug Release dll tmp pthreads-w32-2-8-0-release pthreads-w32-2-8-0-release.tar.gz
 
-pthreads-w32: pthreads-w32-2-8-0-release/libpthreadGC2.a
-pthreads-w32-2-8-0-release.tar.gz:
-	wget ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-8-0-release.tar.gz
-pthreads-w32-2-8-0-release: pthreads-w32-2-8-0-release.tar.gz
-	tar xzf pthreads-w32-2-8-0-release.tar.gz
-pthreads-w32-2-8-0-release/libpthreadGC2.a: pthreads-w32-2-8-0-release
-	cd pthreads-w32-2-8-0-release && make clean PTW32_FLAGS=-DPTW32_BUILD GC
+pthreads-20100604.zip:
+	wget http://superb-sea2.dl.sourceforge.net/project/mingw-w64/External%20binary%20packages%20%28Win64%20hosted%29/pthreads/pthreads-20100604.zip
+pthreads: pthreads-20100604.zip
+	unzip pthreads-20100604.zip
+	mv pthreads-20100604 pthreads
+	chmod +x pthreads/source/*sh
+pthreads/$(CHOST): pthreads
+	patch -p0 < static_pthread.patch
+ifeq ($(CHOST),x86_64-w64-mingw32)
+	pthreads/source/build_w64.sh
+	unzip pthreads/source/pthreads/pthreads-w64.zip -d pthreads "$(CHOST)/*"
+else
+	pthreads/source/build_w32.sh
+	unzip pthreads/source/pthreads/pthreads-w32.zip -d pthreads "$(CHOST)/*"
+endif
+pthreads-static: pthreads/$(CHOST)
 
 force:
 
 #suffixes
-.SUFFIXES: .o .cpp .h
+.SUFFIXES: .o .cpp .c .h
 # #
 # # rules to generate .h and .cpp files from predicate.y and predicate.l
 # predicate: predicate.tab.h predicate.tab.cpp predicate.yy.cpp
@@ -182,6 +192,8 @@ force:
 # suffixes based rules
 .cpp.o:
 	$(CXX) $(CCFLAGS) -c $<
+.c.o:
+	$(CXX) $(CCFLAGS) -c $<
 ############################################################
 # dependencies generated with g++ -MM
 trydll.exe: ../src/ibis.h ../src/meshQuery.h ../src/query.h \
diff --git a/win/static_pthread.patch b/win/static_pthread.patch
new file mode 100644
index 0000000..8ec34ef
--- /dev/null
+++ b/win/static_pthread.patch
@@ -0,0 +1,68 @@
+--- pthreads/source/build_w64.sh.org	2012-03-05 12:27:56.063799694 -0500
++++ pthreads/source/build_w64.sh	2012-03-05 12:30:26.533904302 -0500
+@@ -1,5 +1,7 @@
+ #!/bin/sh
+ 
++cd "`dirname "$0"`"
++
+ THISDIR=`pwd`
+ TARGET="x86_64-w64-mingw32"
+ 
+@@ -19,7 +21,7 @@
+     -e 's/pthreadGCE\$(DLL_VER)/&-w64/g' \
+     < GNUmakefile.bak > GNUmakefile
+ 
+-make CROSS="$TARGET-" clean GC || exit 1
++make CROSS="$TARGET-" clean GC-static || exit 1
+ 
+ mkdir -p bin
+ mkdir -p $TARGET/include
+@@ -27,14 +29,11 @@
+ mkdir -p share/doc/pthreads-win32
+ 
+ cp -p pthread.h sched.h semaphore.h pthreads_win32_config.h ./$TARGET/include || exit 1
+-cp -p pthreadGC2-w64.dll ./bin || exit 1
+ cp -p libpthreadGC2-w64.a ./$TARGET/lib/libpthread.a || exit 1
+ for i in ANNOUNCE BUGS CONTRIBUTORS COPYING COPYING.LIB FAQ MAINTAINERS NEWS PROGRESS README README.CV README.NONPORTABLE README.WinCE TODO ;
+   do cp -p ${i} ./share/doc/pthreads-win32 ;
+ done
+ 
+-$TARGET-strip ./bin/pthreadGC2-w64.dll
+-
+ zip -9 -r -q pthreads-w64.zip bin $TARGET share || exit 1
+ 
+ cd ..
+--- pthreads/source/build_w32.sh.org	2012-03-05 12:27:50.694831642 -0500
++++ pthreads/source/build_w32.sh	2012-03-05 12:30:51.628754971 -0500
+@@ -1,5 +1,7 @@
+ #!/bin/sh
+ 
++cd "`dirname "$0"`"
++
+ THISDIR=`pwd`
+ TARGET="i686-w64-mingw32"
+ 
+@@ -19,7 +21,7 @@
+     -e 's/pthreadGCE\$(DLL_VER)/&-w32/g' \
+     < GNUmakefile.bak > GNUmakefile
+ 
+-make CROSS="$TARGET-" clean GC || exit 1
++make CROSS="$TARGET-" clean GC-static || exit 1
+ 
+ mkdir -p bin
+ mkdir -p $TARGET/include
+@@ -27,14 +29,11 @@
+ mkdir -p share/doc/pthreads-win32
+ 
+ cp -p pthread.h sched.h semaphore.h pthreads_win32_config.h ./$TARGET/include || exit 1
+-cp -p pthreadGC2-w32.dll ./bin || exit 1
+ cp -p libpthreadGC2-w32.a ./$TARGET/lib/libpthread.a || exit 1
+ for i in ANNOUNCE BUGS CONTRIBUTORS COPYING COPYING.LIB FAQ MAINTAINERS NEWS PROGRESS README README.CV README.NONPORTABLE README.WinCE TODO ;
+   do cp -p ${i} ./share/doc/pthreads-win32 ;
+ done
+ 
+-$TARGET-strip ./bin/pthreadGC2-w32.dll
+-
+ zip -9 -r -q pthreads-w32.zip bin $TARGET share || exit 1
+ 
+ cd ..
diff --git a/win/static_pthread_init.c b/win/static_pthread_init.c
new file mode 100644
index 0000000..b8e2104
--- /dev/null
+++ b/win/static_pthread_init.c
@@ -0,0 +1,87 @@
+/*
+ * Initialy from dll.c (Pthreads-win32) with PTW32_STATIC_LIB test removed
+ *
+ * Description:
+ * This translation unit implements DLL initialisation.
+ *
+ * --------------------------------------------------------------------------
+ *
+ *      Pthreads-win32 - POSIX Threads Library for Win32
+ *      Copyright(C) 1998 John E. Bossom
+ *      Copyright(C) 1999,2005 Pthreads-win32 contributors
+ * 
+ *      Contact Email: rpj@callisto.canberra.edu.au
+ * 
+ *      The current list of contributors is contained
+ *      in the file CONTRIBUTORS included with the source
+ *      code distribution. The list can also be seen at the
+ *      following World Wide Web location:
+ *      http://sources.redhat.com/pthreads-win32/contributors.html
+ * 
+ *      This library is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU Lesser General Public
+ *      License as published by the Free Software Foundation; either
+ *      version 2 of the License, or (at your option) any later version.
+ * 
+ *      This library is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *      Lesser General Public License for more details.
+ * 
+ *      You should have received a copy of the GNU Lesser General Public
+ *      License along with this library in the file COPYING.LIB;
+ *      if not, write to the Free Software Foundation, Inc.,
+ *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "pthread.h"
+
+#ifdef _MSC_VER
+/* 
+ * lpvReserved yields an unreferenced formal parameter;
+ * ignore it
+ */
+#pragma warning( disable : 4100 )
+#endif
+
+#ifdef __cplusplus
+/*
+ * Dear c++: Please don't mangle this name. -thanks
+ */
+extern "C"
+#endif				/* __cplusplus */
+  BOOL WINAPI
+DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
+{
+  BOOL result = PTW32_TRUE;
+
+  switch (fdwReason)
+    {
+
+    case DLL_PROCESS_ATTACH:
+      result = pthread_win32_process_attach_np ();
+      break;
+
+    case DLL_THREAD_ATTACH:
+      /*
+       * A thread is being created
+       */
+      result = pthread_win32_thread_attach_np ();
+      break;
+
+    case DLL_THREAD_DETACH:
+      /*
+       * A thread is exiting cleanly
+       */
+      result = pthread_win32_thread_detach_np ();
+      break;
+
+    case DLL_PROCESS_DETACH:
+      (void) pthread_win32_thread_detach_np ();
+      result = pthread_win32_process_detach_np ();
+      break;
+    }
+
+  return (result);
+
+}				/* DllMain */
