Commit 945c61c3 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

winegcc: Lookup PATH in find_binary and don't try to run binaries that can't be found.

Based on winebuild. Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent adc34d4a
......@@ -34,6 +34,12 @@
# define min(x,y) (((x) < (y)) ? (x) : (y))
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
# define PATH_SEPARATOR ';'
#else
# define PATH_SEPARATOR ':'
#endif
int verbose = 0;
void error(const char* s, ...)
......@@ -305,18 +311,44 @@ file_type get_lib_type(enum target_platform platform, strarray* path, const char
const char *find_binary( const strarray* prefix, const char *name )
{
char *file_name, *args;
static strarray *path;
unsigned int i;
if (!prefix) return name;
if (strchr( name, '/' )) return name;
for (i = 0; i < prefix->size; i++)
file_name = xstrdup( name );
if ((args = strchr( file_name, ' ' ))) *args++ = 0;
if (prefix)
{
for (i = 0; i < prefix->size; i++)
{
struct stat st;
char *prog = strmake( "%s/%s%s", prefix->base[i], file_name, EXEEXT );
if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111))
return args ? strmake( "%s %s", prog, args ) : prog;
free( prog );
}
}
if (!path)
{
struct stat st;
char *prog = strmake( "%s/%s%s", prefix->base[i], name, EXEEXT );
if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111)) return prog;
path = strarray_alloc();
/* then append the PATH directories */
if (getenv( "PATH" ))
{
char *p = xstrdup( getenv( "PATH" ));
while (*p)
{
strarray_add( path, p );
while (*p && *p != PATH_SEPARATOR) p++;
if (!*p) break;
*p++ = 0;
}
}
}
return name;
return prefix == path ? NULL : find_binary( path, name );
}
int spawn(const strarray* prefix, const strarray* args, int ignore_errors)
......
......@@ -316,6 +316,7 @@ static char* get_temp_file(const char* prefix, const char* suffix)
static const char* build_tool_name(struct options *opts, const char* base, const char* deflt)
{
const char *path;
char* str;
if (opts->target && opts->version)
......@@ -332,7 +333,10 @@ static const char* build_tool_name(struct options *opts, const char* base, const
}
else
str = xstrdup(deflt);
return find_binary( opts->prefix, str );
if ((path = find_binary( opts->prefix, str ))) return path;
error( "Could not find %s\n", base );
return NULL;
}
static strarray* get_translator(struct options *opts)
......@@ -877,6 +881,7 @@ static strarray *get_winebuild_args(struct options *opts)
binary = strmake( "%s/winebuild%s", bindir, EXEEXT );
else
binary = find_binary( opts->prefix, "winebuild" );
if (!binary) error( "Could not find winebuild\n" );
strarray_add( spec_args, binary );
if (verbose) strarray_add( spec_args, "-v" );
if (keep_generated) strarray_add( spec_args, "--save-temps" );
......
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