Ticket #1463: premake_backport.diff
File premake_backport.diff, 16.1 KB (added by , 12 years ago) |
---|
-
build/premake/premake4/src/base/os.lua
1 1 -- 2 2 -- os.lua 3 3 -- Additions to the OS namespace. 4 -- Copyright (c) 2002-201 0Jason Perkins and the Premake project4 -- Copyright (c) 2002-2011 Jason Perkins and the Premake project 5 5 -- 6 6 7 7 … … 26 26 if os.is("windows") then 27 27 formats = { "%s.dll", "%s" } 28 28 path = os.getenv("PATH") 29 elseif os.is("haiku") then 30 formats = { "lib%s.so", "%s.so" } 31 path = os.getenv("LIBRARY_PATH") 29 32 else 30 33 if os.is("macosx") then 31 34 formats = { "lib%s.dylib", "%s.dylib" } … … 43 46 end 44 47 end 45 48 46 table.insert(formats, "%s") 49 table.insert(formats, "%s") 47 50 path = (path or "") .. ":/lib:/usr/lib:/usr/local/lib" 48 51 end 49 52 … … 180 183 181 184 182 185 -- 186 -- Run a shell command and return the output. 187 -- 188 189 function os.outputof(cmd) 190 local pipe = io.popen(cmd) 191 local result = pipe:read('*a') 192 pipe:close() 193 return result 194 end 195 196 197 -- 183 198 -- Remove a directory, along with any contained files or subdirectories. 184 199 -- 185 200 -
build/premake/premake4/src/host/os_getversion.c
1 /** 2 * \file os_getversioninfo.c 3 * \brief Retrieve operating system version information. 4 * \author Copyright (c) 2011 Jason Perkins and the Premake project 5 */ 6 7 #include "premake.h" 8 9 struct OsVersionInfo 10 { 11 int majorversion; 12 int minorversion; 13 int revision; 14 const char* description; 15 } ; 16 17 static void getversion(struct OsVersionInfo* info); 18 19 int os_getversion(lua_State* L) 20 { 21 struct OsVersionInfo info; 22 getversion(&info); 23 24 lua_newtable(L); 25 26 lua_pushstring(L, "majorversion"); 27 lua_pushnumber(L, info.majorversion); 28 lua_settable(L, -3); 29 30 lua_pushstring(L, "minorversion"); 31 lua_pushnumber(L, info.minorversion); 32 lua_settable(L, -3); 33 34 lua_pushstring(L, "revision"); 35 lua_pushnumber(L, info.revision); 36 lua_settable(L, -3); 37 38 lua_pushstring(L, "description"); 39 lua_pushstring(L, info.description); 40 lua_settable(L, -3); 41 42 return 1; 43 } 44 45 /*************************************************************/ 46 47 #if defined(PLATFORM_WINDOWS) 48 49 #if !defined(VER_SUITE_WH_SERVER) 50 #define VER_SUITE_WH_SERVER (0x00008000) 51 #endif 52 53 #ifndef SM_SERVERR2 54 # define SM_SERVERR2 89 55 #endif 56 57 SYSTEM_INFO getsysteminfo() 58 { 59 typedef void (WINAPI *GetNativeSystemInfoSig)(LPSYSTEM_INFO); 60 GetNativeSystemInfoSig nativeSystemInfo = (GetNativeSystemInfoSig) 61 GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo"); 62 63 SYSTEM_INFO systemInfo = {{0}}; 64 if ( nativeSystemInfo ) nativeSystemInfo(&systemInfo); 65 else GetSystemInfo(&systemInfo); 66 return systemInfo; 67 } 68 69 void getversion(struct OsVersionInfo* info) 70 { 71 OSVERSIONINFOEX versionInfo = {0}; 72 73 versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 74 GetVersionEx((OSVERSIONINFO*)&versionInfo); 75 76 info->majorversion = versionInfo.dwMajorVersion; 77 info->minorversion = versionInfo.dwMinorVersion; 78 info->revision = versionInfo.wServicePackMajor; 79 80 if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0) 81 { 82 info->description = "Windows 2000"; 83 } 84 else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1) 85 { 86 info->description = "Windows XP"; 87 } 88 else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 2) 89 { 90 SYSTEM_INFO systemInfo = getsysteminfo(); 91 if (versionInfo.wProductType == VER_NT_WORKSTATION && 92 systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) 93 { 94 info->description = "Windows XP Professional x64"; 95 } 96 else if (versionInfo.wSuiteMask & VER_SUITE_WH_SERVER) 97 { 98 info->description = "Windows Home Server"; 99 } 100 else if (GetSystemMetrics(SM_SERVERR2) == 0) 101 { 102 info->description = "Windows Server 2003"; 103 } 104 else 105 { 106 info->description = "Windows Server 2003 R2"; 107 } 108 } 109 else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0) 110 { 111 if (versionInfo.wProductType == VER_NT_WORKSTATION) 112 { 113 info->description = "Windows Vista"; 114 } 115 else 116 { 117 info->description = "Windows Server 2008"; 118 } 119 } 120 else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 ) 121 { 122 if (versionInfo.wProductType != VER_NT_WORKSTATION) 123 { 124 info->description = "Windows Server 2008 R2"; 125 } 126 else 127 { 128 info->description = "Windows 7"; 129 } 130 } 131 else 132 { 133 info->description = "Windows"; 134 } 135 } 136 137 /*************************************************************/ 138 139 #elif defined(PLATFORM_MACOSX) 140 141 #include <CoreServices/CoreServices.h> 142 143 void getversion(struct OsVersionInfo* info) 144 { 145 SInt32 majorversion, minorversion, bugfix; 146 Gestalt(gestaltSystemVersionMajor, &majorversion); 147 Gestalt(gestaltSystemVersionMinor, &minorversion); 148 Gestalt(gestaltSystemVersionBugFix, &bugfix); 149 150 info->majorversion = majorversion; 151 info->minorversion = minorversion; 152 info->revision = bugfix; 153 154 info->description = "Mac OS X"; 155 if (info->majorversion == 10) 156 { 157 switch (info->minorversion) 158 { 159 case 4: 160 info->description = "Mac OS X Tiger"; 161 break; 162 case 5: 163 info->description = "Mac OS X Leopard"; 164 break; 165 case 6: 166 info->description = "Mac OS X Snow Leopard"; 167 break; 168 case 7: 169 info->description = "Mac OS X Lion"; 170 break; 171 } 172 } 173 } 174 175 /*************************************************************/ 176 177 #elif defined(PLATFORM_BSD) || defined(PLATFORM_LINUX) || defined(PLATFORM_SOLARIS) 178 179 #include <stdlib.h> 180 #include <string.h> 181 #include <sys/utsname.h> 182 183 void getversion(struct OsVersionInfo* info) 184 { 185 struct utsname u; 186 char* ver; 187 188 info->majorversion = 0; 189 info->minorversion = 0; 190 info->revision = 0; 191 192 if (uname(&u)) 193 { 194 // error 195 info->description = PLATFORM_STRING; 196 return; 197 } 198 199 #if !defined(PLATFORM_LINUX) 200 info->description = u.sysname; 201 #else 202 // On Linux info->sysname gets set, but it isn't passed out of this function 203 info->description = "Linux"; 204 #endif 205 206 if ((ver = strtok(u.release, ".-")) != NULL) 207 { 208 info->majorversion = atoi(ver); 209 // continue parsing from the previous position 210 if ((ver = strtok(NULL, ".-")) != NULL) 211 { 212 info->minorversion = atoi(ver); 213 if ((ver = strtok(NULL, ".-")) != NULL) 214 info->revision = atoi(ver); 215 } 216 } 217 } 218 219 /*************************************************************/ 220 221 #else 222 223 void getversion(struct OsVersionInfo* info) 224 { 225 info->majorversion = 0; 226 info->minorversion = 0; 227 info->revision = 0; 228 info->description = PLATFORM_STRING; 229 } 230 231 #endif 232 -
build/premake/premake4/src/host/premake.c
38 38 { "copyfile", os_copyfile }, 39 39 { "isdir", os_isdir }, 40 40 { "getcwd", os_getcwd }, 41 { "getversion", os_getversion }, 41 42 { "isfile", os_isfile }, 42 43 { "matchdone", os_matchdone }, 43 44 { "matchisfile", os_matchisfile }, -
build/premake/premake4/src/host/premake.h
1 1 /** 2 2 * \file premake.h 3 3 * \brief Program-wide constants and definitions. 4 * \author Copyright (c) 2002-20 08Jason Perkins and the Premake project4 * \author Copyright (c) 2002-2011 Jason Perkins and the Premake project 5 5 */ 6 6 7 7 #define lua_c … … 15 15 #if defined(__linux__) 16 16 #define PLATFORM_LINUX (1) 17 17 #define PLATFORM_STRING "linux" 18 #elif defined(__FreeBSD__) || defined(__ NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__)18 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 19 19 #define PLATFORM_BSD (1) 20 20 #define PLATFORM_STRING "bsd" 21 21 #elif defined(__APPLE__) && defined(__MACH__) … … 24 24 #elif defined(__sun__) && defined(__svr4__) 25 25 #define PLATFORM_SOLARIS (1) 26 26 #define PLATFORM_STRING "solaris" 27 #elif defined(__HAIKU__) 28 #define PLATFORM_HAIKU (1) 29 #define PLATFORM_STRING "haiku" 27 30 #else 28 31 #define PLATFORM_WINDOWS (1) 29 32 #define PLATFORM_STRING "windows" … … 52 55 int os_chdir(lua_State* L); 53 56 int os_copyfile(lua_State* L); 54 57 int os_getcwd(lua_State* L); 58 int os_getversion(lua_State* L); 55 59 int os_isdir(lua_State* L); 56 60 int os_isfile(lua_State* L); 57 61 int os_matchdone(lua_State* L); -
build/premake/premake4/src/host/scripts.c
4 4 5 5 const char* builtin_scripts[] = { 6 6 /* base/os.lua */ 7 "function os.executef(cmd, ...)\ncmd = string.format(cmd, unpack(arg))\nreturn os.execute(cmd)\nend\nfunction os.findlib(libname)\nlocal path, formats\nif os.is(\"windows\") then\nformats = { \"%s.dll\", \"%s\" }\npath = os.getenv(\"PATH\")\nelse\nif os.is(\"macosx\") then\nformats = { \"lib%s.dylib\", \"%s.dylib\" }\npath = os.getenv(\"DYLD_LIBRARY_PATH\")\nelse\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LD_LIBRARY_PATH\") or \"\"\nio.input(\"/etc/ld.so.conf\")\nif io.input() then\nfor line in io.lines() do\npath = path .. \":\" .. line\nend\nio.input():close()\nend\nend\ntable.insert(formats, \"%s\")\npath = (path or \"\") .. \":/lib:/usr/lib:/usr/local/lib\"\nend\nfor _, fmt in ipairs(formats) do\nlocal name = string.format(fmt, libname)\nlocal result = os.pathsearch(name, path)\nif result then return result end\nend\nend\nfunction os.get()\nreturn _OPTIONS.os or _OS\nend\nfunction os.is(id)\nreturn (os.get():lower() == id:lower())\nend\nlocal function domatch(result, mask, wantfiles)\nif mas" 8 "k:startswith(\"./\") then\nmask = mask:sub(3)\nend\nlocal basedir = mask\nlocal starpos = mask:find(\"%*\")\nif starpos then\nbasedir = basedir:sub(1, starpos - 1)\nend\nbasedir = path.getdirectory(basedir)\nif (basedir == \".\") then basedir = \"\" end\nlocal recurse = mask:find(\"**\", nil, true)\nmask = path.wildcards(mask)\nlocal function matchwalker(basedir)\nlocal wildcard = path.join(basedir, \"*\")\nlocal m = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nlocal isfile = os.matchisfile(m)\nif ((wantfiles and isfile) or (not wantfiles and not isfile)) then\nlocal fname = path.join(basedir, os.matchname(m))\nif fname:match(mask) == fname then\ntable.insert(result, fname)\nend\nend\nend\nos.matchdone(m)\nif recurse then\nm = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nif not os.matchisfile(m) then\nlocal dirname = os.matchname(m)\nmatchwalker(path.join(basedir, dirname))\nend\nend\nos.matchdone(m)\nend\nend\nmatchwalker(basedir)\nend\nfunction os.matchdirs(...)\nlocal result = { }\nfor _, ma" 9 "sk in ipairs(arg) do\ndomatch(result, mask, false)\nend\nreturn result\nend\nfunction os.matchfiles(...)\nlocal result = { }\nfor _, mask in ipairs(arg) do\ndomatch(result, mask, true)\nend\nreturn result\nend\nlocal builtin_mkdir = os.mkdir\nfunction os.mkdir(p)\nlocal dir = iif(p:startswith(\"/\"), \"/\", \"\")\nfor part in p:gmatch(\"[^/]+\") do\ndir = dir .. part\nif (part ~= \"\" and not path.isabsolute(part) and not os.isdir(dir)) then\nlocal ok, err = builtin_mkdir(dir)\nif (not ok) then\nreturn nil, err\nend\nend\ndir = dir .. \"/\"\nend\nreturn true\nend\nlocal builtin_rmdir = os.rmdir\nfunction os.rmdir(p)\nlocal dirs = os.matchdirs(p .. \"/*\")\nfor _, dname in ipairs(dirs) do\nos.rmdir(dname)\nend\nlocal files = os.matchfiles(p .. \"/*\")\nfor _, fname in ipairs(files) do\nos.remove(fname)\nend\nbuiltin_rmdir(p)\nend\n", 7 "function os.executef(cmd, ...)\ncmd = string.format(cmd, unpack(arg))\nreturn os.execute(cmd)\nend\nfunction os.findlib(libname)\nlocal path, formats\nif os.is(\"windows\") then\nformats = { \"%s.dll\", \"%s\" }\npath = os.getenv(\"PATH\")\nelseif os.is(\"haiku\") then\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LIBRARY_PATH\")\nelse\nif os.is(\"macosx\") then\nformats = { \"lib%s.dylib\", \"%s.dylib\" }\npath = os.getenv(\"DYLD_LIBRARY_PATH\")\nelse\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LD_LIBRARY_PATH\") or \"\"\nio.input(\"/etc/ld.so.conf\")\nif io.input() then\nfor line in io.lines() do\npath = path .. \":\" .. line\nend\nio.input():close()\nend\nend\ntable.insert(formats, \"%s\")\npath = (path or \"\") .. \":/lib:/usr/lib:/usr/local/lib\"\nend\nfor _, fmt in ipairs(formats) do\nlocal name = string.format(fmt, libname)\nlocal result = os.pathsearch(name, path)\nif result then return result end\nend\nend\nfunction os.get()\nreturn _OPTIONS.os or _OS\nend\nfunction os.is(i" 8 "d)\nreturn (os.get():lower() == id:lower())\nend\nlocal function domatch(result, mask, wantfiles)\nif mask:startswith(\"./\") then\nmask = mask:sub(3)\nend\nlocal basedir = mask\nlocal starpos = mask:find(\"%*\")\nif starpos then\nbasedir = basedir:sub(1, starpos - 1)\nend\nbasedir = path.getdirectory(basedir)\nif (basedir == \".\") then basedir = \"\" end\nlocal recurse = mask:find(\"**\", nil, true)\nmask = path.wildcards(mask)\nlocal function matchwalker(basedir)\nlocal wildcard = path.join(basedir, \"*\")\nlocal m = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nlocal isfile = os.matchisfile(m)\nif ((wantfiles and isfile) or (not wantfiles and not isfile)) then\nlocal fname = path.join(basedir, os.matchname(m))\nif fname:match(mask) == fname then\ntable.insert(result, fname)\nend\nend\nend\nos.matchdone(m)\nif recurse then\nm = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nif not os.matchisfile(m) then\nlocal dirname = os.matchname(m)\nmatchwalker(path.join(basedir, dirname))\nend\nend\nos.mat" 9 "chdone(m)\nend\nend\nmatchwalker(basedir)\nend\nfunction os.matchdirs(...)\nlocal result = { }\nfor _, mask in ipairs(arg) do\ndomatch(result, mask, false)\nend\nreturn result\nend\nfunction os.matchfiles(...)\nlocal result = { }\nfor _, mask in ipairs(arg) do\ndomatch(result, mask, true)\nend\nreturn result\nend\nlocal builtin_mkdir = os.mkdir\nfunction os.mkdir(p)\nlocal dir = iif(p:startswith(\"/\"), \"/\", \"\")\nfor part in p:gmatch(\"[^/]+\") do\ndir = dir .. part\nif (part ~= \"\" and not path.isabsolute(part) and not os.isdir(dir)) then\nlocal ok, err = builtin_mkdir(dir)\nif (not ok) then\nreturn nil, err\nend\nend\ndir = dir .. \"/\"\nend\nreturn true\nend\nfunction os.outputof(cmd)\nlocal pipe = io.popen(cmd)\nlocal result = pipe:read('*a')\npipe:close()\nreturn result\nend\nlocal builtin_rmdir = os.rmdir\nfunction os.rmdir(p)\nlocal dirs = os.matchdirs(p .. \"/*\")\nfor _, dname in ipairs(dirs) do\nos.rmdir(dname)\nend\nlocal files = os.matchfiles(p .. \"/*\")\nfor _, fname in ipairs(files) do\nos." 10 "remove(fname)\nend\nbuiltin_rmdir(p)\nend\n", 10 11 11 12 /* base/path.lua */ 12 13 "function path.getabsolute(p)\np = path.translate(p, \"/\")\nif (p == \"\") then p = \".\" end\nlocal result = iif (path.isabsolute(p), nil, os.getcwd())\nfor n, part in ipairs(p:explode(\"/\", true)) do\nif (part == \"\" and n == 1) then\nresult = \"/\"\nelseif (part == \"..\") then\nresult = path.getdirectory(result)\nelseif (part ~= \".\") then\nresult = path.join(result, part)\nend\nend\nresult = iif(result:endswith(\"/\"), result:sub(1, -2), result)\nreturn result\nend\nfunction path.getbasename(p)\nlocal name = path.getname(p)\nlocal i = name:findlast(\".\", true)\nif (i) then\nreturn name:sub(1, i - 1)\nelse\nreturn name\nend\nend\nfunction path.getdirectory(p)\nlocal i = p:findlast(\"/\", true)\nif (i) then\nif i > 1 then i = i - 1 end\nreturn p:sub(1, i)\nelse\nreturn \".\"\nend\nend\nfunction path.getdrive(p)\nlocal ch1 = p:sub(1,1)\nlocal ch2 = p:sub(2,2)\nif ch2 == \":\" then\nreturn ch1\nend\nend\nfunction path.getextension(p)\nlocal i = p:findlast(\".\", true)\nif (i) then\nreturn p:sub(i)\nelse\n" … … 298 299 "\npremake.action.call(action.trigger)\nprint(\"Done.\")\nreturn 0\nend\n", 299 300 300 301 0 301 }; 302 No newline at end of file 302 };