winebuild: Simplify the code for finding the various build tools.

This commit is contained in:
Alexandre Julliard 2009-12-30 12:42:25 +01:00
parent 76ac103b80
commit 38ca263374
3 changed files with 28 additions and 58 deletions

View File

@ -209,10 +209,10 @@ extern void warning( const char *msg, ... )
__attribute__ ((__format__ (__printf__, 1, 2))); __attribute__ ((__format__ (__printf__, 1, 2)));
extern int output( const char *format, ... ) extern int output( const char *format, ... )
__attribute__ ((__format__ (__printf__, 1, 2))); __attribute__ ((__format__ (__printf__, 1, 2)));
extern char *find_tool( const char *name, const char * const *names );
extern const char *get_as_command(void); extern const char *get_as_command(void);
extern const char *get_ld_command(void); extern const char *get_ld_command(void);
extern const char *get_nm_command(void); extern const char *get_nm_command(void);
extern const char *get_windres_command(void);
extern char *get_temp_file_name( const char *prefix, const char *suffix ); 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 );

View File

@ -652,13 +652,14 @@ void output_res_o_file( DLLSPEC *spec )
if (res_file) if (res_file)
{ {
const char *prog = get_windres_command(); char *prog = find_tool( "windres", NULL );
char *cmd = xmalloc( strlen(prog) + strlen(res_file) + strlen(output_file_name) + 9 ); char *cmd = xmalloc( strlen(prog) + strlen(res_file) + strlen(output_file_name) + 9 );
sprintf( cmd, "%s -i %s -o %s", prog, res_file, output_file_name ); sprintf( cmd, "%s -i %s -o %s", prog, res_file, output_file_name );
if (verbose) fprintf( stderr, "%s\n", cmd ); if (verbose) fprintf( stderr, "%s\n", cmd );
err = system( cmd ); err = system( cmd );
if (err) fatal_error( "%s failed with status %d\n", prog, err ); if (err) fatal_error( "%s failed with status %d\n", prog, err );
free( cmd ); free( cmd );
free( prog );
} }
output_file_name = NULL; /* so we don't try to assemble it */ output_file_name = NULL; /* so we don't try to assemble it */
} }

View File

@ -199,15 +199,25 @@ int output( const char *format, ... )
} }
/* find a build tool in the path, trying the various names */ /* find a build tool in the path, trying the various names */
static char *find_tool( const char * const *names ) char *find_tool( const char *name, const char * const *names )
{ {
static char **dirs; static char **dirs;
static unsigned int count, maxlen; static unsigned int count, maxlen;
char *p, *file; char *p, *file;
const char *alt_names[2];
unsigned int i, len; unsigned int i, len;
struct stat st; struct stat st;
if (target_alias)
{
file = xmalloc( strlen(target_alias) + strlen(name) + 2 );
strcpy( file, target_alias );
strcat( file, "-" );
strcat( file, name );
return file;
}
if (!dirs) if (!dirs)
{ {
char *path; char *path;
@ -230,6 +240,13 @@ static char *find_tool( const char * const *names )
for (i = 0; i < count; i++) maxlen = max( maxlen, strlen(dirs[i])+2 ); for (i = 0; i < count; i++) maxlen = max( maxlen, strlen(dirs[i])+2 );
} }
if (!names)
{
alt_names[0] = name;
alt_names[1] = NULL;
names = alt_names;
}
while (*names) while (*names)
{ {
len = strlen(*names) + sizeof(EXEEXT) + 1; len = strlen(*names) + sizeof(EXEEXT) + 1;
@ -249,24 +266,15 @@ static char *find_tool( const char * const *names )
free( file ); free( file );
names++; names++;
} }
return NULL; return xstrdup( name );
} }
const char *get_as_command(void) const char *get_as_command(void)
{ {
if (!as_command) if (!as_command)
{ {
if (target_alias) static const char * const commands[] = { "gas", "as", NULL };
{ as_command = find_tool( "as", commands );
as_command = xmalloc( strlen(target_alias) + sizeof("-as") );
strcpy( as_command, target_alias );
strcat( as_command, "-as" );
}
else
{
static const char * const commands[] = { "gas", "as", NULL };
if (!(as_command = find_tool( commands ))) as_command = xstrdup("as");
}
if (force_pointer_size) if (force_pointer_size)
{ {
@ -284,17 +292,8 @@ const char *get_ld_command(void)
{ {
if (!ld_command) if (!ld_command)
{ {
if (target_alias) static const char * const commands[] = { "ld", "gld", NULL };
{ ld_command = find_tool( "ld", commands );
ld_command = xmalloc( strlen(target_alias) + sizeof("-ld") );
strcpy( ld_command, target_alias );
strcat( ld_command, "-ld" );
}
else
{
static const char * const commands[] = { "ld", "gld", NULL };
if (!(ld_command = find_tool( commands ))) ld_command = xstrdup("ld");
}
if (force_pointer_size) if (force_pointer_size)
{ {
@ -323,42 +322,12 @@ const char *get_nm_command(void)
{ {
if (!nm_command) if (!nm_command)
{ {
if (target_alias) static const char * const commands[] = { "nm", "gnm", NULL };
{ nm_command = find_tool( "nm", commands );
nm_command = xmalloc( strlen(target_alias) + sizeof("-nm") );
strcpy( nm_command, target_alias );
strcat( nm_command, "-nm" );
}
else
{
static const char * const commands[] = { "nm", "gnm", NULL };
if (!(nm_command = find_tool( commands ))) nm_command = xstrdup("nm");
}
} }
return nm_command; return nm_command;
} }
const char *get_windres_command(void)
{
static char *windres_command;
if (!windres_command)
{
if (target_alias)
{
windres_command = xmalloc( strlen(target_alias) + sizeof("-windres") );
strcpy( windres_command, target_alias );
strcat( windres_command, "-windres" );
}
else
{
static const char * const commands[] = { "windres", NULL };
if (!(windres_command = find_tool( commands ))) windres_command = xstrdup("windres");
}
}
return windres_command;
}
/* get a name for a temp file, automatically cleaned up on exit */ /* get a name for a temp file, automatically cleaned up on exit */
char *get_temp_file_name( const char *prefix, const char *suffix ) char *get_temp_file_name( const char *prefix, const char *suffix )
{ {