winegcc: proper -x <lang> support [take 2]

Dimitrie O. Paun dpaun at rogers.com
Thu Apr 15 23:36:40 CDT 2004


This should also fix the .spec.c compilation when
-x c++ is used, and should work on non-gcc compilers
as well.

ChangeLog
   Add proper -x <lang> support to winegcc.

Index: tools/winegcc/winegcc.c
===================================================================
RCS file: /var/cvs/wine/tools/winegcc/winegcc.c,v
retrieving revision 1.25
diff -u -r1.25 winegcc.c
--- tools/winegcc/winegcc.c	9 Apr 2004 19:02:18 -0000	1.25
+++ tools/winegcc/winegcc.c	16 Apr 2004 04:33:36 -0000
@@ -152,7 +152,7 @@
 
 struct options 
 {
-    enum { proc_cc = 0, proc_cxx = 1, proc_cpp = 2} processor;
+    enum processor_t { proc_cc = 0, proc_cxx = 1, proc_cpp = 2} processor;
     int shared;
     int use_msvcrt;
     int nostdinc;
@@ -220,7 +220,7 @@
     error("Unknown processor");
 }
 
-static void compile(struct options* opts)
+static void compile(struct options* opts, const char* lang)
 {
     strarray* comp_args = strarray_alloc();
     int j, gcc_defs = 0;
@@ -313,14 +313,21 @@
     for ( j = 0 ; j < opts->compiler_args->size ; j++ ) 
         strarray_add(comp_args, opts->compiler_args->base[j]);
 
+    /* the language option, if any */
+    if (lang && strcmp(lang, "-xnone"))
+	strarray_add(comp_args, lang);
+
     /* last, but not least, the files */
     for ( j = 0; j < opts->files->size; j++ )
-	strarray_add(comp_args, opts->files->base[j]);
+    {
+	if (opts->files->base[j][0] != '-')
+	    strarray_add(comp_args, opts->files->base[j]);
+    }
 
     spawn(opts->prefix, comp_args);
 }
 
-static const char* compile_to_object(struct options* opts, const char* file)
+static const char* compile_to_object(struct options* opts, const char* file, const char* lang)
 {
     struct options copts;
     char* base_name;
@@ -329,12 +336,11 @@
     /* a shallow copy is exactly what we want in this case */
     base_name = get_basename(file);
     copts = *opts;
-    copts.processor = proc_cc;
     copts.output_name = get_temp_file(base_name, ".o");
     copts.compile_only = 1;
     copts.files = strarray_alloc();
     strarray_add(copts.files, file);
-    compile(&copts);
+    compile(&copts, lang);
     strarray_free(copts.files);
     free(base_name);
 
@@ -345,12 +351,13 @@
 {
     static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
     strarray *lib_dirs, *files;
-    strarray *spec_args, *comp_args, *link_args;
+    strarray *spec_args, *link_args;
     char *output_file;
     const char *spec_c_name, *spec_o_name;
-    const char *output_name, *spec_file;
+    const char *output_name, *spec_file, *lang;
     const char* winebuild = getenv("WINEBUILD");
     int generate_app_loader = 1;
+    enum processor_t temp_proc;
     int j;
 
     /* NOTE: for the files array we'll use the following convention:
@@ -360,6 +367,7 @@
      *    -oxxx:  xxx is an object (.o)
      *    -rxxx:  xxx is a resource (.res)
      *    -sxxx:  xxx is a shared lib (.so)
+     *    -xlll:  lll is the language (c, c++, etc.)
      */
 
     if (!winebuild) winebuild = "winebuild";
@@ -403,7 +411,7 @@
     }
 
     /* mark the files with their appropriate type */
-    spec_file = 0;
+    spec_file = lang = 0;
     files = strarray_alloc();
     for ( j = 0; j < opts->files->size; j++ )
     {
@@ -440,7 +448,7 @@
 		    error("File does not exist: %s", file);
 		    break;
 	        default:
-		    file = compile_to_object(opts, file);
+		    file = compile_to_object(opts, file, lang);
 		    strarray_add(files, strmake("-o%s", file));
 		    break;
 	    }
@@ -466,6 +474,8 @@
 	    }
 	    free(fullname);
 	}
+	else if (file[1] == 'x')
+	    lang = file;
     }
     if (opts->shared && !spec_file)
 	error("A spec file is currently needed in shared mode");
@@ -535,8 +545,10 @@
     spawn(opts->prefix, spec_args);
 
     /* compile the .spec.c file into a .spec.o file */
-    comp_args = strarray_alloc();
-    spec_o_name = compile_to_object(opts, spec_c_name);
+    temp_proc = opts->processor;
+    opts->processor = proc_cc;   /* we must use the C compiler */
+    spec_o_name = compile_to_object(opts, spec_c_name, 0);
+    opts->processor = temp_proc;
     
     /* link everything together now */
     link_args = strarray_alloc();
@@ -678,6 +690,7 @@
     int raw_compiler_arg, raw_linker_arg;
     const char* option_arg;
     struct options opts;
+    char* lang = 0;
     char* str;
 
     /* setup tmp file removal at exit */
@@ -839,6 +852,12 @@
                         raw_compiler_arg = raw_linker_arg = 0;
 		    }
                     break;
+		case 'x':
+		    lang = strmake("-x%s", option_arg);
+		    strarray_add(opts.files, lang);
+		    /* we'll pass these flags ourselves, explicitely */
+                    raw_compiler_arg = raw_linker_arg = 0;
+		    break;
                 case '-':
                     if (strcmp("-static", argv[i]+1) == 0)
                         linking = -1;
@@ -873,7 +892,7 @@
 
     if (opts.files->size == 0) forward(argc, argv, &opts);
     else if (linking) build(&opts);
-    else compile(&opts);
+    else compile(&opts, lang);
 
     return 0;
 }


-- 
Dimi.




More information about the wine-patches mailing list