Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2011-04-05 00:49:55 +0400
committerJason Perkins <starkos@industriousone.com>2011-04-05 00:49:55 +0400
commit3737111c6847822eacf53d2e0ea5b4fe19c379fa (patch)
tree5996bc716280905cf4c069e065d99e396aeb9395
parentb2e7af94cf870722c2abea7df3d91a4b3aa38f6f (diff)
Some cleanup for is64bit() to make it look a bit like the other os functions
-rwxr-xr-xsrc/base/host.lua67
-rw-r--r--src/base/os.lua54
-rwxr-xr-xsrc/host/host.c29
-rwxr-xr-xsrc/host/os_getversion.c6
-rwxr-xr-xsrc/host/os_is64bit.c30
-rwxr-xr-xsrc/host/premake.c8
-rwxr-xr-xsrc/host/premake.h2
7 files changed, 88 insertions, 108 deletions
diff --git a/src/base/host.lua b/src/base/host.lua
deleted file mode 100755
index 9544a4e..0000000
--- a/src/base/host.lua
+++ /dev/null
@@ -1,67 +0,0 @@
-
---
---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.is64bit = 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/base/os.lua b/src/base/os.lua
index 59dc041..78ae130 100644
--- a/src/base/os.lua
+++ b/src/base/os.lua
@@ -77,7 +77,49 @@
return (os.get():lower() == id:lower())
end
+
+
+--
+-- Determine if the current system is running a 64-bit architecture
+--
+
+ local _64BitHostTypes = {
+ "x86_64",
+ "ia64",
+ "amd64",
+ "ppc64",
+ "powerpc64",
+ "sparc64"
+ }
+ function os.is64bit()
+ -- Call the native code implementation. If this returns true then
+ -- we're 64-bit, otherwise do more checking locally
+ if (os._is64bit()) then
+ return true
+ end
+
+ -- Identify the system
+ local arch
+ if _OS == "windows" then
+ arch = os.getenv("PROCESSOR_ARCHITECTURE")
+ elseif _OS == "macosx" then
+ arch = os.outputof("echo $HOSTTYPE")
+ else
+ arch = os.outputof("uname -m")
+ end
+
+ -- Check our known 64-bit identifiers
+ arch = arch:lower()
+ for _, hosttype in ipairs(_64BitHostTypes) do
+ if arch:find(hosttype) then
+ return true
+ end
+ end
+ return false
+ end
+
+
--
-- The os.matchdirs() and os.matchfiles() functions
@@ -183,6 +225,18 @@
--
+-- Run a shell command and return the output.
+--
+
+ function os.outputof(cmd)
+ local pipe = io.popen(cmd)
+ local result = pipe:read('*a')
+ pipe:close()
+ return result
+ end
+
+
+--
-- Remove a directory, along with any contained files or subdirectories.
--
diff --git a/src/host/host.c b/src/host/host.c
deleted file mode 100755
index 6414359..0000000
--- a/src/host/host.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * \file host.c
- * \brief Functions to query the specifics of the operating environment.
- * \author Copyright (c) 2011 Jason Perkins and the Premake project
- */
-
-#include "premake.h"
-
-/**
- * Determine if we're running under 64-bit Windows.
- */
-int windows_is_64bit_running_under_wow(struct lua_State* L)
-{
-#if PLATFORM_WINDOWS
- 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;
-}
diff --git a/src/host/os_getversion.c b/src/host/os_getversion.c
index c396ed2..d59d06e 100755
--- a/src/host/os_getversion.c
+++ b/src/host/os_getversion.c
@@ -52,10 +52,9 @@ int os_getversion(lua_State* L)
void getversion(struct OsVersionInfo* info)
{
- OSVERSIONINFOEX versionInfo;
- SYSTEM_INFO systemInfo;
+ OSVERSIONINFOEX versionInfo = {0};
+ SYSTEM_INFO systemInfo = {0};
- ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX));
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO*)&versionInfo);
@@ -63,7 +62,6 @@ void getversion(struct OsVersionInfo* info)
info->minorversion = versionInfo.dwMinorVersion;
info->revision = versionInfo.wServicePackMajor;
- ZeroMemory(&systemInfo, sizeof(SYSTEM_INFO));
GetSystemInfo(&systemInfo);
if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0)
diff --git a/src/host/os_is64bit.c b/src/host/os_is64bit.c
new file mode 100755
index 0000000..3134751
--- /dev/null
+++ b/src/host/os_is64bit.c
@@ -0,0 +1,30 @@
+/**
+ * \file os_is64bit.c
+ * \brief Native code-side checking for a 64-bit architecture.
+ * \author Copyright (c) 2011 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+
+int os_is64bit(lua_State* L)
+{
+ // If this code returns true, then the platform is 64-bit. If it
+ // returns false, the platform might still be 64-bit, but more
+ // checking will need to be done on the Lua side of things.
+#if PLATFORM_WINDOWS
+ typedef BOOL (WINAPI* WowFuncSig)(HANDLE, PBOOL);
+ WowFuncSig func = (WowFuncSig)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
+ if (func)
+ {
+ BOOL isWow = FALSE;
+ if (func(GetCurrentProcess(), &isWow))
+ {
+ lua_pushboolean(L, isWow);
+ return 1;
+ }
+ }
+#endif
+
+ lua_pushboolean(L, 0);
+ return 1;
+}
diff --git a/src/host/premake.c b/src/host/premake.c
index ff0bdde..7548ff4 100755
--- a/src/host/premake.c
+++ b/src/host/premake.c
@@ -36,6 +36,7 @@ static const luaL_Reg path_functions[] = {
static const luaL_Reg os_functions[] = {
{ "chdir", os_chdir },
{ "copyfile", os_copyfile },
+ { "_is64bit", os_is64bit },
{ "isdir", os_isdir },
{ "getcwd", os_getcwd },
{ "getversion", os_getversion },
@@ -57,12 +58,6 @@ 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.
*/
@@ -77,7 +72,6 @@ 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);
diff --git a/src/host/premake.h b/src/host/premake.h
index 0e99b6c..cd7d522 100755
--- a/src/host/premake.h
+++ b/src/host/premake.h
@@ -56,6 +56,7 @@ int os_chdir(lua_State* L);
int os_copyfile(lua_State* L);
int os_getcwd(lua_State* L);
int os_getversion(lua_State* L);
+int os_is64bit(lua_State* L);
int os_isdir(lua_State* L);
int os_isfile(lua_State* L);
int os_matchdone(lua_State* L);
@@ -68,6 +69,5 @@ 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);