diff options
| author | ruki <[email protected]> | 2020-07-04 23:52:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-07-04 23:52:15 +0800 |
| commit | 22229713a006394d0bb5d70865850bad60898f00 (patch) | |
| tree | 3cd65734f56637e650f312d04418658c8550d689 /xmake/modules | |
| parent | b131172723bd99c7df027e7244fc9d0cee8fffa8 (diff) | |
add gfortran compiler
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gfortran.lua | 22 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gfortran.lua | 54 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gfortran/has_flags.lua | 122 |
4 files changed, 202 insertions, 24 deletions
diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 378c68642..2d8fe8f44 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -38,8 +38,6 @@ end -- make the optimize flag function nf_optimize(self, level) - - -- the maps local maps = { fast = "-O" @@ -48,42 +46,30 @@ function nf_optimize(self, level) , smallest = "-O -release -boundscheck=off" , aggressive = "-O -release -inline -boundscheck=off" } - - -- make it return maps[level] end -- make the strip flag function nf_strip(self, level) - - -- the maps local maps = { debug = "-L-S" , all = "-L-s" } - - -- make it return maps[level] end -- make the symbol flag function nf_symbol(self, level) - - -- the maps local maps = { debug = "-g -debug" } - - -- make it return maps[level] end -- make the warning flag function nf_warning(self, level) - - -- the maps local maps = { none = "-d" @@ -93,22 +79,16 @@ function nf_warning(self, level) , everything = "-w -wi" , error = "-de" } - - -- make it return maps[level] end -- make the vector extension flag function nf_vectorext(self, extension) - - -- the maps local maps = { avx = "-mcpu=avx" , avx2 = "-mcpu=avx" } - - -- make it return maps[extension] end @@ -171,17 +151,17 @@ function link(self, objectfiles, targetkind, targetfile, flags) end -- make the compile arguments list -function compargv(self, sourcefiles, objectfile, flags) - return self:program(), table.join("-c", flags, "-of" .. objectfile, sourcefiles) +function compargv(self, sourcefile, objectfile, flags) + return self:program(), table.join("-c", flags, "-of" .. objectfile, sourcefile) end -- compile the source file -function compile(self, sourcefiles, objectfile, dependinfo, flags) +function compile(self, sourcefile, objectfile, dependinfo, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.runv(compargv(self, sourcefiles, objectfile, flags)) + os.runv(compargv(self, sourcefile, objectfile, flags)) end diff --git a/xmake/modules/core/tools/gfortran.lua b/xmake/modules/core/tools/gfortran.lua new file mode 100644 index 000000000..16a6dfdb6 --- /dev/null +++ b/xmake/modules/core/tools/gfortran.lua @@ -0,0 +1,22 @@ +--!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 gfortran.lua +-- + +-- inherit gcc +inherit("gcc") diff --git a/xmake/modules/detect/tools/find_gfortran.lua b/xmake/modules/detect/tools/find_gfortran.lua new file mode 100644 index 000000000..1d5bec7b6 --- /dev/null +++ b/xmake/modules/detect/tools/find_gfortran.lua @@ -0,0 +1,54 @@ +--!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 find_gfortran.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find gfortran +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local gfortran = find_gfortran() +-- local gfortran, version = find_gfortran({program = "gfortran9", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "gfortran", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/modules/detect/tools/gfortran/has_flags.lua b/xmake/modules/detect/tools/gfortran/has_flags.lua new file mode 100644 index 000000000..5f209a3fc --- /dev/null +++ b/xmake/modules/detect/tools/gfortran/has_flags.lua @@ -0,0 +1,122 @@ +--!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 has_flags.lua +-- + +-- imports +import("lib.detect.cache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl,<arg>" or "-Xlinker <arg>"? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "detect.tools.gfortran.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- load cache + local cacheinfo = cache.load(key) + + -- get all flags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + cacheinfo[flagskey] = allflags + cache.save(key, cacheinfo) + end + + -- ok? + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "gfortran_has_flags.f90") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "program hello\n print *, \"Hello World!\"\nend program hello") + end + + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + |
