summaryrefslogtreecommitdiff
path: root/xmake/modules/os/winver.lua
blob: 50763417a997172b3a6adc0b8328f3e9f1c3d4e1 (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
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
114
115
116
117
118
119
120
121
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements.  See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership.  The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License.  You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- 
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author      ruki
-- @file        winver.lua
--

-- get WINVER from name
--
-- reference: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
--
function version(name)
    
    -- init values
    _g.values = _g.values or 
    {
        nt4      = "0x0400"
    ,   win2k    = "0x0500"
    ,   winxp    = "0x0501"
    ,   ws03     = "0x0502"
    ,   win6     = "0x0600"
    ,   vista    = "0x0600"
    ,   ws08     = "0x0600"
    ,   longhorn = "0x0600"
    ,   win7     = "0x0601"
    ,   win8     = "0x0602"
    ,   winblue  = "0x0603"
    ,   win81    = "0x0603"
    ,   win10    = "0x0A00"
    }

    -- ignore the subname with '_xxx'
    name = name:split('_')[1]

    -- get value
    return _g.values[name]
end

-- get NTDDI_VERSION from name 
function ntddi_version(name)
    
    -- init subvalues
    _g.subvalues = _g.subvalues or 
    {
        sp1    = "0100"
    ,   sp2    = "0200"
    ,   sp3    = "0300"
    ,   sp4    = "0400"
    ,   th2    = "0001"
    ,   rs1    = "0002"
    ,   rs2    = "0003"
    ,   rs3    = "0004"
    }

    -- get subvalue
    local subvalue = nil
    local subname = name:split('_')[2]
    if subname then
        subvalue = _g.subvalues[subname]
    end

    -- get value
    local val = version(name)
    if val then
        val = val .. (subvalue or "0000")
    end
    return val
end

-- get WIN32_WINNT from name 
function winnt_version(name)
    return ntddi_version(name)
end 

-- get windows system version
--
-- $ xmake l os.winver
--
--   - win10: 10.0.14393
--   - xp:    5.1.2600
--
function main()

    -- get it from cache first
    if _g.winver ~= nil then
        return _g.winver 
    end

    -- get winver
    local winver = nil
    local verstr = try { function () return os.iorun("cmd /c ver") end }
    if verstr then
        winver = verstr:match("%[.-(%d+%.%d+%.%d+)]")
        if winver then
            winver = winver:trim()
        end
    end

    -- save to cache
    _g.winver = winver or false

    -- done
    return winver
end