diff options
Diffstat (limited to 'android/main-emulator.c')
-rw-r--r-- | android/main-emulator.c | 110 |
1 files changed, 89 insertions, 21 deletions
diff --git a/android/main-emulator.c b/android/main-emulator.c index a6e95c7..0981a71 100644 --- a/android/main-emulator.c +++ b/android/main-emulator.c @@ -50,10 +50,20 @@ int android_verbose; # define DLL_EXTENSION ".so" #endif +#if defined(__x86_64__) +/* Normally emulator is compiled in 32-bit. In standalone it can be compiled + in 64-bit (with ,/android-configure.sh --try-64). In this case, emulator-$ARCH + are also compiled in 64-bit and will search for lib64*.so instead of lib*so */ +#define GLES_EMULATION_LIB "lib64OpenglRender" DLL_EXTENSION +#elif defined(__i386__) #define GLES_EMULATION_LIB "libOpenglRender" DLL_EXTENSION +#else +#error Unknown architecture for codegen +#endif + /* Forward declarations */ -static char* getTargetEmulatorPath(const char* progName, const char* avdArch); +static char* getTargetEmulatorPath(const char* progName, const char* avdArch, const int force_32bit); static char* getSharedLibraryPath(const char* progName, const char* libName); static void prependSharedLibraryPath(const char* prefix); @@ -80,6 +90,7 @@ int main(int argc, char** argv) const char* avdName = NULL; char* avdArch = NULL; char* emulatorPath; + int force_32bit = 0; /* Define ANDROID_EMULATOR_DEBUG to 1 in your environment if you want to * see the debug messages from this launcher program. @@ -89,8 +100,9 @@ int main(int argc, char** argv) if (debug != NULL && *debug && *debug != '0') android_verbose = 1; - /* Parse command-line and look for an avd name - * Either in the form or '-avd <name>' or '@<name>' + /* Parse command-line and look for + * 1) an avd name either in the form or '-avd <name>' or '@<name>' + * 2) '-force-32bit' which always use 32-bit emulator on 64-bit platforms */ int nn; for (nn = 1; nn < argc; nn++) { @@ -99,13 +111,18 @@ int main(int argc, char** argv) if (!strcmp(opt,"-qemu")) break; - if (!strcmp(opt,"-avd") && nn+1 < argc) { - avdName = argv[nn+1]; - break; + if (!strcmp(opt,"-force-32bit")) { + force_32bit = 1; + continue; } - else if (opt[0] == '@' && opt[1] != '\0') { - avdName = opt+1; - break; + + if (!avdName) { + if (!strcmp(opt,"-avd") && nn+1 < argc) { + avdName = argv[nn+1]; + } + else if (opt[0] == '@' && opt[1] != '\0') { + avdName = opt+1; + } } } @@ -133,7 +150,7 @@ int main(int argc, char** argv) } /* Find the architecture-specific program in the same directory */ - emulatorPath = getTargetEmulatorPath(argv[0], avdArch); + emulatorPath = getTargetEmulatorPath(argv[0], avdArch, force_32bit); D("Found target-specific emulator binary: %s\n", emulatorPath); /* Replace it in our command-line */ @@ -173,33 +190,75 @@ int main(int argc, char** argv) return errno; } +static int +getHostOSBitness() +{ + /* + This function returns 64 if host is running 64-bit OS, or 32 otherwise. + + It uses the same technique in ndk/build/core/ndk-common.sh. + Here are comments from there: + + ## On Linux or Darwin, a 64-bit kernel (*) doesn't mean that the user-land + ## is always 32-bit, so use "file" to determine the bitness of the shell + ## that invoked us. The -L option is used to de-reference symlinks. + ## + ## Note that on Darwin, a single executable can contain both x86 and + ## x86_64 machine code, so just look for x86_64 (darwin) or x86-64 (Linux) + ## in the output. + + (*) ie. The following code doesn't always work: + struct utsname u; + int host_runs_64bit_OS = (uname(&u) == 0 && strcmp(u.machine, "x86_64") == 0); + */ + return system("file -L \"$SHELL\" | grep -q \"x86[_-]64\"") == 0 ? 64 : 32; +} /* Find the target-specific emulator binary. This will be something * like <programDir>/emulator-<targetArch>, where <programDir> is * the directory of the current program. */ static char* -getTargetEmulatorPath(const char* progName, const char* avdArch) +getTargetEmulatorPath(const char* progName, const char* avdArch, const int force_32bit) { char* progDir; - char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp); + char path[PATH_MAX], *pathEnd=path+sizeof(path), *p; + const char* emulatorPrefix = "emulator-"; + const char* emulator64Prefix = "emulator64-"; #ifdef _WIN32 const char* exeExt = ".exe"; + /* ToDo: currently amd64-mingw32msvc-gcc doesn't work (http://b/issue?id=5949152) + which prevents us from generating 64-bit emulator for Windows */ + int search_for_64bit_emulator = 0; #else const char* exeExt = ""; + int search_for_64bit_emulator = !force_32bit && getHostOSBitness() == 64; #endif /* Get program's directory name in progDir */ path_split(progName, &progDir, NULL); - p = bufprint(temp, end, "%s/emulator-%s%s", progDir, avdArch, exeExt); + if (search_for_64bit_emulator) { + /* Find 64-bit emulator first */ + p = bufprint(path, pathEnd, "%s/%s%s%s", progDir, emulator64Prefix, avdArch, exeExt); + if (p >= pathEnd) { + APANIC("Path too long: %s\n", progName); + } + if (path_exists(path)) { + free(progDir); + return strdup(path); + } + } + + /* Find 32-bit emulator */ + p = bufprint(path, pathEnd, "%s/%s%s%s", progDir, emulatorPrefix, avdArch, exeExt); free(progDir); - if (p >= end) { + if (p >= pathEnd) { APANIC("Path too long: %s\n", progName); } - if (path_exists(temp)) { - return strdup(temp); + if (path_exists(path)) { + return strdup(path); } /* Mmm, the file doesn't exist, If there is no slash / backslash @@ -210,16 +269,25 @@ getTargetEmulatorPath(const char* progName, const char* avdArch) #else if (strchr(progName, '/') == NULL) { #endif - p = bufprint(temp, end, "emulator-%s%s", avdArch, exeExt); - if (p < end) { - char* resolved = path_search_exec(temp); + if (search_for_64bit_emulator) { + p = bufprint(path, pathEnd, "%s%s%s", emulator64Prefix, avdArch, exeExt); + if (p < pathEnd) { + char* resolved = path_search_exec(path); + if (resolved != NULL) + return resolved; + } + } + + p = bufprint(path, pathEnd, "%s%s%s", emulatorPrefix, avdArch, exeExt); + if (p < pathEnd) { + char* resolved = path_search_exec(path); if (resolved != NULL) return resolved; } } /* Otherwise, the program is missing */ - APANIC("Missing arch-specific emulator program: %s\n", temp); + APANIC("Missing arch-specific emulator program: %s\n", path); return NULL; } @@ -271,7 +339,7 @@ getSharedLibraryPath(const char* progName, const char* libName) } /* try in $progDir/../lib, this corresponds to the platform build - * where the emulator binary is under out/host/<system>/lib and + * where the emulator binary is under out/host/<system>/bin and * the libraries are under out/host/<system>/lib */ { |