Commit 6a912649 authored by Alexandre Julliard's avatar Alexandre Julliard

makefiles: Store PE objects in subdirectories in the build tree.

This will make it possible to build multiple PE architectures.
parent 8d43170b
...@@ -2930,12 +2930,13 @@ static NTSTATUS find_builtin_without_file( const WCHAR *name, UNICODE_STRING *ne ...@@ -2930,12 +2930,13 @@ static NTSTATUS find_builtin_without_file( const WCHAR *name, UNICODE_STRING *ne
if (!name[1] || wcscmp( name + wcslen(name) - 2, L"16" )) return status; if (!name[1] || wcscmp( name + wcslen(name) - 2, L"16" )) return status;
} }
if (!get_env_var( L"WINEBUILDDIR", 20 + 2 * wcslen(name), new_name )) if (!get_env_var( L"WINEBUILDDIR", 20 + 2 * wcslen(name) + wcslen(pe_dir), new_name ))
{ {
len = new_name->Length; len = new_name->Length;
RtlAppendUnicodeToString( new_name, L"\\dlls\\" ); RtlAppendUnicodeToString( new_name, L"\\dlls\\" );
RtlAppendUnicodeToString( new_name, name ); RtlAppendUnicodeToString( new_name, name );
if ((ext = wcsrchr( name, '.' )) && !wcscmp( ext, L".dll" )) new_name->Length -= 4 * sizeof(WCHAR); if ((ext = wcsrchr( name, '.' )) && !wcscmp( ext, L".dll" )) new_name->Length -= 4 * sizeof(WCHAR);
RtlAppendUnicodeToString( new_name, pe_dir );
RtlAppendUnicodeToString( new_name, L"\\" ); RtlAppendUnicodeToString( new_name, L"\\" );
RtlAppendUnicodeToString( new_name, name ); RtlAppendUnicodeToString( new_name, name );
status = open_dll_file( new_name, pwm, mapping, image_info, id ); status = open_dll_file( new_name, pwm, mapping, image_info, id );
...@@ -2944,6 +2945,7 @@ static NTSTATUS find_builtin_without_file( const WCHAR *name, UNICODE_STRING *ne ...@@ -2944,6 +2945,7 @@ static NTSTATUS find_builtin_without_file( const WCHAR *name, UNICODE_STRING *ne
new_name->Length = len; new_name->Length = len;
RtlAppendUnicodeToString( new_name, L"\\programs\\" ); RtlAppendUnicodeToString( new_name, L"\\programs\\" );
RtlAppendUnicodeToString( new_name, name ); RtlAppendUnicodeToString( new_name, name );
RtlAppendUnicodeToString( new_name, pe_dir );
RtlAppendUnicodeToString( new_name, L"\\" ); RtlAppendUnicodeToString( new_name, L"\\" );
RtlAppendUnicodeToString( new_name, name ); RtlAppendUnicodeToString( new_name, name );
status = open_dll_file( new_name, pwm, mapping, image_info, id ); status = open_dll_file( new_name, pwm, mapping, image_info, id );
......
...@@ -1441,6 +1441,21 @@ static inline char *prepend( char *buffer, const char *str, size_t len ) ...@@ -1441,6 +1441,21 @@ static inline char *prepend( char *buffer, const char *str, size_t len )
return memcpy( buffer - len, str, len ); return memcpy( buffer - len, str, len );
} }
static inline char *prepend_build_dir_path( char *ptr, const char *ext, const char *arch_dir,
const char *top_dir )
{
char *name = ptr;
unsigned int namelen = strlen(name), extlen = strlen(ext);
if (namelen > extlen && !strcmp( name + namelen - extlen, ext )) namelen -= extlen;
ptr = prepend( ptr, arch_dir, strlen(arch_dir) );
ptr = prepend( ptr, name, namelen );
ptr = prepend( ptr, top_dir, strlen(top_dir) );
ptr = prepend( ptr, build_dir, strlen(build_dir) );
return ptr;
}
/*********************************************************************** /***********************************************************************
* open_dll_file * open_dll_file
* *
...@@ -1536,7 +1551,7 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T ...@@ -1536,7 +1551,7 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T
SECTION_IMAGE_INFORMATION *image_info, SECTION_IMAGE_INFORMATION *image_info,
ULONG_PTR zero_bits, WORD machine, BOOL prefer_native ) ULONG_PTR zero_bits, WORD machine, BOOL prefer_native )
{ {
unsigned int i, pos, namepos, namelen, maxlen = 0; unsigned int i, pos, namepos, maxlen = 0;
unsigned int len = nt_name->Length / sizeof(WCHAR); unsigned int len = nt_name->Length / sizeof(WCHAR);
char *ptr = NULL, *file, *ext = NULL; char *ptr = NULL, *file, *ext = NULL;
const char *pe_dir = get_pe_dir( machine ); const char *pe_dir = get_pe_dir( machine );
...@@ -1569,28 +1584,20 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T ...@@ -1569,28 +1584,20 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T
if (build_dir) if (build_dir)
{ {
/* try as a dll */ /* try as a dll */
ptr = file + pos;
namelen = len + 1;
file[pos + len + 1] = 0; file[pos + len + 1] = 0;
if (ext && !strcmp( ext, ".dll" )) namelen -= 4; ptr = prepend_build_dir_path( file + pos, ".dll", pe_dir, "/dlls" );
ptr = prepend( ptr, ptr, namelen );
ptr = prepend( ptr, "/dlls", sizeof("/dlls") - 1 );
ptr = prepend( ptr, build_dir, strlen(build_dir) );
status = open_builtin_pe_file( ptr, &attr, module, size_ptr, image_info, zero_bits, machine, prefer_native ); status = open_builtin_pe_file( ptr, &attr, module, size_ptr, image_info, zero_bits, machine, prefer_native );
ptr = prepend_build_dir_path( file + pos, ".dll", "", "/dlls" );
if (status != STATUS_DLL_NOT_FOUND) goto done; if (status != STATUS_DLL_NOT_FOUND) goto done;
strcpy( file + pos + len + 1, ".so" ); strcpy( file + pos + len + 1, ".so" );
status = open_builtin_so_file( ptr, &attr, module, image_info, machine, prefer_native ); status = open_builtin_so_file( ptr, &attr, module, image_info, machine, prefer_native );
if (status != STATUS_DLL_NOT_FOUND) goto done; if (status != STATUS_DLL_NOT_FOUND) goto done;
/* now as a program */ /* now as a program */
ptr = file + pos;
namelen = len + 1;
file[pos + len + 1] = 0; file[pos + len + 1] = 0;
if (ext && !strcmp( ext, ".exe" )) namelen -= 4; ptr = prepend_build_dir_path( file + pos, ".exe", pe_dir, "/programs" );
ptr = prepend( ptr, ptr, namelen );
ptr = prepend( ptr, "/programs", sizeof("/programs") - 1 );
ptr = prepend( ptr, build_dir, strlen(build_dir) );
status = open_builtin_pe_file( ptr, &attr, module, size_ptr, image_info, zero_bits, machine, prefer_native ); status = open_builtin_pe_file( ptr, &attr, module, size_ptr, image_info, zero_bits, machine, prefer_native );
ptr = prepend_build_dir_path( file + pos, ".exe", "", "/programs" );
if (status != STATUS_DLL_NOT_FOUND) goto done; if (status != STATUS_DLL_NOT_FOUND) goto done;
strcpy( file + pos + len + 1, ".so" ); strcpy( file + pos + len + 1, ".so" );
status = open_builtin_so_file( ptr, &attr, module, image_info, machine, prefer_native ); status = open_builtin_so_file( ptr, &attr, module, image_info, machine, prefer_native );
...@@ -1983,7 +1990,7 @@ static void load_ntdll(void) ...@@ -1983,7 +1990,7 @@ static void load_ntdll(void)
InitializeObjectAttributes( &attr, &str, 0, 0, NULL ); InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
name = malloc( strlen( ntdll_dir ) + strlen( pe_dir ) + sizeof("/ntdll.dll.so") ); name = malloc( strlen( ntdll_dir ) + strlen( pe_dir ) + sizeof("/ntdll.dll.so") );
if (build_dir) sprintf( name, "%s/ntdll.dll", ntdll_dir ); if (build_dir) sprintf( name, "%s%s/ntdll.dll", ntdll_dir, pe_dir );
else sprintf( name, "%s%s/ntdll.dll", dll_dir, pe_dir ); else sprintf( name, "%s%s/ntdll.dll", dll_dir, pe_dir );
status = open_builtin_pe_file( name, &attr, &module, &size, &info, 0, current_machine, FALSE ); status = open_builtin_pe_file( name, &attr, &module, &size, &info, 0, current_machine, FALSE );
if (status == STATUS_DLL_NOT_FOUND) if (status == STATUS_DLL_NOT_FOUND)
...@@ -2023,8 +2030,8 @@ static void load_apiset_dll(void) ...@@ -2023,8 +2030,8 @@ static void load_apiset_dll(void)
init_unicode_string( &str, path ); init_unicode_string( &str, path );
InitializeObjectAttributes( &attr, &str, 0, 0, NULL ); InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
name = malloc( strlen( ntdll_dir ) + strlen( pe_dir ) + sizeof("/apisetschema.dll") ); name = malloc( strlen( ntdll_dir ) + strlen( pe_dir ) + sizeof("/apisetschema/apisetschema.dll") );
if (build_dir) sprintf( name, "%s/dlls/apisetschema/apisetschema.dll", build_dir ); if (build_dir) sprintf( name, "%s/dlls/apisetschema%s/apisetschema.dll", build_dir, pe_dir );
else sprintf( name, "%s%s/apisetschema.dll", dll_dir, pe_dir ); else sprintf( name, "%s%s/apisetschema.dll", dll_dir, pe_dir );
status = open_unix_file( &handle, name, GENERIC_READ | SYNCHRONIZE, &attr, 0, status = open_unix_file( &handle, name, GENERIC_READ | SYNCHRONIZE, &attr, 0,
FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_OPEN, FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_OPEN,
......
...@@ -407,6 +407,21 @@ static inline WCHAR *prepend( WCHAR *buffer, const WCHAR *str, size_t len ) ...@@ -407,6 +407,21 @@ static inline WCHAR *prepend( WCHAR *buffer, const WCHAR *str, size_t len )
return memcpy( buffer - len, str, len * sizeof(WCHAR) ); return memcpy( buffer - len, str, len * sizeof(WCHAR) );
} }
static inline WCHAR *prepend_build_dir_path( WCHAR *ptr, const WCHAR *ext, const WCHAR *arch_dir,
const WCHAR *top_dir, const WCHAR *build_dir )
{
WCHAR *name = ptr;
unsigned int namelen = wcslen(name), extlen = wcslen(ext);
if (namelen > extlen && !wcscmp( name + namelen - extlen, ext )) namelen -= extlen;
ptr = prepend( ptr, arch_dir, wcslen(arch_dir) );
ptr = prepend( ptr, name, namelen );
ptr = prepend( ptr, top_dir, wcslen(top_dir) );
ptr = prepend( ptr, build_dir, wcslen(build_dir) );
return ptr;
}
static const WCHAR *enum_load_path( unsigned int idx ) static const WCHAR *enum_load_path( unsigned int idx )
{ {
WCHAR buffer[32]; WCHAR buffer[32];
...@@ -421,7 +436,7 @@ static void *load_fake_dll( const WCHAR *name, SIZE_T *size ) ...@@ -421,7 +436,7 @@ static void *load_fake_dll( const WCHAR *name, SIZE_T *size )
const WCHAR *path; const WCHAR *path;
WCHAR *file, *ptr; WCHAR *file, *ptr;
void *data = NULL; void *data = NULL;
unsigned int i, pos, len, namelen, maxlen = 0; unsigned int i, pos, len, maxlen = 0;
WCHAR *p; WCHAR *p;
int res = 0; int res = 0;
...@@ -442,23 +457,13 @@ static void *load_fake_dll( const WCHAR *name, SIZE_T *size ) ...@@ -442,23 +457,13 @@ static void *load_fake_dll( const WCHAR *name, SIZE_T *size )
if (build_dir) if (build_dir)
{ {
/* try as a dll */ /* try as a dll */
ptr = file + pos;
namelen = len + 1;
file[pos + len + 1] = 0; file[pos + len + 1] = 0;
if (namelen > 4 && !wcsncmp( ptr + namelen - 4, L".dll", 4 )) namelen -= 4; ptr = prepend_build_dir_path( file + pos, L".dll", pe_dir, L"\\dlls", build_dir );
ptr = prepend( ptr, ptr, namelen );
ptr = prepend( ptr, L"\\dlls", 5 );
ptr = prepend( ptr, build_dir, lstrlenW(build_dir) );
if ((res = read_file( ptr, &data, size ))) goto done; if ((res = read_file( ptr, &data, size ))) goto done;
/* now as a program */ /* now as a program */
ptr = file + pos;
namelen = len + 1;
file[pos + len + 1] = 0; file[pos + len + 1] = 0;
if (namelen > 4 && !wcsncmp( ptr + namelen - 4, L".exe", 4 )) namelen -= 4; ptr = prepend_build_dir_path( file + pos, L".exe", pe_dir, L"\\programs", build_dir );
ptr = prepend( ptr, ptr, namelen );
ptr = prepend( ptr, L"\\programs", 9 );
ptr = prepend( ptr, build_dir, lstrlenW(build_dir) );
if ((res = read_file( ptr, &data, size ))) goto done; if ((res = read_file( ptr, &data, size ))) goto done;
} }
...@@ -979,6 +984,7 @@ static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *wildcard, ...@@ -979,6 +984,7 @@ static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *wildcard,
lstrcpyW( name, data.name ); lstrcpyW( name, data.name );
if (default_ext) /* inside build dir */ if (default_ext) /* inside build dir */
{ {
lstrcatW( name, pe_dir );
lstrcatW( name, L"\\" ); lstrcatW( name, L"\\" );
lstrcatW( name, data.name ); lstrcatW( name, data.name );
if (wcschr( data.name, '.' ) && install_fake_dll( dest, file, delete, &delay_copy )) if (wcschr( data.name, '.' ) && install_fake_dll( dest, file, delete, &delay_copy ))
......
...@@ -252,14 +252,14 @@ static void clear_settings(HWND dialog) ...@@ -252,14 +252,14 @@ static void clear_settings(HWND dialog)
/* load the list of available libraries from a given dir */ /* load the list of available libraries from a given dir */
static void load_library_list_from_dir( HWND dialog, const WCHAR *dir_path, int check_subdirs ) static void load_library_list_from_dir( HWND dialog, const WCHAR *dir_path, int check_subdirs )
{ {
static const WCHAR * const ext[] = { L".dll", L".dll.so", L".so", L"" }; static const WCHAR * const ext[] = { L".dll", L"", L".dll.so", L".so" };
WCHAR *buffer, *p, name[256]; WCHAR *buffer, *p, name[256];
unsigned int i; unsigned int i;
HANDLE handle; HANDLE handle;
WIN32_FIND_DATAW data; WIN32_FIND_DATAW data;
ULONG maxlen = wcslen(dir_path) + wcslen(pe_dir) + 10 + 2 * ARRAY_SIZE(name);
buffer = HeapAlloc( GetProcessHeap(), 0, (wcslen(dir_path) + 10) * sizeof(WCHAR) + 2 * sizeof(name) ); buffer = HeapAlloc( GetProcessHeap(), 0, maxlen * sizeof(WCHAR) );
wcscpy( buffer, dir_path ); wcscpy( buffer, dir_path );
wcscat( buffer, L"\\*" ); wcscat( buffer, L"\\*" );
buffer[1] = '\\'; /* change \??\ to \\?\ */ buffer[1] = '\\'; /* change \??\ to \\?\ */
...@@ -282,7 +282,9 @@ static void load_library_list_from_dir( HWND dialog, const WCHAR *dir_path, int ...@@ -282,7 +282,9 @@ static void load_library_list_from_dir( HWND dialog, const WCHAR *dir_path, int
if (!show_dll_in_list( data.cFileName )) continue; if (!show_dll_in_list( data.cFileName )) continue;
for (i = 0; i < ARRAY_SIZE( ext ); i++) for (i = 0; i < ARRAY_SIZE( ext ); i++)
{ {
swprintf( p, 2 * ARRAY_SIZE(name) + 10, L"%s\\%s%s", data.cFileName, data.cFileName, ext[i] ); if (!ext[i][0] && !wcschr( data.cFileName, '.' )) continue;
swprintf( p, buffer + maxlen - p, L"%s%s\\%s%s", data.cFileName,
i > 1 ? L"" : pe_dir, data.cFileName, ext[i] );
if (GetFileAttributesW( buffer ) != INVALID_FILE_ATTRIBUTES) if (GetFileAttributesW( buffer ) != INVALID_FILE_ATTRIBUTES)
{ {
SendDlgItemMessageW( dialog, IDC_DLLCOMBO, CB_ADDSTRING, 0, (LPARAM)data.cFileName ); SendDlgItemMessageW( dialog, IDC_DLLCOMBO, CB_ADDSTRING, 0, (LPARAM)data.cFileName );
......
...@@ -686,8 +686,8 @@ int open_typelib( const char *name ) ...@@ -686,8 +686,8 @@ int open_typelib( const char *name )
{ {
int namelen = strlen( name ); int namelen = strlen( name );
if (strendswith( name, ".dll" )) namelen -= 4; if (strendswith( name, ".dll" )) namelen -= 4;
TRYOPEN( strmake( "%.*s/%.*s/%s", (int)strlen(dlldirs.str[i]) - 2, dlldirs.str[i], TRYOPEN( strmake( "%.*s/%.*s%s/%s", (int)strlen(dlldirs.str[i]) - 2, dlldirs.str[i],
namelen, name, name )); namelen, name, pe_dir, name ));
} }
else else
{ {
......
...@@ -93,7 +93,7 @@ file_type get_file_type(const char* filename) ...@@ -93,7 +93,7 @@ file_type get_file_type(const char* filename)
return file_other; return file_other;
} }
static char* try_lib_path(const char* dir, const char* pre, static char* try_lib_path(const char *dir, const char *arch_dir, const char *pre,
const char* library, const char* ext, const char* library, const char* ext,
file_type expected_type) file_type expected_type)
{ {
...@@ -101,7 +101,7 @@ static char* try_lib_path(const char* dir, const char* pre, ...@@ -101,7 +101,7 @@ static char* try_lib_path(const char* dir, const char* pre,
file_type type; file_type type;
/* first try a subdir named from the library we are looking for */ /* first try a subdir named from the library we are looking for */
fullname = strmake("%s/%s/%s%s%s", dir, library, pre, library, ext); fullname = strmake("%s/%s%s/%s%s%s", dir, library, arch_dir, pre, library, ext);
if (verbose > 1) fprintf(stderr, "Try %s...", fullname); if (verbose > 1) fprintf(stderr, "Try %s...", fullname);
type = get_file_type(fullname); type = get_file_type(fullname);
if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n"); if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n");
...@@ -120,25 +120,28 @@ static char* try_lib_path(const char* dir, const char* pre, ...@@ -120,25 +120,28 @@ static char* try_lib_path(const char* dir, const char* pre,
static file_type guess_lib_type(struct target target, const char* dir, static file_type guess_lib_type(struct target target, const char* dir,
const char* library, const char *prefix, const char *suffix, char** file) const char* library, const char *prefix, const char *suffix, char** file)
{ {
const char *arch_dir = "";
if (target.platform != PLATFORM_WINDOWS && if (target.platform != PLATFORM_WINDOWS &&
target.platform != PLATFORM_MINGW && target.platform != PLATFORM_MINGW &&
target.platform != PLATFORM_CYGWIN) target.platform != PLATFORM_CYGWIN)
{ {
/* Unix shared object */ /* Unix shared object */
if ((*file = try_lib_path(dir, prefix, library, ".so", file_so))) if ((*file = try_lib_path(dir, "", prefix, library, ".so", file_so)))
return file_so; return file_so;
/* Mach-O (Darwin/Mac OS X) Dynamic Library behaves mostly like .so */ /* Mach-O (Darwin/Mac OS X) Dynamic Library behaves mostly like .so */
if ((*file = try_lib_path(dir, prefix, library, ".dylib", file_so))) if ((*file = try_lib_path(dir, "", prefix, library, ".dylib", file_so)))
return file_so; return file_so;
/* Windows DLL */ /* Windows DLL */
if ((*file = try_lib_path(dir, prefix, library, ".def", file_def))) if ((*file = try_lib_path(dir, "", prefix, library, ".def", file_def)))
return file_dll; return file_dll;
} }
else arch_dir = get_arch_dir( target );
/* static archives */ /* static archives */
if ((*file = try_lib_path(dir, prefix, library, suffix, file_arh))) if ((*file = try_lib_path(dir, arch_dir, prefix, library, suffix, file_arh)))
return file_arh; return file_arh;
return file_na; return file_na;
......
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