summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-20 00:22:40 +0800
committerruki <[email protected]>2020-05-19 20:16:04 +0800
commit86598231b463786d3a20bdb267e54f352f3c1b63 (patch)
treeb626554185a9aca47504c3dc354dd71032a5d482
parentdc156eb40a6aa5f3a564ccbb82bd8319274bfb0c (diff)
add mingw toolchain
-rw-r--r--xmake/modules/detect/sdks/find_mingw.lua2
-rw-r--r--xmake/platforms/mingw/check.lua108
-rw-r--r--xmake/platforms/mingw/load.lua52
-rw-r--r--xmake/platforms/mingw/xmake.lua4
-rw-r--r--xmake/toolchains/mingw/check.lua40
-rw-r--r--xmake/toolchains/mingw/xmake.lua70
-rw-r--r--xmake/toolchains/ndk/check.lua1
7 files changed, 123 insertions, 154 deletions
diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua
index a8c22a9ee..06723859c 100644
--- a/xmake/modules/detect/sdks/find_mingw.lua
+++ b/xmake/modules/detect/sdks/find_mingw.lua
@@ -54,7 +54,7 @@ function _find_mingw(sdkdir, bindir, cross)
-- find mingw root directory
sdkdir = _find_mingwdir(sdkdir)
if not sdkdir then
- return {}
+ return
end
-- select cross on macos, e.g x86_64-w64-mingw32- or i686-w64-mingw32-
diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua
index 9905a53cc..a44983421 100644
--- a/xmake/platforms/mingw/check.lua
+++ b/xmake/platforms/mingw/check.lua
@@ -20,109 +20,21 @@
-- imports
import("core.project.config")
-import("core.base.singleton")
-import("detect.sdks.find_mingw")
-import("private.platform.toolchain")
import("private.platform.check_arch")
-import("private.platform.check_toolchain")
-
--- check the mingw toolchain
-function _check_mingw()
- local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")})
- if mingw then
- config.set("mingw", mingw.sdkdir, {force = true, readonly = true})
- config.set("cross", mingw.cross, {readonly = true, force = true})
- config.set("bin", mingw.bindir, {readonly = true, force = true})
- else
- -- failed
- cprint("${bright color.error}please run:")
- cprint(" - xmake config --ndk=xxx")
- cprint("or - xmake global --ndk=xxx")
- raise()
- end
-end
-
--- get toolchains
-function _toolchains()
-
- -- get cross
- local cross = config.get("cross")
-
- -- TODO add to environment module
- -- add bin search library for loading some dependent .dll files windows
- local bindir = config.get("bin")
- if bindir and is_host("windows") then
- os.addenv("PATH", bindir)
- end
-
- -- init toolchains
- local cc = toolchain("the c compiler")
- local cxx = toolchain("the c++ compiler")
- local cpp = toolchain("the c preprocessor")
- local ld = toolchain("the linker")
- local sh = toolchain("the shared library linker")
- local ar = toolchain("the static library archiver")
- local ex = toolchain("the static library extractor")
- local ranlib = toolchain("the static library index generator")
- local as = toolchain("the assember")
- local mrc = toolchain("the resource compiler")
- local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc}
-
- -- init the c compiler
- cc:add("$(env CC)", {name = "gcc", cross = cross})
-
- -- init the c++ compiler
- cxx:add("$(env CXX)")
- cxx:add({name = "gcc", cross = cross})
- cxx:add({name = "g++", cross = cross})
-
- -- init the c preprocessor
- cpp:add("$(env CPP)", {name = "gcc -E", cross = cross})
-
- -- init the assember
- as:add("$(env AS)", {name = "gcc", cross = cross})
-
- -- init the linker
- ld:add("$(env LD)", "$(env CXX)")
- ld:add({name = "g++", cross = cross})
- ld:add({name = "gcc", cross = cross})
-
- -- init the shared library linker
- sh:add("$(env SH)", "$(env CXX)")
- sh:add({name = "g++", cross = cross})
- sh:add({name = "gcc", cross = cross})
-
- -- init the static library archiver
- ar:add("$(env AR)", {name = "ar", cross = cross})
-
- -- init the static library extractor
- ex:add("$(env AR)", {name = "ar", cross = cross})
-
- -- init the static library extractor
- ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross})
-
- -- init the resource compiler
- mrc:add({name = "windres", cross = cross})
-
- return toolchains
-end
-- check it
-function main(platform, name)
+function main(platform)
- -- only check the given config name?
- if name then
- local toolchain = singleton.get("mingw.toolchains", _toolchains)[name]
- if toolchain then
- check_toolchain(config, name, toolchain)
- end
- else
+ -- check arch
+ check_arch(config, "x86_64")
- -- check arch
- check_arch(config, "x86_64")
-
- -- check mingw
- _check_mingw()
+ -- check toolchains
+ local toolchains = platform:toolchains()
+ for idx, toolchain in irpairs(toolchains) do
+ if not toolchain:check() then
+ table.remove(toolchains, idx)
+ end
end
+ assert(#toolchains > 0, "toolchains not found!")
end
diff --git a/xmake/platforms/mingw/load.lua b/xmake/platforms/mingw/load.lua
deleted file mode 100644
index 653527e6d..000000000
--- a/xmake/platforms/mingw/load.lua
+++ /dev/null
@@ -1,52 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed 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-2020, TBOOX Open Source Group.
---
--- @author ruki
--- @file load.lua
---
-
--- imports
-import("core.project.config")
-
--- load it
-function main(platform)
-
- -- 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
- if archflags then
- platform:add("cxflags", archflags)
- platform:add("asflags", archflags)
- platform:add("ldflags", archflags)
- platform:add("shflags", archflags)
- end
-
- -- init flags for asm
- platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32")
-
- -- add bin search library for loading some dependent .dll files windows
- local bindir = config.get("bin")
- if bindir and is_host("windows") then
- os.addenv("PATH", bindir)
- end
-end
-
diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua
index e119f137f..1c19443b8 100644
--- a/xmake/platforms/mingw/xmake.lua
+++ b/xmake/platforms/mingw/xmake.lua
@@ -36,8 +36,8 @@ platform("mingw")
-- on check
on_check("check")
- -- on load
- on_load("load")
+ -- set toolchains
+ set_toolchains("envs", "mingw")
-- set menu
set_menu {
diff --git a/xmake/toolchains/mingw/check.lua b/xmake/toolchains/mingw/check.lua
new file mode 100644
index 000000000..0bf65a0ce
--- /dev/null
+++ b/xmake/toolchains/mingw/check.lua
@@ -0,0 +1,40 @@
+--!A cross-toolchain build utility based on Lua
+--
+-- Licensed 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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check.lua
+--
+
+-- imports
+import("core.project.config")
+import("detect.sdks.find_mingw")
+
+-- check the mingw toolchain
+function main(toolchain)
+ local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")})
+ if mingw then
+ config.set("mingw", mingw.sdkdir, {force = true, readonly = true})
+ config.set("cross", mingw.cross, {readonly = true, force = true})
+ config.set("bin", mingw.bindir, {readonly = true, force = true})
+ else
+ -- failed
+ cprint("${bright color.error}please run:")
+ cprint(" - xmake config --mingw=xxx")
+ cprint("or - xmake global --mingw=xxx")
+ raise()
+ end
+ return true
+end
diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua
new file mode 100644
index 000000000..10a9b2ffa
--- /dev/null
+++ b/xmake/toolchains/mingw/xmake.lua
@@ -0,0 +1,70 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define toolchain
+toolchain("mingw")
+
+ -- check toolchain
+ on_check("check")
+
+ -- on load
+ on_load(function (toolchain)
+
+ -- imports
+ import("core.project.config")
+
+ -- get cross
+ local cross = config.get("cross") or ""
+
+ -- TODO add to environment module
+ -- add bin search library for loading some dependent .dll files windows
+ local bindir = toolchain:bindir()
+ if bindir and is_host("windows") then
+ os.addenv("PATH", bindir)
+ end
+
+ -- set toolsets
+ toolchain:set("toolsets", "cc", cross .. "gcc")
+ toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "g++")
+ toolchain:set("toolsets", "cpp", cross .. "gcc -E")
+ toolchain:set("toolsets", "as", cross .. "gcc")
+ toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc")
+ toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc")
+ toolchain:set("toolsets", "ar", cross .. "ar")
+ toolchain:set("toolsets", "ex", cross .. "ar")
+ toolchain:set("toolsets", "ranlib", cross .. "ranlib")
+ toolchain:set("toolsets", "mrc", cross .. "windres")
+
+ -- 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
+ if archflags then
+ toolchain:add("cxflags", archflags)
+ toolchain:add("asflags", archflags)
+ toolchain:add("ldflags", archflags)
+ toolchain:add("shflags", archflags)
+ end
+ end)
diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua
index fe9d7629f..4cd4eea11 100644
--- a/xmake/toolchains/ndk/check.lua
+++ b/xmake/toolchains/ndk/check.lua
@@ -19,7 +19,6 @@
--
-- imports
-import("core.base.option")
import("core.project.config")
import("detect.sdks.find_ndk")
import("detect.sdks.find_android_sdk")