diff --git a/tools/winegcc/utils.c b/tools/winegcc/utils.c index 52f46c491b3..1a9bc0a63c2 100644 --- a/tools/winegcc/utils.c +++ b/tools/winegcc/utils.c @@ -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) { - 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; + 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 ); + } } - return name; + if (!path) + { + 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 prefix == path ? NULL : find_binary( path, name ); } int spawn(const strarray* prefix, const strarray* args, int ignore_errors) diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 20c72ec3c5d..f2802e2460e 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -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" );