RedPanda-CPP/packages/debian/compiler_hint.lua

247 lines
6.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function apiVersion()
return {
kind = "compiler_hint",
major = 0,
minor = 1,
}
end
local nameMap = {
systemGcc = {
en_US = "System GCC",
pt_BR = "GCC do sistema",
zh_CN = "系统 GCC",
zh_TW = "系統 GCC",
},
systemClang = {
en_US = "System Clang",
pt_BR = "Clang do sistema",
zh_CN = "系统 Clang",
zh_TW = "系統 Clang",
},
multilibGcc = {
en_US = "Multilib GCC",
pt_BR = "GCC multilib",
zh_CN = "Multilib GCC",
zh_TW = "Multilib GCC",
},
multilibClang = {
en_US = "Multilib Clang",
pt_BR = "Clang multilib",
zh_CN = "Multilib Clang",
zh_TW = "Multilib Clang",
},
mingwGcc = {
en_US = "MinGW GCC",
pt_BR = "GCC MinGW",
zh_CN = "MinGW GCC",
zh_TW = "MinGW GCC",
},
release = {
en_US = ", release",
pt_BR = ", lançamento",
zh_CN = ",发布",
zh_TW = ",發佈",
},
debug = {
en_US = ", debug",
pt_BR = ", depuração",
zh_CN = ",调试",
zh_TW = ",偵錯",
},
debugWithAsan = {
en_US = ", debug with ASan",
pt_BR = ", depuração com ASan",
zh_CN = "ASan 调试",
zh_TW = "ASan 偵錯",
},
}
local function mergeCompilerSet(compilerSet, other)
local c = compilerSet
local o = other
for k, v in pairs(o) do
c[k] = v
end
end
local function generateConfig(
name, lang,
cCompiler, cxxCompiler,
config)
local commonOptions = {
cCompiler = cCompiler,
cxxCompiler = cxxCompiler,
debugger = "/usr/bin/gdb",
debugServer = "/usr/bin/gdbserver",
make = "/usr/bin/make",
compilerType = config.isClang and "Clang" or "GCC_UTF8",
preprocessingSuffix = ".i",
compilationProperSuffix = ".s",
assemblingSuffix = ".o",
executableSuffix = config.isMingw and ".exe" or "",
compilationStage = 3,
ccCmdOptUsePipe = "on",
ccCmdOptWarningAll = "on",
ccCmdOptWarningExtra = "on",
ccCmdOptCheckIsoConformance = "on",
binDirs = { "/usr/bin" },
}
if config.isMultilib then
commonOptions.ccCmdOptPointerSize = "32"
end
if config.isMingw then
commonOptions.resourceCompiler = "/usr/bin/" .. config.triplet .. "-windres"
end
if config.customCompileParams then
commonOptions.customCompileParams = config.customCompileParams
end
if config.customLinkParams then
commonOptions.customLinkParams = config.customLinkParams
end
local release = {
name = name .. (nameMap.release[lang] or nameMap.release.en_US),
staticLink = true,
linkCmdOptStripExe = "on",
ccCmdOptOptimize = "2",
}
local debug_ = {
name = name .. (nameMap.debug[lang] or nameMap.debug.en_US),
ccCmdOptDebugInfo = "on",
}
local debugWithAsan = {
name = name .. (nameMap.debugWithAsan[lang] or nameMap.debugWithAsan.en_US),
ccCmdOptDebugInfo = "on",
ccCmdOptAddressSanitizer = "address",
}
mergeCompilerSet(release, commonOptions)
mergeCompilerSet(debug_, commonOptions)
mergeCompilerSet(debugWithAsan, commonOptions)
return release, debug_, debugWithAsan
end
function main()
local arch = C_System.osArch()
local libexecDir = C_System.appLibexecDir()
local lang = C_Desktop.language()
local compilerList = {}
do
local release, debug_, debugWithAsan = generateConfig(
nameMap.systemGcc[lang] or nameMap.systemGcc.en_US, lang,
"/usr/bin/gcc", "/usr/bin/g++",
{})
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
if C_FileSystem.isExecutable("/usr/bin/clang") then
local release, debug_, debugWithAsan = generateConfig(
nameMap.systemClang[lang] or nameMap.systemClang.en_US, lang,
"/usr/bin/clang", "/usr/bin/clang++",
{ isClang = true })
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
if arch == "x86_64" and C_FileSystem.exists("/usr/lib32/libc.a") then
do
local release, debug_, debugWithAsan = generateConfig(
nameMap.multilibGcc[lang] or nameMap.multilibGcc.en_US, lang,
"/usr/bin/gcc", "/usr/bin/g++",
{ isMultilib = true })
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
if C_FileSystem.isExecutable("/usr/bin/clang") then
local release, debug_, debugWithAsan = generateConfig(
nameMap.multilibClang[lang] or nameMap.multilibClang.en_US, lang,
"/usr/bin/clang", "/usr/bin/clang++",
{ isClang = true, isMultilib = true })
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
end
if (
arch == "x86_64" and (
C_FileSystem.exists("/proc/sys/fs/binfmt_misc/DOSWin") or
C_FileSystem.exists("/proc/sys/fs/binfmt_misc/WSLInterop"))) then
if C_FileSystem.isExecutable("/usr/bin/x86_64-w64-mingw32-gcc") then
local extraObjects = {
utf8init = libexecDir .. "/x86_64-w64-mingw32/utf8init.o",
utf8manifest = libexecDir .. "/x86_64-w64-mingw32/utf8manifest.o",
}
do
local release, _, _ = generateConfig(
(nameMap.mingwGcc[lang] or nameMap.mingwGcc.en_US) .. " x86_64", lang,
"/usr/bin/x86_64-w64-mingw32-gcc", "/usr/bin/x86_64-w64-mingw32-g++",
{
isMingw = true,
triplet = "x86_64-w64-mingw32",
customLinkParams = { extraObjects.utf8init, extraObjects.utf8manifest },
})
table.insert(compilerList, release)
end
end
if C_FileSystem.isExecutable("/usr/bin/i686-w64-mingw32-gcc") then
local extraObjects = {
utf8init = libexecDir .. "/i686-w64-mingw32/utf8init.o",
utf8manifest = libexecDir .. "/i686-w64-mingw32/utf8manifest.o",
}
do
local release, _, _ = generateConfig(
(nameMap.mingwGcc[lang] or nameMap.mingwGcc.en_US) .. " i686", lang,
"/usr/bin/i686-w64-mingw32-gcc", "/usr/bin/i686-w64-mingw32-g++",
{
isMingw = true,
triplet = "i686-w64-mingw32",
customLinkParams = { extraObjects.utf8init, extraObjects.utf8manifest },
})
table.insert(compilerList, release)
end
end
end
local result = {
compilerList = compilerList,
noSearch = {
"/usr/bin",
"/usr/lib/ccache",
},
preferCompiler = 3,
}
return result
end