Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/xmake/xmake/modules/private/tools | repos/xmake/xmake/modules/private/tools/go/goenv.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file goenv.lua
--
-- imports
import("lib.detect.find_tool")
function GOOS(plat)
local goos
if plat == "windows" or plat == "mingw" or plat == "msys" or plat == "cygwin" then
goos = "windows"
elseif plat == "linux" then
goos = "linux"
elseif plat == "macosx" then
goos = "darwin"
end
return goos
end
function GOARCH(arch)
return (arch == "x86" or arch == "i386") and "386" or "amd64"
end
function GOROOT(toolchain)
local go = find_tool("go")
if go then
local gorootdir = try { function() return os.iorunv(go.program, {"env", "GOROOT"}) end }
if gorootdir then
return gorootdir:trim()
end
end
end
|
0 | repos/xmake/xmake/modules/private/tools | repos/xmake/xmake/modules/private/tools/rc/parse_deps.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file parse_deps.lua
--
-- imports
import("core.project.project")
import("core.base.hashset")
-- normailize path of a dependecy
function _normailize_dep(dep, projectdir)
if path.is_absolute(dep) then
dep = path.translate(dep)
else
dep = path.absolute(dep, projectdir)
end
if dep:startswith(projectdir) then
return path.relative(dep, projectdir)
else
return deps
end
end
-- parse depsfiles from string
function main(depsdata)
local results = hashset.new()
local projectdir = os.projectdir()
for _, includefile in ipairs(depsdata:split('\n', {plain = true})) do
if #includefile > 0 then
includefile = _normailize_dep(includefile, projectdir)
if includefile then
results:insert(includefile)
end
end
end
return results:to_array()
end
|
0 | repos/xmake/xmake/modules/private | repos/xmake/xmake/modules/private/detect/find_cudatool.lua | --!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-present, TBOOX Open Source Group.
--
-- @author OpportunityLiu
-- @file find_cudatool.lua
--
-- imports
import("core.project.config")
import("lib.detect.find_program")
import("lib.detect.find_programver")
import("detect.sdks.find_cuda")
-- find cuda tool
--
-- @param toolname name of cuda tool, e.g. "nvcc"
-- parse default pattern for version string
-- opt the argument options, e.g. {version = true}
--
-- @return program, version
--
-- @code
--
-- local nvcc = find_cudatool("nvcc", "V(%d+%.?%d*%.?%d*.-)%s")
-- local nvcc, version = find_cudatool("nvcc", "V(%d+%.?%d*%.?%d*.-)%s", {program = "nvcc", version = true})
--
-- @endcode
--
function main(toolname, parse, opt)
-- init options
opt = opt or {}
opt.parse = opt.parse or parse
-- always keep consistency with cuda cache
local program
local toolchains = find_cuda()
if toolchains and toolchains.bindir then
local opt2 = table.clone(opt)
opt2.paths = opt2.paths or {}
table.insert(opt2.paths, toolchains.bindir)
program = find_program(opt2.program or toolname, opt2)
end
-- not found? attempt to find program only
if not program then
program = find_program(opt.program or toolname, opt)
end
-- find program version
local version = nil
if program and opt.version then
version = find_programver(program, opt)
end
return program, version
end
|
0 | repos/xmake/xmake/modules/private | repos/xmake/xmake/modules/private/detect/find_platform.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file find_platform.lua
--
-- imports
import("core.project.config")
import("core.project.project")
import("detect.sdks.find_cross_toolchain")
-- find platform
function _find_plat(plat)
plat = plat or config.get("plat")
if not plat then
if not plat then
plat = project.get("defaultplat")
end
if not plat then
plat = os.subhost()
end
if plat == "msys" then
local msystem = os.getenv("MSYSTEM")
if msystem and msystem:lower():find("mingw", 1, true) then
plat = "mingw"
end
end
end
return plat
end
-- find architecture for cross platform
function _find_arch_from_cross()
local cross = config.get("cross")
if not cross then
local cross_toolchain = find_cross_toolchain(config.get("sdk"), {bindir = config.get("bin")})
if cross_toolchain then
cross = cross_toolchain.cross
end
end
local arch = "none"
if cross then
if cross:find("aarch64", 1, true) then
arch = "arm64"
elseif cross:find("arm", 1, true) then
arch = "arm"
elseif cross:find("mips64", 1, true) then
arch = "mips64"
elseif cross:find("mips", 1, true) then
arch = "mips"
elseif cross:find("riscv64", 1, true) then
arch = "riscv64"
elseif cross:find("riscv", 1, true) then
arch = "riscv"
elseif cross:find("loong64", 1, true) then
arch = "loong64"
elseif cross:find("s390x", 1, true) then
arch = "s390x"
elseif cross:find("powerpc64", 1, true) then
arch = "ppc64"
elseif cross:find("powerpc", 1, true) then
arch = "ppc"
elseif cross:find("sh4", 1, true) then
arch = "sh4"
elseif cross:find("x86_64", 1, true) then
arch = "x86_64"
elseif cross:find("i386", 1, true) or cross:find("i686", 1, true) then
arch = "i386"
end
end
return arch
end
-- find architecture
function _find_arch(plat, arch)
arch = arch or config.get("arch")
if not arch then
if not arch then
arch = project.default_arch(plat)
end
if not arch then
local appledev = config.get("appledev")
if plat == "android" then
arch = "armeabi-v7a"
elseif plat == "iphoneos" or plat == "appletvos" or plat == "applexros" then
arch = appledev == "simulator" and os.arch() or "arm64"
elseif plat == "watchos" then
arch = appledev == "simulator" and os.arch() or "armv7k"
elseif plat == "wasm" then
arch = "wasm32"
elseif plat == "mingw" then
local mingw_chost = nil
if is_subhost("msys") then
mingw_chost = os.getenv("MINGW_CHOST")
end
if mingw_chost == "i686-w64-mingw32" then
arch = "i386"
else
arch = "x86_64"
end
elseif plat == "harmony" then
arch = "arm64-v8a"
elseif plat == "cross" then
arch = _find_arch_from_cross()
else
arch = os.subarch()
end
end
end
return arch
end
-- find default platform and architecture
--
-- @param opt the argument options, e.g. {plat = "", arch = "", global = true}
--
-- @return plat, arch
--
-- @code
--
-- find the default platform:
-- local result = find_platform()
--
-- find the default architecture from the given platform:
-- local result = find_platform({plat = "iphoneos"})
--
-- @endcode
--
function main(opt)
-- find platform
opt = opt or {}
local plat = _find_plat(opt.plat)
if opt.global then
if not opt.plat and not config.get("plat") then
config.set("plat", plat)
cprint("checking for platform ... ${color.success}%s", plat)
end
end
-- find architecture
local arch = _find_arch(plat, opt.arch)
if opt.global then
if not opt.arch and not config.get("arch") then
config.set("arch", arch)
cprint("checking for architecture ... ${color.success}%s", arch)
end
end
return plat, arch
end
|
0 | repos/xmake/xmake/modules | repos/xmake/xmake/modules/async/runjobs.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file runjobs.lua
--
-- imports
import("core.base.scheduler")
import("utils.progress")
-- print back characters
function _print_backchars(backnum)
if backnum > 0 then
local str = ('\b'):rep(backnum) .. (' '):rep(backnum) .. ('\b'):rep(backnum)
if #str > 0 then
printf(str)
end
end
end
-- asynchronous run jobs
--
-- e.g.
-- runjobs("test", function (index) print("hello") end, {total = 100, comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end})
-- runjobs("test", function () os.sleep(10000) end, { progress = true })
-- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module utils.progress
--
-- local jobs = jobpool.new()
-- local root = jobs:addjob("job/root", function (index, total, opt)
-- print(index, total, opt.progress)
-- end)
-- for i = 1, 3 do
-- local job = jobs:addjob("job/" .. i, function (index, total, opt)
-- print(index, total, opt.progress)
-- end, {rootjob = root})
-- end
-- runjobs("test", jobs, {comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end})
--
-- distributed build:
-- runjobs("test", jobs, {comax = 6, distcc = distcc_build_client.singleton()}
--
function main(name, jobs, opt)
-- init options
opt = opt or {}
local total = opt.total or (type(jobs) == "table" and jobs:size()) or 1
local comax = opt.comax or math.min(total, 4)
local distcc = opt.distcc
local timeout = opt.timeout or 500
local group_name = name
local jobs_cb = type(jobs) == "function" and jobs or nil
assert(timeout < 60000, "runjobs: invalid timeout!")
assert(jobs, "runjobs: no jobs!")
-- show waiting tips?
local showprogress = io.isatty() and (opt.progress or opt.showtips) -- we need to hide wait characters if is not a tty
local progress_helper
local backnum = 0
if showprogress then
local opt = nil
if type(showprogress) == 'table' then opt = showprogress end
progress_helper = progress.new(nil, opt)
end
-- isolate environments
local is_isolated = false
local co_running = scheduler.co_running()
if co_running and opt.isolate then
is_isolated = co_running:is_isolated()
co_running:isolate(true)
end
-- run timer
local stop = false
local running_jobs_indices = {}
local group_timer
if opt.on_timer then
group_timer = group_name .. "/timer"
scheduler.co_group_begin(group_timer, function (co_group)
scheduler.co_start_withopt({name = name .. "/timer", isolate = opt.isolate}, function ()
while not stop do
os.sleep(timeout)
if not stop then
local indices
if running_jobs_indices then
indices = table.keys(running_jobs_indices)
end
opt.on_timer(indices)
end
end
end)
end)
elseif showprogress then
group_timer = group_name .. "/timer"
scheduler.co_group_begin(group_timer, function (co_group)
scheduler.co_start_withopt({name = name .. "/tips", isolate = opt.isolate}, function ()
while not stop do
os.sleep(timeout)
if not stop then
-- show waitchars
local tips = nil
local waitobjs = scheduler.co_group_waitobjs(group_name)
if waitobjs:size() > 0 then
local names = {}
for _, obj in waitobjs:keys() do
if obj:otype() == scheduler.OT_PROC then
table.insert(names, obj:name())
elseif obj:otype() == scheduler.OT_SOCK then
table.insert(names, "sock")
elseif obj:otype() == scheduler.OT_PIPE then
table.insert(names, "pipe")
end
end
names = table.unique(names)
if #names > 0 then
names = table.concat(names, ",")
if #names > 16 then
names = names:sub(1, 16) .. ".."
end
tips = string.format("(%d/%s)", waitobjs:size(), names)
end
end
-- print back characters
progress_helper:clear()
_print_backchars(backnum)
if tips then
cprintf("${dim}%s${clear} ", tips)
backnum = #tips + 1
end
progress_helper:write()
end
end
end)
end)
end
-- run jobs
local index = 0
local count = 0
local abort = false
local abort_errors
local progress_wrapper = {}
local job_pending
progress_wrapper.current = function ()
return count
end
progress_wrapper.total = function ()
return total
end
progress_wrapper.percent = function ()
if total and total > 0 then
return math.floor((count * 100) / total)
else
return 0
end
end
debug.setmetatable(progress_wrapper, {
__tostring = function ()
return string.format("%d%%", progress_wrapper.percent())
end
})
while index < total do
scheduler.co_group_begin(group_name, function (co_group)
local freemax = comax - #co_group
local local_max = math.min(index + freemax, total)
local total_max = local_max
if distcc then
total_max = math.min(index + freemax + distcc:freejobs(), total)
end
local jobfunc = jobs_cb
while index < total_max do
-- uses job pool?
local job
local jobname
local distccjob = false
if not jobs_cb then
-- get free job
job = job_pending and job_pending or jobs:getfree()
if not job then
break
end
-- we can only continue to run the job with distcc if local jobs are full
if distcc and index >= local_max then
if job.distcc then
distccjob = true
else
job_pending = job
break
end
end
-- get run function
jobfunc = job.run
jobname = job.name
job_pending = nil
else
jobname = tostring(index)
end
-- start this job
index = index + 1
scheduler.co_start_withopt({name = name .. '/' .. jobname, isolate = opt.isolate}, function(i)
try
{
function()
if stop then
return
end
if distcc then
local co_running = scheduler.co_running()
if co_running then
co_running:data_set("distcc.distccjob", distccjob)
end
end
running_jobs_indices[i] = i
if jobfunc then
if opt.curdir then
os.cd(opt.curdir)
end
count = count + 1
jobfunc(i, total, {progress = progress_wrapper})
end
running_jobs_indices[i] = nil
end,
catch
{
function (errors)
-- stop timer and disable show waitchars first
stop = true
-- remove wait charactor
if showprogress then
_print_backchars(backnum)
progress_helper:stop()
end
-- we need re-throw this errors outside scheduler
abort = true
if abort_errors == nil then
abort_errors = errors
end
-- kill all waited objects in this group
local waitobjs = scheduler.co_group_waitobjs(group_name)
if waitobjs:size() > 0 then
for _, obj in waitobjs:keys() do
-- TODO, kill pipe is not supported now
if obj.kill then
obj:kill()
end
end
end
end
},
finally
{
function ()
if job then
jobs:remove(job)
end
end
}
}
end, index)
end
end)
-- wait for free jobs
scheduler.co_group_wait(group_name, {limit = 1})
end
-- wait all jobs exited
scheduler.co_group_wait(group_name)
-- wait timer job exited
if group_timer then
stop = true
scheduler.co_group_wait(group_timer)
end
-- restore isolated environments
if co_running and opt.isolate then
co_running:isolate(is_isolated)
end
-- remove wait charactor
if showprogress then
_print_backchars(backnum)
progress_helper:stop()
end
-- do exit callback
if opt.on_exit then
opt.on_exit(abort_errors)
end
-- re-throw abort errors
--
-- @note we cannot throw it in coroutine,
-- because his causes a direct exit from the entire runloop and
-- a quick escape from nested try-catch blocks and coroutines groups.
-- so we can not catch runjobs errors, e.g. build fails
if abort then
raise(abort_errors)
end
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/debugger/run.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file run.lua
--
-- imports
import("core.base.json")
import("core.base.option")
import("core.project.config")
import("detect.tools.find_cudagdb")
import("detect.tools.find_cudamemcheck")
import("detect.tools.find_gdb")
import("detect.tools.find_lldb")
import("detect.tools.find_windbg")
import("detect.tools.find_x64dbg")
import("detect.tools.find_ollydbg")
import("detect.tools.find_devenv")
import("detect.tools.find_vsjitdebugger")
import("detect.tools.find_renderdoc")
import("lib.detect.find_tool")
import("private.action.run.runenvs")
-- run gdb
function _run_gdb(program, argv, opt)
-- find gdb
opt = opt or {}
local gdb = find_gdb({program = config.get("debugger")})
if not gdb then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
table.insert(argv, 1, "--args")
-- run it
os.execv(gdb, argv, table.join(opt, {exclusive = true}))
return true
end
-- run cuda-gdb
function _run_cudagdb(program, argv, opt)
-- find cudagdb
opt = opt or {}
local gdb = find_cudagdb({program = config.get("debugger")})
if not gdb then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
table.insert(argv, 1, "--args")
-- run it
os.execv(gdb, argv, table.join(opt, {exclusive = true}))
return true
end
-- run lldb
function _run_lldb(program, argv, opt)
-- find lldb
opt = opt or {}
local lldb = find_lldb({program = config.get("debugger")})
if not lldb then
return false
end
-- attempt to split name, e.g. xcrun -sdk macosx lldb
local names = lldb:split("%s")
-- patch arguments
argv = argv or {}
table.insert(argv, 1, "--")
table.insert(argv, 1, program)
table.insert(argv, 1, "-f")
for i = #names, 2, -1 do
table.insert(argv, 1, names[i])
end
-- run it
os.execv(names[1], argv, table.join(opt, {exclusive = true}))
return true
end
-- run windbg
function _run_windbg(program, argv, opt)
-- find windbg
local windbg = find_windbg({program = config.get("debugger")})
if not windbg then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
-- run it
opt.detach = true
os.execv(windbg, argv, opt)
return true
end
-- run cuda-memcheck
function _run_cudamemcheck(program, argv, opt)
-- find cudamemcheck
local cudamemcheck = find_cudamemcheck({program = config.get("debugger")})
if not cudamemcheck then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
-- run it
os.execv(cudamemcheck, argv, opt)
return true
end
-- run x64dbg
function _run_x64dbg(program, argv, opt)
-- find x64dbg
local x64dbg = find_x64dbg({program = config.get("debugger")})
if not x64dbg then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
-- run it
opt.detach = true
os.execv(x64dbg, argv, opt)
return true
end
-- run ollydbg
function _run_ollydbg(program, argv, opt)
-- find ollydbg
local ollydbg = find_ollydbg({program = config.get("debugger")})
if not ollydbg then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
-- run it
opt.detach = true
os.execv(ollydbg, argv, opt)
return true
end
-- run vsjitdebugger
function _run_vsjitdebugger(program, argv, opt)
-- find vsjitdebugger
local vsjitdebugger = find_vsjitdebugger({program = config.get("debugger")})
if not vsjitdebugger then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
-- run it
opt.detach = true
os.execv(vsjitdebugger, argv, opt)
return true
end
-- run devenv
function _run_devenv(program, argv, opt)
-- find devenv
local devenv = find_devenv({program = config.get("debugger")})
if not devenv then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, "/DebugExe")
table.insert(argv, 2, program)
-- run it
opt.detach = true
os.execv(devenv, argv, opt)
return true
end
-- run renderdoc
function _run_renderdoc(program, argv, opt)
-- find renderdoc
local renderdoc = find_renderdoc({program = config.get("debugger")})
if not renderdoc then
return false
end
-- build capture settings
local environment = {}
if opt.addenvs then
for name, values in pairs(opt.addenvs) do
table.insert(environment, {
separator = "Platform style",
type = "Append",
value = path.joinenv(values),
variable = name
})
end
end
if opt.setenvs then
for name, values in pairs(opt.setenvs) do
table.insert(environment, {
separator = "Platform style",
type = "Set",
value = path.joinenv(values),
variable = name
})
end
end
local settings = {
rdocCaptureSettings = 1,
settings = {
autoStart = false,
commandLine = table.concat(table.wrap(argv), " "),
environment = json.mark_as_array(environment),
executable = program,
inject = false,
numQueuedFrames = 0,
queuedFrameCap = 0,
workingDir = opt.curdir and path.absolute(opt.curdir) or "",
options = {
allowFullscreen = true,
allowVSync = true,
apiValidation = false,
captureAllCmdLists = false,
captureCallstacks = false,
captureCallstacksOnlyDraws = false,
debugOutputMute = true,
delayForDebugger = 0,
hookIntoChildren = false,
refAllResources = false,
verifyBufferAccess = false
}
}
}
-- save to temporary file
local capturefile = os.tmpfile() .. ".cap"
json.savefile(capturefile, settings)
-- run renderdoc
opt.detach = true
opt.addenvs = nil
opt.setenvs = nil
os.execv(renderdoc, { capturefile }, opt)
return true
end
-- run gede
function _run_gede(program, argv, opt)
-- find gede
opt = opt or {}
-- 'gede --version' return with non-zero code
local gede = find_tool("gede", {program = config.get("debugger"), norun = true})
if not gede then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
table.insert(argv, 1, "--args")
table.insert(argv, 1, "--no-show-config")
-- run it
os.execv(gede.program, argv, table.join(opt, {exclusive = true}))
return true
end
-- run seergdb
function _run_seergdb(program, argv, opt)
-- find seergdb
opt = opt or {}
local seergdb = find_tool("seergdb", {program = config.get("debugger")})
if not seergdb then
return false
end
-- patch arguments
argv = argv or {}
table.insert(argv, 1, program)
table.insert(argv, 1, "--start")
-- run it
os.execv(seergdb.program, argv, table.join(opt, {exclusive = true}))
return true
end
-- run program with debugger
--
-- @param program the program name
-- @param argv the program rguments
--
-- @code
--
-- import("devel.debugger")
--
-- debugger.run("test")
-- debugger.run("echo", {"hello xmake!"})
--
-- @endcode
--
function main(program, argv, opt)
-- init debuggers
local debuggers =
{
{"lldb" , _run_lldb}
, {"gdb" , _run_gdb}
, {"cudagdb" , _run_cudagdb}
, {"cudamemcheck", _run_cudamemcheck}
, {"renderdoc" , _run_renderdoc}
, {"gede" , _run_gede}
, {"seergdb" , _run_seergdb}
}
-- for windows target or on windows?
if (config.plat() or os.host()) == "windows" then
table.insert(debuggers, 1, {"windbg", _run_windbg})
table.insert(debuggers, 1, {"ollydbg", _run_ollydbg})
table.insert(debuggers, 1, {"x64dbg", _run_x64dbg})
table.insert(debuggers, 1, {"vsjitdebugger", _run_vsjitdebugger})
table.insert(debuggers, 1, {"devenv", _run_devenv})
end
-- get debugger from configuration
opt = opt or {}
local debugger = config.get("debugger")
if debugger then
-- try exactmatch first
debugger = debugger:lower()
local debuggername = path.basename(debugger)
for _, _debugger in ipairs(debuggers) do
if debuggername:startswith(_debugger[1]) then
if _debugger[2](program, argv, opt) then
return
end
end
end
for _, _debugger in ipairs(debuggers) do
if debugger:find(_debugger[1]) then
if _debugger[2](program, argv, opt) then
return
end
end
end
else
-- run debugger
for _, _debugger in ipairs(debuggers) do
if _debugger[2](program, argv, opt) then
return
end
end
end
-- no debugger
raise("debugger%s not found!", debugger and ("(" .. debugger .. ")") or "")
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/init.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file init.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- init project
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.init()
-- git.init({repodir = "/tmp/xmake"})
--
-- @endcode
--
function main(opt)
-- init options
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"init"}
-- verbose?
if not option.get("verbose") then
table.insert(argv, "-q")
end
-- init it
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/apply.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file apply.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- apply remote commits
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.apply("xxx.patch")
-- git.apply("xxx.diff")
--
-- @endcode
--
function main(patchfile, opt)
opt = opt or {}
local git = assert(find_tool("git"), "git not found!")
local argv = {"apply", "--reject", "--ignore-whitespace"}
if opt.reverse then
table.insert(argv, "-R")
end
if opt.gitdir then
table.insert(argv, 1, "--git-dir=" .. opt.gitdir)
end
table.insert(argv, patchfile)
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/branch.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file branch.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
import("net.proxy")
-- get current branch
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- local branch = git.branch()
-- local branch = git.branch({repodir = "/tmp/xmake"})
--
-- @endcode
--
function main(opt)
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init arguments
local argv = {"branch", "--show-current"}
-- trace
if option.get("verbose") then
print("%s %s", git.program, os.args(argv))
end
-- use proxy?
local envs
local proxy_conf = proxy.config(url)
if proxy_conf then
envs = {ALL_PROXY = proxy_conf}
end
-- get current branch
local branch = os.iorunv(git.program, argv, {envs = envs, curdir = opt.repodir})
if branch then
branch = branch:trim()
end
return branch
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/tags.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file tags.lua
--
-- imports
import("core.base.option")
import("ls_remote")
-- get all tags from url
--
-- @param url the remote url, optional
--
-- @return the tags
--
-- @code
--
-- import("devel.git")
--
-- local tags = git.tags(url)
--
-- @endcode
--
function main(url)
return ls_remote("tags", url)
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/push.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file push.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
import("branch", {alias = "git_branch"})
-- push to given remote url and branch
--
-- @param url the remote url
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.push(url, {branch = "master, remote_branch = "xxx", force = true, "repodir = "/tmp/xmake"})
--
-- @endcode
--
function main(url, opt)
opt = opt or {}
local git = assert(find_tool("git"), "git not found!")
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
table.insert(argv, "push")
table.insert(argv, url)
if opt.force then
table.insert(argv, "--force")
end
local branch = opt.branch or git_branch(opt)
assert(branch, "git branch not found!")
if opt.remote_branch then
branch = branch .. ":" .. opt.remote_branch
end
table.insert(argv, branch)
if opt.verbose then
os.execv(git.program, argv, {curdir = opt.repodir})
else
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/ls_remote.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ls_remote.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
import("net.proxy")
-- ls_remote to given branch, tag or commit
--
-- @param reftype the reference type, "tags", "heads" and "refs"
-- @param url the remote url, optional
--
-- @return the tags, heads or refs
--
-- @code
--
-- import("devel.git")
--
-- local tags = git.ls_remote("tags", url)
-- local heads = git.ls_remote("heads", url)
-- local refs = git.ls_remote("refs")
--
-- @endcode
--
function main(reftype, url)
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init reference type
reftype = reftype or "refs"
-- init arguments
local argv = {"ls-remote", "--" .. reftype, url or "."}
-- trace
if option.get("verbose") then
print("%s %s", git.program, os.args(argv))
end
-- use proxy?
local envs
local proxy_conf = proxy.config(url)
if proxy_conf then
envs = {ALL_PROXY = proxy_conf}
end
-- get refs
local data = os.iorunv(git.program, argv, {envs = envs})
-- get commmits and tags
local refs = {}
for _, line in ipairs(data:split('\n')) do
-- parse commit and ref
local refinfo = line:split('%s')
-- get commit
local commit = refinfo[1]
-- get ref
local ref = refinfo[2]
-- save this ref
local prefix = reftype == "refs" and "refs/" or ("refs/" .. reftype .. "/")
if ref and ref:startswith(prefix) and commit and #commit == 40 then
table.insert(refs, ref:sub(#prefix + 1))
end
end
-- ok
return refs
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/clone.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file clone.lua
--
-- imports
import("core.base.option")
import("core.base.semver")
import("lib.detect.find_tool")
import("net.proxy")
-- can clone tag?
-- @see https://github.com/xmake-io/xmake/issues/4151
function can_clone_tag()
local can = _g.can_clone_tag
if can == nil then
local git = assert(find_tool("git", {version = true}), "git not found!")
if git.version and semver.compare(git.version, "1.7.10") >= 0 then
can = true
end
_g.can_clone_tag = can or false
end
return can or false
end
-- can clone with --shallow-submodules?
-- @see https://github.com/xmake-io/xmake/issues/4151
function can_shallow_submodules()
local can = _g.can_shallow_submodules
if can == nil then
local git = assert(find_tool("git", {version = true}), "git not found!")
if git.version and semver.compare(git.version, "2.9.0") >= 0 then
can = true
end
_g.can_shallow_submodules = can or false
end
return can or false
end
-- clone url
--
-- @param url the git url
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.clone("[email protected]:xmake-io/xmake.git")
-- git.clone("[email protected]:xmake-io/xmake.git", {depth = 1, treeless = true, branch = "master", outputdir = "/tmp/xmake", longpaths = true})
--
-- @endcode
--
function main(url, opt)
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {"clone", url}
-- set branch
opt = opt or {}
if opt.branch then
table.insert(argv, "-b")
table.insert(argv, opt.branch)
end
-- set depth
if opt.depth then
table.insert(argv, "--depth")
table.insert(argv, type(opt.depth) == "number" and tostring(opt.depth) or opt.depth)
end
-- treeless?
-- @see https://github.com/xmake-io/xmake/issues/5507
if opt.treeless then
table.insert(argv, "--filter=tree:0")
end
-- no checkout
if opt.checkout == false then
table.insert(argv, "--no-checkout")
end
-- recursive?
if opt.recursive then
table.insert(argv, "--recursive")
end
-- clone for submodules
if opt.recurse_submodules then
table.insert(argv, "--recurse-submodules")
end
if opt.shallow_submodules and can_shallow_submodules() then
table.insert(argv, "--shallow-submodules")
end
-- use longpaths, we need it on windows
if opt.longpaths then
table.insert(argv, "-c")
table.insert(argv, "core.longpaths=true")
end
-- set fsmonitor
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
-- set core.autocrlf
if opt.autocrlf then
table.insert(argv, "-c")
table.insert(argv, "core.autocrlf=true")
elseif opt.autocrlf == false then
table.insert(argv, "-c")
table.insert(argv, "core.autocrlf=false")
end
-- set outputdir
if opt.outputdir then
table.insert(argv, path.translate(opt.outputdir))
end
-- use proxy?
local envs
local proxy_conf = proxy.config(url)
if proxy_conf then
envs = {ALL_PROXY = proxy_conf}
end
-- clone it
os.vrunv(git.program, argv, {envs = envs})
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/pull.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file pull.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
import("net.proxy")
-- pull remote commits
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.pull()
-- git.pull({remote = "origin", tags = true, branch = "master", repodir = "/tmp/xmake"})
--
-- @endcode
--
function main(opt)
-- init options
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
table.insert(argv, "pull")
-- set remote
table.insert(argv, opt.remote or "origin")
-- set branch
if opt.branch then
table.insert(argv, opt.branch)
end
-- set tags
if opt.tags then
table.insert(argv, "--tags")
end
if opt.force then
table.insert(argv, "-f")
end
-- use proxy?
local envs
local proxy_conf = proxy.config()
if proxy_conf then
-- get proxy configuration from the current remote url
local remoteinfo = try { function() return os.iorunv(git.program, {"remote", "-v"}, {curdir = opt.repodir}) end }
if remoteinfo then
for _, line in ipairs(remoteinfo:split('\n', {plain = true})) do
local splitinfo = line:split("%s+")
if #splitinfo > 1 and splitinfo[1] == (opt.remote or "origin") then
local url = splitinfo[2]
if url then
proxy_conf = proxy.config(url)
end
break
end
end
end
envs = {ALL_PROXY = proxy_conf}
end
-- pull it
os.vrunv(git.program, argv, {envs = envs, curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/checkout.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file checkout.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- checkout to given branch, tag or commit
--
-- @param commit the commit, tag or branch
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.checkout("master", {repodir = "/tmp/xmake"})
-- git.checkout("v1.0.1", {repodir = "/tmp/xmake"})
--
-- @endcode
--
function main(commit, opt)
opt = opt or {}
local git = assert(find_tool("git"), "git not found!")
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
table.insert(argv, "checkout")
table.insert(argv, commit)
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/asgiturl.lua | --!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-present, TBOOX Open Source Group.
--
-- @author OpportunityLiu
-- @file asgiturl.lua
--
-- imports
import("checkurl")
local custom_protocol =
{
["github:"] = "https://github.com"
, ["gitlab:"] = "https://gitlab.com"
, ["gitee:"] = "https://gitee.com"
, ["bitbucket:"] = "https://bitbucket.org"
}
-- try to parse given url as a git url
--
-- @param url url can be transformed to a git url
--
-- @return a git url or nil, if failed
--
function main(url)
-- check
url = url:trim()
assert(#url > 0)
-- safe because all custom_protocol supports https
local lower = url:lower()
local n_url = url
if lower:startswith("http://") then
n_url = "https" .. url:sub(#"http" + 1)
lower = n_url:lower()
end
for k, v in pairs(custom_protocol) do
if lower:startswith(k) then
local data = n_url:sub(#k + 1):split("/")
if #data ~= 2 then return nil end
return v .. "/" .. data[1] .. "/" .. data[2] .. ".git"
elseif lower:startswith(v) then
local data = n_url:sub(#v + 1):split("/")
if #data ~= 2 then return nil end
return v .. "/" .. data[1] .. "/" .. (data[2]:endswith(".git") and data[2] or (data[2] .. ".git"))
end
end
if checkurl(url) then
return url
end
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/branches.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file branches.lua
--
-- imports
import("core.base.option")
import("ls_remote")
-- get all branches from url
--
-- @param url the remote url, optional
--
-- @return the branches
--
-- @code
--
-- import("devel.git")
--
-- local branches = git.branches(url)
--
-- @endcode
--
function main(url)
return ls_remote("heads", url)
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/reset.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file reset.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- reset files
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.reset()
-- git.reset({repodir = "/tmp/xmake", force = true})
--
-- @endcode
--
function main(opt)
-- init options
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
table.insert(argv, "reset")
-- verbose?
if not option.get("verbose") then
table.insert(argv, "-q")
end
-- hard?
if opt.hard then
table.insert(argv, "--hard")
end
-- soft?
if opt.soft then
table.insert(argv, "--soft")
end
-- keep?
if opt.keep then
table.insert(argv, "--keep")
end
-- reset to the given commit
if opt.commit then
table.insert(argv, opt.commit)
end
-- reset it
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/refs.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file refs.lua
--
-- imports
import("core.base.option")
import("ls_remote")
-- get all refs from url, contains tags and branchs
--
-- @param url the remote url, optional
--
-- @return the tags, branches
--
-- @code
--
-- import("devel.git")
--
-- local tags, branches = git.refs(url)
--
-- @endcode
--
function main(url)
-- get refs
local refs = ls_remote("refs", url)
if not refs or #refs == 0 then
return {}, {}
end
-- get tags and branches
local tags = {}
local branches = {}
for _, ref in ipairs(refs) do
if ref:startswith("tags/") then
table.insert(tags, ref:sub(6))
elseif ref:startswith("heads/") then
table.insert(branches, ref:sub(7))
end
end
-- ok
return tags, branches
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/checkurl.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file checkurl.lua
--
-- check git url
--
-- @param url is git url?
--
-- @return true or false
--
function main(url)
return url:endswith(".git") or url:startswith("git://") or os.isdir(url .. ".git")
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/lastcommit.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file lastcommit.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
import("net.proxy")
-- get last commit in git repository
--
-- @param opt the options, e.g. {repodir = ..}
--
-- @return the last commit
--
-- @code
--
-- import("devel.git")
--
-- local lastcommit = git.lastcommit({repodir = ..})
--
-- @endcode
--
function main(opt)
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init arguments
local argv = {"rev-parse", "HEAD"}
-- trace
if option.get("verbose") then
print("%s %s", git.program, os.args(argv))
end
-- use proxy?
local envs
local proxy_conf = proxy.config(url)
if proxy_conf then
envs = {ALL_PROXY = proxy_conf}
end
-- get last commit
local lastcommit = os.iorunv(git.program, argv, {envs = envs, curdir = opt.repodir})
if lastcommit then
lastcommit = lastcommit:trim()
end
return lastcommit
end
|
0 | repos/xmake/xmake/modules/devel | repos/xmake/xmake/modules/devel/git/clean.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file clean.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- clean files
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.clean()
-- git.clean({repodir = "/tmp/xmake", force = true})
--
-- @endcode
--
function main(opt)
-- init options
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
table.insert(argv, "clean")
table.insert(argv, "-d")
-- verbose?
if not option.get("verbose") then
table.insert(argv, "-q")
end
-- force?
if opt.force then
table.insert(argv, "-f")
end
-- remove all files and does not use the standard ignore rules
if opt.all then
table.insert(argv, "-x")
end
-- clean it
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel/git | repos/xmake/xmake/modules/devel/git/submodule/reset.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file reset.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- reset files
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.reset()
-- git.reset({repodir = "/tmp/xmake", force = true})
--
-- @endcode
--
function main(opt)
opt = opt or {}
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
-- use longpaths, we need it on windows
if opt.longpaths then
table.insert(argv, "-c")
table.insert(argv, "core.longpaths=true")
end
table.join2(argv, "submodule", "foreach", "--recursive", "git", "reset")
-- verbose?
if not option.get("verbose") then
table.insert(argv, "-q")
end
-- hard?
if opt.hard then
table.insert(argv, "--hard")
end
-- soft?
if opt.soft then
table.insert(argv, "--soft")
end
-- keep?
if opt.keep then
table.insert(argv, "--keep")
end
-- reset to the given commit
if opt.commit then
table.insert(argv, opt.commit)
end
-- reset it
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel/git | repos/xmake/xmake/modules/devel/git/submodule/update.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file update.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- update submodule
--
-- @param opt the argument options, e.g. repodir, init, remote, force, checkout, merge, rebase, recursive, reference, paths
--
-- @code
--
-- import("devel.git.submodule")
--
-- submodule.update({repodir = "/tmp/xmake", init = true, remote = true})
-- submodule.update({repodir = "/tmp/xmake", recursive = true, longpaths = true, reference = "xxx", paths = "xxx"})
--
-- @endcode
--
function main(opt)
opt = opt or {}
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
-- use longpaths, we need it on windows
if opt.longpaths then
table.insert(argv, "-c")
table.insert(argv, "core.longpaths=true")
end
table.insert(argv, "submodule")
table.insert(argv, "update")
for _, name in ipairs({"init", "remote", "force", "checkout", "merge", "rebase", "recursive"}) do
if opt[name] then
table.insert(argv, "--" .. name)
end
end
if opt.reference then
table.insert(argv, "--reference")
table.insert(argv, opt.reference)
end
if opt.paths then
table.join2(argv, opt.paths)
end
-- update it
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/devel/git | repos/xmake/xmake/modules/devel/git/submodule/clean.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file clean.lua
--
-- imports
import("core.base.option")
import("lib.detect.find_tool")
-- clean files
--
-- @param opt the argument options
--
-- @code
--
-- import("devel.git")
--
-- git.clean()
-- git.clean({repodir = "/tmp/xmake", force = true})
--
-- @endcode
--
function main(opt)
-- init options
opt = opt or {}
-- find git
local git = assert(find_tool("git"), "git not found!")
-- init argv
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=true")
else
table.insert(argv, "-c")
table.insert(argv, "core.fsmonitor=false")
end
table.join2(argv, "submodule", "foreach", "--recursive", "git", "clean", "-d")
-- verbose?
if not option.get("verbose") then
table.insert(argv, "-q")
end
-- force?
if opt.force then
table.insert(argv, "-f")
end
-- remove all files and does not use the standard ignore rules
if opt.all then
table.insert(argv, "-x")
end
-- clean it
os.vrunv(git.program, argv, {curdir = opt.repodir})
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/project/depend.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file depend.lua
--
-- imports
import("core.base.option")
import("core.project.project")
import("private.tools.cl.parse_deps", {alias = "parse_deps_cl"})
import("private.tools.cl.parse_deps_json", {alias = "parse_deps_cl_json"})
import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"})
import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"})
import("private.tools.armcc.parse_deps", {alias = "parse_deps_armcc"})
-- load depfiles
function _load_depfiles(parser, dependinfo, depfiles, opt)
depfiles = parser(depfiles, opt)
if depfiles then
if dependinfo.files then
table.join2(dependinfo.files, depfiles)
else
dependinfo.files = depfiles
end
end
end
-- load dependent info from the given file (.d)
function load(dependfile, opt)
if os.isfile(dependfile) then
-- may be the depend file has been incomplete when if the compilation process is abnormally interrupted
local dependinfo = try { function() return io.load(dependfile) end }
if dependinfo then
-- attempt to load depfiles from the compilers
if dependinfo.depfiles_gcc then
_load_depfiles(parse_deps_gcc, dependinfo, dependinfo.depfiles_gcc, opt)
dependinfo.depfiles_gcc = nil
elseif dependinfo.depfiles_cl_json then
_load_depfiles(parse_deps_cl_json, dependinfo, dependinfo.depfiles_cl_json, opt)
dependinfo.depfiles_cl_json = nil
elseif dependinfo.depfiles_cl then
_load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl, opt)
dependinfo.depfiles_cl = nil
elseif dependinfo.depfiles_rc then
_load_depfiles(parse_deps_rc, dependinfo, dependinfo.depfiles_rc, opt)
dependinfo.depfiles_rc = nil
elseif dependinfo.depfiles_armcc then
_load_depfiles(parse_deps_armcc, dependinfo, dependinfo.depfiles_armcc, opt)
dependinfo.depfiles_armcc = nil
end
return dependinfo
end
end
end
-- show diagnosis info?
function _is_show_diagnosis_info()
local show = _g.is_show_diagnosis_info
if show == nil then
if project.policy("diagnosis.check_build_deps") then
show = true
else
show = false
end
_g.is_show_diagnosis_info = show
end
return show
end
-- save dependent info to file
function save(dependinfo, dependfile)
io.save(dependfile, dependinfo)
end
-- Is the dependent info changed?
--
-- if not depend.is_changed(dependinfo, {filemtime = os.mtime(objectfile), values = {...}}) then
-- return
-- end
--
function is_changed(dependinfo, opt)
-- empty depend info? always be changed
local files = table.wrap(dependinfo.files)
local values = table.wrap(dependinfo.values)
if #files == 0 and #values == 0 then
return true
end
-- check whether the dependent files are changed
local lastmtime = opt.lastmtime or 0
_g.files_mtime = _g.files_mtime or {}
local files_mtime = _g.files_mtime
for _, file in ipairs(files) do
-- get and cache the file mtime
local mtime = files_mtime[file] or os.mtime(file)
files_mtime[file] = mtime
-- source and header files have been changed or not exists?
if mtime == 0 or mtime > lastmtime then
if _is_show_diagnosis_info() then
cprint("${color.warning}[check_build_deps]: file %s is changed, mtime: %s, lastmtime: %s", file, mtime, lastmtime)
end
return true
end
end
-- check whether the dependent values are changed
local depvalues = values
local optvalues = table.wrap(opt.values)
if #depvalues ~= #optvalues then
return true
end
for idx, depvalue in ipairs(depvalues) do
local optvalue = optvalues[idx]
local deptype = type(depvalue)
local opttype = type(optvalue)
if deptype ~= opttype then
return true
elseif deptype == "string" and depvalue ~= optvalue then
if _is_show_diagnosis_info() then
cprint("${color.warning}[check_build_deps]: value %s != %s", depvalue, optvalue)
end
return true
elseif deptype == "table" then
for subidx, subvalue in ipairs(depvalue) do
if subvalue ~= optvalue[subidx] then
if _is_show_diagnosis_info() then
cprint("${color.warning}[check_build_deps]: value %s != %s at index %d", subvalue, optvalue[subidx], subidx)
end
return true
end
end
end
end
-- check whether the dependent files list are changed
if opt.files then
local optfiles = table.wrap(opt.files)
if #files ~= #optfiles then
return true
end
for idx, file in ipairs(files) do
if file ~= optfiles[idx] then
if _is_show_diagnosis_info() then
cprint("${color.warning}[check_build_deps]: file %s != %s at index %d", file, optfiles[idx], idx)
end
return true
end
end
end
end
-- on changed for the dependent files and values
--
-- e.g.
--
-- depend.on_changed(function ()
-- -- do some thing
-- -- ..
--
-- -- maybe need update dependent files
-- dependinfo.files = {""}
--
-- -- return new dependinfo (optional)
-- return {files = {}, ..}
--
-- end, {dependfile = "/xx/xx",
-- values = {compinst:program(), compflags},
-- files = {sourcefile, ...}})
--
function on_changed(callback, opt)
-- init option
opt = opt or {}
-- dry run? we only do callback directly and do not change any status
if opt.dryrun then
return callback()
end
-- get files
assert(opt.files, "depend.on_changed(): please set files list!")
-- get dependfile
local dependfile = opt.dependfile
if not dependfile then
dependfile = project.tmpfile(table.concat(table.wrap(opt.files), ""))
end
-- load dependent info
local dependinfo = opt.changed and {} or (load(dependfile) or {})
-- @note we use mtime(dependfile) instead of mtime(objectfile) to ensure the object file is is fully compiled.
-- @see https://github.com/xmake-io/xmake/issues/748
if not is_changed(dependinfo, {lastmtime = opt.lastmtime or os.mtime(dependfile), values = opt.values, files = opt.files}) then
return
end
-- do callback if changed and maybe files and values will be updated
dependinfo = callback() or {}
-- update files and values to the dependent file
dependinfo.files = dependinfo.files or {}
table.join2(dependinfo.files, opt.files)
if opt.values then
dependinfo.values = dependinfo.values or {}
table.join2(dependinfo.values, opt.values)
end
save(dependinfo, dependfile)
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/base/license.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file license.lua
--
-- imports
import("core.base.object")
import("core.base.hashset")
-- get licenses
function _licenses()
local licenses = _g.licenses
if not licenses then
licenses = hashset.from({"Apache-1.1", "Apache-2.0",
"MIT",
"Zlib",
"Public Domain",
"CC0",
"LLVM",
"AFL-3.0",
"AGPL-3.0",
"LGPL-2.0", "LGPL-2.1", "LGPL-3.0",
"GPL-2.0", "GPL-3.0",
"BSD-2-Clause", "BSD-3-Clause",
"BSL-1.0",
"MPL-2.0",
"libpng-2.0",
"Python-2.0"})
_g.licenses = licenses
end
return licenses
end
-- get all licenses list
function list()
return _licenses():to_array()
end
-- normalize license
function normalize(license)
-- TODO parse and convert license strings in other formats
return license
end
-- check if the license is compatible
-- @see https://github.com/xmake-io/xmake/issues/1016
--
function compatible(target_license, library_license, opt)
opt = opt or {}
library_license = normalize(library_license)
if library_license then
target_license = normalize(target_license)
if library_license:startswith("GPL-") then
return target_license and target_license:startswith("GPL-")
elseif library_license:startswith("LGPL-") then
if target_license and target_license:startswith("LGPL-") then
return true
elseif opt.library_kind and opt.library_kind == "shared" then
-- we can only use shared library with LGPL-x
return true
else
return false, string.format("we can use shared libraries with %s or use set_license()/set_policy() to modify/disable license", library_license)
end
else
-- TODO maybe we need handle more licenses
end
end
return true
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/llvm_rc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file llvm_rc.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.project.project")
-- init it
function init(self)
end
-- make the define flag
function nf_define(self, macro)
return {"/D", macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return {"/U", macro}
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"/I", dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "/FO", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- compiling errors
os.raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/emxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file em++.lua
--
-- inherit emcc
inherit("emcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/nim.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file nim.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- init it
--
-- @see https://nim-lang.org/docs/nimc.html
function init(self)
-- init arflags
self:set("ncarflags", "--app:staticlib", "--noMain")
-- init shflags
self:set("ncshflags", "--app:lib", "--noMain")
end
-- make the warning flag
function nf_warning(self, level)
local maps =
{
none = "--warning:X:off"
, less = "--warning:X:on"
, more = "--warning:X:on"
, all = "--warning:X:on"
, allextra = "--warning:X:on"
, everything = "--warning:X:on"
, error = "--warningAsError:X:on"
}
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return {"--define:" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "--undef:" .. macro
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "--opt:none"
, fast = "-d:release"
, faster = "-d:release"
, fastest = "-d:release"
, smallest = {"-d:release", "--opt:size"}
, aggressive = "-d:danger"
}
return maps[level]
end
end
-- make the symbol flag
function nf_symbol(self, level)
local maps =
{
debug = "--debugger:native"
}
return maps[level]
end
-- make the strip flag
function nf_strip(self, level)
if self:is_plat("linux", "macosx", "bsd") then
if level == "debug" or level == "all" then
return "--passL:-s"
end
end
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"--passC:-I" .. path.translate(dir)}
end
-- make the link flag
function nf_link(self, lib)
if self:is_plat("windows") then
return "--passL:" .. lib .. ".lib"
else
return "--passL:-l" .. lib
end
end
-- make the linkdir flag
function nf_linkdir(self, dir)
if self:is_plat("windows") then
return {"--passL:-libpath:" .. path.translate(dir)}
else
return {"--passL:-L" .. path.translate(dir)}
end
end
-- make the build arguments list
function buildargv(self, sourcefiles, targetkind, targetfile, flags)
local flags_extra = {}
if targetkind ~= "static" and self:is_plat("windows") then
-- fix link flags for windows
-- @see https://github.com/nim-lang/Nim/issues/19033
local flags_new = {}
local flags_link = {}
for _, flag in ipairs(flags) do
if flag:find("passL:", 1, true) then
table.insert(flags_link, flag)
else
table.insert(flags_new, flag)
end
end
if #flags_link > 0 then
table.insert(flags_new, "--passL:-link")
table.join2(flags_new, flags_link)
end
flags = flags_new
end
return self:program(), table.join("c", flags, flags_extra, "-o:" .. targetfile, sourcefiles)
end
-- build the target file
function build(self, sourcefiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
local program, argv = buildargv(self, sourcefiles, targetkind, targetfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/dpcpp.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file icpc.lua
--
-- inherit icc
inherit("icx")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/go.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file go.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- init it
function init(self)
self:set("gcarflags", "grc")
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = {
none = "-N"
}
return maps[level]
end
end
-- make the symbol flag
function nf_symbol(self, level, opt)
local targetkind = opt.targetkind
if targetkind ~= "object" then
return
end
local maps = {
debug = "-E"
}
return maps[level]
end
-- make the strip flag
function nf_strip(self, level)
local maps = {
debug = "-s"
, all = "-s"
}
return maps[level]
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I", dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L", dir}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
if targetkind == "static" then
return self:program(), table.join("tool", "pack", flags, targetfile, objectfiles)
else
return self:program(), table.join("tool", "link", flags, "-o", targetfile, objectfiles)
end
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
-- make the compile arguments list
function compargv(self, sourcefiles, objectfile, flags)
return self:program(), table.join("tool", "compile", flags, "-o", objectfile, sourcefiles)
end
-- compile the source file
function compile(self, sourcefiles, objectfile, dependinfo, flags)
os.mkdir(path.directory(objectfile))
local program, argv = compargv(self, sourcefiles, objectfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/fasm.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file fasm.lua
--
-- init it
function init(self)
-- init flags map
self:set("mapflags",
{
-- symbols
["-g"] = ""
, ["-fvisibility=.*"] = ""
-- warnings
, ["-Wall"] = "" -- = "-Wall" will enable too more warnings
, ["-W1"] = ""
, ["-W2"] = ""
, ["-W3"] = ""
, ["-Werror"] = ""
, ["%-Wno%-error=.*"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the define flag
function nf_define(self, macro)
return {"-d" .. macro}
end
-- make the compile arguments list
function _compargv1(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, sourcefile, objectfile)
end
-- compile the source file
function _compile1(self, sourcefile, objectfile, dependinfo, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
os.runv(_compargv1(self, sourcefile, objectfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefiles, objectfile, flags)
-- only support single source file now
assert(type(sourcefiles) ~= "table", "'object:sources' not support!")
-- for only single source file
return _compargv1(self, sourcefiles, objectfile, flags)
end
-- compile the source file
function compile(self, sourcefiles, objectfile, dependinfo, flags)
-- only support single source file now
assert(type(sourcefiles) ~= "table", "'object:sources' not support!")
-- for only single source file
_compile1(self, sourcefiles, objectfile, dependinfo, flags)
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/gxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file gxx.lua
--
-- inherit gcc
inherit("gcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armasm.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armasm.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.language.language")
import("utils.progress")
-- init it
function init(self)
end
-- make the symbol flag
function nf_symbol(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps =
{
debug = "-g"
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
end
end
-- make runtime flag
function nf_runtime(self, runtime)
if runtime == "microlib" then
return {"--pd", "__MICROLIB SETA 1"}
end
end
-- make the define flag
-- eg.
-- add_defines("MACRO") -> --pd "MACRO SETA 1
-- add_defines("MACRO=3") -> --pd "MACRO SETA 3"
function nf_define(self, macro)
local def = macro:split("=")
local key = def[1]:trim()
local value = "1"
if #def == 2 then
value = def[2]:trim()
end
return {"--pd", key .. " SETA " .. value}
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cparser.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cparser.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.project.policy")
import("core.language.language")
-- init it
function init(self)
-- init mxflags
self:set("mxflags", "-fmessage-length=0"
, "-pipe"
, "-DIBOutlet=__attribute__((iboutlet))"
, "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))"
, "-DIBAction=void)__attribute__((ibaction)")
-- init shflags
self:set("shflags", "-shared", "-fPIC")
-- init cxflags for the kind: shared
self:set("shared.cxflags", "-fPIC")
-- init flags map
self:set("mapflags",
{
-- warnings
["-W1"] = "-Wall"
, ["-W2"] = "-Wall"
, ["-W3"] = "-Wall"
, ["-W4"] = "-Wall -Wextra"
, ["-Weverything"] = "-Wall -Wextra"
-- strip
, ["-s"] = "-s"
, ["-S"] = "-S"
})
end
-- make the strip flag
function nf_strip(self, level)
-- the maps
local maps =
{
debug = "-S"
, all = "-s"
}
-- make it
return maps[level]
end
-- make the symbol flag
function nf_symbol(self, level)
-- the maps
local maps =
{
debug = "-g"
, hidden = "-fvisibility=hidden"
}
-- make it
return maps[level]
end
-- make the warning flag
function nf_warning(self, level)
-- the maps
local maps =
{
none = "-w"
, less = "-Wall"
, more = "-Wall"
, all = "-Wall"
, everything = "-Wextra -Wall"
, error = "-Werror"
}
-- make it
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return "-D" .. macro
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. dir}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
return self:program(), table.join("-o", targetfile, objectfiles, flags)
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/nvcc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file nvcc.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("core.language.language")
import("core.project.policy")
import("utils.progress")
-- init it
function init(self)
-- init cuflags
if not self:is_plat("windows", "mingw") then
self:set("shared.cuflags", "-Xcompiler -fPIC")
self:set("binary.cuflags", "-Xcompiler -fPIE")
end
-- init flags map
self:set("mapflags", {
-- warnings
["-W4"] = "-Wreorder --Wno-deprecated-gpu-targets --Wno-deprecated-declarations"
, ["-Wextra"] = "-Wreorder --Wno-deprecated-gpu-targets --Wno-deprecated-declarations"
, ["-Weverything"] = "-Wreorder --Wno-deprecated-gpu-targets --Wno-deprecated-declarations"
})
end
-- make the symbol flag
function nf_symbol(self, level, opt)
-- debug? generate *.pdb file
local flags = nil
if level == "debug" then
flags = {"-G", "-g", "-lineinfo"}
if self:is_plat("windows") then
local host_flags = nil
local symbolfile = nil
local target = opt.target
if target and target.symbolfile then
symbolfile = target:symbolfile()
end
if symbolfile then
-- ensure the object directory
local symboldir = path.directory(symbolfile)
if not os.isdir(symboldir) then
os.mkdir(symboldir)
end
-- check and add symbol output file
host_flags = "-Zi -Fd" .. path.join(symboldir, "compile." .. path.filename(symbolfile))
if self:has_flags({'-Xcompiler "-Zi -FS -Fd' .. os.nuldev() .. '.pdb"'}, "cuflags", { flagskey = '-Xcompiler "-Zi -FS -Fd"' }) then
host_flags = "-FS " .. host_flags
end
else
host_flags = "-Zi"
end
table.insert(flags, "-Xcompiler")
table.insert(flags, host_flags)
end
end
return flags
end
-- make the warning flag
function nf_warning(self, level)
-- the maps
local maps =
{
none = "-w"
, everything = { "-Wreorder", "--Wno-deprecated-gpu-targets", "--Wno-deprecated-declarations" }
, error = { "-Werror", "cross-execution-space-call,reorder,deprecated-declarations" }
}
-- for cl.exe on windows
local cl_maps =
{
none = "-W0"
, less = "-W1"
, more = "-W3"
, all = "-W3" -- = "-Wall" will enable too more warnings
, allextra = "-W4"
, everything = "-Wall"
, error = "-WX"
}
-- for gcc & clang on linux, may be work for other gnu compatible compilers such as icc
--
-- gcc dosen't support `-Weverything`, use `-Wall -Wextra -Weffc++` for it
-- no warning will emit for unsupoorted `-W` flags by clang/gcc
--
local gcc_clang_maps =
{
none = "-w"
, less = "-Wall"
, more = "-Wall"
, all = "-Wall"
, allextra = "-Wall -Wextra"
, everything = "-Weverything -Wall -Wextra -Weffc++"
, error = "-Werror"
}
-- get warning for nvcc
local warning = maps[level]
-- add host warning
--
-- for cl.exe on windows, it is the only supported host compiler on the platform
-- for gcc/clang, or any gnu compatible compiler on *nix
--
local host_warning = nil
if self:is_plat("windows") then
host_warning = cl_maps[level]
else
host_warning = gcc_clang_maps[level]
end
if host_warning then
warning = table.wrap(warning)
table.insert(warning, '-Xcompiler')
table.insert(warning, host_warning)
end
return warning
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "-O0"
, fast = "-O1"
, faster = "-O2"
, fastest = "-O3"
, smallest = "-Os"
, aggressive = "-Ofast"
}
return maps[level]
end
end
-- make vs runtime flag
function nf_runtime(self, runtime)
if self:is_plat("windows") and runtime then
local maps = {
MT = '-Xcompiler "-MT"',
MD = '-Xcompiler "-MD"',
MTd = '-Xcompiler "-MTd"',
MDd = '-Xcompiler "-MDd"'
}
return maps[runtime]
end
end
-- make the language flag
function nf_language(self, stdname)
-- the stdc++ maps
if _g.cxxmaps == nil then
_g.cxxmaps =
{
cxx03 = "--std c++03"
, cxx11 = "--std c++11"
, cxx14 = "--std c++14"
, cxx17 = "--std c++17"
, cxx20 = "--std c++20"
, cxxlatest = {"--std c++20", "--std c++17", "--std c++14", "--std c++11", "--std c++03"}
}
local cxxmaps2 = {}
for k, v in pairs(_g.cxxmaps) do
cxxmaps2[k:gsub("xx", "++")] = v
end
table.join2(_g.cxxmaps, cxxmaps2)
end
local maps = _g.cxxmaps
local result = maps[stdname]
if type(result) == "table" then
for _, v in ipairs(result) do
if self:has_flags(v, "cxflags") then
result = v
maps[stdname] = result
break
end
end
end
return result
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. path.translate(dir)}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the link flag
function nf_link(self, lib)
if lib:endswith(".a") or lib:endswith(".so") or lib:endswith(".dylib") or lib:endswith(".lib") then
return lib
else
return "-l" .. lib
end
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. path.translate(dir)}
end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
if self:has_flags("-Wl,-rpath=" .. dir, "ldflags") then
return {"-Wl,-rpath=" .. (dir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir, "ldflags") then
return {"-Xlinker", "-rpath", "-Xlinker", (dir:gsub("%$ORIGIN", "@loader_path"))}
end
end
-- make the c precompiled header flag
function nf_pcheader(self, pcheaderfile)
return {"-include", pcheaderfile}
end
-- make the c++ precompiled header flag
function nf_pcxxheader(self, pcheaderfile)
return {"-include", pcheaderfile}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
-- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
local flags_extra = {}
if targetkind == "shared" and targetfile:endswith(".dylib") then
table.insert(flags_extra, "-Xlinker")
table.insert(flags_extra, "-install_name")
table.insert(flags_extra, "-Xlinker")
table.insert(flags_extra, "@rpath/" .. path.filename(targetfile))
end
-- add `-Wl,--out-implib,outputdir/libxxx.a` for xxx.dll on mingw/gcc
if targetkind == "shared" and self:is_plat("mingw") then
table.insert(flags_extra, "-Xlinker")
table.insert(flags_extra, "-Wl,--out-implib," .. path.join(path.directory(targetfile), path.basename(targetfile) .. ".dll.a"))
end
-- make link args
return self:program(), table.join("-o", targetfile, objectfiles, flags, flags_extra)
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
-- support `-MD -MF depfile.d`?
function _has_flags_md_mf(self)
local has_md_mf = _g._HAS_MD_MF
if has_md_mf == nil then
has_md_mf = self:has_flags({"-MD", "-MF", os.nuldev()}, "cuflags", { flagskey = "-MD -MF" }) or false
_g._HAS_MD_MF = has_md_mf
end
return has_md_mf
end
-- support `-MMD -MF depfile.d`? some old gcc does not support it at same time
function _has_flags_mmd_mf(self)
local has_mmd_mf = _g._HAS_MMD_MF
if has_mmd_mf == nil and not is_host("windows") then
has_mmd_mf = self:has_flags({"-MMD", "-MF", os.nuldev()}, "cuflags", { flagskey = "-MMD -MF" }) or false
_g._HAS_MMD_MF = has_mmd_mf
end
return has_mmd_mf
end
-- support `-M -o depfile.d`?
function _has_flags_m(self)
local has_m = _g._HAS_M
if not has_md_mf and has_m == nil then
has_m = self:has_flags("-M", "cuflags", { flagskey = "-M" }) or false
_g._HAS_M = has_m
end
return has_m
end
-- support `-MM -o depfile.d`?
function _has_flags_mm(self)
local has_mm = _g._HAS_MM
if not has_mmd_mf and has_mm == nil and not is_host("windows") then
has_mm = self:has_flags("-MM", "cuflags", { flagskey = "-MM" }) or false
_g._HAS_MM = has_mm
end
return has_mm
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
local depfile = dependinfo and os.tmpfile() or nil
try
{
function ()
-- generate includes file
local compflags = flags
if depfile then
if _has_flags_mmd_mf(self) then
compflags = table.join(compflags, "-MMD", "-MF", depfile)
elseif _has_flags_mm(self) then
-- since -MMD is not supported, run nvcc twice
local program, argv = compargv(self, sourcefile, depfile, table.join(flags, "-MM"))
os.runv(program, argv, {envs = self:runenvs()})
elseif _has_flags_md_mf(self) then
-- on windows only -MD and -M are supported
compflags = table.join(compflags, "-MD", "-MF", depfile)
elseif _has_flags_m(self) then
-- since -MD is not supported, run nvcc twice
local program, argv = compargv(self, sourcefile, depfile, table.join(flags, "-M"))
os.runv(program, argv, {envs = self:runenvs()})
end
end
-- do compile
local program, argv = compargv(self, sourcefile, objectfile, compflags)
local outdata, errdata = os.iorunv(program, argv, {envs = self:runenvs()})
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- use nvcc/stdout as errors first from os.iorunv()
if type(errors) == "table" then
errors = (errors.stdout or "") .. (errors.stderr or "")
else
errors = tostring(errors)
end
-- find the start line of error
local lines = errors:split("\n", {plain = true})
local start = 0
for index, line in ipairs(lines) do
if line:match("[eE]rror:", 1, true) or line:find("错误:", 1, true) or line:match("ptxas fatal%s*:") or line:match("error %a+[0-9]+%s*:") then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
if not option.get("verbose") then
errors = errors .. "\n ${yellow}> in ${bright}" .. sourcefile
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n', {plain = true}), 1, 8), '\n'))
end
-- generate the dependent includes
if depfile and os.isfile(depfile) then
if dependinfo then
-- nvcc uses gcc-style depfiles
dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"})
end
-- remove the temporary dependent file
os.tryrm(depfile)
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/lld_link.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file lld_link.lua
--
-- imports
inherit("link")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/clang_cl.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file clang_cl.lua
--
-- inherit cl
inherit("cl")
import("core.base.option")
import("core.base.tty")
import("core.base.colors")
import("core.project.policy")
-- init it
function init(self)
-- init flags map
self:set("mapflags",
{
-- warnings
["-W1"] = "-Wall"
, ["-W2"] = "-Wall"
, ["-W3"] = "-Wall"
, ["-W4"] = "-Wall -Wextra"
, ["-Weverything"] = "-Wall -Wextra -Weffc++"
-- language
, ["-ansi"] = "-Xclang -ansi"
, ["-std=c89"] = "-Xclang -std=c89"
, ["-std=c99"] = "-Xclang -std=c99"
, ["-std=c11"] = "-Xclang -std=c11"
, ["-std=gnu89"] = "-Xclang -std=gnu89"
, ["-std=gnu99"] = "-Xclang -std=gnu99"
, ["-std=gnu11"] = "-Xclang -std=gnu11"
, ["-std=c++98"] = "-Xclang -std=c++98"
, ["-std=c++11"] = "-Xclang -std=c++11"
, ["-std=c++14"] = "-Xclang -std=c++14"
, ["-std=c++17"] = "-Xclang -std=c++17"
, ["-std=c++1z"] = "-Xclang -std=c++1z"
, ["-std=c++1a"] = "-Xclang -std=c++1a"
, ["-std=c++20"] = "-Xclang -std=c++20"
, ["-std=c++2a"] = "-Xclang -std=c++2a"
, ["-std=c++23"] = "-Xclang -std=c++23"
, ["-std=c++2b"] = "-Xclang -std=c++2b"
, ["-std=gnu++98"] = "-Xclang -std=gnu++98"
, ["-std=gnu++11"] = "-Xclang -std=gnu++11"
, ["-std=gnu++14"] = "-Xclang -std=gnu++14"
, ["-std=gnu++17"] = "-Xclang -std=gnu++17"
, ["-std=gnu++1z"] = "-Xclang -std=gnu++1z"
, ["-std=gnu++1a"] = "-Xclang -std=gnu++1a"
, ["-std=gnu++20"] = "-Xclang -std=gnu++20"
, ["-std=gnu++2a"] = "-Xclang -std=gnu++2a"
, ["-std=gnu++23"] = "-Xclang -std=gnu++23"
, ["-std=gnu++2b"] = "-Xclang -std=gnu++2b"
})
end
-- has color diagnostics?
function _has_color_diagnostics(self)
local colors_diagnostics = _g._HAS_COLOR_DIAGNOSTICS
if colors_diagnostics == nil then
if io.isatty() and (tty.has_color8() or tty.has_color256()) then
local theme = colors.theme()
if theme and theme:name() ~= "plain" then
-- for clang
if self:has_flags("-fcolor-diagnostics", "cxflags") then
colors_diagnostics = "-fcolor-diagnostics"
-- for gcc
elseif self:has_flags("-fdiagnostics-color=always", "cxflags") then
colors_diagnostics = "-fdiagnostics-color=always"
end
-- enable color output for windows, @see https://github.com/xmake-io/xmake-vscode/discussions/260
if colors_diagnostics and
self:has_flags("-fansi-escape-codes", "cxflags") then
colors_diagnostics = table.join(colors_diagnostics, "-fansi-escape-codes")
end
end
end
colors_diagnostics = colors_diagnostics or false
_g._HAS_COLOR_DIAGNOSTICS = colors_diagnostics
end
return colors_diagnostics
end
-- make the optimize flag
function nf_optimize(self, level)
local maps =
{
none = "-Od"
, faster = "-Ox"
, fastest = "-O2"
, smallest = "-O1"
, aggressive = "-O2"
}
return maps[level]
end
-- make the c precompiled header flag
function nf_pcheader(self, pcheaderfile, opt)
local target = opt.target
if self:kind() == "cc" then
local objectfiles = target:objectfiles()
if objectfiles then
table.insert(objectfiles, target:pcoutputfile("c") .. ".obj")
end
return {"-Yu" .. path.filename(pcheaderfile),
"-FI" .. path.filename(pcheaderfile),
"-I" .. path.directory(pcheaderfile),
"-Fp" .. target:pcoutputfile("c")}
end
end
-- make the c++ precompiled header flag
function nf_pcxxheader(self, pcheaderfile, opt)
local target = opt.target
if self:kind() == "cxx" then
local objectfiles = target:objectfiles()
if objectfiles then
table.insert(objectfiles, target:pcoutputfile("cxx") .. ".obj")
end
-- https://github.com/xmake-io/xmake/issues/3905
-- clang-cl need extra include search path
return {"-Yu" .. path.filename(pcheaderfile),
"-FI" .. path.filename(pcheaderfile),
"-I" .. path.directory(pcheaderfile),
"-Fp" .. target:pcoutputfile("cxx")}
end
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
local outdata = try
{
function ()
-- generate includes file
local compflags = flags
if dependinfo then
compflags = table.join(flags, "-showIncludes")
end
-- has color diagnostics? enable it
local colors_diagnostics = _has_color_diagnostics(self)
if colors_diagnostics then
compflags = table.join(compflags, colors_diagnostics)
end
-- do compile
local program, argv = compargv(self, sourcefile, objectfile, compflags)
return os.iorunv(program, argv, {envs = self:runenvs()})
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- parse and strip errors
local lines = errors and tostring(errors):split('\n', {plain = true}) or {}
if not option.get("verbose") then
-- find the start line of error
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 then
lines = table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start)))
end
end
-- raise compiling errors
raise(#lines > 0 and table.concat(lines, "\n") or "")
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and errdata and #errdata > 0 and policy.build_warnings(opt) then
local lines = errdata:split('\n', {plain = true})
if #lines > 0 then
local warnings = table.concat(table.slice(lines, 1, (#lines > 8 and 8 or #lines)), "\n")
cprint("${color.warning}%s", warnings)
end
end
end
}
}
-- generate the dependent includes
if dependinfo and outdata then
dependinfo.depfiles_cl = outdata
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/nvc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file nvc.lua
--
-- inherit gcc
inherit("gcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/swiftc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file swiftc.lua
--
-- imports
import("core.project.config")
import("core.language.language")
-- init it
function init(self)
-- init flags map
self:set("mapflags", {
-- symbols
["-fvisibility=hidden"] = ""
-- warnings
, ["-w"] = "-suppress-warnings"
, ["-W%d*"] = "-warn-swift3-objc-inference-minimal"
, ["-Wall"] = "-warn-swift3-objc-inference-complete"
, ["-Wextra"] = "-warn-swift3-objc-inference-complete"
, ["-Weverything"] = "-warn-swift3-objc-inference-complete"
, ["-Werror"] = "-warnings-as-errors"
-- optimize
, ["-O0"] = "-Onone"
, ["-Ofast"] = "-Ounchecked"
, ["-O.*"] = "-O"
-- vectorexts
, ["-m.*"] = ""
-- strip
, ["-s"] = ""
, ["-S"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the strip flag
function nf_strip(self, level)
local maps = {
debug = "-Xlinker -S"
, all = "-Xlinker -s"
}
return maps[level]
end
-- make the symbol flag
function nf_symbol(self, level)
local maps = {
debug = "-g"
}
return maps[level]
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-suppress-warnings"
, less = "-warn-swift3-objc-inference-minimal"
, more = "-warn-swift3-objc-inference-minimal"
, all = "-warn-swift3-objc-inference-complete"
, everything = "-warn-swift3-objc-inference-complete"
, error = "-warnings-as-errors"
}
return maps[level]
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "-Onone"
, fast = "-O"
, faster = "-O"
, fastest = "-O"
, smallest = "-O"
, aggressive = "-Ounchecked"
}
return maps[level]
end
end
-- make the vector extension flag
function nf_vectorext(self, extension)
local maps = {
mmx = "-mmmx"
, sse = "-msse"
, sse2 = "-msse2"
, sse3 = "-msse3"
, ssse3 = "-mssse3"
, avx = "-mavx"
, avx2 = "-mavx2"
, neon = "-mfpu=neon"
}
return maps[extension]
end
-- make the define flag
function nf_define(self, macro)
return {"-Xcc", "-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return {"-Xcc", "-U" .. macro}
end
-- make the framework flag
function nf_framework(self, framework)
return {"-framework", framework}
end
-- make the frameworkdir flag
function nf_frameworkdir(self, frameworkdir)
return {"-F", frameworkdir}
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L", dir}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
return self:program(), table.join("-o", targetfile, objectfiles, flags)
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags)
os.mkdir(path.directory(objectfile))
os.runv(compargv(self, sourcefile, objectfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/gcc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file gcc.lua
--
-- imports
import("core.base.option")
import("core.base.tty")
import("core.base.colors")
import("core.base.global")
import("core.cache.memcache")
import("core.project.config")
import("core.project.policy")
import("core.project.project")
import("core.language.language")
import("utils.progress")
import("private.cache.build_cache")
import("private.service.distcc_build.client", {alias = "distcc_build_client"})
function init(self)
-- init mxflags
self:set("mxflags", "-pipe"
, "-DIBOutlet=__attribute__((iboutlet))"
, "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))"
, "-DIBAction=void)__attribute__((ibaction)")
-- init shflags
self:set("shflags", "-shared")
-- init flags map
self:set("mapflags", {
-- warnings
["-W1"] = "-Wall"
, ["-W2"] = "-Wall"
, ["-W3"] = "-Wall"
, ["-W4"] = "-Wall -Wextra"
, ["-Weverything"] = "-Wall -Wextra -Weffc++"
-- strip
, ["-s"] = "-s"
, ["-S"] = "-Wl,-S"
})
-- for macho target
if self:is_plat("macosx", "iphoneos") then
self:add("mapflags", {
["-s"] = "-Wl,-x"
})
end
end
-- we can only call has_flags in load(),
-- as it requires the full platform toolchain flags.
--
function load(self)
-- add -fPIC for shared
--
-- we need check it for clang/gcc with window target
-- @see https://github.com/xmake-io/xmake/issues/1392
--
if not self:is_plat("windows", "mingw") and self:has_flags("-fPIC") then
self:add("shflags", "-fPIC")
self:add("shared.cxflags", "-fPIC")
end
end
-- make the strip flag
function nf_strip(self, level)
local maps = {
debug = "-Wl,-S"
, all = "-s"
}
if self:is_plat("macosx", "iphoneos", "watchos", "appletvos", "applexros") then
maps.all = {"-Wl,-x", "-Wl,-dead_strip"}
elseif self:is_plat("windows") then
-- clang does not it on windows, TODO maybe we need test it for gcc
maps = {}
end
return maps[level]
end
-- make the symbol flag
function nf_symbol(self, level)
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps = {
debug = "-g"
, hidden = "-fvisibility=hidden"
}
if kind == "cxx" and self:has_flags("-fvisibility-inlines-hidden", "cxflags") then
maps.hidden_cxx = {"-fvisibility=hidden", "-fvisibility-inlines-hidden"}
end
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
elseif kind == "ld" or kind == "sh" then
-- we need to add `-g` to linker to generate pdb symbol file for mingw-gcc, llvm-clang on windows
local plat = self:plat()
if level == "debug" and (plat == "windows" or (plat == "mingw" and is_host("windows"))) then
return "-g"
end
end
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-w"
, less = "-Wall"
, more = "-Wall"
, all = "-Wall"
, allextra = {"-Wall", "-Wextra"}
, extra = "-Wextra"
, pedantic = "-Wpedantic"
, everything = self:kind() == "cxx" and {"-Wall", "-Wextra", "-Weffc++"} or {"-Wall", "-Wextra"}
, error = "-Werror"
}
return maps[level]
end
-- make the fp-model flag
function nf_fpmodel(self, level)
local maps = {
precise = "" --default
, fast = "-ffast-math"
, strict = {"-frounding-math", "-ftrapping-math"}
, except = "-ftrapping-math"
, noexcept = "-fno-trapping-math"
}
return maps[level]
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = {
none = "-O0"
, fast = "-O1"
, faster = "-O2"
, fastest = "-O3"
, smallest = "-Os"
, aggressive = "-Ofast"
}
return maps[level]
end
end
-- make the vector extension flag
-- @see https://github.com/xmake-io/xmake/issues/1613
function nf_vectorext(self, extension)
local maps = {
mmx = "-mmmx"
, sse = "-msse"
, sse2 = "-msse2"
, sse3 = "-msse3"
, ssse3 = "-mssse3"
, ["sse4.2"] = "-msse4.2"
, avx = "-mavx"
, avx2 = "-mavx2"
, avx512 = {"-mavx512f", "-mavx512dq", "-mavx512bw", "-mavx512vl"}
, fma = "-mfma"
, neon = "-mfpu=neon"
, all = "-march=native"
}
if extension == "all" and self:is_cross() then
-- https://github.com/xmake-io/xmake-repo/pull/4040#discussion_r1605121207
maps[extension] = nil
end
return maps[extension]
end
-- has -static-libstdc++?
function _has_static_libstdcxx(self)
local has_static_libstdcxx = _g._HAS_STATIC_LIBSTDCXX
if has_static_libstdcxx == nil then
if self:has_flags("-static-libstdc++ -Werror", "ldflags", {flagskey = "gcc_static_libstdcxx"}) then
has_static_libstdcxx = true
end
has_static_libstdcxx = has_static_libstdcxx or false
_g._HAS_STATIC_LIBSTDCXX = has_static_libstdcxx
end
return has_static_libstdcxx
end
-- make the runtime flag
function nf_runtime(self, runtime, opt)
opt = opt or {}
local maps
local kind = self:kind()
if not self:is_plat("android") then -- we will set runtimes in android ndk toolchain
maps = maps or {}
if kind == "ld" or kind == "sh" then
local target = opt.target
if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then
if runtime:endswith("_static") and _has_static_libstdcxx(self) then
maps["stdc++_static"] = "-static-libstdc++"
end
end
end
end
return maps and maps[runtime]
end
-- make the language flag
function nf_language(self, stdname)
-- the stdc maps
if _g.cmaps == nil then
_g.cmaps = {
-- stdc
ansi = "-ansi"
, c89 = "-std=c89"
, gnu89 = "-std=gnu89"
, c90 = "-std=c90"
, gnu90 = "-std=gnu90"
, c99 = "-std=c99"
, gnu99 = "-std=gnu99"
, c11 = "-std=c11"
, gnu11 = "-std=gnu11"
, c17 = "-std=c17"
, gnu17 = "-std=gnu17"
, c23 = {"-std=c23", "-std=c2x"}
, gnu23 = {"-std=gnu23", "-std=gnu2x"}
, clatest = {"-std=c23", "-std=c2x", "-std=c17", "-std=c11", "-std=c99", "-std=c89", "-ansi"}
, gnulatest = {"-std=gnu23", "-std=gnu2x", "-std=gnu17", "-std=gnu11", "-std=gnu99", "-std=gnu89", "-ansi"}
}
end
-- the stdc++ maps
if _g.cxxmaps == nil then
_g.cxxmaps = {
cxx98 = "-std=c++98"
, gnuxx98 = "-std=gnu++98"
, cxx03 = "-std=c++03"
, gnuxx03 = "-std=gnu++03"
, cxx11 = "-std=c++11"
, gnuxx11 = "-std=gnu++11"
, cxx14 = "-std=c++14"
, gnuxx14 = "-std=gnu++14"
, cxx17 = "-std=c++17"
, gnuxx17 = "-std=gnu++17"
, cxx1z = "-std=c++1z"
, gnuxx1z = "-std=gnu++1z"
, cxx20 = {"-std=c++20", "-std=c++2a"}
, gnuxx20 = {"-std=gnu++20", "-std=c++2a"}
, cxx2a = "-std=c++2a"
, gnuxx2a = "-std=gnu++2a"
, cxx23 = {"-std=c++23", "-std=c++2b"}
, gnuxx23 = {"-std=gnu++23", "-std=c++2b"}
, cxx2b = "-std=c++2b"
, gnuxx2b = "-std=gnu++2b"
, cxx2c = "-std=c++2c"
, gnuxx2c = "-std=gnu++2c"
, cxx26 = {"-std=c++26", "-std=c++2c"}
, gnuxx26 = {"-std=gnu++26", "-std=gnu++2c"}
, cxxlatest = {"-std=c++26", "-std=c++2c", "-std=c++23", "-std=c++2b", "-std=c++20", "-std=c++2a", "-std=c++17", "-std=c++14", "-std=c++11", "-std=c++1z", "-std=c++98"}
, gnuxxlatest = {"-std=gnu++26", "-std=gnu++2c", "-std=gnu++23", "-std=gnu++2", "-std=gnu++20", "-std=gnu++2a", "-std=gnu++17", "-std=gnu++14", "-std=gnu++11", "-std=c++1z", "-std=gnu++98"}
}
local cxxmaps2 = {}
for k, v in pairs(_g.cxxmaps) do
cxxmaps2[k:gsub("xx", "++")] = v
end
table.join2(_g.cxxmaps, cxxmaps2)
end
-- select maps
local maps = _g.cmaps
if self:kind() == "cxx" or self:kind() == "mxx" then
maps = _g.cxxmaps
elseif self:kind() == "sc" then
maps = {}
end
local result = maps[stdname]
if type(result) == "table" then
for _, v in ipairs(result) do
if self:has_flags(v, "cxflags") then
result = v
maps[stdname] = result
return result
end
end
else
return result
end
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. path.translate(dir)}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return {"-isystem", path.translate(dir)}
end
-- make the force include flag
function nf_forceinclude(self, headerfile, opt)
local target = opt.target
local sourcekinds = target and target:extraconf("forceincludes", headerfile, "sourcekinds")
if not sourcekinds or table.contains(table.wrap(sourcekinds), self:kind()) then
return {"-include", headerfile}
end
end
-- make the link flag
function nf_link(self, lib)
if self:is_plat("linux") and (lib:endswith(".a") or lib:endswith(".so")) and not lib:find(path.sep(), 1, true) then
return "-l:" .. lib
elseif lib:endswith(".a") or lib:endswith(".so") or lib:endswith(".dylib") or lib:endswith(".lib") then
return lib
else
return "-l" .. lib
end
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the link group flag
function nf_linkgroup(self, linkgroup, opt)
local linkflags = {}
for _, lib in ipairs(linkgroup) do
table.insert(linkflags, nf_link(self, lib))
end
local flags = {}
local extra = opt.extra
if extra and not self:is_plat("macosx", "windows", "mingw") then
local group = extra.group
local whole = extra.whole
if group and whole then
-- https://github.com/xmake-io/xmake/issues/4308
table.join2(flags, "-Wl,--whole-archive", "-Wl,--start-group", linkflags, "-Wl,--end-group", "-Wl,--no-whole-archive")
elseif group then
table.join2(flags, "-Wl,--start-group", linkflags, "-Wl,--end-group")
elseif whole then
table.join2(flags, "-Wl,--whole-archive", linkflags, "-Wl,--no-whole-archive")
end
local static = extra.static
if static then
table.join2(flags, "-Wl,-Bstatic", linkflags, "-Wl,-Bdynamic")
end
end
if #flags == 0 then
flags = linkflags
end
return flags
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. path.translate(dir)}
end
-- make the rpathdir flag
function nf_rpathdir(self, dir, opt)
if self:is_plat("windows", "mingw") then
return
end
opt = opt or {}
local extra = opt.extra
if extra and extra.installonly then
return
end
dir = path.translate(dir)
if self:has_flags("-Wl,-rpath=" .. dir, "ldflags") then
local flags = {"-Wl,-rpath=" .. (dir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
-- add_rpathdirs("...", {runpath = false})
-- https://github.com/xmake-io/xmake/issues/5109
if extra then
if extra.runpath == false and self:has_flags("-Wl,-rpath=" .. dir .. ",--disable-new-dtags", "ldflags") then
flags[1] = flags[1] .. ",--disable-new-dtags"
elseif extra.runpath == true and self:has_flags("-Wl,-rpath=" .. dir .. ",--enable-new-dtags", "ldflags") then
flags[1] = flags[1] .. ",--enable-new-dtags"
end
end
if self:is_plat("bsd") then
-- FreeBSD ld must have "-zorigin" with "-rpath". Otherwise, $ORIGIN is not translated and it is literal.
table.insert(flags, 1, "-Wl,-zorigin")
end
return flags
elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir, "ldflags") then
return {"-Xlinker", "-rpath", "-Xlinker", (dir:gsub("%$ORIGIN", "@loader_path"))}
end
end
-- make the framework flag
function nf_framework(self, framework)
return {"-framework", framework}
end
-- make the frameworkdir flag
function nf_frameworkdir(self, frameworkdir)
return {"-F" .. path.translate(frameworkdir)}
end
-- make the exception flag
--
-- e.g.
-- set_exceptions("cxx")
-- set_exceptions("objc")
-- set_exceptions("no-cxx")
-- set_exceptions("no-objc")
-- set_exceptions("cxx", "objc")
function nf_exception(self, exp)
return exp:startswith("no-") and "-fno-exceptions" or "-fexceptions"
end
-- make the encoding flag
-- @see https://github.com/xmake-io/xmake/issues/2471
--
-- e.g.
-- set_encodings("utf-8")
-- set_encodings("source:utf-8", "target:utf-8")
function nf_encoding(self, encoding)
local kind
local charset
local splitinfo = encoding:split(":")
if #splitinfo > 1 then
kind = splitinfo[1]
charset = splitinfo[2]
else
charset = encoding
end
local charsets = {
["utf-8"] = "UTF-8",
utf8 = "UTF-8"
}
local flags = {}
charset = charsets[charset:lower()]
if charset then
if kind == "source" or not kind then
table.insert(flags, "-finput-charset=" .. charset)
end
if kind == "target" or not kind then
table.insert(flags, "-fexec-charset=" .. charset)
end
end
if #flags > 0 then
return flags
end
end
-- make the c precompiled header flag
function nf_pcheader(self, pcheaderfile, opt)
if self:kind() == "cc" then
local target = opt.target
local pcoutputfile = target:pcoutputfile("c")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
else
return {"-include", path.filename(pcheaderfile), "-I", path.directory(pcoutputfile)}
end
end
end
-- make the c++ precompiled header flag
function nf_pcxxheader(self, pcheaderfile, opt)
if self:kind() == "cxx" then
local target = opt.target
local pcoutputfile = target:pcoutputfile("cxx")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
else
return {"-include", path.filename(pcheaderfile), "-I", path.directory(pcoutputfile)}
end
end
end
-- make the objc precompiled header flag
function nf_pmheader(self, pcheaderfile, opt)
if self:kind() == "mm" then
local target = opt.target
local pcoutputfile = target:pcoutputfile("m")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
else
return {"-include", path.filename(pcheaderfile), "-I", path.directory(pcoutputfile)}
end
end
end
-- make the objc++ precompiled header flag
function nf_pmxxheader(self, pcheaderfile, opt)
if self:kind() == "mxx" then
local target = opt.target
local pcoutputfile = target:pcoutputfile("mxx")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
else
return {"-include", path.filename(pcheaderfile), "-I", path.directory(pcoutputfile)}
end
end
end
-- add the special flags for the given source file of target
--
-- @note only it called when fileconfig is set
--
function add_sourceflags(self, sourcefile, fileconfig, target, targetkind)
-- add language type flags explicitly if the sourcekind is changed.
--
-- because compiler maybe compile `.c` as c++.
-- e.g.
-- add_files("*.c", {sourcekind = "cxx"})
--
local sourcekind = fileconfig.sourcekind
if sourcekind and sourcekind ~= language.sourcekind_of(sourcefile) then
local maps = {cc = "-x c", cxx = "-x c++"}
return maps[sourcekind]
end
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
local flags_extra = {}
if targetkind == "shared" and self:is_plat("macosx", "iphoneos", "watchos") then
if not table.contains(flags, "-install_name") then
table.insert(flags_extra, "-install_name")
table.insert(flags_extra, "@rpath/" .. path.filename(targetfile))
end
end
-- add `-Wl,--out-implib,outputdir/libxxx.a` for xxx.dll on mingw/gcc
if targetkind == "shared" and self:is_plat("mingw") then
table.insert(flags_extra, "-Wl,--out-implib," .. path.join(path.directory(targetfile), path.basename(targetfile) .. ".dll.a"))
end
-- init arguments
opt = opt or {}
local argv = table.join("-o", targetfile, objectfiles, flags, flags_extra)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
return self:program(), argv
end
-- link the target file
--
-- maybe we need to use os.vrunv() to show link output when enable verbose information
-- @see https://github.com/xmake-io/xmake/discussions/2916
--
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
os.mkdir(path.directory(targetfile))
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
if option.get("verbose") then
os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell})
else
os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell})
end
end
-- has color diagnostics?
function _has_color_diagnostics(self)
local colors_diagnostics = _g._HAS_COLOR_DIAGNOSTICS
if colors_diagnostics == nil then
if io.isatty() and (tty.has_color8() or tty.has_color256()) then
local theme = colors.theme()
if theme and theme:name() ~= "plain" then
-- for gcc
if self:has_flags("-fdiagnostics-color=always", "cxflags") then
colors_diagnostics = "-fdiagnostics-color=always"
-- for clang
elseif self:has_flags("-fcolor-diagnostics", "cxflags") then
colors_diagnostics = "-fcolor-diagnostics"
end
-- enable color output for windows, @see https://github.com/xmake-io/xmake-vscode/discussions/260
if colors_diagnostics and self:name() == "clang" and is_host("windows") and
self:has_flags("-fansi-escape-codes", "cxflags") then
colors_diagnostics = table.join(colors_diagnostics, "-fansi-escape-codes")
end
end
end
colors_diagnostics = colors_diagnostics or false
_g._HAS_COLOR_DIAGNOSTICS = colors_diagnostics
end
return colors_diagnostics
end
-- get preprocess file path
function _get_cppfile(sourcefile, objectfile)
return path.join(path.directory(objectfile), "__cpp_" .. path.basename(objectfile) .. path.extension(sourcefile))
end
-- do preprocess
function _preprocess(program, argv, opt)
-- is gcc or clang?
local tool = opt.tool
local is_gcc = false
local is_clang = false
if tool then
if tool:name() == "gcc" or tool:name() == "gxx" then
is_gcc = true
elseif tool:name():startswith("clang") then
is_clang = true
elseif tool:name() == "circle" then
return
end
end
-- enable "-fdirectives-only"? we need to enable it manually
--
-- @see https://github.com/xmake-io/xmake/issues/2603
-- https://github.com/xmake-io/xmake/issues/2425
local directives_only
if is_gcc then
local cachekey = "core.tools." .. tool:name()
directives_only = memcache.get(cachekey, "directives_only")
if directives_only == nil then
if os.isfile(os.projectfile()) and project.policy("preprocessor.gcc.directives_only") then
directives_only = true
end
memcache.set(cachekey, "directives_only", directives_only)
end
end
-- get flags and source file
local flags = {}
local cppflags = {}
local skipped = program:endswith("cache") and 1 or 0
for _, flag in ipairs(argv) do
if flag == "-o" then
break
end
-- get preprocessor flags
table.insert(cppflags, flag)
-- for c++ modules, we cannot support it for clang now
if is_clang and flag:startswith("-fmodules") then
return
end
-- we cannot enable "-fdirectives-only"
if directives_only and (flag:startswith("-D__TIME__=") or
flag:startswith("-D__DATE__=") or flag:startswith("-D__TIMESTAMP__=")) then
directives_only = false
end
-- get compiler flags
if flag == "-MMD" or (flag:startswith("-I") and #flag > 2) or flag:startswith("--sysroot=") then
skipped = 1
elseif flag == "-MF" or
flag == "-I" or flag == "-isystem" or flag == "-include" or flag == "-include-pch" or
flag == "-isysroot" or flag == "-gcc-toolchain" then
skipped = 2
elseif flag:endswith("xcrun") then
skipped = 4
end
if skipped > 0 then
skipped = skipped - 1
else
table.insert(flags, flag)
end
end
local objectfile = argv[#argv - 1]
local sourcefile = argv[#argv]
assert(objectfile and sourcefile, "%s: iorunv(%s): invalid arguments!", self, program)
-- is precompiled header?
if objectfile:endswith(".gch") or objectfile:endswith(".pch") then
return
end
-- disable linemarkers?
local linemarkers = _g.linemarkers
if linemarkers == nil then
if os.isfile(os.projectfile()) and project.policy("preprocessor.linemarkers") == false then
linemarkers = false
else
linemarkers = true
end
_g.linemarkers = linemarkers
end
-- do preprocess
local cppfile = _get_cppfile(sourcefile, objectfile)
local cppfiledir = path.directory(cppfile)
if not os.isdir(cppfiledir) then
os.mkdir(cppfiledir)
end
table.insert(cppflags, "-E")
-- it will be faster for preprocessing
-- when preprocessing, handle directives, but do not expand macros.
if directives_only then
table.insert(cppflags, "-fdirectives-only")
end
if linemarkers == false then
table.insert(cppflags, "-P")
end
table.insert(cppflags, "-o")
table.insert(cppflags, cppfile)
table.insert(cppflags, sourcefile)
-- we need to mark as it when compiling the preprocessed source file
-- it will indicate to the preprocessor that the input file has already been preprocessed.
if is_gcc then
table.insert(flags, "-fpreprocessed")
end
-- with -fpreprocessed, predefinition of command line and most builtin macros is disabled.
if directives_only then
table.insert(flags, "-fdirectives-only")
end
-- do preprocess
local cppinfo = try {function ()
if is_host("windows") then
cppflags = winos.cmdargv(cppflags, {escape = true})
end
local outdata, errdata = os.iorunv(program, cppflags, opt)
return {outdata = outdata, errdata = errdata,
sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags}
end}
if not cppinfo then
if is_gcc then
local cachekey = "core.tools." .. tool:name()
memcache.set(cachekey, "directives_only", false)
end
end
return cppinfo
end
-- compile preprocessed file
function _compile_preprocessed_file(program, cppinfo, opt)
local argv = table.join(cppinfo.cppflags, "-o", cppinfo.objectfile, cppinfo.cppfile)
if is_host("windows") then
argv = winos.cmdargv(argv, {escape = true})
end
local outdata, errdata = os.iorunv(program, argv, opt)
-- we need to get warning information from output
cppinfo.outdata = outdata
cppinfo.errdata = errdata
end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
opt = opt or {}
local program, argv = compargv(self, sourcefile, objectfile, compflags, opt)
local function _compile_fallback()
local runargv = argv
if is_host("windows") then
runargv = winos.cmdargv(argv, {escape = true})
end
return os.iorunv(program, runargv, {envs = self:runenvs(), shell = opt.shell})
end
local cppinfo
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
tool = self, remote = true, shell = opt.shell})
elseif build_cache.is_enabled(opt.target) and build_cache.is_supported(self:kind()) then
cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
tool = self, shell = opt.shell})
end
if cppinfo then
return cppinfo.outdata, cppinfo.errdata
else
return _compile_fallback()
end
end
-- make the compile arguments list for the precompiled header
function _compargv_pch(self, pcheaderfile, pcoutputfile, flags, opt)
-- remove "-include xxx.h" and "-include-pch xxx.pch"
local pchflags = {}
local include = false
for _, flag in ipairs(flags) do
if not flag:startswith("-include") then
if not include then
table.insert(pchflags, flag)
end
include = false
else
include = true
end
end
-- set the language of precompiled header?
if self:kind() == "cxx" then
table.insert(pchflags, "-x")
table.insert(pchflags, "c++-header")
elseif self:kind() == "cc" then
table.insert(pchflags, "-x")
table.insert(pchflags, "c-header")
elseif self:kind() == "mxx" then
table.insert(pchflags, "-x")
table.insert(pchflags, "objective-c++-header")
elseif self:kind() == "mm" then
table.insert(pchflags, "-x")
table.insert(pchflags, "objective-c-header")
end
-- make the compile arguments list
local argv = table.join("-c", pchflags, "-o", pcoutputfile, pcheaderfile)
return self:program(), argv
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags, opt)
-- precompiled header?
local extension = path.extension(sourcefile)
if (extension:startswith(".h") or extension == ".inl") then
return _compargv_pch(self, sourcefile, objectfile, flags, opt)
end
local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
return self:program(), argv
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
opt = opt or {}
local depfile = dependinfo and os.tmpfile() or nil
try
{
function ()
-- support `-MMD -MF depfile.d`? some old gcc does not support it at same time
if depfile and _g._HAS_MMD_MF == nil then
_g._HAS_MMD_MF = self:has_flags({"-MMD", "-MF", os.nuldev()}, "cxflags", { flagskey = "-MMD -MF" }) or false
end
-- generate includes file
local compflags = flags
if depfile and _g._HAS_MMD_MF then
compflags = table.join(compflags, "-MMD", "-MF", depfile)
end
-- has color diagnostics? enable it
local colors_diagnostics = _has_color_diagnostics(self)
if colors_diagnostics then
compflags = table.join(compflags, colors_diagnostics)
end
-- do compile
return _compile(self, sourcefile, objectfile, compflags, opt)
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- remove preprocess file
local cppfile = _get_cppfile(sourcefile, objectfile)
os.tryrm(cppfile)
-- parse and strip errors
local lines = errors and tostring(errors):split('\n', {plain = true}) or {}
if not option.get("verbose") then
-- find the start line of error
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 then
lines = table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start)))
end
end
-- raise compiling errors
local results = #lines > 0 and table.concat(lines, "\n") or ""
if not option.get("verbose") then
results = results .. "\n ${yellow}> in ${bright}" .. sourcefile
end
raise(results)
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and errdata and #errdata > 0 and policy.build_warnings(opt) then
local lines = errdata:split('\n', {plain = true})
if #lines > 0 then
if not option.get("diagnosis") then
lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines))
end
local warnings = table.concat(lines, "\n")
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", warnings)
end
end
-- generate the dependent includes
if depfile and os.isfile(depfile) then
if dependinfo then
dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"})
end
-- remove the temporary dependent file
os.tryrm(depfile)
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/gdc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki, BarrOff
-- @file gdc.lua
--
-- imports
inherit("gcc")
-- init it
function init(self)
-- init arflags
self:set("dcarflags", "-cr")
-- init shflags
self:set("dcshflags", "-shared", "-fPIC")
-- init dcflags for the kind: shared
self:set("shared.dcflags", "-fPIC")
end
-- make the optimize flag
function nf_optimize(self, level)
local maps =
{
fast = "-O"
, faster = "-O -frelease"
, fastest = "-O -frelease -fbounds-check=off"
, smallest = "-O -frelease -fbounds-check=off"
, aggressive = "-O -frelease -fbounds-check=off"
}
return maps[level]
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/emar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file emar.lua
--
-- inherit ar
inherit("ar")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/zig_cxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file zig_cxx.lua
--
inherit("zig_cc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/rc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file rc.lua
--
-- imports
import("core.base.option")
import("core.base.hashset")
import("core.project.project")
import("private.tools.vstool")
-- normailize path of a dependecy
function _normailize_dep(dep, projectdir)
if path.is_absolute(dep) then
dep = path.translate(dep)
else
dep = path.absolute(dep, projectdir)
end
if dep:startswith(projectdir) then
return path.relative(dep, projectdir)
else
return deps
end
end
-- parse include file
function _parse_includefile(line)
if line:startswith("#line") then
return line:match("#line %d+ \"(.+)\"")
elseif line:find("ICON", 1, true) and line:find(".ico", 1, true) then
-- 101 ICON "xxx.ico"
return line:match("ICON%s+\"(.+.ico)\"")
elseif line:find("BITMAP", 1, true) and line:find(".bmp", 1, true) then
return line:match("BITMAP%s+\"(.+.bmp)\"")
end
end
-- init it
function init(self)
if self:has_flags("-nologo", "mrcflags") then
-- fix vs2008 on xp, e.g. fatal error RC1106: invalid option: -ologo
self:set("mrcflags", "-nologo")
end
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "-Fo" .. objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
-- @note we don't need to use vstool.iorunv to enable unicode output for rc.exe
local program, argv = compargv(self, sourcefile, objectfile, flags)
local outdata, errdata = os.iorunv(program, argv, {envs = self:runenvs()})
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- use stdout as errors first from vstool.iorunv()
if type(errors) == "table" then
local errs = errors.stdout or ""
if #errs:trim() == 0 then
errs = errors.stderr or ""
end
errors = errs
end
os.raise(tostring(errors))
end
},
finally
{
function (ok, warnings)
if warnings and #warnings > 0 and option.get("verbose") then
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
-- try to use cl.exe to parse includes, but cl.exe maybe not exists in masm32 sdk
-- @see https://github.com/xmake-io/xmake/issues/2562
local cl = self:toolchain():tool("cxx")
if cl then
local outfile = os.tmpfile() .. ".rc.out"
local errfile = os.tmpfile() .. ".rc.err"
local includeflags = {}
for _, flag in ipairs(flags) do
if flag:match("^[-/]I") then
table.insert(includeflags, flag)
end
end
local ok = try {function () os.execv(cl, table.join("-E", includeflags, sourcefile), {stdout = outfile, stderr = errfile, envs = self:runenvs()}); return true end}
if ok and os.isfile(outfile) then
local depfiles_rc
local includeset = hashset.new()
local file = io.open(outfile)
local projectdir = os.projectdir()
for line in file:lines() do
local includefile = _parse_includefile(line)
if includefile then
includefile = _normailize_dep(includefile, projectdir)
if includefile and not includeset:has(includefile)
and path.absolute(includefile) ~= path.absolute(sourcefile)
and os.isfile(includefile) then
depfiles_rc = (depfiles_rc or "") .. "\n" .. includefile
includeset:insert(includefile)
end
end
end
file:close()
if dependinfo then
dependinfo.depfiles_rc = depfiles_rc
end
end
os.tryrm(outfile)
os.tryrm(errfile)
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armasm64_msvc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armasm64_msvc.lua
--
-- imports
inherit("armasm_msvc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/llvm_ar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file llvm_ar.lua
--
-- imports
import("core.tool.compiler")
-- init it
function init(self)
self:set("arflags", "cr")
end
-- make the strip flag
function strip(self, level)
local maps = {
debug = "S"
, all = "S"
}
return maps[level]
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
assert(targetkind == "static")
opt = opt or {}
local argv = table.join(flags, targetfile, objectfiles)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
return self:program(), argv
end
-- link the library file
function link(self, objectfiles, targetkind, targetfile, flags)
assert(targetkind == "static", "the target kind: %s is not support for ar", targetkind)
os.mkdir(path.directory(targetfile))
-- @note remove the previous archived file first to force recreating a new file
os.tryrm(targetfile)
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/zig_cc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file zig_cc.lua
--
-- inherit gcc
inherit("gcc")
-- make the strip flag
function nf_strip(self, level)
local maps = {
debug = "-Wl,-S"
, all = "-s"
}
return maps[level]
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/gfortran.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file gfortran.lua
--
-- inherit gcc
inherit("gcc")
-- init it
function init(self)
-- init super
_super.init(self)
-- init shflags
self:set("fcshflags", "-shared")
-- add -fPIC for shared
if not self:is_plat("windows", "mingw") then
self:add("fcshflags", "-fPIC")
self:add("shared.fcflags", "-fPIC")
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/bl51.lua | --!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-present, TBOOX Open Source Group.
--
-- @author DawnMagnet
-- @file bl51.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("utils.progress")
function init(self)
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
return self:program(), table.join(table.concat(objectfiles, ","), "TO", targetfile, flags)
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/windres.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file windres.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.project.project")
-- init it
function init(self)
self:add("mrcflags", "--use-temp-file", "-O", "coff")
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I", dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, sourcefile, objectfile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
os.mkdir(path.directory(objectfile))
try
{
function ()
local program, argv = compargv(self, sourcefile, objectfile, flags)
local outdata, errdata = os.iorunv(program, argv, {envs = self:runenvs()})
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
os.raise(errors)
end
},
finally
{
function (ok, warnings)
if warnings and #warnings > 0 and policy.build_warnings(opt) then
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/mold.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file mold.lua
--
-- imports
inherit("ld")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ld_lld.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ld_lld.lua
--
-- imports
inherit("ld")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/sdar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file sdar.lua
--
-- imports
import("core.tool.compiler")
-- init it
function init(self)
-- init flags
self:set("arflags", "-cr")
end
-- make the strip flag
function strip(self, level)
-- the maps
local maps =
{
debug = "-S"
, all = "-s"
}
-- make it
return maps[level]
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- check
assert(targetkind == "static")
-- init arguments
opt = opt or {}
local argv = table.join(flags, targetfile, objectfiles)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
-- make it
return self:program(), argv
end
-- link the library file
function link(self, objectfiles, targetkind, targetfile, flags)
-- check
assert(targetkind == "static", "the target kind: %s is not support for ar", targetkind)
-- ensure the target directory
os.mkdir(path.directory(targetfile))
-- @note remove the previous archived file first to force recreating a new file
os.tryrm(targetfile)
-- link it
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/icpc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file icpc.lua
--
-- inherit icc
inherit("icc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cosmocxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cosmocxx.lua
--
-- inherit cosmocc
inherit("cosmocc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/sdasstm8.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file sdasstm8.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.language.language")
import("utils.progress")
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armar.lua
--
inherit("ar")
function init(self)
_super.init(self)
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
local argv = table.join(flags, targetfile, objectfiles)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
if #argv > 0 and argv[1] and argv[1]:startswith("@") then
argv[1] = argv[1]:replace("@", "", {plain = true})
table.insert(argv, 1, "--via")
end
end
return self:program(), argv
end
-- link the library file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
-- @note remove the previous archived file first to force recreating a new file
os.tryrm(targetfile)
-- link it
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/icc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file icc.lua
--
-- inherit gcc
inherit("gcc")
-- init it
function init(self)
_super.init(self)
end
-- make the fp-model flag
function nf_fpmodel(self, level)
local maps =
{
precise = "-fp-model=precise"
, fast = "-fp-model=fast" --default
, strict = "-fp-model=strict"
, except = "-fp-model=except"
, noexcept = "-fp-model=no-except"
}
return maps[level]
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/fpc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file fpc.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- init it
function init(self)
if not self:is_plat("windows", "mingw") then
self:add("shared.pcflags", "-Cg")
end
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "-O-"
, fast = "-O1"
, fastest = "-O3"
, smallest = "-O2"
, aggressive = "-O4"
}
return maps[level]
end
end
-- make the strip flag
function nf_strip(self, level)
if level == "all" then
return "-Xs"
end
end
-- make the symbol flag
function nf_symbol(self, level)
if level == "debug" and self:kind() == "pc" then
if self:is_plat("windows") then
return {"-gw3", "-WN"}
else
return "-gw3"
end
end
end
-- make the link flag
function nf_link(self, lib)
return "-k-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-k-L" .. dir}
end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
dir = path.translate(dir)
if self:has_flags("-k-rpath=" .. dir, "ldflags") then
return {"-k-rpath=" .. (dir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
end
end
-- make the framework flag
function nf_framework(self, framework)
return {"-k-framework", framework}
end
-- make the frameworkdir flag
function nf_frameworkdir(self, frameworkdir)
return {"-k-F", path.translate(frameworkdir)}
end
-- make the build arguments list
function buildargv(self, sourcefiles, targetkind, targetfile, flags)
return self:program(), table.join(flags, "-o" .. targetfile, sourcefiles)
end
-- build the target file
function build(self, sourcefiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/sdcc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file sdcc.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.language.language")
import("utils.progress")
-- init it
function init(self)
-- init flags map
self:set("mapflags",
{
-- optimize
["-O0"] = ""
, ["-Os"] = "--opt-code-speed"
, ["-O3"] = "--opt-code-size"
, ["-Ofast"] = "--opt-code-speed"
-- symbols
, ["-fvisibility=.*"] = ""
-- warnings
, ["-Weverything"] = ""
, ["-Wextra"] = ""
, ["-Wall"] = ""
, ["-W1"] = "--less-pedantic"
, ["-W2"] = "--less-pedantic"
, ["-W3"] = ""
, ["%-Wno%-error=.*"] = ""
, ["%-fno%-.*"] = ""
-- language
, ["-ansi"] = "--std-c89"
, ["-std=c89"] = "--std-c89"
, ["-std=c99"] = "--std-c99"
, ["-std=c11"] = "--std-c11"
, ["-std=c20"] = "--std-c2x"
, ["-std=gnu89"] = "--std-sdcc89"
, ["-std=gnu99"] = "--std-sdcc99"
, ["-std=gnu11"] = "--std-sdcc11"
, ["-std=gnu20"] = "--std-sdcc2x"
, ["-std=.*"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the warning flag
function nf_warning(self, level)
local maps =
{
none = "--less-pedantic"
, less = "--less-pedantic"
, error = "-Werror"
}
return maps[level]
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = ""
, fast = "--opt-code-speed"
, faster = "--opt-code-speed"
, fastest = "--opt-code-speed"
, smallest = "--opt-code-size"
, aggressive = "--opt-code-speed"
}
return maps[level]
end
end
-- make the language flag
function nf_language(self, stdname)
if _g.cmaps == nil then
_g.cmaps =
{
ansi = "--std-c89"
, c89 = "--std-c89"
, gnu89 = "--std-sdcc89"
, c99 = "--std-c99"
, gnu99 = "--std-sdcc99"
, c11 = "--std-c11"
, gnu11 = "--std-sdcc11"
, c20 = "--std-c2x"
, gnu20 = "--std-sdcc2x"
, clatest = {"--std-c2x", "--std-c11", "--std-c99", "--std-c89"}
, gnulatest = {"--std-sdcc2x", "--std-sdcc11", "--std-sdcc99", "--std-sdcc89"}
}
end
local maps = _g.cmaps
local result = maps[stdname]
if type(result) == "table" then
for _, v in ipairs(result) do
if self:has_flags(v, "cxflags") then
result = v
maps[stdname] = result
return result
end
end
else
return result
end
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. dir}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
return self:program(), table.join("-o", targetfile, objectfiles, flags)
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armcc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armcc.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.language.language")
import("utils.progress")
-- init it
function init(self)
end
-- make the symbol flag
function nf_symbol(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps =
{
debug = "-g"
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
end
end
-- make runtime flag
function nf_runtime(self, runtime)
if runtime == "microlib" then
return "-D__MICROLIB"
end
end
-- make the optimize flag
function nf_optimize(self, level)
local maps =
{
none = "-O0"
, fast = "-O1"
, faster = "-O2"
, fastest = "-O3"
, smallest = "-Os"
, aggressive = "-Ofast"
}
return maps[level]
end
-- make the language flag
function nf_language(self, stdname)
-- the stdc maps
if _g.cmaps == nil then
_g.cmaps =
{
ansi = "-c89"
, c89 = "-c89"
, gnu89 = "-c89"
, c99 = "-c99"
, gnu99 = "-c99"
, c11 = "-c11"
, gnu11 = "-c11"
, clatest = {"-c11", "-c99", "-c89"}
, gnulatest = {"-c11", "-c99", "-c89"}
}
end
local maps = _g.cmaps
local result = maps[stdname]
if type(result) == "table" then
for _, v in ipairs(result) do
if self:has_flags(v, "cxflags") then
result = v
maps[stdname] = result
return result
end
end
else
return result
end
end
-- make the define flag
function nf_define(self, macro)
return "-D" .. macro
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
local depfile = dependinfo and os.tmpfile() or nil
try
{
function ()
local compflags = flags
if depfile then
compflags = table.join(compflags, "--depend", depfile)
end
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
-- generate the dependent includes
if depfile and os.isfile(depfile) then
if dependinfo then
dependinfo.depfiles_armcc = io.readfile(depfile, {continuation = "\\"})
end
-- remove the temporary dependent file
os.tryrm(depfile)
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/icpx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file icpc.lua
--
-- inherit icc
inherit("icx")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/clang.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file clang.lua
--
-- inherit gcc
inherit("gcc")
import("core.language.language")
-- init it
function init(self)
-- init super
_super.init(self)
-- add cuflags
if not self:is_plat("windows", "mingw") then
self:add("shared.cuflags", "-fPIC")
end
-- suppress warning
self:add("cxflags", "-Qunused-arguments")
self:add("cuflags", "-Qunused-arguments")
self:add("mxflags", "-Qunused-arguments")
self:add("asflags", "-Qunused-arguments")
-- add cuda path
local cuda = get_config("cuda")
if cuda then
local cuda_path = "--cuda-path=" .. os.args(path.translate(cuda))
self:add("cuflags", cuda_path)
end
-- init flags map
self:set("mapflags",
{
-- warnings
["-W1"] = "-Wall"
, ["-W2"] = "-Wall"
, ["-W3"] = "-Wall"
, ["-W4"] = "-Wall -Wextra"
-- strip
, ["-s"] = "-s"
, ["-S"] = "-S"
-- rdc
, ["-rdc=true"] = "-fcuda-rdc"
, ["-rdc true"] = "-fcuda-rdc"
, ["--relocatable-device-code=true"] = "-fcuda-rdc"
, ["--relocatable-device-code true"] = "-fcuda-rdc"
, ["-rdc=false"] = ""
, ["-rdc false"] = ""
, ["--relocatable-device-code=false"] = ""
, ["--relocatable-device-code false"] = ""
})
end
-- make the fp-model flag
function nf_fpmodel(self, level)
local maps
if self:has_flags("-ffp-model=fast") then
maps =
{
precise = "-ffp-model=precise"
, fast = "-ffp-model=fast"
, strict = "-ffp-model=strict"
, except = "-ftrapping-math"
, noexcept = "-fno-trapping-math"
}
else
maps =
{
precise = "" -- default
, fast = "-ffast-math"
, strict = {"-frounding-math", "-ftrapping-math"}
, except = "-ftrapping-math"
, noexcept = "-fno-trapping-math"
}
end
return maps[level]
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "-O0"
, fast = "-O1"
, faster = "-O2"
, fastest = "-O3"
, smallest = "-Oz" -- smaller than -Os
, aggressive = "-Ofast"
}
return maps[level]
end
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-w"
, less = "-Wall"
, more = "-Wall"
, all = "-Wall"
, allextra = {"-Wall", "-Wextra"}
, extra = "-Wextra"
, pedantic = "-Wpedantic"
, everything = "-Weverything"
, error = "-Werror"
}
return maps[level]
end
-- make the symbol flag
function nf_symbol(self, level)
local kind = self:kind()
if kind == "ld" or kind == "sh" then
-- clang/windows need add `-g` to linker to generate pdb symbol file
if self:is_plat("windows") and level == "debug" then
return "-g"
end
else
return _super.nf_symbol(self, level)
end
end
-- make the exception flag
--
-- e.g.
-- set_exceptions("cxx")
-- set_exceptions("objc")
-- set_exceptions("no-cxx")
-- set_exceptions("no-objc")
-- set_exceptions("cxx", "objc")
function nf_exception(self, exp)
local maps = {
cxx = "-fcxx-exceptions",
["no-cxx"] = "-fno-cxx-exceptions",
objc = "-fobjc-exceptions",
["no-objc"] = "-fno-objc-exceptions"
}
local value = maps[exp]
if value then
return {exp:startswith("no-") and "-fno-exceptions" or "-fexceptions", value}
end
end
-- has -fms-runtime-lib?
function _has_ms_runtime_lib(self)
local has_ms_runtime_lib = _g._HAS_MS_RUNTIME_LIB
if has_ms_runtime_lib == nil then
if self:has_flags("-fms-runtime-lib=dll", "cxflags", {flagskey = "clang_ms_runtime_lib"}) then
has_ms_runtime_lib = true
end
has_ms_runtime_lib = has_ms_runtime_lib or false
_g._HAS_MS_RUNTIME_LIB = has_ms_runtime_lib
end
return has_ms_runtime_lib
end
-- has -static-libstdc++?
function _has_static_libstdcxx(self)
local has_static_libstdcxx = _g._HAS_STATIC_LIBSTDCXX
if has_static_libstdcxx == nil then
if self:has_flags("-static-libstdc++ -Werror", "ldflags", {flagskey = "clang_static_libstdcxx"}) then
has_static_libstdcxx = true
end
has_static_libstdcxx = has_static_libstdcxx or false
_g._HAS_STATIC_LIBSTDCXX = has_static_libstdcxx
end
return has_static_libstdcxx
end
-- get llvm sdk root directory
function _get_llvm_rootdir(self)
local llvm_rootdir = _g._LLVM_ROOTDIR
if llvm_rootdir == nil then
local outdata = try { function() return os.iorunv(self:program(), {"-print-resource-dir"}, {envs = self:runenvs()}) end }
if outdata then
llvm_rootdir = path.normalize(path.join(outdata:trim(), "..", "..", ".."))
if not os.isdir(llvm_rootdir) then
llvm_rootdir = nil
end
end
_g._LLVM_ROOTDIR = llvm_rootdir or false
end
return llvm_rootdir or nil
end
-- get llvm target triple
function _get_llvm_target_triple(self)
local llvm_targettriple = _g._LLVM_TARGETTRIPLE
if llvm_targettriple == nil then
local outdata = try { function() return os.iorunv(self:program(), {"-print-target-triple"}, {envs = self:runenvs()}) end }
if outdata then
llvm_targettriple = outdata:trim()
end
_g._LLVM_TARGETTRIPLE = llvm_targettriple or false
end
return llvm_targettriple or nil
end
-- make the runtime flag
-- @see https://github.com/xmake-io/xmake/issues/3546
function nf_runtime(self, runtime, opt)
opt = opt or {}
local maps
-- if a sdk dir is defined, we should redirect include / library path to have the correct includes / libc++ link
local kind = self:kind()
if self:is_plat("windows") and runtime then
if not _has_ms_runtime_lib(self) then
if runtime:startswith("MD") then
wprint("%s runtime is not available for the current Clang compiler.", runtime)
end
return
end
if language.sourcekinds()[kind] then
maps = {
MT = "-fms-runtime-lib=static",
MTd = "-fms-runtime-lib=static_dbg",
MD = "-fms-runtime-lib=dll",
MDd = "-fms-runtime-lib=dll_dbg"
}
elseif kind == "ld" or kind == "sh" then
maps = {
MT = "-nostdlib",
MTd = "-nostdlib",
MD = "-nostdlib",
MDd = "-nostdlib"
}
end
end
if not self:is_plat("android") then -- we will set runtimes in android ndk toolchain
maps = maps or {}
local llvm_rootdir = self:toolchain():sdkdir()
if kind == "cxx" then
maps["c++_static"] = "-stdlib=libc++"
maps["c++_shared"] = "-stdlib=libc++"
maps["stdc++_static"] = "-stdlib=libstdc++"
maps["stdc++_shared"] = "-stdlib=libstdc++"
if not llvm_rootdir and self:is_plat("windows") then
-- clang on windows fail to add libc++ includepath when using -stdlib=libc++ so we manually add it
-- @see https://github.com/llvm/llvm-project/issues/79647
llvm_rootdir = _get_llvm_rootdir(self)
end
if llvm_rootdir then
maps["c++_static"] = table.join(maps["c++_static"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1"))
maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1"))
end
elseif kind == "ld" or kind == "sh" then
local target = opt.target or opt
local is_cxx = target and (target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx"))
if is_cxx then
maps["c++_static"] = "-stdlib=libc++"
maps["c++_shared"] = "-stdlib=libc++"
maps["stdc++_static"] = "-stdlib=libstdc++"
maps["stdc++_shared"] = "-stdlib=libstdc++"
if not llvm_rootdir and self:is_plat("windows") then
-- clang on windows fail to add libc++ librarypath when using -stdlib=libc++ so we manually add it
-- @see https://github.com/llvm/llvm-project/issues/79647
llvm_rootdir = _get_llvm_rootdir(self)
end
if llvm_rootdir then
local libdir = path.absolute(path.join(llvm_rootdir, "lib"))
maps["c++_static"] = table.join(maps["c++_static"], "-L" .. libdir)
maps["c++_shared"] = table.join(maps["c++_shared"], "-L" .. libdir)
-- sometimes llvm runtimes are located in a target-triple subfolder
local target_triple = _get_llvm_target_triple(self)
local triple_libdir = (target_triple and os.isdir(path.join(libdir, target_triple))) and path.join(libdir, target_triple)
if triple_libdir then
maps["c++_static"] = table.join(maps["c++_static"], "-L" .. triple_libdir)
maps["c++_shared"] = table.join(maps["c++_shared"], "-L" .. triple_libdir)
end
-- add rpath to avoid the user need to set LD_LIBRARY_PATH by hand
maps["c++_shared"] = table.join(maps["c++_shared"], nf_rpathdir(self, libdir))
if triple_libdir then
maps["c++_shared"] = table.join(maps["c++_shared"], nf_rpathdir(self, triple_libdir))
end
if target:is_shared() and target.filename and self:is_plat("macosx", "iphoneos", "watchos") then
maps["c++_shared"] = table.join(maps["c++_shared"], "-install_name")
maps["c++_shared"] = table.join(maps["c++_shared"], "@rpath/" .. target:filename())
end
end
if runtime:endswith("_static") and _has_static_libstdcxx(self) then
maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++")
maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++")
end
end
end
end
return maps and maps[runtime]
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/nvcxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file nvcxx.lua
--
-- inherit gcc
inherit("gcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/circle.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file circle.lua
--
inherit("gcc")
function init(self)
_super.init(self)
end
function nf_strip(self, level)
local maps =
{
debug = "-Wl,-S"
, all = "-Wl,-s"
}
return maps[level]
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/clangxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file clangxx.lua
--
-- inherit clang
inherit("clang")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ld.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ld.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- init it
function init(self)
-- init shflags
self:set("shflags", "-shared")
-- add -fPIC for shared
if not self:is_plat("windows", "mingw") then
self:add("shflags", "-fPIC")
self:add("shared.cxflags", "-fPIC")
end
end
-- make the strip flag
function nf_strip(self, level)
local maps = {
debug = "-S"
, all = "-s"
}
if self:is_plat("macosx", "iphoneos") then
maps.all = "-Wl,-x"
maps.debug = "-Wl,-S"
end
return maps[level]
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L", path.translate(dir)}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
local argv = table.join("-o", targetfile, objectfiles, flags)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ifort.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ifort.lua
--
if is_host("windows") then
-- imports
inherit("cl")
inherit("link")
import("private.tools.vstool")
-- init it
function init(self)
self:set("fcflags", "-nologo")
self:set("fcldflags", "-nologo", "-dynamicbase", "-nxcompat")
self:set("fcshflags", "-nologo")
end
-- get the property
function get(self, name)
local values = self._INFO[name]
if name == "fcldflags" or name == "fcarflags" or name == "fcshflags" then
-- switch architecture, @note does cache it in init() for generating vs201x project
values = table.join(values, "-machine:" .. (self:arch() or "x86"))
end
return values
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
local argv = table.join("-o", targetfile, objectfiles, "/link", flags)
if not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
-- @note we cannot put -dll to @args.txt
if targetkind == "shared" then
table.insert(argv, 1, "-dll")
end
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
-- ensure the target directory
os.mkdir(path.directory(targetfile))
try
{
function ()
-- use vstool to link and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
vstool.runv(program, argv, {envs = self:runenvs()})
end,
catch
{
function (errors)
-- use link/stdout as errors first from vstool.iorunv()
if type(errors) == "table" then
local errs = errors.stdout or ""
if #errs:trim() == 0 then
errs = errors.stderr or ""
end
errors = errs
end
os.raise(tostring(errors))
end
}
}
end
else
inherit("gfortran")
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cosmoar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cosmoar.lua
--
inherit("ar")
function init(self)
_super.init(self)
end
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
if is_host("windows") then
targetfile = targetfile:gsub("\\", "/")
local objectfiles_new = {}
for idx, objectfile in ipairs(objectfiles) do
objectfiles_new[idx] = objectfiles[idx]:gsub("\\", "/")
end
objectfiles = objectfiles_new
end
return _super.link(self, objectfiles, targetkind, targetfile, flags, table.join(opt, {shell = true}))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/emcc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file emcc.lua
--
-- inherit gcc
inherit("gcc")
-- make the optimize flag
--
-- same options must be used at compile and link, @see https://github.com/xmake-io/xmake/issues/2455
-- https://emscripten.org/docs/compiling/Building-Projects.html?highlight=optimization#building-projects-optimizations
function nf_optimize(self, level)
local maps = {
none = "-O0"
, fast = "-O1"
, faster = "-O2"
, fastest = "-O3"
, smallest = "-Os"
, aggressive = "-O3"
}
return maps[level]
end
-- make the strip flag
function nf_strip(self, level)
end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
end
-- make the symbol flag
function nf_symbol(self, level)
local kind = self:kind()
if kind == "ld" or kind == "sh" then
-- emscripten requires -g when linking to map JS/wasm code back to original source
if level == "debug" then
return "-g"
end
end
return _super.nf_symbol(self, level)
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- init arguments
opt = opt or {}
local argv = table.join("-o", targetfile, objectfiles, flags)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
return self:program(), argv
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ifx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ifx.lua
--
inherit("ifort")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/c51.lua | --!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-present, TBOOX Open Source Group.
--
-- @author DawnMagnet
-- @file c51.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.language.language")
import("utils.progress")
import("core.project.policy")
-- init it
function init(self)
end
-- make the optimize flag
function nf_optimize(self, level)
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = {
fast = "OT(8,SPEED)"
, faster = "OT(9,SPEED)"
, fastest = "OT(10,SPEED)"
, smallest = "OT(10,SIZE)"
, aggressive = "OT(11,SPEED)"
}
return maps[level]
end
end
-- make the includedir flag
function nf_includedirs(self, dirs)
local paths = {}
for _, dir in ipairs(dirs) do
table.insert(paths, path.translate(dir))
end
if #paths > 0 then
return {"INCDIR(" .. table.concat(paths, ";") .. ")"}
end
end
-- make the define flag
function nf_defines(self, defines)
if defines and #defines > 0 then
return {"DEFINE(" .. table.concat(defines, ",") .. ")"}
end
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
local lstfile = objectfile:gsub("%.c%.obj", ".lst")
lstfile = lstfile:gsub("%.c%.o$", ".lst")
return self:program(), table.join(sourcefile, "OBJECT(" .. objectfile .. ")", "PRINT(" .. lstfile .. ")", flags)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
os.mkdir(path.directory(objectfile))
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and outdata and #outdata > 0 and policy.build_warnings(opt) then
local warnings_count = outdata:match("(%d-) WARNING")
if warnings_count and tonumber(warnings_count) > 0 then
local lines = outdata:split('\n', {plain = true})
if #lines > 0 then
if not option.get("diagnosis") then
lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines))
end
local warnings = table.concat(lines, "\n")
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", warnings)
end
end
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/gccgo.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file gccgo.lua
--
-- inherit gcc
inherit("gcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ldc2.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki, BarrOff
-- @file ldc2.lua
--
-- imports
inherit("dmd")
import("core.language.language")
-- init it
function init(self)
-- init arflags
self:set("dcarflags", "-lib")
-- init shflags
self:set("dcshflags", "-shared", "--relocation-model=pic")
-- init dcflags for the kind: shared
self:set("shared.dcflags", "--relocation-model=pic")
end
-- make the optimize flag
function nf_optimize(self, level)
local maps = {
none = "--O0"
, fast = "--O1"
, faster = {"--O2", "--release"}
, fastest = {"--O3", "--release", "--boundscheck=off"}
, smallest = {"--Oz", "--release", "--boundscheck=off"}
, aggressive = {"--O4", "--release", "--boundscheck=off"}
}
return maps[level]
end
-- make the symbol flag
function nf_symbol(self, level)
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps = {
debug = {"-g", "--d-debug"}
, hidden = "-fvisibility=hidden"
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
elseif (kind == "dcld" or kind == "dcsh") and self:is_plat("windows") and level == "debug" then
return "-g"
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/nvfortran.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file nvfortran.lua
--
inherit("gfortran")
import("core.language.language")
-- make the symbol flag
function nf_symbol(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps = {
debug = "-g"
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/nasm.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file nasm.lua
--
-- imports
import("core.base.option")
import("core.project.policy")
import("core.language.language")
-- init it
function init(self)
-- init flags map
self:set("mapflags",
{
-- symbols
["-g"] = ""
, ["-fvisibility=.*"] = ""
-- warnings
, ["-Wall"] = "" -- = "-Wall" will enable too more warnings
, ["-W1"] = ""
, ["-W2"] = ""
, ["-W3"] = ""
, ["-Werror"] = ""
, ["%-Wno%-error=.*"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the symbol flag
function nf_symbol(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = {
debug = "-g"
}
return maps[level]
end
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-w"
}
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I", dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
local outdata, errdata = try
{
function ()
return os.iorunv(compargv(self, sourcefile, objectfile, flags))
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- raise compiling errors
raise(tostring(errors))
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and errdata and policy.build_warnings(opt) then
errdata = errdata:trim()
if #errdata > 0 then
cprint("${color.warning}%s", errdata)
end
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cxx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cxx.lua
--
-- inherit gcc
inherit("gcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/icl.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file icl.lua
--
-- inherit cl
inherit("cl")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ml64.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ml64.lua
--
-- inherit ml
inherit("ml")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armclang.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armclang.lua
--
inherit("gcc")
import("core.language.language")
function init(self)
_super.init(self)
end
-- make runtime flag
function nf_runtime(self, runtime)
if runtime == "microlib" then
return "-D__MICROLIB"
end
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "-O0"
, fast = "-O1"
, faster = "-O2"
, fastest = "-O3"
, smallest = "-Oz" -- smaller than -Os
, aggressive = "-Ofast"
}
return maps[level]
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ar.lua
--
-- imports
import("core.tool.compiler")
import("utils.progress")
-- init it
function init(self)
self:set("arflags", "-cr")
self:set("dcarflags", "-cr") -- for dlang/gdc, e.g. x86_64-unknown-linux-gnu-gcc-ar
end
-- make the strip flag
function strip(self, level)
local maps = {
debug = "-S"
, all = "-s"
}
return maps[level]
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
local argv = table.join(flags, targetfile, objectfiles)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
return self:program(), argv
end
-- link the library file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
os.mkdir(path.directory(targetfile))
-- @note remove the previous archived file first to force recreating a new file
os.tryrm(targetfile)
-- link it
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
os.runv(program, argv, {envs = self:runenvs(), shell = opt.shell})
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/gcc_ar.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file gcc_ar.lua
--
inherit("ar")
import("lib.detect.find_file")
-- replace gcc-ar
function _replace_gcc_ar(program, name)
local dir = path.directory(program)
local filename = path.filename(program)
filename = filename:gsub("gcc%-ar", name)
if dir and dir ~= "." then
program = path.join(dir, filename)
else
program = filename
end
return program
end
-- get liblto_plugin.so path for gcc
function _get_gcc_liblto_plugin_path(self, program)
local plugin_path = _g.LTO_PLUGIN_PATH
if plugin_path == nil then
local gcc = _replace_gcc_ar(program, "gcc")
local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end }
if outdata then
local lto_plugindir = path.directory(outdata:trim())
if os.isdir(lto_plugindir) then
if is_host("windows") then
plugin_path = find_file("liblto_plugin*.dll", lto_plugindir)
else
plugin_path = find_file("liblto_plugin.so", lto_plugindir)
end
end
end
plugin_path = plugin_path or false
_g.LTO_PLUGIN_PATH = plugin_path
end
return plugin_path or nil
end
-- link the library file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
os.mkdir(path.directory(targetfile))
-- @note remove the previous archived file first to force recreating a new file
os.tryrm(targetfile)
-- generate link arguments
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
if is_host("windows") and argv and #argv > 0 and argv[1]:startswith("@") then
-- gcc-ar.exe does not support `@file`, so we need use ar.exe to instead of it.
-- @see https://github.com/xmake-io/xmake/issues/5051
--
-- but ar.exe does not support lto, we need also add lto_plugin-0.dll path in `@file` for gcc
-- @see https://github.com/xmake-io/xmake/issues/5015
--
-- gcc-ar is the wrapper of `ar --plugin lto_plugin.so ...`
--
local _, rawargv = linkargv(self, objectfiles, targetkind, targetfile, flags, table.join(opt, {rawargs = true}))
local plugin_path = _get_gcc_liblto_plugin_path(self, program)
if plugin_path then
argv = winos.cmdargv(table.join({"--plugin", plugin_path}, rawargv), {escape = true})
end
program = _replace_gcc_ar(program, "ar")
end
-- link it
os.runv(program, argv, {envs = self:runenvs(), shell = opt.shell})
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/yasm.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file yasm.lua
--
-- imports
import("core.base.option")
import("core.project.policy")
import("core.language.language")
-- init it
function init(self)
-- init flags map
self:set("mapflags",
{
-- symbols
["-g"] = ""
, ["-fvisibility=.*"] = ""
-- warnings
, ["-Wall"] = "" -- = "-Wall" will enable too more warnings
, ["-W1"] = ""
, ["-W2"] = ""
, ["-W3"] = ""
, ["-Werror"] = ""
, ["%-Wno%-error=.*"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-w"
}
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I", dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
local outdata, errdata = try
{
function ()
return os.iorunv(compargv(self, sourcefile, objectfile, flags))
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- raise compiling errors
raise(tostring(errors))
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and errdata and policy.build_warnings(opt) then
errdata = errdata:trim()
if #errdata > 0 then
cprint("${color.warning}%s", errdata)
end
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/zig.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file zig.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.project.target")
-- init it
function init(self)
-- init shflags
self:set("zcshflags", "-dynamic", "-fPIC")
-- init zcflags for the kind: shared
self:set("shared.zcflags", "-fPIC")
end
-- make the strip flag
function nf_strip(self, level)
local maps = {
debug = "-fstrip"
, all = {"-fstrip", "-dead_strip"}
}
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the optimize flag
function nf_optimize(self, level)
local maps =
{
none = "-O Debug"
, fast = "-O ReleaseSafe"
, fastest = "-O ReleaseFast"
, smallest = "-O ReleaseSmall"
, aggressive = "-O ReleaseFast"
}
return maps[level]
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L", dir}
end
-- make the framework flag
function nf_framework(self, framework)
return {"-framework", framework}
end
-- make the frameworkdir flag
function nf_frameworkdir(self, frameworkdir)
return {"-F", path.translate(frameworkdir)}
end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
dir = path.translate(dir)
if self:is_plat("macosx") then
return {"-rpath", (dir:gsub("%$ORIGIN", "@loader_path"))}
else
return {"-rpath", (dir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
end
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
local argv = {}
if targetkind == "binary" then
table.insert(argv, "build-exe")
elseif targetkind == "static" or targetkind == "shared" then
table.insert(argv, "build-lib")
else
raise("unknown target kind(%s)!", targetkind)
end
table.join2(argv, flags, "-femit-bin=" .. targetfile, objectfiles)
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("build-obj", flags, "-femit-bin=" .. objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags)
os.mkdir(path.directory(objectfile))
os.runv(compargv(self, sourcefile, objectfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/rustc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file rustc.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- init it
function init(self)
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
none = "-C opt-level=0"
, fast = "-C opt-level=1"
, faster = "-C opt-level=2"
, fastest = "-C opt-level=3"
, smallest = "-C opt-level=s"
, aggressive = "-C opt-level=z"
}
return maps[level]
end
end
-- make the symbol flag
function nf_symbol(self, level)
local maps =
{
debug = "-C debuginfo=2"
}
return maps[level]
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. dir}
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the frameworkdir flag, crate module dependency directories
function nf_frameworkdir(self, frameworkdir)
return {"-L", "dependency=" .. frameworkdir}
end
-- make the framework flag, crate module
function nf_framework(self, framework)
local basename = path.basename(framework)
-- return "mycrate" from libmycrate-f882feaebb8ba0ca.rlib or libmycrate.rlib
local cratename = basename:match("lib(.-)%-.-") or basename:match("lib(.+)")
if not cratename and framework:endswith(".dll") then
-- @see https://github.com/xmake-io/xmake/issues/5156#issuecomment-2143978086
-- mycrate-f882feaebb8ba0ca.dll or mycrate.dll
cratename = basename:split("-", {plain = true})[1]
end
if cratename then
return {"--extern", cratename .. "=" .. framework}
end
end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
dir = path.translate(dir)
if self:has_flags({"-C", "link-arg=-Wl,-rpath=$ORIGIN"}, "ldflags") then
return {"-C", "link-arg=-Wl,-rpath=" .. (dir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
elseif self:has_flags({"-C", "link-arg=-Xlinker", "-C", "link-arg=-rpath", "-C", "link-arg=-Xlinker", "-C", "link-arg=@loader_path"}, "ldflags") then
return {"-C", "link-arg=-Xlinker",
"-C", "link-arg=-rpath",
"-C", "link-arg=-Xlinker",
"-C", "link-arg=" .. (dir:gsub("%$ORIGIN", "@loader_path"))}
end
end
-- make the build arguments list
function buildargv(self, sourcefiles, targetkind, targetfile, flags)
-- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
local flags_extra = {}
if targetkind == "shared" and self:is_plat("macosx", "iphoneos", "watchos") then
table.insert(flags_extra, "-C")
table.insert(flags_extra, "link-arg=-Xlinker")
table.insert(flags_extra, "-C")
table.insert(flags_extra, "link-arg=-install_name")
table.insert(flags_extra, "-C")
table.insert(flags_extra, "link-arg=-Xlinker")
table.insert(flags_extra, "-C")
table.insert(flags_extra, "link-arg=@rpath/" .. path.filename(targetfile))
end
return self:program(), table.join(flags, flags_extra, "-o", targetfile, sourcefiles)
end
-- build the target file
function build(self, sourcefiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefiles, objectfile, flags)
return self:program(), table.join("--emit", "obj", flags, "-o", objectfile, sourcefiles)
end
-- compile the source file
function compile(self, sourcefiles, objectfile, dependinfo, flags)
os.mkdir(path.directory(objectfile))
os.runv(compargv(self, sourcefiles, objectfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/tcc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file tcc.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.config")
import("core.project.project")
import("core.project.policy")
import("core.language.language")
-- init it
function init(self)
-- init shflags
self:set("shflags", "-shared", "-rdynamic")
-- init cxflags for the kind: shared
self:set("shared.cxflags", "-fPIC")
-- init flags map
self:set("mapflags",
{
-- warnings
["-W1"] = "-Wall"
, ["-W2"] = "-Wall"
, ["-W3"] = "-Wall"
, ["-W4"] = "-Wall -Wunsupported"
-- strip
, ["-s"] = "-s"
, ["-S"] = "-S"
})
end
-- make the strip flag
function nf_strip(self, level)
local maps =
{
debug = "-S"
, all = "-s"
}
return maps[level]
end
-- make the symbol flag
function nf_symbol(self, level)
local maps =
{
debug = "-g"
, hidden = "-fvisibility=hidden"
}
return maps[level]
end
-- make the warning flag
function nf_warning(self, level)
local maps =
{
none = "-w"
, less = "-W1"
, more = "-W3"
, all = "-Wall"
, allextra = "-Wall -Wunsupported -Wwrite-strings -Wimplicit-function-declaration"
, everything = "-Wall -Wunsupported -Wwrite-strings -Wimplicit-function-declaration"
, error = "-Werror"
}
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the link flag
function nf_link(self, lib)
return "-l" .. lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. dir}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
local argv
if targetkind == "static" then
argv = table.join("-ar", "cr", targetfile, objectfiles)
else
argv = table.join("-o", targetfile, objectfiles, flags)
end
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armasm_msvc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armasm_msvc.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("core.language.language")
import("utils.progress")
-- init it
function init(self)
self:add("asflags", "-nologo")
end
-- make the symbol flag
function nf_symbol(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps =
{
debug = "-g"
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
end
end
-- make the define flag
-- eg.
-- add_defines("MACRO") -> --pd "MACRO SETA 1
-- add_defines("MACRO=3") -> --pd "MACRO SETA 3"
function nf_define(self, macro)
local def = macro:split("=")
local key = def[1]:trim()
local value = "1"
if #def == 2 then
value = def[2]:trim()
end
return {"-pd", key .. " SETA " .. value}
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-i", dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join(flags, "-o", objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
try
{
function ()
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- find the start line of error
local lines = tostring(errors):split("\n")
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 or not option.get("verbose") then
if start == 0 then start = 1 end
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
end
-- raise compiling errors
raise(errors)
end
},
finally
{
function (ok, warnings)
-- print some warnings
if warnings and #warnings > 0 and policy.build_warnings(opt) then
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cosmocc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cosmocc.lua
--
-- inherit gcc
inherit("gcc")
-- init it
function init(self)
_super.init(self)
end
-- make the strip flag
function nf_strip(self, level)
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
if is_host("windows") then
targetfile = targetfile:gsub("\\", "/")
local objectfiles_new = {}
for idx, objectfile in ipairs(objectfiles) do
objectfiles_new[idx] = objectfiles[idx]:gsub("\\", "/")
end
objectfiles = objectfiles_new
end
return _super.link(self, objectfiles, targetkind, targetfile, flags, table.join(opt, {shell = true}))
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
opt = opt or {}
if is_host("windows") then
sourcefile = sourcefile:gsub("\\", "/")
objectfile = objectfile:gsub("\\", "/")
local target = opt.target
if target then
target:set("policy", "build.ccache", false)
end
end
return _super.compile(self, sourcefile, objectfile, dependinfo, flags, table.join(opt, {shell = true}))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cl.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cl.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.base.hashset")
import("core.project.project")
import("core.project.policy")
import("core.language.language")
import("private.tools.vstool")
import("private.tools.cl.parse_include")
import("private.cache.build_cache")
import("private.service.distcc_build.client", {alias = "distcc_build_client"})
import("utils.progress")
-- init it
function init(self)
-- init cxflags
self:set("cxflags", "-nologo")
-- init flags map
self:set("mapflags",
{
-- optimize
["-O0"] = "-Od"
, ["-Os"] = "-O1"
, ["-O3"] = "-Ox"
, ["-Ofast"] = "-Ox -fp:fast"
, ["-fomit-frame-pointer"] = "-Oy"
-- symbols
, ["-g"] = "-Z7"
, ["-fvisibility=.*"] = ""
-- warnings
, ["-Weverything"] = "-Wall"
, ["-Wextra"] = "-W4"
, ["-Wall"] = "-W3" -- = "-Wall" will enable too more warnings
, ["-W1"] = "-W1"
, ["-W2"] = "-W2"
, ["-W3"] = "-W3"
, ["-Werror"] = "-WX"
, ["-Wswitch"] = "-we4062"
, ["-Wswitch-enum"] = "-we4061"
, ["%-Wno%-error=.*"] = ""
, ["%-fno%-.*"] = ""
-- vectorexts
, ["-mmmx"] = "-arch:MMX"
, ["-msse"] = "-arch:SSE"
, ["-msse2"] = "-arch:SSE2"
, ["-msse3"] = "-arch:SSE3"
, ["-mssse3"] = "-arch:SSSE3"
, ["-mavx"] = "-arch:AVX"
, ["-mavx2"] = "-arch:AVX2"
, ["-mfpu=.*"] = ""
-- language
, ["-ansi"] = ""
, ["-std=c99"] = "-TP" -- compile as c++ files because msvc doesn't support c99
, ["-std=c11"] = "-std:c11"
, ["-std=c17"] = "-std:c17"
, ["-std=c2x"] = "-std:clatest"
, ["-std=c23"] = "-std:clatest"
, ["-std=gnu99"] = "-TP" -- compile as c++ files because msvc doesn't support c99
, ["-std=gnu11"] = "-std:c11"
, ["-std=gnu17"] = "-std:c17"
, ["-std=gnu2x"] = "-std:clatest"
, ["-std=gnu23"] = "-std:clatest"
, ["-std=.*"] = ""
-- others
, ["-ftrapv"] = ""
})
end
-- make the symbol flags
function nf_symbols(self, levels, opt)
local flags = nil
local values = hashset.from(levels)
if values:has("debug") then
flags = {}
if values:has("edit") then
table.insert(flags, "-ZI")
elseif values:has("embed") then
table.insert(flags, "-Z7")
else
table.insert(flags, "-Zi")
end
-- generate *.pdb file
local symbolfile = nil
local target = opt.target
if target and target.symbolfile and not values:has("embed") then
symbolfile = target:symbolfile()
end
if symbolfile then
-- ensure the object directory
local symboldir = path.directory(symbolfile)
if not os.isdir(symboldir) then
os.mkdir(symboldir)
end
-- check and add symbol output file
--
-- @note we need to use `{}` to wrap it to avoid expand it
-- https://github.com/xmake-io/xmake/issues/2061#issuecomment-1042590085
local pdbflags = {"-Fd" .. (target:is_static() and symbolfile or path.join(symboldir, "compile." .. path.filename(symbolfile)))}
if self:has_flags({"-FS", "-Fd" .. os.nuldev() .. ".pdb"}, "cxflags", { flagskey = "-FS -Fd" }) then
table.insert(pdbflags, 1, "-FS")
end
table.insert(flags, pdbflags)
end
end
return flags
end
-- make the fp-model flag
function nf_fpmodel(self, level)
local maps = {
precise = "-fp:precise" -- default
, fast = "-fp:fast"
, strict = "-fp:strict"
, except = "-fp:except"
, noexcept = "-fp:except-"
}
return maps[level]
end
-- make the warning flag
function nf_warnings(self, levels)
local flags = {}
local values = hashset.from(levels)
if values:has("all") and values:has("extra") then
table.insert(flags, "-W4")
values:remove("all")
values:remove("extra")
end
local maps = {
none = "-w"
, less = "-W1"
, more = "-W3"
, all = "-W3" -- = "-Wall" will enable too more warnings
, allextra = "-W4"
, everything = "-Wall"
, error = "-WX"
}
for _, level in values:orderkeys() do
local flag = maps[level]
if flag then
table.insert(flags, flag)
end
end
if #flags > 0 then
return flags
end
end
-- make the optimize flag
function nf_optimize(self, level)
local maps =
{
none = "-Od"
, faster = "-Ox"
, fastest = "-O2"
, smallest = "-O1 -GL" -- /GL and (/OPT:REF is on by default in linker), we need to enable /ltcg
, aggressive = "-O2"
}
return maps[level]
end
-- make the runtime flag
function nf_runtime(self, runtime)
if runtime then
local maps = {
MT = "-MT",
MD = "-MD",
MTd = "-MTd",
MDd = "-MDd"
}
return maps[runtime]
end
end
-- make the vector extension flag
function nf_vectorext(self, extension)
local maps =
{
sse = "-arch:SSE"
, sse2 = "-arch:SSE2"
, ["sse4.2"] = "/d2archSSE42" -- the only undocumented way works, @see https://github.com/xmake-io/xmake/issues/3786
, avx = "-arch:AVX"
, avx2 = "-arch:AVX2"
, avx512 = "-arch:AVX512" -- for msvc 2019+ avx512 support
, fma = "-arch:AVX2"
, all = {"-arch:SSE", "-arch:SSE2", "/d2archSSE42", "-arch:AVX", "-arch:AVX2", "-arch:AVX512"}
}
local flags = maps[extension]
if flags then
-- @see https://github.com/xmake-io/xmake/issues/5499
if type(flags) == "string" then
return flags
else
local result = {}
for _, flag in ipairs(flags) do
if self:has_flags(flag, "cxflags") then
table.insert(result, flag)
end
end
if #result > 0 then
return table.unwrap(result)
end
end
end
end
-- make the language flag
-- clang-cl should also use it, @see https://github.com/xmake-io/xmake/issues/2211#issuecomment-1083322178
function nf_language(self, stdname)
-- the stdc maps
if _g.cmaps == nil then
_g.cmaps =
{
-- stdc
c99 = "-TP" -- compile as c++ files because older msvc only support c89
, gnu99 = "-TP"
, c11 = {"-std:c11", "-std:clatest", "-TP"}
, gnu11 = {"-std:c11", "-std:clatest", "-TP"}
, c17 = {"-std:c17", "-std:clatest", "-TP"}
, gnu17 = {"-std:c17", "-std:clatest", "-TP"}
, c2x = {"-std:c23", "-std:clatest", "-TP"}
, gnu2x = {"-std:c23", "-std:clatest", "-TP"}
, c23 = {"-std:c23", "-std:clatest", "-TP"}
, gnu23 = {"-std:c23", "-std:clatest", "-TP"}
, clatest = {"-std:clatest", "-std:c23", "-std:c17", "-std:c11", "-TP"}
, gnulatest = {"-std:clatest", "-std:c23", "-std:c17", "-std:c11", "-TP"}
}
end
-- the stdc++ maps
if _g.cxxmaps == nil then
_g.cxxmaps =
{
cxx11 = "-std:c++11"
, gnuxx11 = "-std:c++11"
, cxx14 = "-std:c++14"
, gnuxx14 = "-std:c++14"
, cxx17 = "-std:c++17"
, gnuxx17 = "-std:c++17"
, cxx1z = "-std:c++17"
, gnuxx1z = "-std:c++17"
, cxx20 = {"-std:c++20", "-std:c++latest"}
, gnuxx20 = {"-std:c++20", "-std:c++latest"}
, cxx2a = {"-std:c++20", "-std:c++latest"}
, gnuxx2a = {"-std:c++20", "-std:c++latest"}
, cxx23 = {"-std:c++23", "-std:c++latest"}
, gnuxx23 = {"-std:c++23", "-std:c++latest"}
, cxx2b = {"-std:c++23", "-std:c++latest"}
, gnuxx2b = {"-std:c++23", "-std:c++latest"}
, cxx26 = {"-std:c++26", "-std:c++latest"}
, gnuxx26 = {"-std:c++26", "-std:c++latest"}
, cxxlatest = "-std:c++latest"
, gnuxxlatest = "-std:c++latest"
}
local cxxmaps2 = {}
for k, v in pairs(_g.cxxmaps) do
cxxmaps2[k:gsub("xx", "++")] = v
end
table.join2(_g.cxxmaps, cxxmaps2)
end
-- select maps
local maps = _g.cmaps
if self:kind() == "cxx" or self:kind() == "mxx" then
maps = _g.cxxmaps
end
-- map it
local result = maps[stdname]
if type(result) == "table" then
for _, v in ipairs(result) do
if self:has_flags(v, "cxflags") then
result = v
maps[stdname] = result
return result
end
end
else
return result
end
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. path.translate(dir)}
end
-- make the force include flag
function nf_forceinclude(self, headerfile, opt)
local target = opt.target
local sourcekinds = target and target:extraconf("forceincludes", headerfile, "sourcekinds")
if not sourcekinds or table.contains(table.wrap(sourcekinds), self:kind()) then
return {"-FI", headerfile}
end
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
local has_external_includedir = _g._HAS_EXTERNAL_INCLUDEDIR
if has_external_includedir == nil then
if self:has_flags({"-external:W0", "-external:I" .. os.args(path.translate(dir))}, "cxflags", {flagskey = "cl_external_includedir"}) then
has_external_includedir = 2 -- full support
elseif self:has_flags({"-experimental:external", "-external:W0", "-external:I" .. os.args(path.translate(dir))}, "cxflags", {flagskey = "cl_external_includedir_experimental"}) then
has_external_includedir = 1 -- experimental support
end
has_external_includedir = has_external_includedir or 0
_g._HAS_EXTERNAL_INCLUDEDIR = has_external_includedir
end
if has_external_includedir >= 2 then
return {"-external:W0", "-external:I" .. path.translate(dir)}
elseif has_external_includedir >= 1 then
return {"-experimental:external", "-external:W0", "-external:I" .. path.translate(dir)}
else
return nf_includedir(self, dir)
end
end
-- make the exception flag
--
-- e.g.
-- set_exceptions("cxx")
-- set_exceptions("no-cxx")
function nf_exception(self, exp)
local maps = {
cxx = "/EHsc",
["no-cxx"] = "/EHsc-"
}
return maps[exp]
end
-- make the encoding flag
-- @see https://github.com/xmake-io/xmake/issues/2471
--
-- e.g.
-- set_encodings("utf-8")
-- set_encodings("source:utf-8", "target:utf-8")
function nf_encoding(self, encoding)
local kind
local charset
local splitinfo = encoding:split(":")
if #splitinfo > 1 then
kind = splitinfo[1]
charset = splitinfo[2]
else
charset = encoding
end
local charsets = {
["utf-8"] = "utf-8",
utf8 = "utf-8",
gb2312 = "gb2312"
}
local flags = {}
charset = charsets[charset:lower()]
if charset then
if not kind and charset == "utf-8" then
table.insert(flags, "/utf-8")
else
if kind == "source" or not kind then
table.insert(flags, "-source-charset:" .. charset)
end
if kind == "target" or not kind then
table.insert(flags, "-execution-charset:" .. charset)
end
end
end
if #flags > 0 then
return flags
end
end
-- make the c precompiled header flag
function nf_pcheader(self, pcheaderfile, opt)
if self:kind() == "cc" then
local target = opt.target
local objectfiles = target:objectfiles()
if objectfiles then
table.insert(objectfiles, target:pcoutputfile("c") .. ".obj")
end
return {"-Yu" .. path.absolute(pcheaderfile), "-FI" .. path.absolute(pcheaderfile), "-Fp" .. target:pcoutputfile("c")}
end
end
-- make the c++ precompiled header flag
function nf_pcxxheader(self, pcheaderfile, opt)
if self:kind() == "cxx" then
local target = opt.target
local objectfiles = target:objectfiles()
if objectfiles then
table.insert(objectfiles, target:pcoutputfile("cxx") .. ".obj")
end
return {"-Yu" .. path.absolute(pcheaderfile), "-FI" .. path.absolute(pcheaderfile), "-Fp" .. target:pcoutputfile("cxx")}
end
end
-- add the special flags for the given source file of target
--
-- @note only it called when fileconfig is set
--
function add_sourceflags(self, sourcefile, fileconfig, target, targetkind)
-- add language type flags explicitly if the sourcekind is changed.
--
-- because compiler maybe compile `.c` as c++.
-- e.g.
-- add_files("*.c", {sourcekind = "cxx"})
--
local sourcekind = fileconfig.sourcekind
if sourcekind and sourcekind ~= language.sourcekind_of(sourcefile) then
local maps = {cc = "-TC", cxx = "-TP"}
return maps[sourcekind]
end
end
-- make the compile arguments list for the precompiled header
function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
-- remove "-Yuxxx.h" and "-Fpxxx.pch"
local pchflags = {}
for _, flag in ipairs(flags) do
if not flag:find("-Yu", 1, true) and not flag:find("-Fp", 1, true) then
table.insert(pchflags, flag)
end
end
-- compile as c/c++ source file
if self:kind() == "cc" then
table.insert(pchflags, "-TC")
elseif self:kind() == "cxx" then
table.insert(pchflags, "-TP")
end
-- make the compile arguments list
return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcoutputfile, "-Fo" .. pcoutputfile .. ".obj", pcheaderfile)
end
-- has /sourceDependencies xxx.json @see https://github.com/xmake-io/xmake/issues/868?
function _has_source_dependencies(self)
local has_source_dependencies = _g._HAS_SOURCE_DEPENDENCIES
if has_source_dependencies == nil then
local source_dependencies_jsonfile = os.tmpfile() .. ".json"
if self:has_flags("/sourceDependencies " .. source_dependencies_jsonfile, "cxflags", {flagskey = "cl_sourceDependencies",
on_check = function (ok, errors)
-- even if cl does not support /sourceDependencies, it will not interrupt compilation
if ok and not os.isfile(source_dependencies_jsonfile) then
ok = false
end
return ok, errors
end}) then
has_source_dependencies = true
end
has_source_dependencies = has_source_dependencies or false
_g._HAS_SOURCE_DEPENDENCIES = has_source_dependencies
end
return has_source_dependencies
end
function _is_in_vstudio()
local is_in_vstudio = _g._IS_IN_VSTUDIO
if is_in_vstudio == nil then
is_in_vstudio = os.getenv("XMAKE_IN_VSTUDIO") or false
_g._IS_IN_VSTUDIO = is_in_vstudio
end
return is_in_vstudio
end
-- get preprocess file path
function _get_cppfile(sourcefile, objectfile)
return path.join(path.directory(objectfile), "__cpp_" .. path.basename(objectfile) .. path.extension(sourcefile))
end
-- do preprocess
function _preprocess(program, argv, opt)
-- get flags and source file
local flags = {}
local cppflags = {}
local skipped = 0
local objectfile
local pdbfile
local sourcefile = argv[#argv]
local extension = path.extension(sourcefile)
for _, flag in ipairs(argv) do
if flag:startswith("-Fo") or flag:startswith("/Fo") then
objectfile = flag:sub(4)
break
end
-- get preprocessor flags
-- TODO fix precompiled header bug for /P + /FI
local target = opt.target
if target and (flag:startswith("-FI") or flag:startswith("/FI")) then
local pcheaderfile = target:get("pcheader") or target:get("pcxxheader")
if pcheaderfile then
flag = "-FI" .. path.absolute(pcheaderfile)
end
end
table.insert(cppflags, flag)
-- get compiler flags
if flag == "-showIncludes" or flag == "/showIncludes" or
(flag:startswith("-I") and #flag > 2) or (flag:startswith("/I") and #flag > 2) or
flag:startswith("-external:") or flag:startswith("/external:") then
skipped = 1
-- @note we cannot ignore precompiled flags when compiling pch, @see https://github.com/xmake-io/xmake/issues/2885
elseif not extension:startswith(".h") and (
flag:startswith("-Yu") or flag:startswith("/Yu") or
flag:startswith("-FI") or flag:startswith("/FI") or
flag:startswith("-Fp") or flag:startswith("/Fp")) then
skipped = 1
elseif flag == "-I" or flag == "-sourceDependencies" or flag == "/sourceDependencies" then
skipped = 2
elseif opt.remote and flag:startswith("-Fd") or flag:startswith("/Fd") then
skipped = 1
pdbfile = flag:sub(4) --TODO handle remote pdb
end
if skipped > 0 then
skipped = skipped - 1
else
table.insert(flags, flag)
end
end
assert(objectfile and sourcefile, "%s: iorunv(%s): invalid arguments!", self, program)
-- is precompiled header?
if objectfile:endswith(".pch") then
return false
end
-- disable linemarkers?
local linemarkers = _g.linemarkers
if linemarkers == nil then
if os.isfile(os.projectfile()) and project.policy("preprocessor.linemarkers") == false then
linemarkers = false
else
linemarkers = true
end
_g.linemarkers = linemarkers
end
-- do preprocess
local cppfile = _get_cppfile(sourcefile, objectfile)
local cppfiledir = path.directory(cppfile)
if not os.isdir(cppfiledir) then
os.mkdir(cppfiledir)
end
if linemarkers == false then
table.insert(cppflags, "-EP")
else
-- we cannot use `/P`, @see https://github.com/xmake-io/xmake/issues/2445
table.insert(cppflags, "-E")
end
table.insert(cppflags, sourcefile)
return try{ function()
-- https://github.com/xmake-io/xmake/issues/2902#issuecomment-1326934902
local outfile = cppfile
local errfile = os.tmpfile() .. ".i.err"
local inherit_handles_safely = true
if not winos.inherit_handles_safely() then
outfile = os.tmpfile() .. ".i.out"
inherit_handles_safely = false
end
os.execv(program, winos.cmdargv(cppflags), table.join(opt, {stdout = outfile, stderr = errfile}))
local errdata
if os.isfile(errfile) then
errdata = io.readfile(errfile)
end
os.tryrm(errfile)
if not inherit_handles_safely then
os.cp(outfile, cppfile)
os.tryrm(outfile)
end
-- includes information will be output to stderr instead of stdout now
return {outdata = errdata, errdata = errdata,
sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags,
pdbfile = pdbfile}
end}
end
-- compile preprocessed file
function _compile_preprocessed_file(program, cppinfo, opt)
local outdata, errdata = vstool.iorunv(program, winos.cmdargv(table.join(cppinfo.cppflags, "-Fo" .. cppinfo.objectfile, cppinfo.cppfile)), opt)
-- we need to get warning information from output
cppinfo.outdata = outdata
cppinfo.errdata = errdata
end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
opt = opt or {}
local function _compile_fallback()
local program, argv = compargv(self, sourcefile, objectfile, compflags, opt)
return vstool.iorunv(program, argv, {envs = self:runenvs()})
end
local cppinfo
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true}))
cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
target = opt.target, tool = self, remote = true})
elseif build_cache.is_enabled(opt.target) and build_cache.is_supported(self:kind()) then
local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true}))
cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
target = opt.target, tool = self})
end
if cppinfo then
return cppinfo.outdata, cppinfo.errdata
else
return _compile_fallback()
end
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags, opt)
-- precompiled header?
local extension = path.extension(sourcefile)
if (extension:startswith(".h") or extension == ".inl") then
return _compargv_pch(self, sourcefile, objectfile, flags)
end
-- make the compile arguments list
local argv = table.join("-c", flags, "-Fo" .. objectfile, sourcefile)
return self:program(), (opt and opt.rawargs) and argv or winos.cmdargv(argv)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
local objectdir = path.directory(objectfile)
if not os.isdir(objectdir) then
os.mkdir(objectdir)
end
-- compile it
local depfile = nil
local outdata = try
{
function ()
-- generate includes file
local compflags = flags
if dependinfo then
if _has_source_dependencies(self) then
depfile = os.tmpfile() .. ".json"
compflags = table.join(flags, "/sourceDependencies", depfile)
else
compflags = table.join(flags, "-showIncludes")
end
end
-- we need to show full file path to goto error position if xmake is called in vstudio
-- https://github.com/xmake-io/xmake/issues/1049
if _is_in_vstudio() then
if compflags == flags then
compflags = table.join(flags, "-FC")
else
table.join2(compflags, "-FC")
end
end
-- do compile
return _compile(self, sourcefile, objectfile, compflags, opt)
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- remove preprocess file
local cppfile = _get_cppfile(sourcefile, objectfile)
os.tryrm(cppfile)
-- use cl/stdout as errors first from vstool.iorunv()
if type(errors) == "table" then
local errs = errors.stdout or ""
errs = errs .. (errors.stderr or "")
errors = errs
end
local results = ""
if depfile then
results = tostring(errors)
else
-- filter includes notes: "Note: including file: xxx.h", @note maybe not english language
for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do
line = line:rtrim()
if not parse_include(line) then
results = results .. line .. "\r\n"
end
end
end
if not option.get("verbose") then
results = results .. "\n ${yellow}> in ${bright}" .. sourcefile
end
raise(results)
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and policy.build_warnings(opt) then
local output = outdata or ""
if #output:trim() == 0 then
output = errdata or ""
end
if #output:trim() > 0 then
local lines = {}
for _, line in ipairs(output:split("\n", {plain = true})) do
line = line:rtrim()
if line:match("warning %a+[0-9]+%s*:") then
table.insert(lines, line)
end
end
if #lines > 0 then
if not option.get("diagnosis") then
lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines))
end
local warnings = table.concat(lines, "\r\n")
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", warnings)
end
end
end
end
}
}
-- generate the dependent includes
if dependinfo then
if depfile and os.isfile(depfile) then
dependinfo.depfiles_cl_json = io.readfile(depfile)
os.tryrm(depfile)
elseif outdata then
dependinfo.depfiles_cl = outdata
end
end
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ld64_lld.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ld64_lld.lua
--
-- imports
inherit("ld")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/armlink.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file armlink.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.project.policy")
import("utils.progress")
function init(self)
end
-- make the link flag
function nf_link(self, lib)
return "lib" .. lib .. ".a"
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"--userlibpath", dir}
end
-- make runtime flag
function nf_runtime(self, runtime)
if runtime == "microlib" then
return "--library_type=microlib"
end
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
local argv = table.join("-o", targetfile, objectfiles, flags)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
if #argv > 0 and argv[1] and argv[1]:startswith("@") then
argv[1] = argv[1]:replace("@", "", {plain = true})
table.insert(argv, 1, "--via")
end
end
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
try
{
function ()
os.mkdir(path.directory(targetfile))
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
return os.iorunv(program, argv)
end,
catch
{
function (errors)
-- parse and strip errors
local lines = errors and tostring(errors):split('\n', {plain = true}) or {}
if not option.get("verbose") then
-- find the start line of error
local start = 0
for index, line in ipairs(lines) do
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 then
lines = table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start)))
end
end
-- raise errors
local results = #lines > 0 and table.concat(lines, "\n") or ""
if not option.get("verbose") then
results = results .. "\n ${yellow}> in ${bright}" .. sourcefile
end
raise(results)
end
},
finally
{
function (ok, outdata, errdata)
-- show warnings?
if ok and errdata and #errdata > 0 and policy.build_warnings(opt) then
local lines = errdata:split('\n', {plain = true})
if #lines > 0 then
if not option.get("diagnosis") then
lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines))
end
local warnings = table.concat(lines, "\n")
if progress.showing_without_scroll() then
print("")
end
cprint("${color.warning}%s", warnings)
end
end
-- show echo output? e.g. --map data
-- @see https://github.com/xmake-io/xmake/issues/4420
if ok and outdata and #outdata > 0 and option.get("diagnosis") then
print(outdata)
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/link.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file link.lua
--
-- imports
import("core.project.config")
import("private.tools.vstool")
-- init it
function init(self)
-- init ldflags
self:set("ldflags", "-nologo", "-dynamicbase", "-nxcompat")
-- init arflags
self:set("arflags", "-nologo")
-- init shflags
self:set("shflags", "-nologo")
-- init flags map
self:set("mapflags",
{
-- strip
["-s"] = ""
, ["-S"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- get the property
function get(self, name)
local values = self._INFO[name]
if name == "ldflags" or name == "arflags" or name == "shflags" then
-- switch architecture, @note does cache it in init() for generating vs201x project
values = table.join(values, "-machine:" .. (self:arch() or "x86"))
end
return values
end
-- make the strip flag
function nf_strip(self, level, opt)
-- link.exe/arm64 does not support /opt:ref, /opt:icf
local target = opt.target
if target and target:is_arch("arm64") then
return
end
-- @note we explicitly strip some useless code, because `/debug` may keep them
-- @see https://github.com/xmake-io/xmake/issues/907
if level == "all" then
-- we enable /ltcg for optimize/smallest:/Gl
local flags = {"/opt:ref", "/opt:icf"}
if target and target:get("optimize") == "smallest" then
table.insert(flags, "/ltcg")
end
return flags
elseif level == "debug" then
return {"/opt:ref", "/opt:icf"}
end
end
-- make the symbol flag
function nf_symbol(self, level, opt)
-- debug? generate *.pdb file
local flags = nil
local target = opt.target
if target then
if target:type() == "target" then
if level == "debug" and (target:is_binary() or target:is_shared()) then
flags = {"-debug", "-pdb:" .. target:symbolfile()}
end
else -- for option
if level == "debug" then
flags = "-debug"
end
end
end
return flags
end
-- make the link flag
function nf_link(self, lib)
if not lib:endswith(".lib") and not lib:endswith(".obj") then
lib = lib .. ".lib"
end
return lib
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the runtime flag
function nf_runtime(self, runtime)
if runtime and runtime:startswith("MT") then
return "-nodefaultlib:msvcrt.lib"
end
end
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-libpath:" .. path.translate(dir)}
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
local argv = table.join(flags, "-out:" .. targetfile, objectfiles)
if not opt.rawargs then
argv = winos.cmdargv(argv)
end
-- @note we cannot put -lib/-dll to @args.txt
if targetkind == "static" then
table.insert(argv, 1, "-lib")
elseif targetkind == "shared" then
table.insert(argv, 1, "-dll")
end
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
-- ensure the target directory
os.mkdir(path.directory(targetfile))
try
{
function ()
local toolchain = self:toolchain()
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
if toolchain and toolchain:name() == "masm32" then
os.iorunv(program, argv, {envs = self:runenvs()})
else
-- use vstool to link and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528
vstool.runv(program, argv, {envs = self:runenvs()})
end
end,
catch
{
function (errors)
-- use link/stdout as errors first from vstool.iorunv()
if type(errors) == "table" then
local errs = errors.stdout or ""
if #errs:trim() == 0 then
errs = errors.stderr or ""
end
errors = errs
end
os.raise(tostring(errors))
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/cc.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file cc.lua
--
-- inherit gcc
inherit("gcc")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/swift_frontend.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file swift_frontend.lua
--
-- imports
import("core.project.config")
import("core.language.language")
-- init it
function init(self)
-- init flags map
self:set("mapflags", {
-- symbols
["-fvisibility=hidden"] = ""
-- warnings
, ["-w"] = "-suppress-warnings"
, ["-W%d*"] = "-warn-swift3-objc-inference-minimal"
, ["-Wall"] = "-warn-swift3-objc-inference-complete"
, ["-Wextra"] = "-warn-swift3-objc-inference-complete"
, ["-Weverything"] = "-warn-swift3-objc-inference-complete"
, ["-Werror"] = "-warnings-as-errors"
-- optimize
, ["-O0"] = "-Onone"
, ["-Ofast"] = "-Ounchecked"
, ["-O.*"] = "-O"
-- vectorexts
, ["-m.*"] = ""
-- strip
, ["-s"] = ""
, ["-S"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the symbol flag
function nf_symbol(self, level)
local maps = {
debug = "-g"
}
return maps[level]
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-suppress-warnings"
, less = "-warn-swift3-objc-inference-minimal"
, more = "-warn-swift3-objc-inference-minimal"
, all = "-warn-swift3-objc-inference-complete"
, everything = "-warn-swift3-objc-inference-complete"
, error = "-warnings-as-errors"
}
return maps[level]
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = {
none = "-Onone"
, fast = "-O"
, faster = "-O"
, fastest = "-O"
, smallest = "-O"
, aggressive = "-Ounchecked"
}
return maps[level]
end
end
-- make the vector extension flag
function nf_vectorext(self, extension)
local maps = {
mmx = "-mmmx"
, sse = "-msse"
, sse2 = "-msse2"
, sse3 = "-msse3"
, ssse3 = "-mssse3"
, avx = "-mavx"
, avx2 = "-mavx2"
, neon = "-mfpu=neon"
}
return maps[extension]
end
-- make the define flag
function nf_define(self, macro)
return {"-Xcc", "-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return {"-Xcc", "-U" .. macro}
end
-- make the framework flag
function nf_framework(self, framework)
return {"-framework", framework}
end
-- make the frameworkdir flag
function nf_frameworkdir(self, frameworkdir)
return {"-F", frameworkdir}
end
-- make the compile arguments list
-- @see https://github.com/xmake-io/xmake/issues/3916
function compargv(self, sourcefile, objectfile, flags)
local flags_new = {}
for _, flag in ipairs(flags) do
-- we need remove primary file in swift.build rule
if flag ~= sourcefile then
table.insert(flags_new, flag)
end
end
return self:program(), table.join("-c", flags_new, "-o", objectfile, "-primary-file", sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags)
os.mkdir(path.directory(objectfile))
os.runv(compargv(self, sourcefile, objectfile, flags))
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/ml.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ml.lua
--
-- imports
import("private.tools.vstool")
import("core.base.hashset")
-- init it
--
-- @see https://docs.microsoft.com/en-us/cpp/assembler/masm/ml-and-ml64-command-line-reference
--
function init(self)
-- init asflags
self:set("asflags", "-nologo")
-- init flags map
self:set("mapflags",
{
-- symbols
["-g"] = "-Z7"
, ["-fvisibility=.*"] = ""
-- warnings
, ["-W1"] = "-W1"
, ["-W2"] = "-W2"
, ["-W3"] = "-W3"
, ["-Wall"] = "-W3" -- /W level Sets the warning level, where level = 0, 1, 2, or 3.
, ["-Wextra"] = "-W3"
, ["-Weverything"] = "-W3"
, ["-Werror"] = "-WX"
, ["%-Wno%-error=.*"] = ""
-- others
, ["-ftrapv"] = ""
, ["-fsanitize=address"] = ""
})
end
-- make the symbol flags
function nf_symbols(self, levels)
local flags = nil
local values = hashset.from(levels)
if values:has("debug") then
flags = {}
if values:has("edit") then
table.insert(flags, "-ZI")
elseif values:has("embed") then
table.insert(flags, "-Z7")
else
table.insert(flags, "-Zi")
end
end
return flags
end
-- make the warning flag
function nf_warning(self, level)
local maps =
{
none = "-w"
, less = "-W1"
, more = "-W3"
, all = "-W3"
, everything = "-W3"
, error = "-WX"
}
return maps[level]
end
-- make the define flag
function nf_define(self, macro)
return {"-D" .. macro}
end
-- make the undefine flag
function nf_undefine(self, macro)
return "-U" .. macro
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
-- we need to set the default -Gd option for the x86 architecture,
-- if the other calling convention flags are not set
--
-- we can't directly remove -Gd. This is not only for backward compatibility,
-- but also to simplify mixed compilation with c programs.
--
-- although this may affect some performance,
-- it only takes effect under x86 asm, so there will be no major performance issues.
--
-- @see https://github.com/xmake-io/xmake/issues/1779
--
if not self:program():find("64", 1, true) and
not table.contains(flags, "-Gc", "/Gc", "-GZ", "/GZ") then
table.insert(flags, "-Gd")
end
return self:program(), table.join("-c", flags, "-Fo" .. objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
try
{
function ()
-- @note we don't need to use vstool.runv to enable unicode output for ml.exe
local program, argv = compargv(self, sourcefile, objectfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end,
catch
{
function (errors)
-- use link/stdout as errors first from vstool.iorunv()
if type(errors) == "table" then
local errs = errors.stdout or ""
if #errs:trim() == 0 then
errs = errors.stderr or ""
end
errors = errs
end
raise(tostring(errors))
end
}
}
end
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/icx.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file icc.lua
--
-- inherit gcc
inherit("clang")
|
0 | repos/xmake/xmake/modules/core | repos/xmake/xmake/modules/core/tools/dmd.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file dmd.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- init it
function init(self)
-- init arflags
self:set("dcarflags", "-lib")
-- init shflags
self:set("dcshflags", "-shared")
-- add -fPIC for shared
if not self:is_plat("windows", "mingw") then
self:add("dcshflags", "-fPIC")
self:add("shared.dcflags", "-fPIC")
end
end
-- make the optimize flag
function nf_optimize(self, level)
-- only for source kind
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps =
{
fast = "-O"
, faster = {"-O", "-release"}
, fastest = {"-O", "-release", "-inline", "-boundscheck=off"}
, smallest = {"-O", "-release", "-boundscheck=off"}
, aggressive = {"-O", "-release", "-inline", "-boundscheck=off"}
}
return maps[level]
end
end
-- make the strip flag
function nf_strip(self, level)
if not self:is_plat("windows") then
local maps = {
debug = "-L-S",
all = "-L-s"
}
if self:is_plat("macosx", "iphoneos") then
maps.all = {"-L-x", "-L-dead_strip"}
end
return maps[level]
end
end
-- make the symbol flag
function nf_symbol(self, level)
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps = {
debug = {"-g", "-debug"}
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
elseif (kind == "dcld" or kind == "dcsh") and self:is_plat("windows") and level == "debug" then
return "-g"
end
end
-- make the warning flag
function nf_warning(self, level)
local maps = {
none = "-d",
less = "-w",
more = "-w -wi",
all = "-w -wi",
everything = "-w -wi",
error = "-de"
}
return maps[level]
end
-- make the vector extension flag
function nf_vectorext(self, extension)
local maps = {
avx = "-mcpu=avx",
avx2 = "-mcpu=avx"
}
return maps[extension]
end
-- make the includedir flag
function nf_includedir(self, dir)
return {"-I" .. dir}
end
-- make the sysincludedir flag
function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end
-- make the link flag
function nf_link(self, lib)
if self:is_plat("windows") then
return "-L" .. lib .. ".lib"
else
return "-L-l" .. lib
end
end
-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end
-- make the linkdir flag
function nf_linkdir(self, dir)
if self:is_plat("windows") then
return {"-L-libpath:" .. dir}
else
return {"-L-L" .. dir}
end
end
-- make the framework flag
function nf_framework(self, framework)
if self:is_plat("macosx") then
return {"-L-framework", "-L" .. framework}
end
end
-- make the frameworkdir flag
function nf_frameworkdir(self, frameworkdir)
if self:is_plat("macosx") then
return {"-L-F" .. path.translate(frameworkdir)}
end
end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
if not self:is_plat("windows") then
dir = path.translate(dir)
if self:has_flags("-L-rpath=" .. dir, "ldflags") then
return {"-L-rpath=" .. (dir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
elseif self:has_flags("-L-rpath -L" .. dir, "ldflags") then
return {"-L-rpath", "-L" .. (dir:gsub("%$ORIGIN", "@loader_path"))}
end
end
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
-- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
local flags_extra = {}
if targetkind == "shared" and self:is_plat("macosx") then
table.insert(flags_extra, "-L-install_name")
table.insert(flags_extra, "-L@rpath/" .. path.filename(targetfile))
end
-- init arguments
local argv = table.join(flags, flags_extra, "-of" .. targetfile, objectfiles)
if is_host("windows") and not opt.rawargs then
argv = winos.cmdargv(argv, {escape = true})
end
return self:program(), argv
end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
return self:program(), table.join("-c", flags, "-of" .. objectfile, sourcefile)
end
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
opt = opt or {}
local depfile = dependinfo and os.tmpfile() or nil
try
{
function ()
-- generate includes file
local compflags = flags
if depfile then
compflags = table.join(compflags, "-makedeps=" .. depfile)
end
-- do compile
local program, argv = compargv(self, sourcefile, objectfile, compflags)
os.iorunv(program, argv, {envs = self:runenvs()})
end,
catch
{
function (errors)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
-- parse and strip errors
local lines = errors and tostring(errors):split('\n', {plain = true}) or {}
if not option.get("verbose") then
-- find the start line of error
local start = 0
for index, line in ipairs(lines) do
if line:find("Error:", 1, true) or line:find("错误:", 1, true) then
start = index
break
end
end
-- get 16 lines of errors
if start > 0 then
lines = table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start)))
end
end
-- raise compiling errors
local results = #lines > 0 and table.concat(lines, "\n") or ""
if not option.get("verbose") then
results = results .. "\n ${yellow}> in ${bright}" .. sourcefile
end
raise(results)
end
},
finally
{
function (ok, outdata, errdata)
-- generate the dependent includes
if depfile and os.isfile(depfile) then
if dependinfo then
-- it use makefile/gcc compatiable format
dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"})
end
-- remove the temporary dependent file
os.tryrm(depfile)
end
end
}
}
end
|
0 | repos/xmake/xmake/modules/lib | repos/xmake/xmake/modules/lib/detect/find_tool.lua | --!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-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file find_tool.lua
--
-- imports
import("lib.detect.find_program")
import("lib.detect.find_programver")
import("lib.detect.find_toolname")
import("core.base.semver")
-- find tool from modules
function _find_from_modules(name, opt)
local find_tool = import("detect.tools.find_" .. name, {try = true})
if find_tool then
local program, version, toolname = find_tool(opt)
if program then
return {name = toolname or name, program = program, version = version}
end
end
end
-- find tool
function _find_tool(name, opt)
local toolname = find_toolname(name or opt.program)
if toolname then
local tool = _find_from_modules(toolname, opt)
if tool then
return tool
end
end
opt.program = opt.program or name
local program = find_program(opt.program, opt)
if not program then
return
end
local version = nil
if program and opt.version then
version = find_programver(program, opt)
end
return {name = toolname, program = program, version = version}
end
-- find tool
--
-- @param name the tool name
-- @param opt the options, e.g. {program = "xcrun -sdk macosx clang", paths = {"/usr/bin"},
-- check = function (tool) os.run("%s -h", tool) end, version = true
-- force = true, cachekey = "xxx", envs = {PATH = "xxx"}, system = false}
--
-- @return {name = "", program = "", version = ""} or nil
--
-- @code
--
-- local tool = find_tool("clang")
-- local tool = find_tool("clang", {program = "xcrun -sdk macosx clang"})
-- local tool = find_tool("clang", {paths = {"/usr/bin", "/usr/local/bin"}})
-- local tool = find_tool("clang", {check = "--help"}) -- simple check command: ccache --help
-- local tool = find_tool("clang", {check = function (tool) os.run("%s -h", tool) end})
-- local tool = find_tool("clang", {paths = {"$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)"}})
-- local tool = find_tool("clang", {paths = {"$(env PATH)", function () return "/usr/bin"end}})
-- local tool = find_tool("ccache", {version = true})
--
-- @endcode
--
function main(name, opt)
opt = opt or {}
if opt.require_version then
opt.version = true
end
local result = _find_tool(name, opt)
if opt.require_version and opt.require_version:find('.', 1, true) and result then
if not (result.version and (result.version == opt.require_version or semver.satisfies(result.version, opt.require_version))) then
result = nil
end
end
return result
end
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.