From: Jacek Caban Subject: [PATCH 3/4 v2] makedep: Use winegcc -delayload option for delay imports. Message-Id: <13114227-347b-a5d5-9dbe-f94a8920a589@codeweavers.com> Date: Mon, 7 Oct 2019 19:00:04 +0200 Signed-off-by: Jacek Caban --- v2: Fixed a typo, thanks Sven. dlls/setupapi/Makefile.in | 2 +- tools/makedep.c | 120 +++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 69 deletions(-) diff --git a/dlls/setupapi/Makefile.in b/dlls/setupapi/Makefile.in index ae9bf3dce6..6c31365546 100644 --- a/dlls/setupapi/Makefile.in +++ b/dlls/setupapi/Makefile.in @@ -2,7 +2,7 @@ EXTRADEFS = -D_SETUPAPI_ MODULE = setupapi.dll IMPORTLIB = setupapi IMPORTS = uuid version advapi32 rpcrt4 -DELAYIMPORTS = shell32 wintrust ole32 winspool comdlg32 user32 +DELAYIMPORTS = shell32 wintrust ole32 winspool.drv comdlg32 user32 EXTRADLLFLAGS = -mno-cygwin diff --git a/tools/makedep.c b/tools/makedep.c index 67dfea43bb..a5f9f9a4ea 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -2092,6 +2092,17 @@ static struct makefile *get_parent_makefile( struct makefile *make ) } +/******************************************************************* + * needs_delay_lib + */ +static int needs_delay_lib( const struct makefile *make ) +{ + if (*dll_ext && !crosstarget) return 0; + if (!make->importlib) return 0; + return strarray_exists( &delay_import_libs, make->importlib ); +} + + /******************************************************************* * needs_cross_lib */ @@ -2105,18 +2116,7 @@ static int needs_cross_lib( const struct makefile *make ) if (!strncmp( name, "lib", 3 )) name += 3; return strarray_exists( &cross_import_libs, name ); } - return 0; -} - - -/******************************************************************* - * needs_delay_lib - */ -static int needs_delay_lib( const struct makefile *make ) -{ - if (*dll_ext && !crosstarget) return 0; - if (!make->importlib) return 0; - return strarray_exists( &delay_import_libs, make->importlib ); + return needs_delay_lib( make ); } @@ -2181,11 +2181,11 @@ 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 (!delay && (make->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, - strmake( "%s/lib%s.def", submake->base_dir, name ))); + strmake( "%s/lib%s.def", submake->base_dir, name ))); break; } @@ -2194,13 +2194,17 @@ static struct strarray add_import_libs( const struct makefile *make, struct stra if (lib) { - if (delay) lib = replace_extension( lib, ".a", ".delay.a" ); - else if (make->is_cross) lib = replace_extension( lib, ".a", ".cross.a" ); + if (make->is_cross) lib = replace_extension( lib, ".a", ".cross.a" ); lib = top_obj_dir_path( make, lib ); strarray_add( deps, lib ); strarray_add( &ret, lib ); } - else strarray_add( &ret, strmake( "-l%s", name )); + else + { + char *arg = strmake( "-l%s", name ), *p; + if ((p = strchr( arg, '.' ))) *p = 0; + strarray_add( &ret, arg ); + } } return ret; } @@ -2542,7 +2546,6 @@ static struct strarray output_importlib_symlinks( const struct makefile *parent, return ret; ext[count++] = *dll_ext ? "def" : "a"; - if (needs_delay_lib( make )) ext[count++] = "delay.a"; if (needs_cross_lib( make )) ext[count++] = "cross.a"; for (i = 0; i < count; i++) @@ -3011,8 +3014,7 @@ static void output_source_default( struct makefile *make, struct incl_file *sour int need_cross = (crosstarget && !(source->file->flags & FLAG_C_UNIX) && (make->is_cross || - ((source->file->flags & FLAG_C_IMPLIB) && - (needs_cross_lib( make ) || needs_delay_lib( make ))) || + ((source->file->flags & FLAG_C_IMPLIB) && needs_cross_lib( make )) || (make->staticlib && needs_cross_lib( make )))); int need_obj = ((*dll_ext || !make->staticlib || !(source->file->flags & FLAG_C_UNIX)) && (!need_cross || @@ -3196,6 +3198,10 @@ static void output_module( struct makefile *make ) 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 */ + 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")); + if (make->is_cross) { strarray_add( &make->all_targets, strmake( "%s", make->module )); @@ -3209,8 +3215,6 @@ static void output_module( struct makefile *make ) if (*dll_ext) { - for (i = 0; i < make->delayimports.count; i++) - strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] )); 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 ), @@ -3252,7 +3256,7 @@ static void output_module( struct makefile *make ) if (spec_file && make->importlib) { char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib )); - if (*dll_ext && !make->implib_objs.count) + if (needs_delay_lib( make ) || (*dll_ext && !make->implib_objs.count)) { strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib )); output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file ); @@ -3266,14 +3270,9 @@ static void output_module( struct makefile *make ) strmake( "lib%s.def", make->importlib ), strmake( "d$(dlldir)/lib%s.def", make->importlib )); } - else + if (!*dll_ext || make->implib_objs.count) { strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib )); - if (!*dll_ext && needs_delay_lib( make )) - { - strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib )); - output( "%s.delay.a ", importlib_path ); - } output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file ); output_filenames_obj_dir( make, make->implib_objs ); output( "\n" ); @@ -3288,7 +3287,7 @@ static void output_module( struct makefile *make ) strmake( "lib%s.a", make->importlib ), strmake( "d$(dlldir)/lib%s.a", make->importlib )); } - if (crosstarget && (needs_cross_lib( make ) || needs_delay_lib( make ))) + if (crosstarget && (needs_cross_lib( make ))) { struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" ); if (needs_cross_lib( make )) @@ -3296,11 +3295,6 @@ static void output_module( struct makefile *make ) strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib )); output_filename( strmake( "%s.cross.a", importlib_path )); } - if (needs_delay_lib( make )) - { - strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib )); - output_filename( strmake( "%s.delay.a", importlib_path )); - } output( ": %s %s", tools_path( make, "winebuild" ), spec_file ); output_filenames_obj_dir( make, cross_files ); output( "\n" ); @@ -3579,53 +3573,43 @@ static void output_subdirs( struct makefile *make ) output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir, submake->importlib ); strarray_add( &tools_deps, strmake( "%s.cross.a", importlib_path )); } - if (needs_delay_lib( submake )) - { - output( "%s.delay.a: dummy\n", importlib_path ); - output( "\t@cd %s && $(MAKE) lib%s.delay.a\n", subdir, submake->importlib ); - strarray_add( &tools_deps, strmake( "%s.delay.a", importlib_path )); - } } else { char *spec_file = top_src_dir_path( make, base_dir_path( submake, replace_extension( submake->module, ".dll", ".spec" ))); - if (*dll_ext) + if (*dll_ext || needs_delay_lib( submake )) { output( "%s.def: %s", importlib_path, spec_file ); strarray_add( &build_deps, strmake( "%s.def", importlib_path )); + output_filename( tools_path( make, "winebuild" )); + output( "\n" ); + output( "\t%s -w -o $@", tools_path( make, "winebuild" )); + output_filename( "--def" ); + output_filenames( target_flags ); + if (submake->is_win16) output_filename( "-m16" ); + output_filename( "--export" ); + output_filename( spec_file ); + output( "\n" ); } - else + if (!*dll_ext) { - if (needs_delay_lib( submake )) - { - output( "%s.delay.a ", importlib_path ); - strarray_add( &build_deps, strmake( "%s.delay.a", importlib_path )); - } output( "%s.a: %s", importlib_path, spec_file ); strarray_add( &build_deps, strmake( "%s.a", importlib_path )); + output_filename( tools_path( make, "winebuild" )); + output( "\n" ); + output( "\t%s -w -o $@", tools_path( make, "winebuild" )); + output_filename( "--implib" ); + output_filenames( target_flags ); + if (submake->is_win16) output_filename( "-m16" ); + output_filename( "--export" ); + output_filename( spec_file ); + output( "\n" ); } - output_filename( tools_path( make, "winebuild" )); - output( "\n" ); - output( "\t%s -w -o $@", tools_path( make, "winebuild" )); - output_filename( *dll_ext ? "--def" : "--implib" ); - output_filenames( target_flags ); - if (submake->is_win16) output_filename( "-m16" ); - output_filename( "--export" ); - output_filename( spec_file ); - output( "\n" ); - if (crosstarget && (needs_cross_lib( submake ) || needs_delay_lib( submake ))) + if (crosstarget && needs_cross_lib( submake )) { - if (needs_cross_lib( submake )) - { - output_filename( strmake( "%s.cross.a", importlib_path )); - strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path )); - } - if (needs_delay_lib( submake )) - { - output_filename( strmake( "%s.delay.a", importlib_path )); - strarray_add( &build_deps, strmake( "%s.delay.a", importlib_path )); - } + output_filename( strmake( "%s.cross.a", importlib_path )); + strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path )); output( ": %s", spec_file ); output_filename( tools_path( make, "winebuild" )); output( "\n" );