From: Jacek Caban jacek@codeweavers.com
--- tools/winegcc/winegcc.c | 76 ++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 35 deletions(-)
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 533fb3c519b..694242542ad 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -255,7 +255,7 @@ static const struct { "objcopy", "llvm-objcopy" }, };
-static struct strarray build_tool_name( struct options *opts, enum tool tool ) +static struct strarray build_tool_name( struct options *opts, const char *target, enum tool tool ) { const char *base = tool_names[tool].base; const char *llvm_base = tool_names[tool].llvm_base; @@ -264,13 +264,13 @@ static struct strarray build_tool_name( struct options *opts, enum tool tool ) struct strarray ret = empty_strarray; char* str;
- if (opts->target_alias && opts->version) + if (target && opts->version) { - str = strmake("%s-%s-%s", opts->target_alias, base, opts->version); + str = strmake( "%s-%s-%s", target, base, opts->version ); } - else if (opts->target_alias) + else if (target) { - str = strmake("%s-%s", opts->target_alias, base); + str = strmake( "%s-%s", target, base ); } else if (opts->version) { @@ -293,10 +293,10 @@ static struct strarray build_tool_name( struct options *opts, enum tool tool ) ret = strarray_fromstring( path, " " ); if (!strncmp( llvm_base, "clang", 5 )) { - if (opts->target_alias) + if (target) { strarray_add( &ret, "-target" ); - strarray_add( &ret, opts->target_alias ); + strarray_add( &ret, target ); } strarray_add( &ret, "-Wno-unused-command-line-argument" ); strarray_add( &ret, "-fuse-ld=lld" ); @@ -310,12 +310,12 @@ static struct strarray get_translator(struct options *opts) switch(opts->processor) { case proc_cpp: - return build_tool_name( opts, TOOL_CPP ); + return build_tool_name( opts, opts->target_alias, TOOL_CPP ); case proc_cc: case proc_as: - return build_tool_name( opts, TOOL_CC ); + return build_tool_name( opts, opts->target_alias, TOOL_CC ); case proc_cxx: - return build_tool_name( opts, TOOL_CXX ); + return build_tool_name( opts, opts->target_alias, TOOL_CXX ); } assert(0); return empty_strarray; @@ -635,8 +635,8 @@ static void compile(struct options* opts, const char* lang) /* mixing different C and C++ compilers isn't supported in configure anyway */ case proc_cc: case proc_cxx: - gcc = build_tool_name(opts, TOOL_CC); - gpp = build_tool_name(opts, TOOL_CXX); + gcc = build_tool_name( opts, opts->target_alias, TOOL_CC ); + gpp = build_tool_name( opts, opts->target_alias, TOOL_CXX ); for ( j = 0; !gcc_defs && j < comp_args.count; j++ ) { const char *cc = comp_args.str[j]; @@ -810,7 +810,7 @@ static const char* compile_to_object(struct options* opts, const char* file, con }
/* return the initial set of options needed to run winebuild */ -static struct strarray get_winebuild_args(struct options *opts) +static struct strarray get_winebuild_args( struct options *opts, const char *target ) { const char* winebuild = getenv("WINEBUILD"); const char *binary = NULL; @@ -831,10 +831,10 @@ static struct strarray get_winebuild_args(struct options *opts) strarray_add( &spec_args, binary ); if (verbose) strarray_add( &spec_args, "-v" ); if (keep_generated) strarray_add( &spec_args, "--save-temps" ); - if (opts->target_alias) + if (target) { strarray_add( &spec_args, "--target" ); - strarray_add( &spec_args, opts->target_alias ); + strarray_add( &spec_args, target ); } if (opts->force_pointer_size) strarray_add(&spec_args, strmake("-m%u", 8 * opts->force_pointer_size )); @@ -846,7 +846,7 @@ static struct strarray get_winebuild_args(struct options *opts)
static void fixup_constructors( struct options *opts, const char *file ) { - struct strarray args = get_winebuild_args( opts ); + struct strarray args = get_winebuild_args( opts, opts->target_alias );
strarray_add( &args, "--fixup-ctors" ); strarray_add( &args, file ); @@ -855,7 +855,7 @@ static void fixup_constructors( struct options *opts, const char *file )
static void make_wine_builtin( struct options *opts, const char *file ) { - struct strarray args = get_winebuild_args( opts ); + struct strarray args = get_winebuild_args( opts, opts->target_alias );
strarray_add( &args, "--builtin" ); strarray_add( &args, file ); @@ -943,23 +943,24 @@ static void add_library( struct options *opts, struct strarray lib_dirs, }
/* run winebuild to generate the .spec.o file */ -static const char *build_spec_obj( struct options *opts, const char *spec_file, const char *output_file, - struct strarray files, struct strarray lib_dirs, const char *entry_point ) +static void build_spec_obj( struct options *opts, const char *spec_file, const char *output_file, + const char *target, struct strarray files, struct strarray resources, + struct strarray lib_dirs, const char *entry_point, struct strarray *spec_objs ) { unsigned int i; int is_pe = is_pe_target( opts ); - struct strarray spec_args = get_winebuild_args( opts ); + struct strarray spec_args = get_winebuild_args( opts, target ); struct strarray tool; const char *spec_o_name, *output_name;
/* get the filename from the path */ output_name = get_basename( output_file );
- tool = build_tool_name( opts, TOOL_CC ); + tool = build_tool_name( opts, target, TOOL_CC ); strarray_add( &spec_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " ))); if (!is_pe) { - tool = build_tool_name( opts, TOOL_LD ); + tool = build_tool_name( opts, target, TOOL_LD ); strarray_add( &spec_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " ))); }
@@ -1021,9 +1022,7 @@ static const char *build_spec_obj( struct options *opts, const char *spec_file, strarray_add(&spec_args, strmake("-d%s", opts->delayimports.str[i])); }
- /* add resource files */ - for (i = 0; i < files.count; i++) - if (files.str[i][1] == 'r') strarray_add(&spec_args, files.str[i]); + strarray_addall( &spec_args, resources );
/* add other files */ strarray_add(&spec_args, "--"); @@ -1040,14 +1039,14 @@ static const char *build_spec_obj( struct options *opts, const char *spec_file, }
spawn(opts->prefix, spec_args, 0); - return spec_o_name; + strarray_add( spec_objs, spec_o_name ); }
/* run winebuild to generate a data-only library */ static void build_data_lib( struct options *opts, const char *spec_file, const char *output_file, struct strarray files ) { unsigned int i; - struct strarray spec_args = get_winebuild_args( opts ); + struct strarray spec_args = get_winebuild_args( opts, opts->target_alias );
strarray_add(&spec_args, opts->shared ? "--dll" : "--exe"); strarray_add(&spec_args, "-o"); @@ -1067,16 +1066,18 @@ static void build_data_lib( struct options *opts, const char *spec_file, const c
static void build(struct options* opts) { + struct strarray resources = empty_strarray; + struct strarray spec_objs = empty_strarray; struct strarray lib_dirs = empty_strarray; struct strarray files = empty_strarray; struct strarray link_args; char *output_file, *output_path; - const char *spec_o_name = NULL, *libgcc = NULL; const char *output_name, *spec_file, *lang; + const char *libgcc = NULL; int generate_app_loader = 1; const char *crt_lib = NULL, *entry_point = NULL; int is_pe = is_pe_target( opts ); - unsigned int j; + unsigned int i, j;
/* NOTE: for the files array we'll use the following convention: * -axxx: xxx is an archive (.a) @@ -1225,7 +1226,12 @@ static void build(struct options* opts) build_data_lib( opts, spec_file, output_file, files ); return; } - spec_o_name = build_spec_obj( opts, spec_file, output_file, files, lib_dirs, entry_point ); + + for (i = 0; i < files.count; i++) + if (files.str[i][1] == 'r') strarray_add( &resources, files.str[i] ); + + build_spec_obj( opts, spec_file, output_file, opts->target_alias, files, resources, lib_dirs, + entry_point, &spec_objs );
if (opts->fake_module) return; /* nothing else to do */
@@ -1265,7 +1271,7 @@ static void build(struct options* opts) entry_point)); }
- if (spec_o_name) strarray_add(&link_args, spec_o_name); + strarray_addall( &link_args, spec_objs );
if (is_pe) { @@ -1341,7 +1347,7 @@ static void build(struct options* opts)
if (opts->debug_file && !strendswith(opts->debug_file, ".pdb")) { - struct strarray tool, objcopy = build_tool_name(opts, TOOL_OBJCOPY); + struct strarray tool, objcopy = build_tool_name(opts, opts->target_alias, TOOL_OBJCOPY);
tool = empty_strarray; strarray_addall( &tool, objcopy ); @@ -1371,10 +1377,10 @@ static void build(struct options* opts) if (!spec_file) error("--out-implib requires a .spec or .def file\n");
- implib_args = get_winebuild_args( opts ); - tool = build_tool_name( opts, TOOL_CC ); + implib_args = get_winebuild_args( opts, opts->target_alias ); + tool = build_tool_name( opts, opts->target_alias, TOOL_CC ); strarray_add( &implib_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " ))); - tool = build_tool_name( opts, TOOL_LD ); + tool = build_tool_name( opts, opts->target_alias, TOOL_LD ); strarray_add( &implib_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " )));
strarray_add(&implib_args, "--implib");