CVS: packaging/patches gcc-3.2.3-mingw.patch, NONE, 1.1

Chris Liechti <[email protected]> Sat, 31 May 2008 09:41:23 -0700
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/packaging/patches
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8783

Added Files:
	gcc-3.2.3-mingw.patch 
Log Message:
patch to allow to build a cross compiler with gcc-3.2.3 under mingw

--- NEW FILE: gcc-3.2.3-mingw.patch ---
diff -ur gcc-3.2.3-orig/gcc/collect2.c gcc-3.2.3/gcc/collect2.c
--- gcc-3.2.3-orig/gcc/collect2.c	Mon Mar 31 01:14:02 2003
+++ gcc-3.2.3/gcc/collect2.c	Sat May 31 14:43:34 2008
@@ -167,6 +167,63 @@
 #define SCAN_LIBRARIES
 #endif
 
+#ifdef __MINGW32__
+/* We are being compiled with mingw32 as host, so we should prepare some
+   win32 replaces for pipe(), kill(getpid(),...) and vfork() + execv()
+*/
+#include <io.h>
+#include <fcntl.h>
+
+#define pipe(fildes) _pipe((fildes),1024*16,_O_BINARY)
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+int vfork_execv(char *cmdname, char **argv, int fdout);
+
+/* Helper function for vfork() + execv() replacement. */
+int vfork_execv(char *cmdname, char **argv, int fdout)
+{
+ STARTUPINFO SI;
+ PROCESS_INFORMATION PI;
+ char *params;
+ int plen = 0;
+ int i;
+ BOOL bRes;
+
+ /* Prepare one line with arguments */
+ for(i=0;argv[i];i++) plen += strlen(argv[i]) + 1;
+ plen++;
+ params = xmalloc(plen);
+ strcpy(params,argv[0]);
+ for(i=1;argv[i];i++)  strcat(strcat(params," "),argv[i]);
+
+ /* Prepare startup info -- for pipes redirection */
+ memset(&SI,0,sizeof(SI));
+ SI.cb = sizeof(SI);
+ SI.dwFlags = STARTF_USESTDHANDLES;
+ SI.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
+ SI.hStdOutput = (HANDLE)_get_osfhandle(fdout);
+ SI.hStdError  = GetStdHandle(STD_ERROR_HANDLE);
+
+ /* Create new process in same console, with redirected (piped) stdout */
+ bRes = CreateProcess(cmdname,params,
+  NULL,NULL, /* Security attributes */
+  FALSE,  /* Handle inheritance */
+  0,   /* Flags -- default, in this console, etc */
+  NULL,  /* Invironment */
+  NULL,  /* CWD */
+  &SI,  /* Startup info */
+  &PI);  /* Process info */
+ if(!bRes) return -1;
+ CloseHandle(PI.hProcess);
+ CloseHandle(PI.hThread);
+ return 0;
+}
+
+/* END-OF-WIN32-SECTION */
+#endif
+
 #ifdef USE_COLLECT2
 int do_collecting = 1;
 #else
@@ -458,7 +515,11 @@
 #endif
 
   signal (signo, SIG_DFL);
+#ifndef __MINGW32__
   kill (getpid (), signo);
+#else
+  ExitProcess(signo);
+#endif
 }
 
 
@@ -2127,6 +2188,7 @@
   fflush (stderr);
 
   /* Spawn child nm on pipe */
+#ifndef __MINGW32__
   pid = vfork ();
   if (pid == -1)
     fatal_perror (VFORK_STRING);
@@ -2146,6 +2208,11 @@
       execv (nm_file_name, real_nm_argv);
       fatal_perror ("execvp %s", nm_file_name);
     }
+#else
+  if(vfork_execv(nm_file_name, real_nm_argv, pipe_fd[1])) {
+      fatal_perror ("vfork+execv %s", nm_file_name);
+  }
+#endif
 
   /* Parent context from here on.  */
   int_handler  = (void (*) PARAMS ((int))) signal (SIGINT,  SIG_IGN);
@@ -2569,6 +2636,7 @@
   fflush (stderr);
 
   /* Spawn child ldd on pipe */
+#ifndef __MINGW32__
   pid = vfork ();
   if (pid == -1)
     fatal_perror (VFORK_STRING);
@@ -2588,6 +2656,11 @@
       execv (ldd_file_name, real_ldd_argv);
       fatal_perror ("execv %s", ldd_file_name);
     }
+#else
+  if(vfork_execv(ldd_file_name, real_ldd_argv, pipe_fd[1])) {
+      fatal_perror ("vfork+execv %s", nm_file_name);
+  }
+#endif
 
   /* Parent context from here on.  */
   int_handler  = (void (*) PARAMS ((int))) signal (SIGINT,  SIG_IGN);


diff -ur gcc-3.2.3-orig/gcc/fixinc/mkfixinc.sh gcc-3.2.3/gcc/fixinc/mkfixinc.sh
--- gcc-3.2.3-orig/gcc/fixinc/mkfixinc.sh	Sat Jan  5 04:06:51 2002
+++ gcc-3.2.3/gcc/fixinc/mkfixinc.sh	Sat May 31 14:28:13 2008
@@ -80,6 +80,7 @@
     i?86-*-mingw32* | \
     i?86-*-uwin* | \
     mips-sgi-irix5cross64 | \
+    msp430-*-* | \
     powerpc-*-eabiaix* | \
     powerpc-*-eabisim* | \
     powerpc-*-eabi*    | \


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/