diff options
| author | ruki <[email protected]> | 2017-06-16 10:56:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-16 10:56:02 +0800 |
| commit | 4ce04f4a25ac9fa21e19ae4c568d7a253959680a (patch) | |
| tree | f3b702a340fcbb0b1ae6fc5f58871c50b682d13b | |
| parent | 1e907d9090e6e5cbd4013d997f2d14d37e313d2f (diff) | |
add find ms compiler and linker
| -rw-r--r-- | xmake/modules/detect/tool/find_cl.lua | 59 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_lib.lua | 77 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_link.lua | 78 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_ml.lua | 59 |
4 files changed, 273 insertions, 0 deletions
diff --git a/xmake/modules/detect/tool/find_cl.lua b/xmake/modules/detect/tool/find_cl.lua new file mode 100644 index 000000000..8287120f9 --- /dev/null +++ b/xmake/modules/detect/tool/find_cl.lua @@ -0,0 +1,59 @@ +--!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 find_cl.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find cl +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cl = find_cl() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "cl.exe", {}, function (program) os.run(program) end) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, function () local _, info = os.iorun(program); return info end, + function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + end + + -- ok? + return program, version +end + diff --git a/xmake/modules/detect/tool/find_lib.lua b/xmake/modules/detect/tool/find_lib.lua new file mode 100644 index 000000000..5b6545f40 --- /dev/null +++ b/xmake/modules/detect/tool/find_lib.lua @@ -0,0 +1,77 @@ +--!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 find_lib.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find lib +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local lib = find_lib() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local verinfo = nil + local program = find_program(opt.program or "lib.exe", {}, function (program) + + -- make an stub source file + local libraryfile = os.tmpfile() .. ".lib" + local objectfile = os.tmpfile() .. ".obj" + local sourcefile = os.tmpfile() .. ".c" + io.writefile(sourcefile, "int test(void)\n{return 0;}") + + -- check it + os.run("cl -c -Fo%s %s", objectfile, sourcefile) + os.run("link -lib -out:%s %s", libraryfile, objectfile) + verinfo = os.iorun("%s -list %s", program, libraryfile) + + -- remove files + os.rm(objectfile) + os.rm(sourcefile) + os.rm(libraryfile) + end) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, function () return verinfo end, + function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + end + + -- ok? + return program, version +end + diff --git a/xmake/modules/detect/tool/find_link.lua b/xmake/modules/detect/tool/find_link.lua new file mode 100644 index 000000000..209fa1300 --- /dev/null +++ b/xmake/modules/detect/tool/find_link.lua @@ -0,0 +1,78 @@ +--!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 find_link.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find link +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local link = find_link() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local verinfo = nil + local program = find_program(opt.program or "link.exe", {}, function (program) + + -- make an stub source file + local binaryfile = os.tmpfile() .. ".exe" + local objectfile = os.tmpfile() .. ".obj" + local sourcefile = os.tmpfile() .. ".c" + + -- main entry + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") + + -- check it + os.run("cl -c -Fo%s %s", objectfile, sourcefile) + verinfo = os.iorun("%s -out:%s %s", program, binaryfile, objectfile) + + -- remove files + os.rm(objectfile) + os.rm(sourcefile) + os.rm(binaryfile) + end) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, function () return verinfo end, + function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + end + + -- ok? + return program, version +end + diff --git a/xmake/modules/detect/tool/find_ml.lua b/xmake/modules/detect/tool/find_ml.lua new file mode 100644 index 000000000..b4407e452 --- /dev/null +++ b/xmake/modules/detect/tool/find_ml.lua @@ -0,0 +1,59 @@ +--!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 find_ml.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find ml +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ml = find_ml() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "ml.exe", {}, function (program) os.run(program) end) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, function () local _, info = os.iorun(program); return info end, + function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + end + + -- ok? + return program, version +end + |
