Commit aa0572f0 authored by Alexandre Julliard's avatar Alexandre Julliard

winebuild: Open the output file only when needed.

parent 87917df8
......@@ -258,6 +258,8 @@ extern char *get_temp_file_name( const char *prefix, const char *suffix );
extern void output_standard_file_header(void);
extern FILE *open_input_file( const char *srcdir, const char *name );
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 int remove_stdcall_decoration( char *name );
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;
def_file = get_temp_file_name( output_file_name, ".def" );
fclose( output_file );
if (!(output_file = fopen( def_file, "w" )))
fatal_error( "Unable to create output file '%s'\n", def_file );
output_def_file( spec, 0 );
fclose( output_file );
output_file = NULL;
args = find_tool( "dlltool", NULL );
switch (target_cpu)
......@@ -1484,5 +1482,4 @@ void output_import_lib( DLLSPEC *spec, char **argv )
build_unix_import_lib( spec );
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;
FILE *output_file = NULL;
const char *output_file_name = NULL;
static const char *output_file_source_name;
static int fake_module;
struct strarray lib_path = { 0 };
......@@ -450,25 +449,9 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
add_import_dll( optarg, NULL );
break;
case 'o':
{
char *ext = strrchr( 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 */
}
if (unlink( optarg ) == -1 && errno != ENOENT)
fatal_error( "Unable to create output file '%s'\n", optarg );
output_file_name = xstrdup( optarg );
break;
case 'r':
strarray_add( &res_files, xstrdup( optarg ), NULL );
......@@ -636,8 +619,8 @@ int main(int argc, char **argv)
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
output_file = stdout;
argv = parse_options( argc, argv, spec );
atexit( cleanup ); /* make sure we remove the output file on exit */
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 (!spec_file_name) fatal_error( "missing .spec file\n" );
if (!parse_input_file( spec )) break;
open_output_file();
output_def_file( spec, 1 );
close_output_file();
break;
case MODE_IMPLIB:
if (!spec_file_name) fatal_error( "missing .spec file\n" );
......@@ -687,11 +672,6 @@ int main(int argc, char **argv)
break;
}
if (nb_errors) exit(1);
if (output_file_name)
{
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;
}
output_file_name = NULL;
return 0;
}
......@@ -698,6 +698,4 @@ void output_res_o_file( DLLSPEC *spec )
if (format)
strarray_add( &args, "-F", format, NULL );
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 );
needs_get_pc_thunk = 0;
open_output_file();
output_standard_file_header();
output_module( spec32 );
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_gnu_stack_note();
close_output_file();
free_dll_spec( spec32 );
}
......
......@@ -703,6 +703,7 @@ void BuildSpec32File( DLLSPEC *spec )
{
needs_get_pc_thunk = 0;
resolve_imports( spec );
open_output_file();
output_standard_file_header();
output_module( spec );
output_stubs( spec );
......@@ -711,6 +712,7 @@ void BuildSpec32File( DLLSPEC *spec )
if (needs_get_pc_thunk) output_get_pc_thunk();
output_resources( spec );
output_gnu_stack_note();
close_output_file();
}
......
......@@ -47,6 +47,7 @@
static struct strarray tmp_files;
static struct strarray empty_strarray;
static const char *output_file_source_name;
static const struct
{
......@@ -564,8 +565,10 @@ void init_output_buffer(void)
void flush_output_buffer(void)
{
open_output_file();
if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
fatal_error( "Error writing to %s\n", output_file_name );
close_output_file();
free( output_buffer );
}
......@@ -724,6 +727,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 a possible @xx suffix from a function name.
......
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