Check file header to differentiate between object files and resources

so that the -r option is not necessary.
This commit is contained in:
Alexandre Julliard 2002-12-06 23:26:29 +00:00
parent 9afea97a0f
commit 310de886e9
7 changed files with 51 additions and 29 deletions

View file

@ -25,7 +25,7 @@ all: $(MODULE)$(DLLEXT) $(SUBDIRS)
# Rules for .so files # Rules for .so files
$(MAINSPEC).c: $(MAINSPEC) $(RC_SRCS:.rc=.res) $(SYMBOLFILE) $(WINEBUILD) $(MAINSPEC).c: $(MAINSPEC) $(RC_SRCS:.rc=.res) $(SYMBOLFILE) $(WINEBUILD)
$(LDPATH) $(WINEBUILD) $(DEFS) -o $@ --spec $(SRCDIR)/$(MAINSPEC) $(RC_SRCS:%.rc=-r %.res) $(SYMBOLFILE) $(DLLMAIN:%=-e %) -L$(DLLDIR) $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%) $(LDPATH) $(WINEBUILD) $(DEFS) -o $@ --spec $(SRCDIR)/$(MAINSPEC) $(RC_SRCS:.rc=.res) $(SYMBOLFILE) $(DLLMAIN:%=-e %) -L$(DLLDIR) $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%)
$(MODULE).so: $(MAINSPEC).o $(ALL_OBJS) Makefile.in $(MODULE).so: $(MAINSPEC).o $(ALL_OBJS) Makefile.in
$(LDSHARED) $(LDDLLFLAGS) $(MAINSPEC).o $(ALL_OBJS) -o $@ -L$(DLLDIR) $(LDIMPORTS:%=-l%) $(ALL_LIBS) -lc $(LDSHARED) $(LDDLLFLAGS) $(MAINSPEC).o $(ALL_OBJS) -o $@ -L$(DLLDIR) $(LDIMPORTS:%=-l%) $(ALL_LIBS) -lc

View file

@ -32,7 +32,7 @@ all: $(TESTPROGRAM)
# Rule for main module spec file # Rule for main module spec file
$(MODULE).spec.c: $(RC_SRCS:.rc=.res) $(OBJS) $(WINEBUILD) $(MODULE).spec.c: $(RC_SRCS:.rc=.res) $(OBJS) $(WINEBUILD)
$(LDPATH) $(WINEBUILD) $(DEFS) -o $@ -exe $(MODULE) -mcui $(RC_SRCS:%.rc=-r %.res) $(OBJS) -L$(DLLDIR) -L.. $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%) $(LDPATH) $(WINEBUILD) $(DEFS) -o $@ -exe $(MODULE) -mcui $(RC_SRCS:.rc=.res) $(OBJS) -L$(DLLDIR) -L.. $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%)
# Rules for .so main module # Rules for .so main module

View file

@ -24,7 +24,7 @@ all: $(MODULE)$(DLLEXT) $(BASEMODULE)$(EXEEXT)
# Rule for main module spec file # Rule for main module spec file
$(MODULE).spec.c: $(RC_SRCS:.rc=.res) $(ALL_OBJS) $(WINEBUILD) $(MODULE).spec.c: $(RC_SRCS:.rc=.res) $(ALL_OBJS) $(WINEBUILD)
$(LDPATH) $(WINEBUILD) $(DEFS) -o $@ --exe $(MODULE) $(APPMODE:%=-m%) $(RC_SRCS:%.rc=-r %.res) $(ALL_OBJS) -L$(DLLDIR) $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%) $(LDPATH) $(WINEBUILD) $(DEFS) -o $@ --exe $(MODULE) $(APPMODE:%=-m%) $(RC_SRCS:.rc=.res) $(ALL_OBJS) -L$(DLLDIR) $(DELAYIMPORTS:%=-d%) $(IMPORTS:%=-l%)
# Rules for .so main module # Rules for .so main module

View file

@ -151,7 +151,7 @@ extern void add_ignore_symbol( const char *name );
extern void read_undef_symbols( char **argv ); extern void read_undef_symbols( char **argv );
extern int resolve_imports( void ); extern int resolve_imports( void );
extern int output_imports( FILE *outfile ); extern int output_imports( FILE *outfile );
extern void load_res32_file( const char *name ); extern int load_res32_file( const char *name );
extern int output_resources( FILE *outfile ); extern int output_resources( FILE *outfile );
extern void load_res16_file( const char *name ); extern void load_res16_file( const char *name );
extern int output_res16_data( FILE *outfile ); extern int output_res16_data( FILE *outfile );

View file

@ -350,7 +350,7 @@ static void parse_options( char *argv[] )
char **ptr, **last; char **ptr, **last;
const char* arg=NULL; const char* arg=NULL;
for (ptr = last = argv + 1; *ptr; ptr++) for (ptr = last = argv; *ptr; ptr++)
{ {
/* first check the exact option name */ /* first check the exact option name */
for (opt = option_table; opt->name; opt++) for (opt = option_table; opt->name; opt++)
@ -394,17 +394,31 @@ static void parse_options( char *argv[] )
/* load all specified resource files */ /* load all specified resource files */
static void load_resources(void) static void load_resources( char *argv[] )
{ {
int i; int i;
char **ptr, **last;
switch (SpecType) switch (SpecType)
{ {
case SPEC_WIN16: case SPEC_WIN16:
for (i = 0; i < nb_res_files; i++) load_res16_file( res_files[i] ); for (i = 0; i < nb_res_files; i++) load_res16_file( res_files[i] );
break; break;
case SPEC_WIN32: case SPEC_WIN32:
for (i = 0; i < nb_res_files; i++) load_res32_file( res_files[i] ); for (i = 0; i < nb_res_files; i++)
{
if (!load_res32_file( res_files[i] ))
fatal_error( "%s is not a valid Win32 resource file\n", res_files[i] );
}
/* load any resource file found in the remaining arguments */
for (ptr = last = argv; *ptr; ptr++)
{
if (!load_res32_file( *ptr ))
*last++ = *ptr; /* not a resource file, keep it in the list */
}
*last = NULL;
break; break;
} }
} }
@ -415,12 +429,12 @@ static void load_resources(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
output_file = stdout; output_file = stdout;
parse_options( argv ); parse_options( argv + 1 );
switch(exec_mode) switch(exec_mode)
{ {
case MODE_SPEC: case MODE_SPEC:
load_resources(); load_resources( argv + 1 );
ParseTopLevel( input_file ); ParseTopLevel( input_file );
switch (SpecType) switch (SpecType)
{ {
@ -438,14 +452,13 @@ int main(int argc, char **argv)
break; break;
case MODE_EXE: case MODE_EXE:
if (SpecType == SPEC_WIN16) fatal_error( "Cannot build 16-bit exe files\n" ); if (SpecType == SPEC_WIN16) fatal_error( "Cannot build 16-bit exe files\n" );
load_resources(); load_resources( argv + 1 );
read_undef_symbols( argv + 1 ); read_undef_symbols( argv + 1 );
BuildSpec32File( output_file ); BuildSpec32File( output_file );
break; break;
case MODE_DEF: case MODE_DEF:
if (argv[1]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[1] ); if (argv[1]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[1] );
if (SpecType == SPEC_WIN16) fatal_error( "Cannot yet build .def file for 16-bit dlls\n" ); if (SpecType == SPEC_WIN16) fatal_error( "Cannot yet build .def file for 16-bit dlls\n" );
load_resources();
ParseTopLevel( input_file ); ParseTopLevel( input_file );
BuildDef32File( output_file ); BuildDef32File( output_file );
break; break;

View file

@ -155,20 +155,18 @@ static void get_string( struct string_id *str )
/* check the file header */ /* check the file header */
/* all values must be zero except header size */ /* all values must be zero except header size */
static void check_header(void) static int check_header(void)
{ {
if (get_dword()) goto error; /* data size */ if (get_dword()) return 0; /* data size */
if (get_dword() != 32) goto error; /* header size */ if (get_dword() != 32) return 0; /* header size */
if (get_word() != 0xffff || get_word()) goto error; /* type, must be id 0 */ if (get_word() != 0xffff || get_word()) return 0; /* type, must be id 0 */
if (get_word() != 0xffff || get_word()) goto error; /* name, must be id 0 */ if (get_word() != 0xffff || get_word()) return 0; /* name, must be id 0 */
if (get_dword()) goto error; /* data version */ if (get_dword()) return 0; /* data version */
if (get_word()) goto error; /* mem options */ if (get_word()) return 0; /* mem options */
if (get_word()) goto error; /* language */ if (get_word()) return 0; /* language */
if (get_dword()) goto error; /* version */ if (get_dword()) return 0; /* version */
if (get_dword()) goto error; /* characteristics */ if (get_dword()) return 0; /* characteristics */
return; return 1;
error:
fatal_error( "%s is not a valid Win32 resource file\n", file_name );
} }
/* load the next resource from the current file */ /* load the next resource from the current file */
@ -196,9 +194,9 @@ static void load_next_resource(void)
} }
/* load a Win32 .res file */ /* load a Win32 .res file */
void load_res32_file( const char *name ) int load_res32_file( const char *name )
{ {
int fd; int fd, ret;
void *base; void *base;
struct stat st; struct stat st;
@ -217,8 +215,12 @@ void load_res32_file( const char *name )
file_name = name; file_name = name;
file_pos = base; file_pos = base;
file_end = file_pos + st.st_size; file_end = file_pos + st.st_size;
check_header(); if ((ret = check_header()))
while (file_pos < file_end) load_next_resource(); {
while (file_pos < file_end) load_next_resource();
}
close( fd );
return ret;
} }
/* compare two unicode strings/ids */ /* compare two unicode strings/ids */

View file

@ -1,5 +1,5 @@
.\" -*- nroff -*- .\" -*- nroff -*-
.TH WINEBUILD 1 "July 2002" "@PACKAGE_STRING@" "Wine dll builder" .TH WINEBUILD 1 "December 2002" "@PACKAGE_STRING@" "Wine dll builder"
.SH NAME .SH NAME
winebuild \- Wine dll builder winebuild \- Wine dll builder
.SH SYNOPSIS .SH SYNOPSIS
@ -159,6 +159,13 @@ Load resources from the specified binary resource file. The
\fIrsrc.res\fR can be produced from a source resource file with \fIrsrc.res\fR can be produced from a source resource file with
.BR wrc(1) .BR wrc(1)
(or with a Windows resource compiler). (or with a Windows resource compiler).
.br
This option is only necessary for Win16 resource files, the Win32 ones
can simply listed as
.I input files
and will automatically be handled correctly (though the
.B \-r
option will also work for Win32 files).
.TP .TP
.B \-w .B \-w
Turn on warnings. Turn on warnings.