summaryrefslogtreecommitdiff
path: root/make/detect_platform.lua
blob: 8dba298c1953bce709cf3751dd26ee43ab6a1ea1 (plain)
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
local lm = require 'luamake'

local platform = require 'bee.platform'

if     platform.OS == 'macOS' then
    if     lm.platform == nil then
    elseif lm.platform == "darwin-arm64" then
        lm.target = "arm64-apple-macos11"
    elseif lm.platform == "darwin-x64" then
        lm.target = "x86_64-apple-macos10.12"
    else
        error "unknown platform"
    end
elseif platform.OS == 'Windows' then
    if     lm.platform == nil then
    elseif lm.platform == "win32-ia32" then
        lm.arch = "x86"
    elseif lm.platform == "win32-x64" then
        lm.arch = "x86_64"
    else
        error "unknown platform"
    end
elseif platform.OS == 'Linux' then
    if     lm.platform == nil then
    elseif lm.platform == "linux-x64" then
    elseif lm.platform == "linux-arm64" then
        lm.cc = 'aarch64-linux-gnu-gcc'
    else
        error "unknown platform"
    end
end

local function detectWindowsArch()
    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 detectPosixArch()
    local f <close> = assert(io.popen("uname -m", 'r'))
    return f:read 'l':lower()
end

local function detectArch()
    if platform.OS == 'Windows' then
        return detectWindowsArch()
    end
    return detectPosixArch()
end

local function targetPlatformArch()
    if lm.platform == nil then
        return detectArch()
    end
    return lm.platform:match "^[^-]*-(.*)$"
end

if not lm.notest then
    lm.notest = (platform.OS ~= 'Windows' and targetPlatformArch() ~= detectArch())
end