Repository navigation
Expand file tree
/
Copy pathdetect_platform.lua
More file actions
113 lines (104 loc) · 2.75 KB
/
Copy pathdetect_platform.lua
File metadata and controls
113 lines (104 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
local lm = require "luamake"
local function windows_arch()
if os.getenv "PROCESSOR_ARCHITECTURE" == "ARM64" then
return "arm64"
end
if os.getenv "PROCESSOR_ARCHITECTURE" == "AMD64" or os.getenv "PROCESSOR_ARCHITEW6432" == "AMD64" then
return "x64"
end
return "ia32"
end
local function macos_support_arm64()
local f = io.popen("sw_vers", "r")
if f then
for line in f:lines() do
local major, minor = line:match "ProductVersion:%s*(%d+)%.(%d+)"
if major and minor then
return tonumber(major) >= 11
end
end
end
end
local function posix_arch()
local f <close> = assert(io.popen("uname -m", 'r'))
return f:read 'l':lower()
end
local function detect_windows()
local arch = windows_arch()
assert(arch ~= "arm64")
if arch == "ia32" then
if lm.platform then
assert(lm.platform == "win32-ia32")
else
lm.platform = "win32-ia32"
end
return
end
if lm.platform then
assert(lm.platform == "win32-ia32" or lm.platform == "win32-x64")
else
lm.platform = "win32-x64"
end
end
local function detect_macos()
if lm.platform then
if lm.platform == "darwin-arm64" then
if posix_arch() ~= "arm64" then
lm.cross_compile = true
end
assert(macos_support_arm64())
else
assert(lm.platform == "darwin-x64")
end
else
if posix_arch() == "arm64" then
lm.platform = "darwin-arm64"
else
lm.platform = "darwin-x64"
end
end
end
local function detect_linux()
if lm.platform then
if lm.platform == "linux-arm64" then
if posix_arch() ~= "aarch64" then
lm.cross_compile = true
lm.cc = "aarch64-linux-gnu-gcc"
end
else
assert(lm.platform == "linux-x64")
end
else
if posix_arch() == "aarch64" then
lm.platform = "linux-arm64"
else
lm.platform = "linux-x64"
end
end
end
local function detect_android()
if lm.platform then
assert(lm.platform == "linux-arm64")
else
lm.platform = "linux-arm64"
end
end
local function detect_bsd()
assert(posix_arch() == "amd64")
lm.platform = "bsd-x64"
end
if lm.os == "windows" then
detect_windows()
elseif lm.os == "macos" then
detect_macos()
elseif lm.os == "linux" then
detect_linux()
elseif lm.os == "android" then
detect_android()
elseif lm.os == "netbsd" then
detect_bsd()
elseif lm.os == "freebsd" then
detect_bsd()
else
error("unknown OS:"..lm.os)
end