Allow multiple -B options.
Do not pass the -Btools/winebuild magic option to the compiler to
avoid warnings.
Pass to the linker even the libraries we didn't find in the lib search
path, in case we are not using the standard paths.

diff --git a/tools/winegcc/utils.c b/tools/winegcc/utils.c
index bfb61de..246dc61 100644
--- a/tools/winegcc/utils.c
+++ b/tools/winegcc/utils.c
@@ -41,7 +41,7 @@
     va_list ap;
     
     va_start(ap, s);
-    fprintf(stderr, "Error: ");
+    fprintf(stderr, "winegcc: ");
     vfprintf(stderr, s, ap);
     fprintf(stderr, "\n");
     va_end(ap);
@@ -273,7 +273,7 @@
     return file_na;
 }
 
-void spawn(const char* prefix, const strarray* args)
+void spawn(const strarray* prefix, const strarray* args)
 {
     int i, status;
     strarray* arr = strarray_dup(args);
@@ -285,16 +285,23 @@
 
     if (prefix)
     {
-        const char* p;
-	struct stat st;
+        for (i = 0; i < prefix->size; i++)
+        {
+            const char* p;
+            struct stat st;
 
-	if (!(p = strrchr(argv[0], '/'))) p = argv[0];
-	prog = strmake("%s/%s", prefix, p);
-	if (stat(prog, &st) == 0)
-	{
-	    if ((st.st_mode & S_IFREG) && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
-		argv[0] = prog;
-	}
+            if (!(p = strrchr(argv[0], '/'))) p = argv[0];
+            free( prog );
+            prog = strmake("%s/%s", prefix->base[i], p);
+            if (stat(prog, &st) == 0)
+            {
+                if ((st.st_mode & S_IFREG) && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+                {
+                    argv[0] = prog;
+                    break;
+                }
+            }
+        }
     }
 
     if (verbose)
@@ -306,7 +313,7 @@
     if ((status = spawnvp( _P_WAIT, argv[0], argv)))
     {
 	if (status > 0) error("%s failed.", argv[0]);
-	else perror("Error:");
+	else perror("winegcc");
 	exit(3);
     }
 
diff --git a/tools/winegcc/utils.h b/tools/winegcc/utils.h
index 6727722..fe8af71 100644
--- a/tools/winegcc/utils.h
+++ b/tools/winegcc/utils.h
@@ -62,6 +62,6 @@
 void create_file(const char* name, int mode, const char* fmt, ...);
 file_type get_file_type(const char* filename);
 file_type get_lib_type(strarray* path, const char* library, char** file);
-void spawn(const char* prefix, const strarray* arr);
+void spawn(const strarray* prefix, const strarray* arr);
 
 extern int verbose;
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 0123417..d456f1c 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -161,8 +161,8 @@
     int gui_app;
     int compile_only;
     int wine_mode;
-    const char* prefix;
     const char* output_name;
+    strarray* prefix;
     strarray* lib_dirs;
     strarray* linker_args;
     strarray* compiler_args;
@@ -342,7 +342,7 @@
 
 static void build(struct options* opts)
 {
-    static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib" };
+    static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
     strarray *lib_dirs, *files;
     strarray *spec_args, *comp_args, *link_args;
     char *spec_c_name, *spec_o_name, *base_file, *base_name;
@@ -433,7 +433,9 @@
 		    strarray_add(files, strmake("-s%s", file + 2));
 		    break;
 	        default:
-		    fprintf(stderr, "Can't find library '%s', ignoring\n", file);
+                    /* keep it anyway, the linker may know what to do with it */
+                    strarray_add(files, file);
+                    break;
 	    }
 	    free(fullname);
 	}
@@ -527,6 +529,7 @@
 	const char* name = files->base[j] + 2;
 	switch(files->base[j][1])
 	{
+	    case 'l':
 	    case 's':
 		strarray_add(link_args, strmake("-l%s", name));
 		break;
@@ -720,28 +723,20 @@
 	    if (argv[i][1] == 'o')
 		raw_compiler_arg = raw_linker_arg = 0;
 
-	    /* put the arg into the appropriate bucket */
-	    if (raw_linker_arg) 
-	    {
-		strarray_add(opts.linker_args, argv[i]);
-		if (next_is_arg && (i + 1 < argc)) 
-		    strarray_add(opts.linker_args, argv[i + 1]);
-	    }
-	    if (raw_compiler_arg)
-	    {
-		strarray_add(opts.compiler_args, argv[i]);
-		if (next_is_arg && (i + 1 < argc))
-		    strarray_add(opts.compiler_args, argv[i + 1]);
-	    }
-
 	    /* do a bit of semantic analysis */
             switch (argv[i][1]) 
 	    {
 		case 'B':
 		    str = strdup(option_arg);
-		    if (strendswith(str, "/tools/winebuild")) opts.wine_mode = 1;
+		    if (strendswith(str, "/tools/winebuild"))
+                    {
+                        opts.wine_mode = 1;
+                        /* don't pass it to the compiler, this generates warnings */
+                        raw_compiler_arg = raw_linker_arg = 0;
+                    }
 		    if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
-		    opts.prefix = str;
+                    if (!opts.prefix) opts.prefix = strarray_alloc();
+                    strarray_add(opts.prefix, str);
 		    break;
                 case 'c':        /* compile or assemble */
 		    if (argv[i][2] == 0) opts.compile_only = 1;
@@ -810,6 +805,20 @@
                     break;
             }
 
+	    /* put the arg into the appropriate bucket */
+	    if (raw_linker_arg) 
+	    {
+		strarray_add(opts.linker_args, argv[i]);
+		if (next_is_arg && (i + 1 < argc)) 
+		    strarray_add(opts.linker_args, argv[i + 1]);
+	    }
+	    if (raw_compiler_arg)
+	    {
+		strarray_add(opts.compiler_args, argv[i]);
+		if (next_is_arg && (i + 1 < argc))
+		    strarray_add(opts.compiler_args, argv[i + 1]);
+	    }
+
 	    /* skip the next token if it's an argument */
 	    if (next_is_arg) i++;
         }