Module: wine Branch: master Commit: 38ca263374fcd9aa28cdaf18d15c50b0cbe5445d URL: http://source.winehq.org/git/wine.git/?a=commit;h=38ca263374fcd9aa28cdaf18d1...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Dec 30 12:42:25 2009 +0100
winebuild: Simplify the code for finding the various build tools.
---
tools/winebuild/build.h | 2 +- tools/winebuild/res32.c | 3 +- tools/winebuild/utils.c | 81 ++++++++++++++-------------------------------- 3 files changed, 28 insertions(+), 58 deletions(-)
diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h index 64ad5b1..7dca2d8 100644 --- a/tools/winebuild/build.h +++ b/tools/winebuild/build.h @@ -209,10 +209,10 @@ extern void warning( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2))); extern int output( const char *format, ... ) __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_ld_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 void output_standard_file_header(void); extern FILE *open_input_file( const char *srcdir, const char *name ); diff --git a/tools/winebuild/res32.c b/tools/winebuild/res32.c index e3d861e..6320a2e 100644 --- a/tools/winebuild/res32.c +++ b/tools/winebuild/res32.c @@ -652,13 +652,14 @@ void output_res_o_file( DLLSPEC *spec )
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 ); sprintf( cmd, "%s -i %s -o %s", prog, res_file, output_file_name ); if (verbose) fprintf( stderr, "%s\n", cmd ); err = system( cmd ); if (err) fatal_error( "%s failed with status %d\n", prog, err ); free( cmd ); + free( prog ); } output_file_name = NULL; /* so we don't try to assemble it */ } diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c index c0b9371..31bf691 100644 --- a/tools/winebuild/utils.c +++ b/tools/winebuild/utils.c @@ -199,15 +199,25 @@ int output( const char *format, ... ) }
/* 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 unsigned int count, maxlen;
char *p, *file; + const char *alt_names[2]; unsigned int i, len; 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) { 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 ); }
+ if (!names) + { + alt_names[0] = name; + alt_names[1] = NULL; + names = alt_names; + } + while (*names) { len = strlen(*names) + sizeof(EXEEXT) + 1; @@ -249,24 +266,15 @@ static char *find_tool( const char * const *names ) free( file ); names++; } - return NULL; + return xstrdup( name ); }
const char *get_as_command(void) { if (!as_command) { - if (target_alias) - { - 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"); - } + static const char * const commands[] = { "gas", "as", NULL }; + as_command = find_tool( "as", commands );
if (force_pointer_size) { @@ -284,17 +292,8 @@ const char *get_ld_command(void) { if (!ld_command) { - if (target_alias) - { - 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"); - } + static const char * const commands[] = { "ld", "gld", NULL }; + ld_command = find_tool( "ld", commands );
if (force_pointer_size) { @@ -323,42 +322,12 @@ const char *get_nm_command(void) { if (!nm_command) { - if (target_alias) - { - 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"); - } + static const char * const commands[] = { "nm", "gnm", NULL }; + nm_command = find_tool( "nm", commands ); } 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 */ char *get_temp_file_name( const char *prefix, const char *suffix ) {