Commit 69a9c2be authored by Alexandre Julliard's avatar Alexandre Julliard

winegcc: Also search the include and lib dirs relative to the binary path.

Suggested by Kevin Puetz. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 90a543d3
...@@ -10,8 +10,9 @@ C_SRCS = \ ...@@ -10,8 +10,9 @@ C_SRCS = \
winegcc_EXTRADEFS = \ winegcc_EXTRADEFS = \
-DINCLUDEDIR="\"${includedir}\"" \ -DINCLUDEDIR="\"${includedir}\"" \
-DDLLDIR="\"${dlldir}\"" \
-DLIBDIR="\"${libdir}\"" \ -DLIBDIR="\"${libdir}\"" \
-DBIN_TO_INCLUDEDIR=\"`$(MAKEDEP) -R ${bindir} ${includedir}`\" \
-DBIN_TO_LIBDIR=\"`$(MAKEDEP) -R ${bindir} ${libdir}`\" \
-DCC="\"$(CC)\"" \ -DCC="\"$(CC)\"" \
-DCPP="\"$(CPPBIN)\"" \ -DCPP="\"$(CPPBIN)\"" \
-DCXX="\"$(CXX)\"" \ -DCXX="\"$(CXX)\"" \
......
...@@ -145,6 +145,10 @@ static strarray* tmp_files; ...@@ -145,6 +145,10 @@ static strarray* tmp_files;
static sigset_t signal_mask; static sigset_t signal_mask;
#endif #endif
static const char *bindir;
static const char *libdir;
static const char *includedir;
enum processor { proc_cc, proc_cxx, proc_cpp, proc_as }; enum processor { proc_cc, proc_cxx, proc_cpp, proc_as };
static const struct static const struct
...@@ -532,7 +536,7 @@ static const char *get_multiarch_dir( enum target_cpu cpu ) ...@@ -532,7 +536,7 @@ static const char *get_multiarch_dir( enum target_cpu cpu )
static char *get_lib_dir( struct options *opts ) static char *get_lib_dir( struct options *opts )
{ {
static const char *stdlibpath[] = { LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" }; const char *stdlibpath[] = { libdir, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
static const char libwine[] = "/libwine.so"; static const char libwine[] = "/libwine.so";
const char *bit_suffix, *other_bit_suffix, *build_multiarch, *target_multiarch; const char *bit_suffix, *other_bit_suffix, *build_multiarch, *target_multiarch;
const char *root = opts->sysroot ? opts->sysroot : ""; const char *root = opts->sysroot ? opts->sysroot : "";
...@@ -548,8 +552,12 @@ static char *get_lib_dir( struct options *opts ) ...@@ -548,8 +552,12 @@ static char *get_lib_dir( struct options *opts )
for (i = 0; i < ARRAY_SIZE(stdlibpath); i++) for (i = 0; i < ARRAY_SIZE(stdlibpath); i++)
{ {
char *p, *buffer = xmalloc( strlen(root) + strlen(stdlibpath[i]) + const char *root = (i && opts->sysroot) ? opts->sysroot : "";
strlen("/arm-linux-gnueabi") + strlen(libwine) + 1 ); char *p, *buffer;
if (!stdlibpath[i]) continue;
buffer = xmalloc( strlen(root) + strlen(stdlibpath[i]) +
strlen("/arm-linux-gnueabi") + strlen(libwine) + 1 );
strcpy( buffer, root ); strcpy( buffer, root );
strcat( buffer, stdlibpath[i] ); strcat( buffer, stdlibpath[i] );
p = buffer + strlen(buffer); p = buffer + strlen(buffer);
...@@ -621,6 +629,28 @@ static char *get_lib_dir( struct options *opts ) ...@@ -621,6 +629,28 @@ static char *get_lib_dir( struct options *opts )
return strmake( "%s%s", root, LIBDIR ); return strmake( "%s%s", root, LIBDIR );
} }
static void init_argv0_dir( const char *argv0 )
{
#ifndef _WIN32
char *p, *dir;
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
dir = realpath( "/proc/self/exe", NULL );
#elif defined (__FreeBSD__) || defined(__DragonFly__)
dir = realpath( "/proc/curproc/file", NULL );
#else
dir = realpath( argv0, NULL );
#endif
if (!dir) return;
if (!(p = strrchr( dir, '/' ))) return;
if (p == dir) p++;
*p = 0;
bindir = dir;
includedir = strmake( "%s/%s", dir, BIN_TO_INCLUDEDIR );
libdir = strmake( "%s/%s", dir, BIN_TO_LIBDIR );
#endif
}
static void compile(struct options* opts, const char* lang) static void compile(struct options* opts, const char* lang)
{ {
strarray* comp_args = strarray_alloc(); strarray* comp_args = strarray_alloc();
...@@ -772,23 +802,28 @@ no_compat_defines: ...@@ -772,23 +802,28 @@ no_compat_defines:
{ {
const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" }; const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
const char *root = opts->isysroot ? opts->isysroot : opts->sysroot ? opts->sysroot : ""; const char *root = opts->isysroot ? opts->isysroot : opts->sysroot ? opts->sysroot : "";
const char *isystem = gcc_defs ? "-isystem" : "-I";
if (opts->use_msvcrt) if (opts->use_msvcrt)
{ {
if (includedir) strarray_add( comp_args, strmake( "%s%s/wine/msvcrt", isystem, includedir ));
for (j = 0; j < ARRAY_SIZE(incl_dirs); j++) for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
{ {
if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue; if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
strarray_add(comp_args, strmake( "%s%s%s/wine/msvcrt", strarray_add(comp_args, strmake( "%s%s%s/wine/msvcrt", isystem, root, incl_dirs[j] ));
gcc_defs ? "-isystem" : "-I", root, incl_dirs[j] ));
} }
strarray_add(comp_args, "-D__MSVCRT__"); strarray_add(comp_args, "-D__MSVCRT__");
} }
if (includedir)
{
strarray_add( comp_args, strmake( "-I%s", includedir ));
strarray_add( comp_args, strmake( "%s%s/wine/windows", isystem, includedir ));
}
for (j = 0; j < ARRAY_SIZE(incl_dirs); j++) for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
{ {
if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue; if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
strarray_add(comp_args, strmake( "-I%s%s", root, incl_dirs[j] )); strarray_add(comp_args, strmake( "-I%s%s", root, incl_dirs[j] ));
strarray_add(comp_args, strmake( "%s%s%s/wine/windows", strarray_add(comp_args, strmake( "%s%s%s/wine/windows", isystem, root, incl_dirs[j] ));
gcc_defs ? "-isystem" : "-I", root, incl_dirs[j] ));
} }
} }
else if (opts->wine_objdir) else if (opts->wine_objdir)
...@@ -830,6 +865,8 @@ static strarray *get_winebuild_args(struct options *opts) ...@@ -830,6 +865,8 @@ static strarray *get_winebuild_args(struct options *opts)
binary = opts->winebuild; binary = opts->winebuild;
else if (opts->wine_objdir) else if (opts->wine_objdir)
binary = strmake( "%s/tools/winebuild/winebuild%s", opts->wine_objdir, EXEEXT ); binary = strmake( "%s/tools/winebuild/winebuild%s", opts->wine_objdir, EXEEXT );
else if (bindir)
binary = strmake( "%s/winebuild%s", bindir, EXEEXT );
else else
binary = find_binary( opts->prefix, winebuild ? winebuild : "winebuild" ); binary = find_binary( opts->prefix, winebuild ? winebuild : "winebuild" );
strarray_add( spec_args, binary ); strarray_add( spec_args, binary );
...@@ -1427,11 +1464,12 @@ int main(int argc, char **argv) ...@@ -1427,11 +1464,12 @@ int main(int argc, char **argv)
sigaddset( &signal_mask, SIGTERM ); sigaddset( &signal_mask, SIGTERM );
sigaddset( &signal_mask, SIGINT ); sigaddset( &signal_mask, SIGINT );
#endif #endif
init_argv0_dir( argv[0] );
/* setup tmp file removal at exit */ /* setup tmp file removal at exit */
tmp_files = strarray_alloc(); tmp_files = strarray_alloc();
atexit(clean_temp_files); atexit(clean_temp_files);
/* initialize options */ /* initialize options */
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.target_cpu = build_cpu; opts.target_cpu = build_cpu;
......
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