Commit 2dabac08 authored by Alexandre Julliard's avatar Alexandre Julliard

Added support in winebuild for specifying import libraries directly on

the command line without the -l option. Changed the -d option to only mark the library as delayed, the actual loading is now done separately.
parent f5c9da68
......@@ -16,9 +16,10 @@ DEFS = -D__WINESRC__ $(DLLDEFS) $(EXTRADEFS)
MAINSPEC = $(MODULE:%.dll=%).spec
SPEC_DEF = $(MAINSPEC).def
WIN16_FILES = $(SPEC_SRCS16:.spec=.spec.o) $(C_SRCS16:.c=.o) $(EXTRA_OBJS16)
ALL_OBJS = @WIN16_FILES@ $(OBJS) $(MODULE).dbg.o
ALL_OBJS = @WIN16_FILES@ $(OBJS) $(MODULE).dbg.o $(RC_SRCS:.rc=.res)
ALL_LIBS = $(LIBWINE) $(EXTRALIBS) $(LIBPORT) $(LDFLAGS) $(LIBS)
IMPORTLIBS = $(DELAYIMPORTS:%=$(DLLDIR)/lib%.$(IMPLIBEXT)) $(IMPORTS:%=$(DLLDIR)/lib%.$(IMPLIBEXT))
ALL_IMPORTS = $(DELAYIMPORTS) $(IMPORTS)
IMPORTLIBS = $(ALL_IMPORTS:%=$(DLLDIR)/lib%.$(IMPLIBEXT))
all: $(MODULE)$(DLLEXT) $(SUBDIRS)
......@@ -26,13 +27,13 @@ all: $(MODULE)$(DLLEXT) $(SUBDIRS)
# Rules for .so files
$(MODULE).so: $(MAINSPEC) $(RC_SRCS:.rc=.res) $(ALL_OBJS) $(IMPORTLIBS) Makefile.in
$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild -shared $(SRCDIR)/$(MAINSPEC) $(ALL_OBJS) $(RC_SRCS:.rc=.res) $(SUBSYSTEM:%=-Wb,--subsystem,%) -o $@ -L$(DLLDIR) $(DELAYIMPORTS:%=-Wb,-d%) $(IMPORTS:%=-l%) $(ALL_LIBS)
$(MODULE).so: $(MAINSPEC) $(ALL_OBJS) $(IMPORTLIBS) Makefile.in
$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild -shared $(SRCDIR)/$(MAINSPEC) $(ALL_OBJS) $(SUBSYSTEM:%=-Wb,--subsystem,%) -o $@ -L$(DLLDIR) $(ALL_IMPORTS:%=-l%) $(DELAYIMPORTS:%=-Wb,-d%) $(ALL_LIBS)
# Rules for .dll files
$(MODULE): $(RCOBJS) $(OBJS) $(MODULE).dbg.o $(SPEC_DEF) $(IMPORTLIBS) Makefile.in
$(DLLWRAP) -k --def $(SPEC_DEF) -o $@ $(RCOBJS) $(OBJS) $(MODULE).dbg.o -L$(DLLDIR) $(DELAYIMPORTS:%=-l%) $(IMPORTS:%=-l%) $(ALL_LIBS)
$(DLLWRAP) -k --def $(SPEC_DEF) -o $@ $(RCOBJS) $(OBJS) $(MODULE).dbg.o -L$(DLLDIR) $(ALL_IMPORTS:%=-l%) $(ALL_LIBS)
$(SPEC_DEF): $(WINEBUILD)
......@@ -55,8 +56,8 @@ crosstest:: $(SUBDIRS:%=%/__crosstest__)
# Rule to explicitly generate the .spec.c for debugging
$(MAINSPEC).c: $(MAINSPEC) $(RC_SRCS:.rc=.res) $(ALL_OBJS) $(IMPORTLIBS) $(WINEBUILD)
$(WINEBUILD) $(DEFS) $(DLLFLAGS) --dll -o $@ --export $(SRCDIR)/$(MAINSPEC) $(SUBSYSTEM:%=--subsystem %) $(RC_SRCS:.rc=.res) $(ALL_OBJS) -L$(DLLDIR) $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%)
$(MAINSPEC).c: $(MAINSPEC) $(ALL_OBJS) $(IMPORTLIBS) $(WINEBUILD)
$(WINEBUILD) $(DEFS) $(DLLFLAGS) --dll -o $@ --export $(SRCDIR)/$(MAINSPEC) $(SUBSYSTEM:%=--subsystem %) $(ALL_OBJS) -L$(DLLDIR) $(ALL_IMPORTS:%=-l%) $(DELAYIMPORTS:%=-d%)
# Rules for auto documentation
......
......@@ -13,9 +13,9 @@ DLLDEFS = @DLLDEFS@
DLLFLAGS = @DLLFLAGS@
DEFS = $(DLLDEFS) $(EXTRADEFS)
ALL_OBJS = $(OBJS) $(MODULE).dbg.o
ALL_LIBS = $(IMPORTS:%=-l%) $(LIBWINE) $(EXTRALIBS) $(LIBPORT) $(LDFLAGS) $(LIBS)
ALL_IMPORTS = $(DELAYIMPORTS) $(IMPORTS)
ALL_LIBS = $(ALL_IMPORTS:%=-l%) $(LIBWINE) $(EXTRALIBS) $(LIBPORT) $(LDFLAGS) $(LIBS)
BASEMODULE = $(MODULE:.exe=)
TESTIMPORTS = $(DELAYIMPORTS) $(IMPORTS)
RUNTESTFLAGS= -q -P wine -T $(TOPOBJDIR)
@MAKE_RULES@
......@@ -25,7 +25,7 @@ all: $(MODULE)$(DLLEXT) $(BASEMODULE)$(EXEEXT)
# Rules for .so main module
$(MODULE).so: $(ALL_OBJS) $(RC_SRCS:.rc=.res) Makefile.in
$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild $(APPMODE) $(ALL_OBJS) $(RC_SRCS:.rc=.res) -o $@ -L$(DLLDIR) $(DELAYIMPORTS:%=-Wb,-d%) $(ALL_LIBS)
$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild $(APPMODE) $(ALL_OBJS) $(RC_SRCS:.rc=.res) -o $@ -L$(DLLDIR) $(ALL_LIBS) $(DELAYIMPORTS:%=-Wb,-d%)
$(BASEMODULE): $(WINEWRAPPER)
$(RM) $@ && $(LN_S) $(WINEWRAPPER) $@
......@@ -33,7 +33,7 @@ $(BASEMODULE): $(WINEWRAPPER)
# Rules for .exe main module
$(MODULE): $(ALL_OBJS) $(RCOBJS) Makefile.in
$(CC) $(APPMODE) $(ALL_OBJS) $(RCOBJS) -o $@ $(DELAYIMPORTS:%=-l%) $(ALL_LIBS)
$(CC) $(APPMODE) $(ALL_OBJS) $(RCOBJS) -o $@ $(ALL_LIBS)
# Rules for testing
......
......@@ -148,6 +148,7 @@ extern void *xmalloc (size_t size);
extern void *xrealloc (void *ptr, size_t size);
extern char *xstrdup( const char *str );
extern char *strupper(char *s);
extern int strendswith(const char* str, const char* end);
extern void fatal_error( const char *msg, ... )
__attribute__ ((__format__ (__printf__, 1, 2)));
extern void fatal_perror( const char *msg, ... )
......@@ -167,7 +168,8 @@ extern void free_dll_spec( DLLSPEC *spec );
extern const char *make_c_identifier( const char *str );
extern int get_alignment(int alignBoundary);
extern void add_import_dll( const char *name, int delay );
extern void add_import_dll( const char *name, const char *filename );
extern void add_delayed_import( const char *name );
extern void add_ignore_symbol( const char *name );
extern void read_undef_symbols( char **argv );
extern int resolve_imports( DLLSPEC *spec );
......
......@@ -27,6 +27,9 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
......@@ -37,7 +40,10 @@
struct import
{
DLLSPEC *spec; /* description of the imported dll */
DLLSPEC *spec; /* description of the imported dll */
char *full_name; /* full name of the input file */
dev_t dev; /* device/inode of the input file */
ino_t ino;
int delay; /* delay or not dll loading ? */
ORDDEF **exports; /* functions exported from this dll */
int nb_exports; /* number of exported functions */
......@@ -60,6 +66,8 @@ static int nb_imports = 0; /* number of imported dlls (delayed or not) */
static int nb_delayed = 0; /* number of delayed dlls */
static int total_imports = 0; /* total number of imported functions */
static int total_delayed = 0; /* total number of imported functions in delayed DLLs */
static char **delayed_imports; /* names of delayed import dlls */
static int nb_delayed_imports; /* size of the delayed_imports array */
/* list of symbols that are ignored by default */
static const char * const default_ignored_symbols[] =
......@@ -189,6 +197,7 @@ static void free_imports( struct import *imp )
free( imp->exports );
free( imp->imports );
free_dll_spec( imp->spec );
free( imp->full_name );
free( imp );
}
......@@ -198,16 +207,28 @@ static void remove_ld_tmp_file(void)
if (ld_tmp_file) unlink( ld_tmp_file );
}
/* check whether a given dll is imported in delayed mode */
static int is_delayed_import( const char *name )
{
int i;
for (i = 0; i < nb_delayed_imports; i++)
{
if (!strcmp( delayed_imports[i], name )) return 1;
}
return 0;
}
/* check whether a given dll has already been imported */
static int is_already_imported( const char *name )
static struct import *is_already_imported( const char *name )
{
int i;
for (i = 0; i < nb_imports; i++)
{
if (!strcmp( dll_imports[i]->spec->file_name, name )) return 1;
if (!strcmp( dll_imports[i]->spec->file_name, name )) return dll_imports[i];
}
return 0;
return NULL;
}
/* open the .so library for a given dll in a specified path */
......@@ -229,8 +250,8 @@ static char *try_library_path( const char *path, const char *name )
return NULL;
}
/* open the .so library for a given dll */
static char *open_library( const char *name )
/* find the .def import library for a given dll */
static char *find_library( const char *name )
{
char *fullname;
int i;
......@@ -244,24 +265,36 @@ static char *open_library( const char *name )
}
/* read in the list of exported symbols of an import library */
static int read_import_lib( const char *name, struct import *imp )
static int read_import_lib( struct import *imp )
{
FILE *f;
char *fullname;
int i, ret;
struct stat stat;
struct import *prev_imp;
DLLSPEC *spec = imp->spec;
imp->exports = NULL;
imp->nb_exports = 0;
fullname = open_library( name );
f = open_input_file( NULL, fullname );
free( fullname );
f = open_input_file( NULL, imp->full_name );
fstat( fileno(f), &stat );
imp->dev = stat.st_dev;
imp->ino = stat.st_ino;
ret = parse_def_file( f, spec );
close_input_file( f );
if (!ret) return 0;
if (is_already_imported( spec->file_name )) return 0;
/* check if we already imported that library from a different file */
if ((prev_imp = is_already_imported( spec->file_name )))
{
if (prev_imp->dev != imp->dev || prev_imp->ino != imp->ino)
fatal_error( "%s and %s have the same export name '%s'\n",
prev_imp->full_name, imp->full_name, spec->file_name );
return 0; /* the same file was already loaded, ignore this one */
}
if (is_delayed_import( spec->file_name ))
{
imp->delay = 1;
nb_delayed++;
}
imp->exports = xmalloc( spec->nb_entry_points * sizeof(*imp->exports) );
......@@ -279,32 +312,47 @@ static int read_import_lib( const char *name, struct import *imp )
return 1;
}
/* add a dll to the list of imports */
void add_import_dll( const char *name, int delay )
/* build the dll exported name from the import lib name or path */
static char *get_dll_name( const char *name, const char *filename )
{
struct import *imp;
char *fullname;
char *ret;
fullname = xmalloc( strlen(name) + 5 );
strcpy( fullname, name );
if (!strchr( fullname, '.' )) strcat( fullname, ".dll" );
/* check if we already imported it */
if (is_already_imported( fullname ))
if (filename)
{
const char *basename = strrchr( filename, '/' );
if (!basename) basename = filename;
else basename++;
if (!strncmp( basename, "lib", 3 )) basename += 3;
ret = xmalloc( strlen(basename) + 5 );
strcpy( ret, basename );
if (strendswith( ret, ".def" )) ret[strlen(ret)-4] = 0;
}
else
{
free( fullname );
return;
ret = xmalloc( strlen(name) + 5 );
strcpy( ret, name );
}
if (!strchr( ret, '.' )) strcat( ret, ".dll" );
return ret;
}
/* add a dll to the list of imports */
void add_import_dll( const char *name, const char *filename )
{
struct import *imp = xmalloc( sizeof(*imp) );
imp = xmalloc( sizeof(*imp) );
imp->spec = alloc_dll_spec();
imp->spec->file_name = fullname;
imp->delay = delay;
imp->spec->file_name = get_dll_name( name, filename );
imp->delay = 0;
imp->imports = NULL;
imp->nb_imports = 0;
if (delay) nb_delayed++;
imp->exports = NULL;
imp->nb_exports = 0;
if (filename) imp->full_name = xstrdup( filename );
else imp->full_name = find_library( name );
if (read_import_lib( name, imp ))
if (read_import_lib( imp ))
{
dll_imports = xrealloc( dll_imports, (nb_imports+1) * sizeof(*dll_imports) );
dll_imports[nb_imports++] = imp;
......@@ -316,6 +364,21 @@ void add_import_dll( const char *name, int delay )
}
}
/* add a library to the list of delayed imports */
void add_delayed_import( const char *name )
{
struct import *imp;
char *fullname = get_dll_name( name, NULL );
delayed_imports = xrealloc( delayed_imports, (nb_delayed_imports+1) * sizeof(*delayed_imports) );
delayed_imports[nb_delayed_imports++] = fullname;
if ((imp = is_already_imported( fullname )) && !imp->delay)
{
imp->delay = 1;
nb_delayed++;
}
}
/* remove an imported dll, based on its index in the dll_imports array */
static void remove_import_dll( int index )
{
......@@ -477,8 +540,8 @@ static void add_extra_undef_symbols( const DLLSPEC *spec )
ntdll_imports += add_extra_symbol( extras, &count, "RtlRaiseException", spec );
/* make sure we import the dlls that contain these functions */
if (kernel_imports) add_import_dll( "kernel32", 0 );
if (ntdll_imports) add_import_dll( "ntdll", 0 );
if (kernel_imports) add_import_dll( "kernel32", NULL );
if (ntdll_imports) add_import_dll( "ntdll", NULL );
if (count)
{
......
......@@ -281,7 +281,7 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
spec->dll_name = xstrdup( optarg );
break;
case 'd':
add_import_dll( optarg, 1 );
add_delayed_import( optarg );
break;
case 'e':
spec->init_func = xstrdup( optarg );
......@@ -310,7 +310,7 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
kill_at = 1;
break;
case 'l':
add_import_dll( optarg, 0 );
add_import_dll( optarg, NULL );
break;
case 'o':
if (unlink( optarg ) == -1 && errno != ENOENT)
......@@ -401,6 +401,21 @@ static void load_resources( char *argv[], DLLSPEC *spec )
}
}
/* add input files that look like import libs to the import list */
static void load_import_libs( char *argv[] )
{
char **ptr, **last;
for (ptr = last = argv; *ptr; ptr++)
{
if (strendswith( *ptr, ".def" ))
add_import_dll( NULL, *ptr );
else
*last++ = *ptr; /* not an import dll, keep it in the list */
}
*last = NULL;
}
static int parse_input_file( DLLSPEC *spec )
{
FILE *input_file = open_input_file( NULL, spec_file_name );
......@@ -437,6 +452,7 @@ int main(int argc, char **argv)
case MODE_DLL:
spec->characteristics |= IMAGE_FILE_DLL;
load_resources( argv, spec );
load_import_libs( argv );
if (!spec_file_name) fatal_error( "missing .spec file\n" );
if (!parse_input_file( spec )) break;
switch (spec->type)
......@@ -457,6 +473,7 @@ int main(int argc, char **argv)
if (spec->type == SPEC_WIN16) fatal_error( "Cannot build 16-bit exe files\n" );
if (!spec->file_name) fatal_error( "executable must be named via the -F option\n" );
load_resources( argv, spec );
load_import_libs( argv );
if (spec_file_name && !parse_input_file( spec )) break;
read_undef_symbols( argv );
BuildSpec32File( output_file, spec );
......
......@@ -71,6 +71,13 @@ char *strupper(char *s)
return s;
}
int strendswith(const char* str, const char* end)
{
int l = strlen(str);
int m = strlen(end);
return l >= m && strcmp(str + l - m, end) == 0;
}
void fatal_error( const char *msg, ... )
{
va_list valist;
......
......@@ -69,6 +69,12 @@ Change to the specified directory before reading source files. Only
meaningful in
.BR \--debug\ mode.
.TP
.BI \-d,\ --delay-lib= name
Set the delayed import mode for the specified library, which must be
one of the libraries imported with the \fB-l\fR option. Delayed mode
means that the library won't be loaded until a function imported from
it is actually called.
.TP
.BI \-D\ symbol
Ignored for compatibility with the C compiler.
.TP
......@@ -138,11 +144,6 @@ Import the specified library, looking for a corresponding
\fIlibname.def\fR file in the directories specified with the \fB-L\fR
option.
.TP
.BI \-d,\ --delay-lib= name
Same as the \fB-l\fR option, but import the specified library in
delayed mode (i.e. the library won't be loaded until a function
imported from it is actually called).
.TP
.BI \-M,\ --main-module= module
Specify that we are building a 16-bit dll, that will ultimately be
linked together with the 32-bit dll specified in \fImodule\fR. Only
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment