summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-21 22:45:23 +0800
committerruki <[email protected]>2017-06-21 22:45:23 +0800
commit521242989cd398a2e1130b9a1be2ed22c143d329 (patch)
tree8c6496d9d2897165c5490e55a7c1920282a98bd2
parent7d1ebfb528f19b16074c7821bc221288e53fb780 (diff)
add link and ml has_flag
-rw-r--r--xmake/modules/detect/tools/ar/has_flag.lua2
-rw-r--r--xmake/modules/detect/tools/link/has_flag.lua111
-rw-r--r--xmake/modules/detect/tools/ml/has_flag.lua98
-rw-r--r--xmake/modules/detect/tools/ml64/has_flag.lua27
4 files changed, 237 insertions, 1 deletions
diff --git a/xmake/modules/detect/tools/ar/has_flag.lua b/xmake/modules/detect/tools/ar/has_flag.lua
index 340d588e4..5358e3e0a 100644
--- a/xmake/modules/detect/tools/ar/has_flag.lua
+++ b/xmake/modules/detect/tools/ar/has_flag.lua
@@ -46,7 +46,7 @@ function _check_from_arglist(flag, opt)
local arglist = nil
try
{
- function () os.iorunv(opt.program, {"--help"}) end,
+ function () os.runv(opt.program, {"--help"}) end,
catch
{
function (errors) arglist = errors end
diff --git a/xmake/modules/detect/tools/link/has_flag.lua b/xmake/modules/detect/tools/link/has_flag.lua
new file mode 100644
index 000000000..e46647f99
--- /dev/null
+++ b/xmake/modules/detect/tools/link/has_flag.lua
@@ -0,0 +1,111 @@
+--!The Make-like 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file has_flag.lua
+--
+
+-- imports
+import("lib.detect.cache")
+
+-- attempt to check it from the argument list
+function _check_from_arglist(flag, opt)
+
+ -- make cache key
+ local key = "detect.tools.link.has_flag"
+
+ -- make flags key
+ local flagskey = opt.program .. "_" .. (opt.programver or "")
+
+ -- load cache
+ local cacheinfo = cache.load(key)
+
+ -- get all flags from argument list
+ local flags = cacheinfo[flagskey]
+ if not flags then
+
+ -- get argument list
+ flags = {}
+ local arglist = nil
+ try
+ {
+ function () os.runv(opt.program, {"-?"}) end,
+ catch
+ {
+ function (errors) arglist = errors end
+ }
+ }
+ if arglist then
+ for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do
+ flags[arg:gsub("/", "-"):lower()] = true
+ end
+ end
+
+ -- save cache
+ cacheinfo[flagskey] = flags
+ cache.save(key, cacheinfo)
+ end
+
+ -- ok?
+ return flags[flag:gsub("/", "-"):lower()]
+end
+
+-- try running to check flag
+function _check_try_running(flag, opt)
+
+ -- make an stub source file
+ local sourcefile = path.join(os.tmpdir(), "detect", "link_has_flag.c")
+ if not os.isfile(sourcefile) then
+ io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
+ end
+
+ -- compile the source file
+ local objectfile = os.tmpfile() .. ".obj"
+ local binaryfile = os.tmpfile() .. ".exe"
+ os.iorunv("cl", {"-c", "-nologo", "-Fo" .. objectfile, sourcefile})
+
+ -- try link it
+ local ok = try { function () os.execv(opt.program, {flag, "-nologo", "-out:" .. binaryfile, objectfile}); return true end }
+
+ -- remove files
+ os.tryrm(objectfile)
+ os.tryrm(binaryfile)
+
+ -- ok?
+ return ok
+end
+
+-- has_flag(flag)?
+--
+-- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
+--
+-- @return true or false
+--
+function main(flag, opt)
+
+ -- attempt to check it from the argument list
+ if _check_from_arglist(flag, opt) then
+ return true
+ end
+
+ -- try running to check it
+ return _check_try_running(flag, opt)
+end
+
diff --git a/xmake/modules/detect/tools/ml/has_flag.lua b/xmake/modules/detect/tools/ml/has_flag.lua
new file mode 100644
index 000000000..f41561953
--- /dev/null
+++ b/xmake/modules/detect/tools/ml/has_flag.lua
@@ -0,0 +1,98 @@
+--!The Make-like 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file has_flag.lua
+--
+
+-- imports
+import("lib.detect.cache")
+
+-- attempt to check it from the argument list
+function _check_from_arglist(flag, opt)
+
+ -- make cache key
+ local key = "detect.tools.ml.has_flag"
+
+ -- make flags key
+ local flagskey = opt.program .. "_" .. (opt.programver or "")
+
+ -- load cache
+ local cacheinfo = cache.load(key)
+
+ -- get all flags from argument list
+ local flags = cacheinfo[flagskey]
+ if not flags then
+
+ -- get argument list
+ flags = {}
+ local arglist = os.iorunv(opt.program, {"-?"})
+ if arglist then
+ for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do
+ flags[arg:gsub("/", "-")] = true
+ end
+ end
+
+ -- save cache
+ cacheinfo[flagskey] = flags
+ cache.save(key, cacheinfo)
+ end
+
+ -- ok?
+ return flags[flag:gsub("/", "-")]
+end
+
+-- try running to check flag
+function _check_try_running(flag, opt)
+
+ -- make an stub source file
+ local sourcefile = path.join(os.tmpdir(), "detect", "ml_has_flag.asm")
+ if not os.isfile(sourcefile) then
+ io.writefile(sourcefile, ".code\nend")
+ end
+
+ -- check it
+ return try { function ()
+ local _, errors = os.iorunv(opt.program, {"-c", "-nologo", flag, "-Fo" .. os.nuldev(), sourcefile})
+ if errors and #errors:trim() > 0 then
+ return false
+ end
+ return true
+ end
+ }
+end
+
+-- has_flag(flag)?
+--
+-- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
+--
+-- @return true or false
+--
+function main(flag, opt)
+
+ -- attempt to check it from the argument list
+ if _check_from_arglist(flag, opt) then
+ return true
+ end
+
+ -- try running to check it
+ return _check_try_running(flag, opt)
+end
+
diff --git a/xmake/modules/detect/tools/ml64/has_flag.lua b/xmake/modules/detect/tools/ml64/has_flag.lua
new file mode 100644
index 000000000..c0086f0e7
--- /dev/null
+++ b/xmake/modules/detect/tools/ml64/has_flag.lua
@@ -0,0 +1,27 @@
+--!The Make-like 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file has_flag.lua
+--
+
+-- imports
+inherit("detect.tools.ml.has_flag")
+