config.gcc (*-*-mingw*): Allow as option the posix threading model.
authorKai Tietz <ktietz@gcc.gnu.org>
Fri, 1 Apr 2011 14:43:22 +0000 (16:43 +0200)
committerKai Tietz <ktietz@gcc.gnu.org>
Fri, 1 Apr 2011 14:43:22 +0000 (16:43 +0200)
2011-04-01  Kai Tietz  <ktietz@redhat.com>

* config.gcc (*-*-mingw*): Allow as option the
posix threading model.
* config/i386/mingw32.h ( SPEC_PTHREAD1,  SPEC_PTHREAD2):
New macros defined dependent to TARGET_USE_PTHREAD_BY_DEFAULT
definition.
(CPP_SPEC): Add pthread/no-pthread handling.
(LIB_SPEC): Likewise.
* config/i386/mingw-w64.h (CPP_SPEC):Likewise.
(LIB_SPEC): Likewise.
* config/i386/t-cygming (SHLIB_PTHREAD_CFLAG): New
flag to pass -pthread option for shared libgcc build.
(SHLIB_PTHREAD_LDFLAG): New option to pass -lpthread
for shared libgcc build.
* config/i386/t-mingw-pthread: New file.
* config/i386/mingw-pthread.h (TARGET_USE_PTHREAD_BY_DEFAULT):
New define to enable use of library pthread by default.
* config/i386/mingw.opt (pthread): New driver option.
(no-pthread): New driver option.
* config/i386/cygming.opt: Make sure trailing empty line
is retained.
* config/i386/mingw-w64.opt: Likewise.

From-SVN: r171833

gcc/config.gcc
gcc/config/i386/cygming.opt
gcc/config/i386/mingw-w64.h
gcc/config/i386/mingw-w64.opt
gcc/config/i386/mingw.opt
gcc/config/i386/mingw32.h
gcc/config/i386/t-cygming

index 0d026e7e3f3000e0c439dc8c8bbfdb3dc22dd135..d40ad44d70fbcffb9920953071ff091948c4ffa0 100644 (file)
@@ -1410,7 +1410,7 @@ i[34567]86-*-cygwin*)
        use_gcc_stdint=wrap
        ;;
 i[34567]86-*-mingw* | x86_64-*-mingw*)
-       tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/cygming.h i386/mingw32.h"
+       tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/cygming.h"
        xm_file=i386/xm-mingw32.h
        case ${target} in
                x86_64-*-* | *-w64-*)
@@ -1420,6 +1420,10 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
                *)
                        ;;
        esac
+       if test x$enable_threads = xposix ; then
+               tm_file="${tm_file} i386/mingw-pthread.h"
+       fi
+       tm_file="${tm_file} i386/mingw32.h"
        # This makes the logic if mingw's or the w64 feature set has to be used
        case ${target} in
                *-w64-*)
@@ -1488,8 +1492,12 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
        use_gcc_stdint=wrap
        case ${enable_threads} in
          "" | yes | win32)       thread_file='win32'
-         tmake_file="${tmake_file} i386/t-gthr-win32"
-         ;;
+           tmake_file="${tmake_file} i386/t-gthr-win32"
+           ;;
+         posix)
+           thread_file='posix'
+           tmake_file="i386/t-mingw-pthread ${tmake_file}"
+           ;;
        esac
        case ${target} in
                x86_64-*-mingw*)
index 0fb325bdeea2e67a95fe61407a7ffc573b3e1204..2d2352370398cea7645a4a46d158ecdfe769c490 100644 (file)
@@ -52,3 +52,5 @@ Compile code that relies on Cygwin DLL wrappers to support C++ operator new/dele
 
 posix
 Driver
+
+; Retain blank line above
index f84434a3fabef893fa93e001bfbbe9555f4bfa71..62a72ef2b92752a994d1341f146f9d43b76cbe60 100644 (file)
@@ -1,8 +1,8 @@
 /* Operating system specific defines to be used when targeting GCC for
    hosting on Windows 32/64 via mingw-w64 runtime, using GNU tools and
    the Windows API Library.
-   Copyright (C) 2009,
-   2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010,
+   2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -20,11 +20,13 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-/* Enable -municode feature.  */
+/* Enable -municode feature and support optional pthread support.  */
 
 #undef CPP_SPEC
-#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} \
-  %{municode:-DUNICODE}"
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
+                "%{municode:-DUNICODE} " \
+                "%{" SPEC_PTHREAD1 ":-D_REENTRANCE} " \
+                "%{" SPEC_PTHREAD2 ":-U_REENTRANCE} "
 
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
@@ -38,6 +40,12 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_SPEC
 #define ASM_SPEC "%{m32:--32} %{m64:--64}"
 
+#undef LIB_SPEC
+#define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \
+                "%{" SPEC_PTHREAD2 ": } " \
+                "%{mwindows:-lgdi32 -lcomdlg32} " \
+                "-ladvapi32 -lshell32 -luser32 -lkernel32"
+
 #undef SPEC_32
 #undef SPEC_64
 #if TARGET_64BIT_DEFAULT
index 965f4c0ce0a52727fb556a9f43042e2e3ba888e9..4eebce64f6b8035c21657f992878eabe00a4c5ed 100644 (file)
@@ -21,3 +21,5 @@
 municode
 Target
 Use unicode startup and define UNICODE macro
+
+; Retain blank line above.
index bd9a4b63035dee5751fd54968e4f9bd9764b2472..f7ae1892ee71829e6d7b5af598c6b8b26d60e917 100644 (file)
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
 
+pthread
+Driver
+
+no-pthread
+Driver
+
 Wpedantic-ms-format
 C ObjC C++ ObjC++ Var(warn_pedantic_ms_format) Init(1) Warning
 Warn about none ISO msvcrt scanf/printf width extensions
@@ -25,3 +31,5 @@ Warn about none ISO msvcrt scanf/printf width extensions
 fset-stack-executable
 Common Report Var(flag_setstackexecutable) Init(1) Optimization
 For nested functions on stack executable permission is set.
+
+; Need to retain blank line above.
index 7485b9d450f4d89ffcb279e98e30401f2c103d2e..fa55ce421cb38e1cb1cadf0293ed28fbefffe0d6 100644 (file)
@@ -43,6 +43,14 @@ along with GCC; see the file COPYING3.  If not see
     }                                                          \
   while (0)
 
+#ifndef TARGET_USE_PTHREAD_BY_DEFAULT
+#define SPEC_PTHREAD1 "pthread"
+#define SPEC_PTHREAD2 "!no-pthread"
+#else
+#define SPEC_PTHREAD1 "!no-pthread"
+#define SPEC_PTHREAD2 "pthread"
+#endif
+
 #undef SUB_LINK_ENTRY32
 #undef SUB_LINK_ENTRY64
 #define SUB_LINK_ENTRY32 "-e _DllMainCRTStartup@12"
@@ -67,13 +75,17 @@ along with GCC; see the file COPYING3.  If not see
 #define STANDARD_INCLUDE_COMPONENT "MINGW"
 
 #undef CPP_SPEC
-#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}"
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
+                "%{" SPEC_PTHREAD1 ":-D_REENTRANCE} " \
+                "%{" SPEC_PTHREAD2 ": } "
 
 /* For Windows applications, include more libraries, but always include
    kernel32.  */
 #undef LIB_SPEC
-#define LIB_SPEC "%{pg:-lgmon} %{mwindows:-lgdi32 -lcomdlg32} \
-                  -ladvapi32 -lshell32 -luser32 -lkernel32"
+#define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \
+                "%{" SPEC_PTHREAD2 ": } " \
+                "%{mwindows:-lgdi32 -lcomdlg32} " \
+                 "-ladvapi32 -lshell32 -luser32 -lkernel32"
 
 /* Weak symbols do not get resolved if using a Windows dll import lib.
    Make the unwind registration references strong undefs.  */
index ccae237d3015617728f569aa3b14d7eeaaaa9694..c4807a0a97b1fb5f5d850ebe6585042f4da221bc 100644 (file)
@@ -77,16 +77,23 @@ SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual@
 ifndef SHLIB_DLLDIR
 $(error SHLIB_DLLDIR must be defined)
 endif
+ifndef SHLIB_PTHREAD_CFLAG
+SHLIB_PTHREAD_CFLAG =
+endif
+ifndef SHLIB_PTHREAD_LDFLAG
+SHLIB_PTHREAD_LDFLAG =
+endif
 
 SHLIB_LINK = $(LN_S) -f $(SHLIB_MAP) $(SHLIB_MAP).def && \
        if [ ! -d $(SHLIB_DIR) ]; then \
                mkdir $(SHLIB_DIR); \
        else true; fi && \
-       $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \
+       $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(SHLIB_PTHREAD_CFLAG) \
+       -shared -nodefaultlibs \
        $(SHLIB_MAP).def \
        -Wl,--out-implib,$(SHLIB_DIR)/$(SHLIB_IMPLIB).tmp \
        -o $(SHLIB_DIR)/$(SHLIB_SONAME).tmp @multilib_flags@ \
-       $(SHLIB_OBJS) $(SHLIB_LC) && \
+       $(SHLIB_OBJS) ${SHLIB_PTHREAD_LDFLAG} $(SHLIB_LC) && \
        if [ -f $(SHLIB_DIR)/$(SHLIB_SONAME) ]; then \
          mv -f $(SHLIB_DIR)/$(SHLIB_SONAME) \
                $(SHLIB_DIR)/$(SHLIB_SONAME).backup; \