forked from Mirrors/wine-wine
winebuild: Open the output file only when needed.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>stable
parent
87917df887
commit
aa0572f0a2
|
@ -258,6 +258,8 @@ extern char *get_temp_file_name( const char *prefix, const char *suffix );
|
||||||
extern void output_standard_file_header(void);
|
extern void output_standard_file_header(void);
|
||||||
extern FILE *open_input_file( const char *srcdir, const char *name );
|
extern FILE *open_input_file( const char *srcdir, const char *name );
|
||||||
extern void close_input_file( FILE *file );
|
extern void close_input_file( FILE *file );
|
||||||
|
extern void open_output_file(void);
|
||||||
|
extern void close_output_file(void);
|
||||||
extern void dump_bytes( const void *buffer, unsigned int size );
|
extern void dump_bytes( const void *buffer, unsigned int size );
|
||||||
extern int remove_stdcall_decoration( char *name );
|
extern int remove_stdcall_decoration( char *name );
|
||||||
extern void assemble_file( const char *src_file, const char *obj_file );
|
extern void assemble_file( const char *src_file, const char *obj_file );
|
||||||
|
|
|
@ -1382,12 +1382,10 @@ static void build_windows_import_lib( DLLSPEC *spec )
|
||||||
const char *as_flags, *m_flag;
|
const char *as_flags, *m_flag;
|
||||||
|
|
||||||
def_file = get_temp_file_name( output_file_name, ".def" );
|
def_file = get_temp_file_name( output_file_name, ".def" );
|
||||||
fclose( output_file );
|
|
||||||
if (!(output_file = fopen( def_file, "w" )))
|
if (!(output_file = fopen( def_file, "w" )))
|
||||||
fatal_error( "Unable to create output file '%s'\n", def_file );
|
fatal_error( "Unable to create output file '%s'\n", def_file );
|
||||||
output_def_file( spec, 0 );
|
output_def_file( spec, 0 );
|
||||||
fclose( output_file );
|
fclose( output_file );
|
||||||
output_file = NULL;
|
|
||||||
|
|
||||||
args = find_tool( "dlltool", NULL );
|
args = find_tool( "dlltool", NULL );
|
||||||
switch (target_cpu)
|
switch (target_cpu)
|
||||||
|
@ -1484,5 +1482,4 @@ void output_import_lib( DLLSPEC *spec, char **argv )
|
||||||
build_unix_import_lib( spec );
|
build_unix_import_lib( spec );
|
||||||
build_library( output_file_name, argv, 1 );
|
build_library( output_file_name, argv, 1 );
|
||||||
}
|
}
|
||||||
output_file_name = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,6 @@ char *input_file_name = NULL;
|
||||||
char *spec_file_name = NULL;
|
char *spec_file_name = NULL;
|
||||||
FILE *output_file = NULL;
|
FILE *output_file = NULL;
|
||||||
const char *output_file_name = NULL;
|
const char *output_file_name = NULL;
|
||||||
static const char *output_file_source_name;
|
|
||||||
static int fake_module;
|
static int fake_module;
|
||||||
|
|
||||||
struct strarray lib_path = { 0 };
|
struct strarray lib_path = { 0 };
|
||||||
|
@ -450,25 +449,9 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
|
||||||
add_import_dll( optarg, NULL );
|
add_import_dll( optarg, NULL );
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
{
|
if (unlink( optarg ) == -1 && errno != ENOENT)
|
||||||
char *ext = strrchr( optarg, '.' );
|
fatal_error( "Unable to create output file '%s'\n", optarg );
|
||||||
|
output_file_name = xstrdup( optarg );
|
||||||
if (unlink( optarg ) == -1 && errno != ENOENT)
|
|
||||||
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
||||||
if (ext && !strcmp( ext, ".o" ))
|
|
||||||
{
|
|
||||||
output_file_source_name = get_temp_file_name( optarg, ".s" );
|
|
||||||
if (!(output_file = fopen( output_file_source_name, "w" )))
|
|
||||||
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(output_file = fopen( optarg, "w" )))
|
|
||||||
fatal_error( "Unable to create output file '%s'\n", optarg );
|
|
||||||
}
|
|
||||||
output_file_name = xstrdup(optarg);
|
|
||||||
atexit( cleanup ); /* make sure we remove the output file on exit */
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
strarray_add( &res_files, xstrdup( optarg ), NULL );
|
strarray_add( &res_files, xstrdup( optarg ), NULL );
|
||||||
|
@ -636,8 +619,8 @@ int main(int argc, char **argv)
|
||||||
signal( SIGTERM, exit_on_signal );
|
signal( SIGTERM, exit_on_signal );
|
||||||
signal( SIGINT, exit_on_signal );
|
signal( SIGINT, exit_on_signal );
|
||||||
|
|
||||||
output_file = stdout;
|
|
||||||
argv = parse_options( argc, argv, spec );
|
argv = parse_options( argc, argv, spec );
|
||||||
|
atexit( cleanup ); /* make sure we remove the output file on exit */
|
||||||
|
|
||||||
switch(exec_mode)
|
switch(exec_mode)
|
||||||
{
|
{
|
||||||
|
@ -671,7 +654,9 @@ int main(int argc, char **argv)
|
||||||
if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
|
if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
|
||||||
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
||||||
if (!parse_input_file( spec )) break;
|
if (!parse_input_file( spec )) break;
|
||||||
|
open_output_file();
|
||||||
output_def_file( spec, 1 );
|
output_def_file( spec, 1 );
|
||||||
|
close_output_file();
|
||||||
break;
|
break;
|
||||||
case MODE_IMPLIB:
|
case MODE_IMPLIB:
|
||||||
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
if (!spec_file_name) fatal_error( "missing .spec file\n" );
|
||||||
|
@ -687,11 +672,6 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nb_errors) exit(1);
|
if (nb_errors) exit(1);
|
||||||
if (output_file_name)
|
output_file_name = NULL;
|
||||||
{
|
|
||||||
if (fclose( output_file ) < 0) fatal_perror( "fclose" );
|
|
||||||
if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
|
|
||||||
output_file_name = NULL;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,6 +698,4 @@ void output_res_o_file( DLLSPEC *spec )
|
||||||
if (format)
|
if (format)
|
||||||
strarray_add( &args, "-F", format, NULL );
|
strarray_add( &args, "-F", format, NULL );
|
||||||
spawn( args );
|
spawn( args );
|
||||||
|
|
||||||
output_file_name = NULL; /* so we don't try to assemble it */
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -816,6 +816,7 @@ void output_spec16_file( DLLSPEC *spec16 )
|
||||||
add_16bit_exports( spec32, spec16 );
|
add_16bit_exports( spec32, spec16 );
|
||||||
|
|
||||||
needs_get_pc_thunk = 0;
|
needs_get_pc_thunk = 0;
|
||||||
|
open_output_file();
|
||||||
output_standard_file_header();
|
output_standard_file_header();
|
||||||
output_module( spec32 );
|
output_module( spec32 );
|
||||||
output_module16( spec16 );
|
output_module16( spec16 );
|
||||||
|
@ -831,6 +832,7 @@ void output_spec16_file( DLLSPEC *spec16 )
|
||||||
output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec16->main_module );
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec16->main_module );
|
||||||
}
|
}
|
||||||
output_gnu_stack_note();
|
output_gnu_stack_note();
|
||||||
|
close_output_file();
|
||||||
free_dll_spec( spec32 );
|
free_dll_spec( spec32 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -703,6 +703,7 @@ void BuildSpec32File( DLLSPEC *spec )
|
||||||
{
|
{
|
||||||
needs_get_pc_thunk = 0;
|
needs_get_pc_thunk = 0;
|
||||||
resolve_imports( spec );
|
resolve_imports( spec );
|
||||||
|
open_output_file();
|
||||||
output_standard_file_header();
|
output_standard_file_header();
|
||||||
output_module( spec );
|
output_module( spec );
|
||||||
output_stubs( spec );
|
output_stubs( spec );
|
||||||
|
@ -711,6 +712,7 @@ void BuildSpec32File( DLLSPEC *spec )
|
||||||
if (needs_get_pc_thunk) output_get_pc_thunk();
|
if (needs_get_pc_thunk) output_get_pc_thunk();
|
||||||
output_resources( spec );
|
output_resources( spec );
|
||||||
output_gnu_stack_note();
|
output_gnu_stack_note();
|
||||||
|
close_output_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
static struct strarray tmp_files;
|
static struct strarray tmp_files;
|
||||||
static struct strarray empty_strarray;
|
static struct strarray empty_strarray;
|
||||||
|
static const char *output_file_source_name;
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
{
|
{
|
||||||
|
@ -564,8 +565,10 @@ void init_output_buffer(void)
|
||||||
|
|
||||||
void flush_output_buffer(void)
|
void flush_output_buffer(void)
|
||||||
{
|
{
|
||||||
|
open_output_file();
|
||||||
if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
|
if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
|
||||||
fatal_error( "Error writing to %s\n", output_file_name );
|
fatal_error( "Error writing to %s\n", output_file_name );
|
||||||
|
close_output_file();
|
||||||
free( output_buffer );
|
free( output_buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,6 +726,41 @@ void close_input_file( FILE *file )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* open_output_file
|
||||||
|
*/
|
||||||
|
void open_output_file(void)
|
||||||
|
{
|
||||||
|
if (output_file_name)
|
||||||
|
{
|
||||||
|
if (strendswith( output_file_name, ".o" ))
|
||||||
|
{
|
||||||
|
output_file_source_name = get_temp_file_name( output_file_name, ".s" );
|
||||||
|
if (!(output_file = fopen( output_file_source_name, "w" )))
|
||||||
|
fatal_error( "Unable to create output file '%s'\n", output_file_name );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(output_file = fopen( output_file_name, "w" )))
|
||||||
|
fatal_error( "Unable to create output file '%s'\n", output_file_name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else output_file = stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* close_output_file
|
||||||
|
*/
|
||||||
|
void close_output_file(void)
|
||||||
|
{
|
||||||
|
if (!output_file || !output_file_name) return;
|
||||||
|
if (fclose( output_file ) < 0) fatal_perror( "fclose" );
|
||||||
|
if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
|
||||||
|
output_file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
* remove_stdcall_decoration
|
* remove_stdcall_decoration
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue