From ecd8d1ae34125057a39e8517a3dd24f81c20ec86 Mon Sep 17 00:00:00 2001 From: Liam Devine Date: Sat, 12 Mar 2011 17:03:10 +0000 Subject: [PATCH] added define _CRT_SECURE_NO_DEPRECATE for visual studio build in premake4.lua. Old versions of vs2005 use this define. added host.c for detecting if the process is running under wow, uses code provided on msdn where we lookup the function at runtime, which fails gracefully if a 32 bit machine. add host.is_64bit function in host.lua --- CHANGES.txt | 1 + premake4.lua | 3 + src/base/host.lua | 67 ++++++++++++++++++++++ src/host/host.c | 19 +++++++ src/host/premake.c | 9 ++- src/host/premake.h | 138 ++++++++++++++++++++++----------------------- 6 files changed, 165 insertions(+), 72 deletions(-) create mode 100755 src/base/host.lua create mode 100755 src/host/host.c mode change 100644 => 100755 src/host/premake.c mode change 100644 => 100755 src/host/premake.h diff --git a/CHANGES.txt b/CHANGES.txt index 8d0da234..95190a95 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,7 @@ * Patch 2963313: Enable setting .NET framework version (Justen Hyde) * Switched PS3 builds from GCC to SNC * Ignore NoRTTI flag for Managed C++ projects (Nick Darnell) +* Added host.is_64bit ------- diff --git a/premake4.lua b/premake4.lua index 1646731b..57de46a7 100644 --- a/premake4.lua +++ b/premake4.lua @@ -48,6 +48,9 @@ configuration "vs*" defines { "_CRT_SECURE_NO_WARNINGS" } + + configuration "vs2005" + defines {"_CRT_SECURE_NO_DEPRECATE" } configuration "linux" defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" } diff --git a/src/base/host.lua b/src/base/host.lua new file mode 100755 index 00000000..3c2018f4 --- /dev/null +++ b/src/base/host.lua @@ -0,0 +1,67 @@ + +-- +--Windows +--AMD64 or IA64 or x86 according to --http://msdn.microsoft.com/en-us/library/aa384274(VS.85).aspx +-- +local function windows_is_64_bit() +--works on 64 bit windows running a 32 bit binary + local arch = os.getenv("PROCESSOR_ARCHITECTURE") + if string.find(arch,'AMD64') or string.find(arch,'IA64') then + --64 bit executable running on 64 bit windows + return true + else + --if running under wow then the above returns X86, so check using this + --function defined in host.c + return host.windows_is_64bit_running_under_wow() + end +end + +local function get_result_of_command(cmd) + local pipe = io.popen(cmd) + local result = pipe:read('*a') + pipe:close() + return result +end + +local function linux_is_64_bit() +--works on 64bit Debian running a 32 bit binary + local contents= get_result_of_command('uname -m') + local t64 = + { + 'x86_64' + ,'ia64' + ,'amd64' + ,'powerpc64' + ,'sparc64' + } + for _,v in ipairs(t64) do + if contents:find(v) then return true end + end + return false +end + + +local function macosx_is_64_bit() +--works on mac mini 10.6 as well as others + local contents= get_result_of_command('echo $HOSTTYPE') + --PPC64 is this correct? + if string.find(contents,'x86_64') or string.find(contents,'PPC64') then + return true + end + return false +end + +host.is_64bit = function() + local host_os = _OS + + if host_os == 'linux' or host_os == 'bsd' or host_os == 'solaris' or host_os == 'haiku' then + --I assume these are correct only tested with 'linux' + return linux_is_64_bit() + elseif host_os == 'macosx' then + return macosx_is_64_bit() + elseif host_os == 'windows' then + return windows_is_64_bit() + else + error('unknown host platform, please contact premake') + end +end diff --git a/src/host/host.c b/src/host/host.c new file mode 100755 index 00000000..c2455062 --- /dev/null +++ b/src/host/host.c @@ -0,0 +1,19 @@ + +#include "premake.h" + +int windows_is_64bit_running_under_wow(struct lua_State* l) +{ +#if PLATFORM_WINDOWS == 1 + typedef BOOL (WINAPI * wow_func_sig)(HANDLE,PBOOL); + + BOOL is_wow = FALSE; + wow_func_sig func = (wow_func_sig)GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); + if(func) + if(! func(GetCurrentProcess(),&is_wow)) + luaL_error(l,"IsWow64Process returned an error"); +#else + int is_wow = 0; +#endif + lua_pushboolean(l,is_wow); + return 1; +} \ No newline at end of file diff --git a/src/host/premake.c b/src/host/premake.c old mode 100644 new mode 100755 index 01beb597..802b6f15 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -56,7 +56,11 @@ static const luaL_Reg string_functions[] = { { NULL, NULL } }; - +static const luaL_Reg host_functions[] = +{ + { "windows_is_64bit_running_under_wow", windows_is_64bit_running_under_wow }, + { NULL, NULL } +}; /** * Program entry point. @@ -72,7 +76,8 @@ int main(int argc, const char** argv) luaL_register(L, "path", path_functions); luaL_register(L, "os", os_functions); luaL_register(L, "string", string_functions); - + luaL_register(L, "host", host_functions); + /* push the application metadata */ lua_pushstring(L, LUA_COPYRIGHT); lua_setglobal(L, "_COPYRIGHT"); diff --git a/src/host/premake.h b/src/host/premake.h old mode 100644 new mode 100755 index 0c83571b..fa77ec61 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -1,70 +1,68 @@ -/** - * \file premake.h - * \brief Program-wide constants and definitions. - * \author Copyright (c) 2002-2011 Jason Perkins and the Premake project - */ - -#define lua_c -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" - - -/* Identify the current platform I'm not sure how to reliably detect - * Windows but since it is the most common I use it as the default */ -#if defined(__linux__) -#define PLATFORM_LINUX (1) -#define PLATFORM_STRING "linux" -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) -#define PLATFORM_BSD (1) -#define PLATFORM_STRING "bsd" -#elif defined(__APPLE__) && defined(__MACH__) -#define PLATFORM_MACOSX (1) -#define PLATFORM_STRING "macosx" -#elif defined(__sun__) && defined(__svr4__) -#define PLATFORM_SOLARIS (1) -#define PLATFORM_STRING "solaris" -#elif defined(__HAIKU__) -#define PLATFORM_HAIKU (1) -#define PLATFORM_STRING "haiku" -#else -#define PLATFORM_WINDOWS (1) -#define PLATFORM_STRING "windows" -#endif - - -/* Pull in platform-specific headers required by built-in functions */ -#if PLATFORM_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include -#else -#include -#endif - - -/* A success return code */ -#define OKAY (0) - - -/* Bootstrapping helper functions */ -int do_isfile(const char* filename); - - -/* Built-in functions */ -int path_isabsolute(lua_State* L); -int os_chdir(lua_State* L); -int os_copyfile(lua_State* L); -int os_getcwd(lua_State* L); -int os_isdir(lua_State* L); -int os_isfile(lua_State* L); -int os_matchdone(lua_State* L); -int os_matchisfile(lua_State* L); -int os_matchname(lua_State* L); -int os_matchnext(lua_State* L); -int os_matchstart(lua_State* L); -int os_mkdir(lua_State* L); -int os_pathsearch(lua_State* L); -int os_rmdir(lua_State* L); -int os_uuid(lua_State* L); -int string_endswith(lua_State* L); - +/** + * \file premake.h + * \brief Program-wide constants and definitions. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ + +#define lua_c +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + + +/* Identify the current platform I'm not sure how to reliably detect + * Windows but since it is the most common I use it as the default */ +#if defined(__linux__) +#define PLATFORM_LINUX (1) +#define PLATFORM_STRING "linux" +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +#define PLATFORM_BSD (1) +#define PLATFORM_STRING "bsd" +#elif defined(__APPLE__) && defined(__MACH__) +#define PLATFORM_MACOSX (1) +#define PLATFORM_STRING "macosx" +#elif defined(__sun__) && defined(__svr4__) +#define PLATFORM_SOLARIS (1) +#define PLATFORM_STRING "solaris" +#else +#define PLATFORM_WINDOWS (1) +#define PLATFORM_STRING "windows" +#endif + + +/* Pull in platform-specific headers required by built-in functions */ +#if PLATFORM_WINDOWS +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif + + +/* A success return code */ +#define OKAY (0) + + +/* Bootstrapping helper functions */ +int do_isfile(const char* filename); + + +/* Built-in functions */ +int path_isabsolute(lua_State* L); +int os_chdir(lua_State* L); +int os_copyfile(lua_State* L); +int os_getcwd(lua_State* L); +int os_isdir(lua_State* L); +int os_isfile(lua_State* L); +int os_matchdone(lua_State* L); +int os_matchisfile(lua_State* L); +int os_matchname(lua_State* L); +int os_matchnext(lua_State* L); +int os_matchstart(lua_State* L); +int os_mkdir(lua_State* L); +int os_pathsearch(lua_State* L); +int os_rmdir(lua_State* L); +int os_uuid(lua_State* L); +int string_endswith(lua_State* L); +int windows_is_64bit_running_under_wow(struct lua_State* l); +