diff options
| author | ruki <[email protected]> | 2016-04-27 14:55:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-27 14:55:32 +0800 |
| commit | db3847c310a6a580d0b5e8407c71b5e8a8a9f171 (patch) | |
| tree | d6252305fa82a955ce8df2b81523c5c3bdbc87b2 | |
| parent | bf7678ececf50ef69f81d4801a43ef572fcc2933 (diff) | |
add mingw and windows platform
| -rw-r--r-- | xmake/core/base/os.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 26 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/checker.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/mingw/checker.lua | 83 | ||||
| -rwxr-xr-x | xmake/platforms/mingw/xmake.lua | 80 | ||||
| -rw-r--r-- | xmake/platforms/watchos/checker.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/windows/checker.lua | 187 | ||||
| -rwxr-xr-x | xmake/platforms/windows/xmake.lua | 79 | ||||
| -rw-r--r-- | xmake/tools/make.lua | 2 |
9 files changed, 452 insertions, 11 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index dfec6dc1d..cc3be857a 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -235,7 +235,7 @@ end function os.run(cmd, ...) -- make temporary log file - local log = os.tmpname() + local log = path.join(os.tmpdir(), "xmake.os.run.log") -- run command if 0 ~= os.execute(cmd .. string.format(" > %s 2>&1", log)) then diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index e6447541e..0a25c46b9 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -159,13 +159,6 @@ function sandbox_os.tmpdir() return tmpdir end --- get the temporary file -function sandbox_os.tmpfile() - - -- get it - return os.tmpname() -end - -- get the tools directory function sandbox_os.toolsdir() @@ -283,6 +276,25 @@ function sandbox_os.nuldev() return xmake._NULDEV end +-- get the envirnoment variables +function sandbox_os.getenv(name) + + -- check + assert(name) + + -- get it + return os.getenv(name) +end + +-- set the envirnoment variables +function sandbox_os.setenv(name, values) + + -- check + assert(name) + + -- set it + os.setenv(name, values) +end -- return module return sandbox_os diff --git a/xmake/platforms/iphoneos/checker.lua b/xmake/platforms/iphoneos/checker.lua index a8fcd1937..21b8bad2d 100644 --- a/xmake/platforms/iphoneos/checker.lua +++ b/xmake/platforms/iphoneos/checker.lua @@ -28,7 +28,7 @@ import("platforms.checker", {rootdir = os.programdir()}) function _check_as(shellname) -- make an empty tmp.S - local tmpfile = os.tmpfile() .. ".S" + local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S") io.write(tmpfile, "") -- check it diff --git a/xmake/platforms/mingw/checker.lua b/xmake/platforms/mingw/checker.lua new file mode 100644 index 000000000..f16d727e6 --- /dev/null +++ b/xmake/platforms/mingw/checker.lua @@ -0,0 +1,83 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file checker.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the toolchains +function _check_toolchains(config) + + -- init the default cross + local cross = "" + local arch = config.get("arch") + if arch then + if os.host() == "macosx" and arch == "i386" then + cross = "i386-mingw32-" + elseif arch == "i386" then + cross = "i686-w64-mingw32-" + elseif arch == "x86_64" then + cross = "x86_64-w64-mingw32-" + end + end + + -- done + checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") + checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") + checker.check_toolchain(config, "cxx", cross, "gcc", "the c++ compiler") + checker.check_toolchain(config, "as", cross, "gcc", "the assember") + checker.check_toolchain(config, "ld", cross, "g++", "the linker") + checker.check_toolchain(config, "ld", cross, "gcc", "the linker") + checker.check_toolchain(config, "ar", cross, "ar", "the static library linker") + checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") + checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") + checker.check_toolchain(config, "sc", cross, "swiftc", "the swift compiler") +end + +-- init it +function init() + + -- init the check list of config + _g.config = + { + { checker.check_arch, "i386" } + , checker.check_make + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_make + , checker.check_ccache + } + +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua new file mode 100755 index 000000000..7b1cc737f --- /dev/null +++ b/xmake/platforms/mingw/xmake.lua @@ -0,0 +1,80 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define platform +platform("mingw") + + -- set os + set_platform_os("windows") + + -- set hosts + set_platform_hosts("macosx", "linux", "windows") + + -- set archs + set_platform_archs("i386", "x86_64") + + -- set checker + set_platform_checker("checker") + + -- on load + on_platform_load(function () + + -- imports + import("core.project.config") + + -- init the file formats + _g.formats = {} + _g.formats.static = {"lib", ".a"} + _g.formats.object = {"", ".o"} + _g.formats.shared = {"lib", ".so"} + + -- init the toolchains + _g.tools = {} + _g.tools.make = config.get("make") + _g.tools.ccache = config.get("__ccache") + _g.tools.cc = config.get("cc") + _g.tools.cxx = config.get("cxx") + _g.tools.as = config.get("as") + _g.tools.ld = config.get("ld") + _g.tools.ar = config.get("ar") + _g.tools.sh = config.get("sh") + _g.tools.ex = config.get("ar") + _g.tools.sc = config.get("sc") + + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then + if arch == "x86_64" then archflags = "-m64" + elseif arch == "i386" then archflags = "-m32" + else archflags = "-arch " .. arch + end + end + _g.cxflags = { archflags } + _g.asflags = { archflags } + _g.ldflags = { archflags } + _g.shflags = { archflags } + + end) + + + diff --git a/xmake/platforms/watchos/checker.lua b/xmake/platforms/watchos/checker.lua index 694cee36d..ba1ae0e59 100644 --- a/xmake/platforms/watchos/checker.lua +++ b/xmake/platforms/watchos/checker.lua @@ -28,7 +28,7 @@ import("platforms.checker", {rootdir = os.programdir()}) function _check_as(shellname) -- make an empty tmp.S - local tmpfile = os.tmpfile() .. ".S" + local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S") io.write(tmpfile, "") -- check it diff --git a/xmake/platforms/windows/checker.lua b/xmake/platforms/windows/checker.lua new file mode 100644 index 000000000..31d3bb386 --- /dev/null +++ b/xmake/platforms/windows/checker.lua @@ -0,0 +1,187 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file checker.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the vs version +function _check_vs_version(config) + + -- get the vs version + local vs = config.get("vs") + if not vs then + + -- make the map table + local map = + { + VS140COMNTOOLS = "2015" + , VS120COMNTOOLS = "2013" + , VS110COMNTOOLS = "2012" + , VS100COMNTOOLS = "2010" + , VS90COMNTOOLS = "2008" + , VS80COMNTOOLS = "2005" + , VS71COMNTOOLS = "2003" + , VS70COMNTOOLS = "7.0" + , VS60COMNTOOLS = "6.0" + , VS50COMNTOOLS = "5.0" + , VS42COMNTOOLS = "4.2" + } + + -- attempt to get it from the envirnoment variable + for k, v in pairs(map) do + if os.getenv(k) then + vs = v + break + end + end + + -- check ok? update it + if vs then + + -- save it + config.set("vs", vs) + + -- trace + print("checking for the Microsoft Visual Studio version ... %s", vs) + else + -- failed + print("checking for the Microsoft Visual Studio version ... no") + print("please run:") + print(" - xmake config --vs=xxx") + print("or - xmake global --vs=xxx") + raise() + end + end +end + +-- check the vs path +function _check_vs_path(config) + + -- no vs path? + if not config.get("__vsenv_path") then + + -- get the vs version + local vs = config.get("vs") + + -- make the map table + local map = + { + ["2015"] = "VS140COMNTOOLS" + , ["2013"] = "VS120COMNTOOLS" + , ["2012"] = "VS110COMNTOOLS" + , ["2010"] = "VS100COMNTOOLS" + , ["2008"] = "VS90COMNTOOLS" + , ["2005"] = "VS80COMNTOOLS" + , ["2003"] = "VS71COMNTOOLS" + , ["7.0"] = "VS70COMNTOOLS" + , ["6.0"] = "VS60COMNTOOLS" + , ["5.0"] = "VS50COMNTOOLS" + , ["4.2"] = "VS42COMNTOOLS" + } + + -- check + if not map[vs] then + raise("vs %s not support!", vs) + end + + -- the vcvarsall.bat path + local vcvarsall = format("%s\\..\\..\\VC\\vcvarsall.bat", os.getenv(map[vs])) + if not os.isfile(vcvarsall) then + raise("not found %s", vcvarsall) + end + + -- make the genvcvars.bat + local genvcvars_bat = path.join(os.tmpdir(), "xmake.genvcvars.bat") + local genvcvars_dat = path.join(os.tmpdir(), "xmake.genvcvars.dat") + local file = io.open(genvcvars_bat, "w") + file:print("@echo off") + file:print("call \"%s\" %s > nul", vcvarsall, config.get("arch")) + file:print("echo { > %s", genvcvars_dat) + file:print("echo path = \"%%path%%\" >> %s", genvcvars_dat) + file:print("echo , lib = \"%%lib%%\" >> %s", genvcvars_dat) + file:print("echo , libpath = \"%%libpath%%\" >> %s", genvcvars_dat) + file:print("echo , include = \"%%include%%\" >> %s", genvcvars_dat) + file:print("echo , devenvdir = \"%%devenvdir%%\" >> %s", genvcvars_dat) + file:print("echo , vsinstalldir = \"%%vsinstalldir%%\" >> %s", genvcvars_dat) + file:print("echo , vcinstalldir = \"%%vcinstalldir%%\" >> %s", genvcvars_dat) + file:print("echo } >> %s", genvcvars_dat) + file:close() + + -- run genvcvars.bat + os.run(genvcvars_bat) + + -- replace "\" => "\\" + io.gsub(genvcvars_dat, "\\", "\\\\") + + -- load all envirnoment variables + local variables = io.load(genvcvars_dat) + + -- save the variables + for k, v in pairs(variables) do + config.set("__vsenv_" .. k, v) + end + end +end + +-- check the toolchains +function _check_toolchains(config) + + -- done + checker.check_toolchain(config, "cc", "", "cl.exe", "the c compiler") + checker.check_toolchain(config, "cxx", "", "cl.exe", "the c++ compiler") + checker.check_toolchain(config, "as", "", "ml.exe", "the assember") + checker.check_toolchain(config, "ld", "", "link.exe", "the linker") + checker.check_toolchain(config, "ar", "", "link.exe -lib", "the static library linker") + checker.check_toolchain(config, "sh", "", "link.exe -dll", "the shared library linker") + checker.check_toolchain(config, "ex", "", "lib.exe", "the library extractor") + checker.check_toolchain(config, "make", "", "nmake.exe", "the make") +end + +-- init it +function init() + + -- init the check list of config + _g.config = + { + { checker.check_arch, "x86" } + , _check_vs_version + , _check_vs_path + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + _check_vs_version + , _check_vs_path + } + +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua new file mode 100755 index 000000000..ef135e7c3 --- /dev/null +++ b/xmake/platforms/windows/xmake.lua @@ -0,0 +1,79 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define platform +platform("windows") + + -- set os + set_platform_os("windows") + + -- set hosts + set_platform_hosts("windows") + + -- set archs + set_platform_archs("x86", "x64", "amd64", "x86_amd64") + + -- set checker + set_platform_checker("checker") + + -- on load + on_platform_load(function () + + -- imports + import("core.project.config") + + -- init the file formats + _g.formats = {} + _g.formats.static = {"", ".lib"} + _g.formats.object = {"", ".obj"} + _g.formats.shared = {"", ".dll"} + _g.formats.binary = {"", ".exe"} + + -- init the toolchains + _g.tools = {} + _g.tools.make = config.get("make") + _g.tools.cc = config.get("cc") + _g.tools.cxx = config.get("cxx") + _g.tools.ld = config.get("ld") + _g.tools.ar = config.get("ar") + _g.tools.sh = config.get("sh") + _g.tools.as = config.get("as") + _g.tools.ex = config.get("ex") + + end) + + -- set menu + set_platform_menu({ + config = + { + {} + , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" } + } + + , global = + { + {} + , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" } + } + }) + + diff --git a/xmake/tools/make.lua b/xmake/tools/make.lua index 2785eaf73..a95685478 100644 --- a/xmake/tools/make.lua +++ b/xmake/tools/make.lua @@ -86,7 +86,7 @@ end function check(flags) -- make an empty makefile - local tmpfile = os.tmpfile() + local tmpfile = path.join(os.tmpdir(), "xmake.checker.make") io.write(tmpfile, "all:\n") -- check it |
