diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h index 4fb6e23700e..104c77db593 100644 --- a/tools/winebuild/build.h +++ b/tools/winebuild/build.h @@ -264,6 +264,7 @@ extern void output_rva( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2))); extern void spawn( struct strarray array ); extern struct strarray find_tool( const char *name, const char * const *names ); +extern struct strarray find_link_tool(void); extern struct strarray get_as_command(void); extern struct strarray get_ld_command(void); extern const char *get_nm_command(void); diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c index 827a875e5df..3c2547c5584 100644 --- a/tools/winebuild/import.c +++ b/tools/winebuild/import.c @@ -1838,23 +1838,36 @@ static void assemble_files( const char *prefix ) } /* build a library from the current asm files and any additional object files in argv */ -static void build_library( const char *output_name, char **argv, int create ) +static void build_library( const char *output_name, char **argv, const char *importlib ) { - struct strarray args = find_tool( "ar", NULL ); - struct strarray ranlib = find_tool( "ranlib", NULL ); + int create = !importlib || importlib != output_name; + struct strarray args; - strarray_add( &args, create ? "rc" : "r", output_name, NULL ); + if (target_platform != PLATFORM_WINDOWS) + { + args = find_tool( "ar", NULL ); + strarray_add( &args, create ? "rc" : "r", output_name, importlib, NULL ); + } + else + { + args = find_link_tool(); + strarray_add( &args, "/lib", strmake( "-out:%s", output_name ), importlib, NULL ); + } strarray_addall( &args, as_files ); strarray_addv( &args, argv ); if (create) unlink( output_name ); spawn( args ); - strarray_add( &ranlib, output_name, NULL ); - spawn( ranlib ); + if (target_platform != PLATFORM_WINDOWS) + { + struct strarray ranlib = find_tool( "ranlib", NULL ); + strarray_add( &ranlib, output_name, NULL ); + spawn( ranlib ); + } } /* create a Windows-style import library */ -static void build_windows_import_lib( DLLSPEC *spec ) +static void build_windows_import_lib( const char *lib_name, DLLSPEC *spec ) { struct strarray args; char *def_file; @@ -1887,8 +1900,9 @@ static void build_windows_import_lib( DLLSPEC *spec ) m_flag = NULL; break; } - strarray_add( &args, "-k", strendswith( output_file_name, ".delay.a" ) ? "-y" : "-l", - output_file_name, "-d", def_file, NULL ); + + strarray_add( &args, "-k", strendswith( lib_name, ".delay.a" ) ? "-y" : "-l", + lib_name, "-d", def_file, NULL ); if (m_flag) strarray_add( &args, "-m", m_flag, as_flags, NULL ); spawn( args ); @@ -1960,12 +1974,19 @@ void output_static_lib( DLLSPEC *spec, char **argv ) { if (is_pe()) { - if (spec) build_windows_import_lib( spec ); - if (argv[0] || !spec) build_library( output_file_name, argv, !spec ); + const char *importlib = NULL; + if (spec) + { + importlib = (argv[0] && target_platform == PLATFORM_WINDOWS) + ? get_temp_file_name( output_file_name, ".a" ) + : output_file_name; + build_windows_import_lib( importlib, spec ); + } + if (argv[0] || !spec) build_library( output_file_name, argv, importlib ); } else { if (spec) build_unix_import_lib( spec ); - build_library( output_file_name, argv, 1 ); + build_library( output_file_name, argv, NULL ); } } diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c index 928a2460aa1..411a53c7133 100644 --- a/tools/winebuild/utils.c +++ b/tools/winebuild/utils.c @@ -387,6 +387,17 @@ struct strarray find_tool( const char *name, const char * const *names ) fatal_error( "cannot find the '%s' tool\n", name ); } +/* find a link tool in the path */ +struct strarray find_link_tool(void) +{ + struct strarray ret = empty_strarray; + const char *file; + if (!(file = find_binary( NULL, "lld-link" ))) + fatal_error( "cannot find the 'lld-link tool\n" ); + strarray_add_one( &ret, file ); + return ret; +} + struct strarray get_as_command(void) { struct strarray args;