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]

[rfa] Keep -B... in order


Hello,

gcc.c carefully reverses the order of the -B options.  I think this is
wrong.  The attatched patch ensures that:

	-B/path/1/ -B/path/2/

is searched in the order that it is specified.  This ``bug'' really
hurts when building gcc -  ``xgcc -B/build/dir -B/dest/dir'' is run. 
Unfortunatly, the reverse causes a previously installed gas/ld/cc1/.. to
be used instead of the one just built :-(

Output from the above (fixed) is:

...
GNU CPP version 2.96 20000724 (experimental) (cpplib)
 (i386 FreeBSD/ELF)
ignoring nonexistent directory "/path/1/include"
ignoring nonexistent directory "/path/2/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/cygnus/H-i386-unknown-freebsd3.4/T-i386-unknown-freebsd3.4/B-ALL/include

/usr/cygnus/H-i386-unknown-freebsd3.4/T-i386-unknown-freebsd3.4/B-ALL/lib/gcc-lib/i386-unknown-freebsd3.4/2.96/include

/usr/cygnus/H-i386-unknown-freebsd3.4/T-i386-unknown-freebsd3.4/B-ALL/i386-unknown-freebsd3.4/include
 /usr/include
End of search list.
...
gcc: file path prefix `/path/1/' never used


I should note that, GCC.c at present only prints out the first unused
path.  I think it was ment to print all unused paths once.  I suspect
that this is another ``feature'' - would you like a patch for that as
well?

enjoy,
	Andrew
Mon Jul 24 13:37:18 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* gcc.c (struct prefix_list): Add member priority.
	(enum path_prefix_priority): Declare.
	(add_prefix): Replace ``first'' with ``priority''.  Append new
 	entry but keep list in priority order.
	(process_command): Update.  Pass PREFIX_PRIORITY_B_OPT or
 	PREFIX_PRIORITY_LAST to add_prefix.
	(process_command): Move include kludge - foo/stageN - to before
 	foo/include.

*** old-gcc.c	Tue Jul 25 15:43:05 2000
--- gcc.c	Tue Jul 25 16:31:35 2000
***************
*** 1266,1271 ****
--- 1266,1272 ----
    int require_machine_suffix; /* Don't use without machine_suffix.  */
    /* 2 means try both machine_suffix and just_machine_suffix.  */
    int *used_flag_ptr;	      /* 1 if a file was found with this prefix.  */
+   int priority;		      /* Sort key - priority within list */
  };
  
  struct path_prefix
***************
*** 2335,2342 ****
    return 0;
  }
  
! /* Add an entry for PREFIX in PLIST.  If FIRST is set, it goes
!    at the start of the list, otherwise it goes at the end.
  
     If WARN is nonzero, we will warn if no file is found
     through this prefix.  WARN should point to an int
--- 2336,2353 ----
    return 0;
  }
  
! /* Ranking of prefixes in the sort list. -B prefixes are put before
!    all others. */
! 
! enum path_prefix_priority
! {
!   PREFIX_PRIORITY_B_OPT,
!   PREFIX_PRIORITY_LAST
! };
! 
! /* Add an entry for PREFIX in PLIST.  The PLIST is kept in assending
!    order according to PRIORITY.  Within each PRIORITY, new entries are
!    appended.
  
     If WARN is nonzero, we will warn if no file is found
     through this prefix.  WARN should point to an int
***************
*** 2349,2373 ****
     2 means try both machine_suffix and just_machine_suffix.  */
  
  static void
! add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
       struct path_prefix *pprefix;
       const char *prefix;
       const char *component;
!      int first;
       int require_machine_suffix;
       int *warn;
  {
    struct prefix_list *pl, **prev;
    int len;
  
!   if (! first && pprefix->plist)
!     {
!       for (pl = pprefix->plist; pl->next; pl = pl->next)
! 	;
!       prev = &pl->next;
!     }
!   else
!     prev = &pprefix->plist;
  
    /* Keep track of the longest prefix */
  
--- 2360,2380 ----
     2 means try both machine_suffix and just_machine_suffix.  */
  
  static void
! add_prefix (pprefix, prefix, component, priority, require_machine_suffix, warn)
       struct path_prefix *pprefix;
       const char *prefix;
       const char *component;
!      /* enum prefix_priority */ int priority;
       int require_machine_suffix;
       int *warn;
  {
    struct prefix_list *pl, **prev;
    int len;
  
!   for (prev = &pprefix->plist;
!        (*prev) != NULL && (*prev)->priority <= priority;
!        prev = &(*prev)->next)
!     ;
  
    /* Keep track of the longest prefix */
  
***************
*** 2380,2393 ****
    pl->prefix = save_string (prefix, len);
    pl->require_machine_suffix = require_machine_suffix;
    pl->used_flag_ptr = warn;
    if (warn)
      *warn = 0;
  
!   if (*prev)
!     pl->next = *prev;
!   else
!     pl->next = (struct prefix_list *) 0;
!   *prev = pl;
  }
  
  /* Print warnings for any prefixes in the list PPREFIX that were not used.  */
--- 2387,2399 ----
    pl->prefix = save_string (prefix, len);
    pl->require_machine_suffix = require_machine_suffix;
    pl->used_flag_ptr = warn;
+   pl->priority = priority;
    if (warn)
      *warn = 0;
  
!   /* Insert after PREV */
!   pl->next = (*prev);
!   (*prev) = pl;
  }
  
  /* Print warnings for any prefixes in the list PPREFIX that were not used.  */
***************
*** 2913,2920 ****
  	}
  
        set_std_prefix (gcc_exec_prefix, len);
!       add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
!       add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
      }
  
    /* COMPILER_PATH and LIBRARY_PATH have values
--- 2919,2928 ----
  	}
  
        set_std_prefix (gcc_exec_prefix, len);
!       add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC",
! 		  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
!       add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
! 		  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
      }
  
    /* COMPILER_PATH and LIBRARY_PATH have values
***************
*** 2941,2950 ****
  		}
  	      else
  		nstore[endp-startp] = 0;
! 	      add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
  	      add_prefix (&include_prefixes,
  			  concat (nstore, "include", NULL_PTR),
! 			  0, 0, 0, NULL_PTR);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
--- 2949,2959 ----
  		}
  	      else
  		nstore[endp-startp] = 0;
! 	      add_prefix (&exec_prefixes, nstore, 0,
! 			  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	      add_prefix (&include_prefixes,
  			  concat (nstore, "include", NULL_PTR),
! 			  0, PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
***************
*** 2976,2982 ****
  	      else
  		nstore[endp-startp] = 0;
  	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
! 			  0, 0, NULL_PTR);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
--- 2985,2991 ----
  	      else
  		nstore[endp-startp] = 0;
  	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
! 			  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
***************
*** 3009,3015 ****
  	      else
  		nstore[endp-startp] = 0;
  	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
! 			  0, 0, NULL_PTR);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
--- 3018,3024 ----
  	      else
  		nstore[endp-startp] = 0;
  	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
! 			  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
***************
*** 3200,3215 ****
  		  value = argv[++i];
  		else
  		  value = p + 1;
- 		add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
- 		add_prefix (&startfile_prefixes, value, NULL_PTR,
- 			    1, 0, &warn_B);
- 		add_prefix (&include_prefixes, concat (value, "include",
- 						       NULL_PTR),
- 			    NULL_PTR, 1, 0, NULL_PTR);
- 
- 		/* As a kludge, if the arg is "[foo/]stageN/", just add
- 		   "[foo/]include" to the include prefix.  */
  		{
  		  int len = strlen (value);
  		  if ((len == 7
  		       || (len > 7
--- 3209,3217 ----
  		  value = argv[++i];
  		else
  		  value = p + 1;
  		{
+ 		  /* As a kludge, if the arg is "[foo/]stageN/", just
+ 		     add "[foo/]include" to the include prefix.  */
  		  int len = strlen (value);
  		  if ((len == 7
  		       || (len > 7
***************
*** 3220,3236 ****
  		    {
  		      if (len == 7)
  			add_prefix (&include_prefixes, "include", NULL_PTR,
! 				    1, 0, NULL_PTR);
  		      else
  			{
  			  char *string = xmalloc (len + 1);
  			  strncpy (string, value, len-7);
  			  strcpy (string+len-7, "include");
  			  add_prefix (&include_prefixes, string, NULL_PTR,
! 				      1, 0, NULL_PTR);
  			}
  		    }
  		}
                  n_switches++;
  	      }
  	      break;
--- 3222,3246 ----
  		    {
  		      if (len == 7)
  			add_prefix (&include_prefixes, "include", NULL_PTR,
! 				    PREFIX_PRIORITY_B_OPT, 0, NULL_PTR);
  		      else
  			{
  			  char *string = xmalloc (len + 1);
  			  strncpy (string, value, len-7);
  			  strcpy (string+len-7, "include");
  			  add_prefix (&include_prefixes, string, NULL_PTR,
! 				      PREFIX_PRIORITY_B_OPT, 0, NULL_PTR);
  			}
  		    }
  		}
+ 		add_prefix (&exec_prefixes, value, NULL_PTR,
+ 			    PREFIX_PRIORITY_B_OPT, 0, &warn_B);
+ 		add_prefix (&startfile_prefixes, value, NULL_PTR,
+ 			    PREFIX_PRIORITY_B_OPT, 0, &warn_B);
+ 		add_prefix (&include_prefixes, concat (value, "include",
+ 						       NULL_PTR),
+ 			    NULL_PTR,
+ 			    PREFIX_PRIORITY_B_OPT, 0, NULL_PTR);
                  n_switches++;
  	      }
  	      break;
***************
*** 3363,3379 ****
       as well as trying the machine and the version.  */
  #ifndef OS2
    add_prefix (&exec_prefixes, standard_exec_prefix, "GCC",
! 	      0, 1, warn_std_ptr);
    add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
! 	      0, 2, warn_std_ptr);
    add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
! 	      0, 2, warn_std_ptr);
  #endif
  
    add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
! 	      0, 1, warn_std_ptr);
    add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
! 	      0, 1, warn_std_ptr);
  
    tooldir_prefix = concat (tooldir_base_prefix, spec_machine, 
  			   dir_separator_str, NULL_PTR);
--- 3373,3389 ----
       as well as trying the machine and the version.  */
  #ifndef OS2
    add_prefix (&exec_prefixes, standard_exec_prefix, "GCC",
! 	      PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
    add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
! 	      PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
    add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
! 	      PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
  #endif
  
    add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
! 	      PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
    add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
! 	      PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
  
    tooldir_prefix = concat (tooldir_base_prefix, spec_machine, 
  			   dir_separator_str, NULL_PTR);
***************
*** 3396,3406 ****
  	  add_prefix (&exec_prefixes,
  		      concat (gcc_exec_tooldir_prefix, "bin", 
  			      dir_separator_str, NULL_PTR),
! 		      NULL_PTR, 0, 0, NULL_PTR);
  	  add_prefix (&startfile_prefixes,
  		      concat (gcc_exec_tooldir_prefix, "lib", 
  			      dir_separator_str, NULL_PTR),
! 		      NULL_PTR, 0, 0, NULL_PTR);
  	}
  
        tooldir_prefix = concat (standard_exec_prefix, spec_machine,
--- 3406,3416 ----
  	  add_prefix (&exec_prefixes,
  		      concat (gcc_exec_tooldir_prefix, "bin", 
  			      dir_separator_str, NULL_PTR),
! 		      NULL_PTR, PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	  add_prefix (&startfile_prefixes,
  		      concat (gcc_exec_tooldir_prefix, "lib", 
  			      dir_separator_str, NULL_PTR),
! 		      NULL_PTR, PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	}
  
        tooldir_prefix = concat (standard_exec_prefix, spec_machine,
***************
*** 3410,3419 ****
  
    add_prefix (&exec_prefixes, 
                concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
! 	      "BINUTILS", 0, 0, NULL_PTR);
    add_prefix (&startfile_prefixes,
  	      concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
! 	      "BINUTILS", 0, 0, NULL_PTR);
  
    /* More prefixes are enabled in main, after we read the specs file
       and determine whether this is cross-compilation or not.  */
--- 3420,3429 ----
  
    add_prefix (&exec_prefixes, 
                concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
! 	      "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL_PTR);
    add_prefix (&startfile_prefixes,
  	      concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
! 	      "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  
    /* More prefixes are enabled in main, after we read the specs file
       and determine whether this is cross-compilation or not.  */
***************
*** 5275,5292 ****
    if (*cross_compile == '0')
      {
  #ifdef MD_EXEC_PREFIX
!       add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
!       add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
  #endif
  
  #ifdef MD_STARTFILE_PREFIX
        add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
! 		  0, 0, NULL_PTR);
  #endif
  
  #ifdef MD_STARTFILE_PREFIX_1
        add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
! 		  0, 0, NULL_PTR);
  #endif
  
        /* If standard_startfile_prefix is relative, base it on
--- 5285,5304 ----
    if (*cross_compile == '0')
      {
  #ifdef MD_EXEC_PREFIX
!       add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
! 		  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
!       add_prefix (&startfile_prefixes, md_exec_prefix, "GCC",
! 		  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  #endif
  
  #ifdef MD_STARTFILE_PREFIX
        add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
! 		  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  #endif
  
  #ifdef MD_STARTFILE_PREFIX_1
        add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
! 		  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  #endif
  
        /* If standard_startfile_prefix is relative, base it on
***************
*** 5302,5328 ****
  #endif
  	  )
  	add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
! 		    0, 0, NULL_PTR);
        else
  	{
  	  if (gcc_exec_prefix)
  	    add_prefix (&startfile_prefixes,
  			concat (gcc_exec_prefix, machine_suffix,
  				standard_startfile_prefix, NULL_PTR),
! 			NULL_PTR, 0, 0, NULL_PTR);
  	  add_prefix (&startfile_prefixes,
  		      concat (standard_exec_prefix,
  			      machine_suffix,
  			      standard_startfile_prefix, NULL_PTR),
! 		      NULL_PTR, 0, 0, NULL_PTR);
  	}		       
  
        add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
! 		  "BINUTILS", 0, 0, NULL_PTR);
        add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
! 		  "BINUTILS", 0, 0, NULL_PTR);
  #if 0 /* Can cause surprises, and one can use -B./ instead.  */
!       add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
  #endif
      }
    else
--- 5314,5341 ----
  #endif
  	  )
  	add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
! 		    PREFIX_PRIORITY_LAST, 0, NULL_PTR);
        else
  	{
  	  if (gcc_exec_prefix)
  	    add_prefix (&startfile_prefixes,
  			concat (gcc_exec_prefix, machine_suffix,
  				standard_startfile_prefix, NULL_PTR),
! 			NULL_PTR, PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	  add_prefix (&startfile_prefixes,
  		      concat (standard_exec_prefix,
  			      machine_suffix,
  			      standard_startfile_prefix, NULL_PTR),
! 		      NULL_PTR, PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  	}		       
  
        add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
! 		  "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL_PTR);
        add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
! 		  "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL_PTR);
  #if 0 /* Can cause surprises, and one can use -B./ instead.  */
!       add_prefix (&startfile_prefixes, "./", NULL_PTR,
! 		  PREFIX_PRIORITY_LAST, 1, NULL_PTR);
  #endif
      }
    else
***************
*** 5331,5337 ****
  	add_prefix (&startfile_prefixes,
  		    concat (gcc_exec_prefix, machine_suffix,
  			    standard_startfile_prefix, NULL_PTR),
! 		    "BINUTILS", 0, 0, NULL_PTR);
      }
  
    /* Process any user specified specs in the order given on the command
--- 5344,5350 ----
  	add_prefix (&startfile_prefixes,
  		    concat (gcc_exec_prefix, machine_suffix,
  			    standard_startfile_prefix, NULL_PTR),
! 		    "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL_PTR);
      }
  
    /* Process any user specified specs in the order given on the command

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