272 lines
9.1 KiB
Lua
272 lines
9.1 KiB
Lua
local arch = C_System.osArch()
|
||
local libexecDir = C_System.appLibexecDir()
|
||
local lang = C_Desktop.language()
|
||
|
||
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",
|
||
},
|
||
crossGcc = {
|
||
en_US = "Cross GCC",
|
||
pt_BR = "GCC cruzado",
|
||
zh_CN = "交叉编译 GCC",
|
||
zh_TW = "交叉編譯 GCC",
|
||
},
|
||
mingwGcc = {
|
||
en_US = "MinGW GCC",
|
||
pt_BR = "GCC MinGW",
|
||
zh_CN = "MinGW GCC",
|
||
zh_TW = "MinGW GCC",
|
||
},
|
||
mingwClang = {
|
||
en_US = "MinGW Clang",
|
||
pt_BR = "Clang MinGW",
|
||
zh_CN = "MinGW Clang",
|
||
zh_TW = "MinGW Clang",
|
||
},
|
||
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 偵錯",
|
||
},
|
||
}
|
||
|
||
function generateConfig(name, 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",
|
||
}
|
||
for k, v in pairs(commonOptions) do
|
||
release[k] = v
|
||
debug[k] = v
|
||
debugWithAsan[k] = v
|
||
end
|
||
return release, debug, debugWithAsan
|
||
end
|
||
|
||
local compilerList = {}
|
||
|
||
do
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
nameMap.systemGcc[lang] or nameMap.systemGcc.en_US,
|
||
"/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,
|
||
"/usr/bin/clang", "/usr/bin/clang++",
|
||
{isClang = true}
|
||
)
|
||
table.insert(compilerList, release)
|
||
table.insert(compilerList, debug)
|
||
table.insert(compilerList, debugWithAsan)
|
||
end
|
||
|
||
-- with lib32-gcc-libs installed, system GCC and Clang can target 32-bit
|
||
if arch == "x86_64" and C_FileSystem.isExecutable("/usr/lib32/libstdc++.so") then
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
nameMap.multilibGcc[lang] or nameMap.multilibGcc.en_US,
|
||
"/usr/bin/gcc", "/usr/bin/g++",
|
||
{isMultilib = true}
|
||
)
|
||
table.insert(compilerList, release)
|
||
table.insert(compilerList, debug)
|
||
table.insert(compilerList, debugWithAsan)
|
||
if C_FileSystem.isExecutable("/usr/bin/clang") then
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
nameMap.multilibClang[lang] or nameMap.multilibClang.en_US,
|
||
"/usr/bin/clang", "/usr/bin/clang++",
|
||
{isClang = true, isMultilib = true}
|
||
)
|
||
table.insert(compilerList, release)
|
||
table.insert(compilerList, debug)
|
||
table.insert(compilerList, debugWithAsan)
|
||
end
|
||
end
|
||
|
||
-- cross GCC
|
||
if (
|
||
arch == "x86_64" and
|
||
C_FileSystem.exists("/proc/sys/fs/binfmt_misc/qemu-aarch64") and
|
||
C_FileSystem.isExecutable("/usr/bin/aarch64-linux-gnu-gcc")
|
||
) then
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
(nameMap.crossGcc[lang] or nameMap.crossGcc.en_US) .. " aarch64",
|
||
"/usr/bin/aarch64-linux-gnu-gcc", "/usr/bin/aarch64-linux-gnu-g++",
|
||
{}
|
||
)
|
||
table.insert(compilerList, release)
|
||
end
|
||
|
||
-- with wine or WSL init registered in binfmt_misc, Windows binaries can run seamlessly
|
||
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",
|
||
}
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
(nameMap.mingwGcc[lang] or nameMap.mingwGcc.en_US) .. " x86_64",
|
||
"/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)
|
||
-- system Clang can target Windows
|
||
if C_FileSystem.isExecutable("/usr/bin/clang") then
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
(nameMap.mingwClang[lang] or nameMap.mingwClang.en_US) .. " x86_64",
|
||
"/usr/bin/clang", "/usr/bin/clang++",
|
||
{
|
||
isClang = true,
|
||
isMingw = true,
|
||
triplet = "x86_64-w64-mingw32",
|
||
customCompileParams = {"-target", "x86_64-w64-mingw32"},
|
||
customLinkParams = {
|
||
"-target", "x86_64-w64-mingw32",
|
||
extraObjects.utf8init, extraObjects.utf8manifest,
|
||
"-lstdc++", "-lwinpthread",
|
||
},
|
||
}
|
||
)
|
||
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",
|
||
}
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
(nameMap.mingwGcc[lang] or nameMap.mingwGcc.en_US) .. " i686",
|
||
"/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)
|
||
-- system Clang can target Windows
|
||
if C_FileSystem.isExecutable("/usr/bin/clang") then
|
||
local release, debug, debugWithAsan = generateConfig(
|
||
(nameMap.mingwClang[lang] or nameMap.mingwClang.en_US) .. " i686",
|
||
"/usr/bin/clang", "/usr/bin/clang++",
|
||
{
|
||
isClang = true,
|
||
isMingw = true,
|
||
triplet = "i686-w64-mingw32",
|
||
customCompileParams = {"-target", "i686-w64-mingw32"},
|
||
customLinkParams = {
|
||
"-target", "i686-w64-mingw32",
|
||
extraObjects.utf8init, extraObjects.utf8manifest,
|
||
"-lstdc++", "-lwinpthread",
|
||
},
|
||
}
|
||
)
|
||
table.insert(compilerList, release)
|
||
end
|
||
end
|
||
end
|
||
|
||
local result = {
|
||
compilerList = compilerList,
|
||
noSearch = {
|
||
"/usr/bin",
|
||
"/opt/cuda/bin",
|
||
"/usr/lib/ccache/bin",
|
||
},
|
||
preferCompiler = 3, -- System GCC Debug with ASan
|
||
}
|
||
|
||
return result
|