makefiles: Add support for building Unix .so libraries.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-05-14 14:03:40 +02:00
parent 469058acc1
commit b7e3c93159
1 changed files with 81 additions and 45 deletions

View File

@ -2144,13 +2144,14 @@ static int needs_delay_lib( const struct makefile *make )
/*******************************************************************
* add_default_libraries
*/
static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps,
int add_unix_libs )
{
struct strarray ret = empty_strarray;
struct strarray all_libs = empty_strarray;
unsigned int i, j;
if (!make->use_msvcrt)
if (add_unix_libs)
{
strarray_add( &all_libs, "-lwine_port" );
strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
@ -2189,10 +2190,11 @@ static struct strarray add_default_libraries( const struct makefile *make, struc
* add_import_libs
*/
static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
struct strarray imports, int delay )
struct strarray imports, int delay, int is_unix )
{
struct strarray ret = empty_strarray;
unsigned int i, j;
int is_cross = make->is_cross && !is_unix;
for (i = 0; i < imports.count; i++)
{
@ -2200,7 +2202,7 @@ static struct strarray add_import_libs( const struct makefile *make, struct stra
const char *lib = NULL;
/* skip module's own importlib, its object files will be linked directly */
if (make->importlib && !strcmp( make->importlib, imports.str[i] )) continue;
if (make->importlib && !is_unix && !strcmp( make->importlib, imports.str[i] )) continue;
for (j = 0; j < top_makefile->subdirs.count; j++)
{
@ -2208,7 +2210,7 @@ static struct strarray add_import_libs( const struct makefile *make, struct stra
if (submake->importlib && !strcmp( submake->importlib, name ))
{
if (make->is_cross || !*dll_ext || submake->staticimplib)
if (is_cross || !*dll_ext || submake->staticimplib)
lib = base_dir_path( submake, strmake( "lib%s.a", name ));
else
strarray_add( deps, top_obj_dir_path( make,
@ -2221,9 +2223,9 @@ static struct strarray add_import_libs( const struct makefile *make, struct stra
if (lib)
{
if (delay && !delay_load_flag && (make->is_cross || !*dll_ext))
if (delay && !delay_load_flag && (is_cross || !*dll_ext))
lib = replace_extension( lib, ".a", ".delay.a" );
else if (make->is_cross)
else if (is_cross)
lib = replace_extension( lib, ".a", ".cross.a" );
lib = top_obj_dir_path( make, lib );
strarray_add( deps, lib );
@ -2360,7 +2362,7 @@ static const char *get_debug_file( struct makefile *make, const char *name )
/*******************************************************************
* output_winegcc_command
*/
static void output_winegcc_command( struct makefile *make )
static void output_winegcc_command( struct makefile *make, int is_cross )
{
output( "\t%s -o $@", tools_path( make, "winegcc" ));
output_filename( "--wine-objdir" );
@ -2370,7 +2372,7 @@ static void output_winegcc_command( struct makefile *make )
output_filename( "--winebuild" );
output_filename( tools_path( make, "winebuild" ));
}
if (make->is_cross)
if (is_cross)
{
output_filename( "-b" );
output_filename( crosstarget );
@ -3019,8 +3021,8 @@ static void output_source_spec( struct makefile *make, struct incl_file *source,
if (!imports.count) imports = make->imports;
if (!dll_flags.count) dll_flags = make->extradllflags;
all_libs = add_import_libs( make, &dep_libs, imports, 0 );
add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
all_libs = add_import_libs( make, &dep_libs, imports, 0, 0 );
add_import_libs( make, &dep_libs, get_default_imports( make ), 0, 0 ); /* dependencies only */
dll_name = strmake( "%s.dll%s", obj, make->is_cross ? "" : dll_ext );
obj_name = strmake( "%s%s", obj_dir_path( make, obj ), make->is_cross ? ".cross.o" : ".o" );
output_file = obj_dir_path( make, dll_name );
@ -3038,7 +3040,7 @@ static void output_source_spec( struct makefile *make, struct incl_file *source,
output_filename( tools_path( make, "winebuild" ));
output_filename( tools_path( make, "winegcc" ));
output( "\n" );
output_winegcc_command( make );
output_winegcc_command( make, make->is_cross );
output_filename( "-s" );
output_filenames( dll_flags );
output_filename( "-shared" );
@ -3247,9 +3249,9 @@ static void output_module( struct makefile *make )
unsigned int i;
if (!make->is_exe) spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 1 ));
strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 1, 0 ));
strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0, 0 ));
add_import_libs( make, &dep_libs, get_default_imports( make ), 0, 0 ); /* dependencies only */
if (make->is_cross)
{
@ -3265,31 +3267,28 @@ static void output_module( struct makefile *make )
debug_file = get_debug_file( make, module_path );
output( "%s:", module_path );
}
else if (*dll_ext)
{
strarray_addall( &all_libs, add_default_libraries( make, &dep_libs, !make->use_msvcrt ));
for (i = 0; i < make->delayimports.count; i++)
strarray_add( &all_libs, strmake( "-Wl,-delayload,%s%s", make->delayimports.str[i],
strchr( make->delayimports.str[i], '.' ) ? "" : ".dll" ));
strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
strmake( "d$(dlldir)/fakedlls/%s", make->module ));
output( "%s%s %s.fake:", module_path, dll_ext, module_path );
}
else
{
strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
if (*dll_ext)
{
for (i = 0; i < make->delayimports.count; i++)
strarray_add( &all_libs, strmake( "-Wl,-delayload,%s%s", make->delayimports.str[i],
strchr( make->delayimports.str[i], '.' ) ? "" : ".dll" ));
strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
strmake( "d$(dlldir)/fakedlls/%s", make->module ));
output( "%s%s %s.fake:", module_path, dll_ext, module_path );
}
else
{
strarray_add( &make->all_targets, make->module );
add_install_rule( make, make->module, make->module,
strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
debug_file = get_debug_file( make, module_path );
output( "%s:", module_path );
}
strarray_addall( &all_libs, add_default_libraries( make, &dep_libs, 1 ));
strarray_add( &make->all_targets, make->module );
add_install_rule( make, make->module, make->module,
strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
debug_file = get_debug_file( make, module_path );
output( "%s:", module_path );
}
if (spec_file) output_filename( spec_file );
@ -3299,7 +3298,7 @@ static void output_module( struct makefile *make )
output_filename( tools_path( make, "winebuild" ));
output_filename( tools_path( make, "winegcc" ));
output( "\n" );
output_winegcc_command( make );
output_winegcc_command( make, make->is_cross );
if (make->is_cross) output_filename( "-Wl,--wine-builtin" );
if (spec_file)
{
@ -3314,6 +3313,43 @@ static void output_module( struct makefile *make )
output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
output( "\n" );
if (make->unixobj_files.count)
{
struct strarray unix_libs = empty_strarray;
struct strarray unix_deps = empty_strarray;
char *ext, *unix_lib = xmalloc( strlen( make->module ) + strlen( dll_ext ) + 1 );
strcpy( unix_lib, make->module );
if ((ext = get_extension( unix_lib ))) *ext = 0;
strcat( unix_lib, dll_ext );
if (make->importlib)
{
struct strarray imp = empty_strarray;
strarray_add( &imp, make->importlib );
strarray_addall( &unix_libs, add_import_libs( make, &unix_deps, imp, 1, 1 ));
}
strarray_addall( &unix_libs, add_import_libs( make, &unix_deps, make->delayimports, 1, 1 ));
strarray_addall( &unix_libs, add_import_libs( make, &unix_deps, make->imports, 0, 1 ));
add_import_libs( make, &unix_deps, get_default_imports( make ), 0, 1 ); /* dependencies only */
strarray_addall( &unix_libs, add_default_libraries( make, &unix_deps, 1 ));
strarray_add( &make->all_targets, unix_lib );
add_install_rule( make, make->module, unix_lib, strmake( "p$(dlldir)/%s", unix_lib ));
output( "%s:", unix_lib );
output_filenames_obj_dir( make, make->unixobj_files );
output_filenames( unix_deps );
output_filename( tools_path( make, "winebuild" ));
output_filename( tools_path( make, "winegcc" ));
output( "\n" );
output_winegcc_command( make, 0 );
output_filename( "-shared" );
if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) output_filename( "-nodefaultlibs" );
output_filenames_obj_dir( make, make->unixobj_files );
output_filenames( unix_libs );
output_filename( "$(LDFLAGS)" );
output( "\n" );
}
if (spec_file && make->importlib)
{
char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
@ -3435,7 +3471,7 @@ static void output_shared_lib( struct makefile *make )
strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
strarray_addall( &all_libs, add_default_libraries( make, &dep_libs, 1 ));
output( "%s:", obj_dir_path( make, make->sharedlib ));
output_filenames_obj_dir( make, make->object_files );
@ -3468,19 +3504,19 @@ static void output_test_module( struct makefile *make )
char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
struct strarray dep_libs = empty_strarray;
struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0, 0 );
struct makefile *parent = get_parent_makefile( make );
const char *ext = make->is_cross ? "" : dll_ext;
const char *parent_ext = parent && parent->is_cross ? "" : dll_ext;
const char *debug_file;
char *output_file;
add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
add_import_libs( make, &dep_libs, get_default_imports( make ), 0, 0 ); /* dependencies only */
strarray_add( &make->all_targets, strmake( "%s%s", testmodule, ext ));
strarray_add( &make->clean_files, strmake( "%s%s", stripped, ext ));
output_file = strmake( "%s%s", obj_dir_path( make, testmodule ), ext );
output( "%s:\n", output_file );
output_winegcc_command( make );
output_winegcc_command( make, make->is_cross );
output_filenames( make->extradllflags );
output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
output_filenames_obj_dir( make, make->res_files );
@ -3490,7 +3526,7 @@ static void output_test_module( struct makefile *make )
output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
output( "\n" );
output( "%s%s:\n", obj_dir_path( make, stripped ), ext );
output_winegcc_command( make );
output_winegcc_command( make, make->is_cross );
output_filename( "-s" );
output_filename( strmake( "-Wb,-F,%s", testmodule ));
output_filenames( make->extradllflags );
@ -3550,7 +3586,7 @@ static void output_programs( struct makefile *make )
if (!objs.count) objs = make->object_files;
if (!strarray_exists( &all_libs, "-nodefaultlibs" ))
strarray_addall( &all_libs, add_default_libraries( make, &deps ));
strarray_addall( &all_libs, add_default_libraries( make, &deps, 1 ));
output( "%s:", obj_dir_path( make, program ) );
output_filenames_obj_dir( make, objs );