This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH for COLLECT2 (revised)


This is a new version of my collect2 patch. The only difference is this 
one can be applied to the current version of collect2.c and tlink.c 
instead of the 1.1 release version.

Here's my changelog again:

collect2.c: Define HAVE_SPAWNVP for MSDOS and Win32 ports.
            Define _P_WAIT if not already defined.
            Include sys/wait.h when HAVE_SYS_WAIT_H is defined.
            Declare returnCode when HAVE_SYS_WAIT_H is defined.
            (collect_wait) Use returnCode when appropriate.
            (collect_execute) Use _spawnvp when appropriate.
            (main) For DJGPP, set flags for system().

tlink.c: Declare fixup_dirsep.
         (read_repo_file) Call fixup_dirsep before setting f->dir when 
appropriate.
         (recompile_files) Send commands to system() one at a time 
when appropriate.

and here's the patches. Somehow my .gz decoder set the time stamp  
set to Nov. 29. Ignore that.


*** collect2.c.orig	Sun Nov 29 08:49:14 1998
--- collect2.c	Thu Oct 29 08:57:06 1998
***************
*** 30,41 ****
  #include <signal.h>
  #include <sys/stat.h>
  
  #define COLLECT
  
  #include "demangle.h"
  #include "obstack.h"
  #include "gansidecl.h"
! #ifdef __CYGWIN32__
  #include <process.h>
  #endif
  
--- 30,57 ----
  #include <signal.h>
  #include <sys/stat.h>
  
+ #if defined(__MSDOS__) || defined(__WIN32__) || 
defined(__DJGPP__)
+ #define HAVE_SPAWNVP
+ #ifndef _P_WAIT
+ #define _P_WAIT P_WAIT
+ #endif /* _P_WAIT */
+ #endif
+ 
+ #if defined(__DJGPP__)
+ #define _spawnvp spawnvp
+ #endif
+ 
+ #if defined(HAVE_SYS_WAIT_H)
+ /* Pull in definitions of WIFSIGNALED, WTERMSIG, etc. for DJGPP 
and possibly others */
+ #include <sys/wait.h>
+ #endif
+ 
  #define COLLECT
  
  #include "demangle.h"
  #include "obstack.h"
  #include "gansidecl.h"
! #if defined(__WIN32__) || defined(__DJGPP__)
  #include <process.h>
  #endif
  
***************
*** 47,52 ****
--- 63,72 ----
  #define vfork fork
  #endif
  
+ #ifdef HAVE_SPAWNVP
+ int	returnCode;
+ #endif
+ 
  #ifndef WIFSIGNALED
  #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
  #endif
***************
*** 995,1000 ****
--- 1015,1024 ----
    int first_file;
    int num_c_args	= argc+9;
  
+ #ifdef __DJGPP__
+   __system_flags |= (__system_allow_multiple_cmds | 
__system_emulate_chdir);
+ #endif
+ 
  #ifdef DEBUG
    debug = 1;
  #endif
***************
*** 1644,1650 ****
--- 1668,1678 ----
  {
    int status;
  
+ #ifdef HAVE_SPAWNVP
+   status=returnCode;
+ #else
    wait (&status);
+ #endif
    if (status)
      {
        if (WIFSIGNALED (status))
***************
*** 1713,1719 ****
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
! #ifndef __CYGWIN32__
    pid = vfork ();
    if (pid == -1)
      {
--- 1741,1747 ----
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
! #ifndef HAVE_SPAWNVP
    pid = vfork ();
    if (pid == -1)
      {
***************
*** 1739,1747 ****
        fatal_perror ("executing %s", prog);
      }
  #else
!   pid = _spawnvp (_P_NOWAIT, argv[0], argv);
!   if (pid == -1)
      fatal ("spawnvp failed");
  #endif
  }
  
--- 1767,1795 ----
        fatal_perror ("executing %s", prog);
      }
  #else
!   if (redir)
!   {
!     unlink (redir);
!     if (freopen (redir, "a", stdout) == NULL)
!       fatal_perror ("redirecting stdout: %s", redir);
!     if (freopen (redir, "a", stderr) == NULL)
!       fatal_perror ("redirecting stderr: %s", redir);
!   }
! 
!   returnCode = _spawnvp(_P_WAIT, argv[0], argv);
! 
!   if (redir)
!   {
!     /* Restore stdout and stderr to console */
!     if (freopen("CON", "a", stdout) == NULL)
!       fatal_perror("redirecting stdout: %s", "CON (console)");
!     if (freopen("CON", "a", stderr) == NULL)
!       fatal_perror ("redirecting stderr: %s", "CON (console)");
!   }
! 
!   if (returnCode == -1)
      fatal ("spawnvp failed");
+ 
  #endif
  }
  
*** tlink.c.orig	Sun Nov 29 08:50:02 1998
--- tlink.c	Thu Oct 29 09:05:28 1998
***************
*** 75,80 ****
--- 75,98 ----
  
  static struct hash_table symbol_table;
  
+ #if defined(__WIN32__) || (defined(__MSDOS__) && 
!defined(__DJGPP__))
+ #define FIXUP_DIRSEP
+ #define FIXUP_NO_MULTI_CMDS
+ 
+ char * fixup_dirsep(char *dir)
+ {
+   char *p = dir;
+   while (*p != '\0')
+   {
+     if (*p == '/')
+       *p = '\\';
+ 
+     p++;
+   }
+   return dir;
+ }
+ #endif
+ 
  static struct hash_entry *
  symbol_hash_newfunc (entry, table, string)
       struct hash_entry *entry;
***************
*** 380,386 ****
  	  f->args = pfgets (stream);
  	  break;
  	case 'D':
! 	  f->dir = pfgets (stream);
  	  break;
  	case 'M':
  	  f->main = pfgets (stream);
--- 398,408 ----
  	  f->args = pfgets (stream);
  	  break;
  	case 'D':
! #ifndef FIXUP_DIRSEP
!           f->dir = pfgets (stream);
! #else
!           f->dir = fixup_dirsep(pfgets (stream));
! #endif
  	  break;
  	case 'M':
  	  f->main = pfgets (stream);
***************
*** 450,455 ****
--- 472,478 ----
        fclose (output);
        rename (outname, f->root.string);
  
+ #ifndef FIXUP_NO_MULTI_CMDS
        obstack_grow (&temporary_obstack, "cd ", 3);
        obstack_grow (&temporary_obstack, f->dir, strlen (f->dir));
        obstack_grow (&temporary_obstack, "; ", 2);
***************
*** 458,463 ****
--- 481,505 ----
        obstack_grow (&temporary_obstack, f->args, strlen (f->args));
        obstack_1grow (&temporary_obstack, ' ');
        command = obstack_copy0 (&temporary_obstack, f->main, strlen 
(f->main));
+ #else
+       obstack_grow (&temporary_obstack, "cd ", 3);
+       obstack_grow (&temporary_obstack, f->dir, strlen (f->dir));
+       command = obstack_copy0 (&temporary_obstack, f->main, strlen 
(f->main));
+ 
+       if (tlink_verbose >= 3)
+ 	fprintf (stderr, "%s\n", command);
+ 
+       if (system (command) != 0)
+         return 0;
+ 
+       obstack_free (&temporary_obstack, temporary_firstobj);
+       obstack_grow (&temporary_obstack, c_file_name, strlen 
(c_file_name));
+       obstack_1grow (&temporary_obstack, ' ');
+       obstack_grow (&temporary_obstack, f->args, strlen (f->args));
+       obstack_1grow (&temporary_obstack, ' ');
+ 
+       command = obstack_copy0 (&temporary_obstack, f->main, strlen 
(f->main));
+ #endif
  
        if (tlink_verbose)
  	fprintf (stderr, "collect: recompiling %s\n", f->main);
***************
*** 465,471 ****
  	fprintf (stderr, "%s\n", command);
  
        if (system (command) != 0)
! 	return 0;
  
        read_repo_file (f);
  
--- 507,513 ----
  	fprintf (stderr, "%s\n", command);
  
        if (system (command) != 0)
!         return 0;
  
        read_repo_file (f);
  


-- 
Mark Elbrecht snowball3@usa.net
http://members.xoom.com/snowball3/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]