Commit 8b5e11c3 authored by Alexandre Julliard's avatar Alexandre Julliard

libwine: Compute relative paths for bin and dll directories at compile time.

parent 35842ca7
...@@ -5,7 +5,7 @@ VPATH = @srcdir@ ...@@ -5,7 +5,7 @@ VPATH = @srcdir@
LIBRARY = wine LIBRARY = wine
SOVERSION = 1 SOVERSION = 1
VERSCRIPT = $(SRCDIR)/wine.map VERSCRIPT = $(SRCDIR)/wine.map
EXTRADEFS = -D__WINESRC__ -DBINDIR="\"$(bindir)\"" -DLIBDIR="\"$(libdir)\"" -DDLLDIR="\"$(dlldir)\"" EXTRADEFS = -D__WINESRC__
EXTRALIBS = $(LIBPORT) @DLLIBS@ @CRTLIBS@ EXTRALIBS = $(LIBPORT) @DLLIBS@ @CRTLIBS@
C_SRCS = \ C_SRCS = \
...@@ -18,4 +18,13 @@ C_SRCS = \ ...@@ -18,4 +18,13 @@ C_SRCS = \
@MAKE_LIB_RULES@ @MAKE_LIB_RULES@
CONFIGDIRS = \
-DBINDIR='"$(bindir)"' \
-DDLLDIR='"$(dlldir)"' \
-DBINDIR_REL=\"`$(RELPATH) $(libdir) $(bindir)`\" \
-DDLLDIR_REL=\"`$(RELPATH) $(libdir) $(dlldir)`\"
config.o: config.c
$(CC) -c $(ALLCFLAGS) -o $@ config.c $(CONFIGDIRS)
### Dependencies: ### Dependencies:
...@@ -101,37 +101,6 @@ inline static void remove_trailing_slashes( char *path ) ...@@ -101,37 +101,6 @@ inline static void remove_trailing_slashes( char *path )
while (len > 1 && path[len-1] == '/') path[--len] = 0; while (len > 1 && path[len-1] == '/') path[--len] = 0;
} }
/* determine where the destination path is located relative to the 'from' path */
inline static const char *get_relative_path( const char *from, const char *dest, unsigned int *dotdots )
{
#define DIR_END(p) (*(p) == 0 || *(p) == '/')
const char *start;
*dotdots = 0;
for (;;)
{
while (*from == '/') from++;
while (*dest == '/') dest++;
start = dest; /* save start of next path element */
if (!*from) break;
while (!DIR_END(from) && *from == *dest) { from++; dest++; }
if (DIR_END(from) && DIR_END(dest)) continue;
/* count remaining elements in 'from' */
do
{
(*dotdots)++;
while (!DIR_END(from)) from++;
while (*from == '/') from++;
}
while (*from);
break;
}
return start;
#undef DIR_END
}
/* return the directory that contains the library at run-time */ /* return the directory that contains the library at run-time */
static const char *get_runtime_libdir(void) static const char *get_runtime_libdir(void)
{ {
...@@ -161,41 +130,28 @@ static char *get_path_from_libdir( const char *path, const char *fallback, const ...@@ -161,41 +130,28 @@ static char *get_path_from_libdir( const char *path, const char *fallback, const
/* retrieve the library load path */ /* retrieve the library load path */
if (libdir) if (path[0] && libdir)
{ {
unsigned int dotdots = 0; ret = xmalloc( strlen(libdir) + strlen(path) + strlen(filename) + 3 );
const char *start = get_relative_path( LIBDIR, path, &dotdots );
ret = xmalloc( strlen(libdir) + 3 * dotdots + strlen(start) + strlen(filename) + 3 );
strcpy( ret, libdir ); strcpy( ret, libdir );
p = ret + strlen(libdir); p = ret + strlen(libdir);
if (p[-1] != '/') *p++ = '/'; if (p[-1] != '/') *p++ = '/';
while (dotdots--)
{
p[0] = '.';
p[1] = '.';
p[2] = '/';
p += 3;
}
strcpy( p, start );
p += strlen(p);
} }
else else
{ {
if (fallback) path = fallback; if (fallback) path = fallback;
ret = xmalloc( strlen(path) + strlen(filename) + 2 ); ret = p = xmalloc( strlen(path) + strlen(filename) + 2 );
strcpy( ret, path );
p = ret + strlen(ret);
} }
strcpy( p, path );
p += strlen(p);
if (*filename) if (*filename)
{ {
if (p[-1] != '/') *p++ = '/'; if (p > ret && p[-1] != '/') *p++ = '/';
strcpy( p, filename ); strcpy( p, filename );
} }
else if (p[-1] == '/') p[-1] = 0; else if (p > ret && p[-1] == '/') p[-1] = 0;
return ret; return ret;
} }
...@@ -230,7 +186,7 @@ const char *get_default_dlldir(void) ...@@ -230,7 +186,7 @@ const char *get_default_dlldir(void)
{ {
static const char *dlldir; static const char *dlldir;
if (!dlldir) dlldir = get_path_from_libdir( DLLDIR, NULL, "" ); if (!dlldir) dlldir = get_path_from_libdir( DLLDIR_REL, DLLDIR, "" );
return dlldir; return dlldir;
} }
...@@ -419,7 +375,7 @@ void wine_exec_wine_binary( const char *name, char **argv, const char *env_var ) ...@@ -419,7 +375,7 @@ void wine_exec_wine_binary( const char *name, char **argv, const char *env_var )
} }
/* first, bin directory from the current libdir or argv0 */ /* first, bin directory from the current libdir or argv0 */
argv[0] = get_path_from_libdir( bindir, argv0_path, name ); argv[0] = get_path_from_libdir( BINDIR_REL, argv0_path, name );
preloader_exec( argv, use_preloader ); preloader_exec( argv, use_preloader );
free( argv[0] ); free( argv[0] );
......
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