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
This commit is contained in:
Liam Devine 2011-03-12 17:03:10 +00:00
parent 33b9dfe543
commit ecd8d1ae34
6 changed files with 165 additions and 72 deletions

View File

@ -7,6 +7,7 @@
* Patch 2963313: Enable setting .NET framework version (Justen Hyde) * Patch 2963313: Enable setting .NET framework version (Justen Hyde)
* Switched PS3 builds from GCC to SNC * Switched PS3 builds from GCC to SNC
* Ignore NoRTTI flag for Managed C++ projects (Nick Darnell) * Ignore NoRTTI flag for Managed C++ projects (Nick Darnell)
* Added host.is_64bit
------- -------

View File

@ -48,6 +48,9 @@
configuration "vs*" configuration "vs*"
defines { "_CRT_SECURE_NO_WARNINGS" } defines { "_CRT_SECURE_NO_WARNINGS" }
configuration "vs2005"
defines {"_CRT_SECURE_NO_DEPRECATE" }
configuration "linux" configuration "linux"
defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" } defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" }

67
src/base/host.lua Executable file
View File

@ -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

19
src/host/host.c Executable file
View File

@ -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;
}

9
src/host/premake.c Normal file → Executable file
View File

@ -56,7 +56,11 @@ static const luaL_Reg string_functions[] = {
{ NULL, NULL } { 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. * Program entry point.
@ -72,7 +76,8 @@ int main(int argc, const char** argv)
luaL_register(L, "path", path_functions); luaL_register(L, "path", path_functions);
luaL_register(L, "os", os_functions); luaL_register(L, "os", os_functions);
luaL_register(L, "string", string_functions); luaL_register(L, "string", string_functions);
luaL_register(L, "host", host_functions);
/* push the application metadata */ /* push the application metadata */
lua_pushstring(L, LUA_COPYRIGHT); lua_pushstring(L, LUA_COPYRIGHT);
lua_setglobal(L, "_COPYRIGHT"); lua_setglobal(L, "_COPYRIGHT");

138
src/host/premake.h Normal file → Executable file
View File

@ -1,70 +1,68 @@
/** /**
* \file premake.h * \file premake.h
* \brief Program-wide constants and definitions. * \brief Program-wide constants and definitions.
* \author Copyright (c) 2002-2011 Jason Perkins and the Premake project * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
*/ */
#define lua_c #define lua_c
#include "lua.h" #include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
/* Identify the current platform I'm not sure how to reliably detect /* 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 */ * Windows but since it is the most common I use it as the default */
#if defined(__linux__) #if defined(__linux__)
#define PLATFORM_LINUX (1) #define PLATFORM_LINUX (1)
#define PLATFORM_STRING "linux" #define PLATFORM_STRING "linux"
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PLATFORM_BSD (1) #define PLATFORM_BSD (1)
#define PLATFORM_STRING "bsd" #define PLATFORM_STRING "bsd"
#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
#define PLATFORM_MACOSX (1) #define PLATFORM_MACOSX (1)
#define PLATFORM_STRING "macosx" #define PLATFORM_STRING "macosx"
#elif defined(__sun__) && defined(__svr4__) #elif defined(__sun__) && defined(__svr4__)
#define PLATFORM_SOLARIS (1) #define PLATFORM_SOLARIS (1)
#define PLATFORM_STRING "solaris" #define PLATFORM_STRING "solaris"
#elif defined(__HAIKU__) #else
#define PLATFORM_HAIKU (1) #define PLATFORM_WINDOWS (1)
#define PLATFORM_STRING "haiku" #define PLATFORM_STRING "windows"
#else #endif
#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
/* Pull in platform-specific headers required by built-in functions */ #include <windows.h>
#if PLATFORM_WINDOWS #else
#define WIN32_LEAN_AND_MEAN #include <unistd.h>
#include <windows.h> #endif
#else
#include <unistd.h>
#endif /* A success return code */
#define OKAY (0)
/* A success return code */
#define OKAY (0) /* Bootstrapping helper functions */
int do_isfile(const char* filename);
/* Bootstrapping helper functions */
int do_isfile(const char* filename); /* Built-in functions */
int path_isabsolute(lua_State* L);
int os_chdir(lua_State* L);
/* Built-in functions */ int os_copyfile(lua_State* L);
int path_isabsolute(lua_State* L); int os_getcwd(lua_State* L);
int os_chdir(lua_State* L); int os_isdir(lua_State* L);
int os_copyfile(lua_State* L); int os_isfile(lua_State* L);
int os_getcwd(lua_State* L); int os_matchdone(lua_State* L);
int os_isdir(lua_State* L); int os_matchisfile(lua_State* L);
int os_isfile(lua_State* L); int os_matchname(lua_State* L);
int os_matchdone(lua_State* L); int os_matchnext(lua_State* L);
int os_matchisfile(lua_State* L); int os_matchstart(lua_State* L);
int os_matchname(lua_State* L); int os_mkdir(lua_State* L);
int os_matchnext(lua_State* L); int os_pathsearch(lua_State* L);
int os_matchstart(lua_State* L); int os_rmdir(lua_State* L);
int os_mkdir(lua_State* L); int os_uuid(lua_State* L);
int os_pathsearch(lua_State* L); int string_endswith(lua_State* L);
int os_rmdir(lua_State* L); int windows_is_64bit_running_under_wow(struct lua_State* l);
int os_uuid(lua_State* L);
int string_endswith(lua_State* L);