diff options
| author | ruki <[email protected]> | 2020-05-24 21:10:49 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-24 21:10:49 +0800 |
| commit | fb2ba113ca1534249b0872002af0f133becd7e51 (patch) | |
| tree | d5bc9fb1553f622842712b18a7959a0c08a92d63 | |
| parent | dd09a2264181f82a0b6aefb38dce5c92fb3af8fe (diff) | |
| parent | 5ad2eaee8cd65987359dbdfc5149bdd61b9260fc (diff) | |
Merge pull request #792 from xmake-io/toolchain
Improve to detect cross-compilation toolchains
112 files changed, 2727 insertions, 3004 deletions
diff --git a/tests/projects/asm/fasm/src/main.S b/tests/projects/asm/fasm/src/main.S new file mode 100644 index 000000000..90f4b88b4 --- /dev/null +++ b/tests/projects/asm/fasm/src/main.S @@ -0,0 +1,28 @@ +format MZ + +entry main:start ; program entry point +stack 100h ; stack size + +segment main ; main program segment + + start: + mov ax,text + mov ds,ax + + mov dx,hello + call extra:write_text + + mov ax,4C00h + int 21h + +segment text + + hello db 'Hello world!',24h + +segment extra + + write_text: + mov ah,9 + int 21h + retf + diff --git a/tests/projects/asm/fasm/xmake.lua b/tests/projects/asm/fasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/fasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/asm/gas/src/main.S b/tests/projects/asm/gas/src/main.S new file mode 100644 index 000000000..9c242f4a1 --- /dev/null +++ b/tests/projects/asm/gas/src/main.S @@ -0,0 +1,9 @@ + .global main + + .text +main: # This is called by C library's startup code + mov $message, %rdi # First integer (or pointer) parameter in %rdi + call puts # puts(message) + ret # Return to C library code +message: + .asciz "Hola, mundo" # asciz puts a 0 byte at the end diff --git a/tests/projects/asm/gas/xmake.lua b/tests/projects/asm/gas/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/gas/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/asm/nasm/src/main.S b/tests/projects/asm/nasm/src/main.S new file mode 100644 index 000000000..e96a8d2c9 --- /dev/null +++ b/tests/projects/asm/nasm/src/main.S @@ -0,0 +1,20 @@ +global _main + +section .text + +_main: + mov rax, 0x2000004 ; write + mov rdi, 1 ; stdout + mov rsi, msg + mov rdx, msg.len + syscall + + mov rax, 0x2000001 ; exit + mov rdi, 0 + syscall + + +section .data + +msg: db "hello xmake!", 10 +.len: equ $ - msg diff --git a/tests/projects/asm/nasm/xmake.lua b/tests/projects/asm/nasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/nasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/asm/yasm/src/main.S b/tests/projects/asm/yasm/src/main.S new file mode 100644 index 000000000..800722a44 --- /dev/null +++ b/tests/projects/asm/yasm/src/main.S @@ -0,0 +1,20 @@ +bits 64 + +extern _puts + +section .data + +message: + db 'hello xmake!', 0 + +section .text + +global _main +_main: + push rbp + mov rbp, rsp + lea rdi, [rel message] + call _puts + xor rax, rax + pop rbp + ret diff --git a/tests/projects/asm/yasm/xmake.lua b/tests/projects/asm/yasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/yasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 4953fc718..621037f53 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -55,7 +55,7 @@ task("config") , {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform." , values = function (complete, opt) - -- import + -- imports import("core.platform.platform") import("core.base.hashset") @@ -77,10 +77,10 @@ task("config") -- show the description of all architectures function () - -- import platform + -- imports import("core.platform.platform") - -- make description + -- get all architectures local description = {} for i, plat in ipairs(platform.plats()) do local archs = platform.archs(plat) @@ -91,20 +91,17 @@ task("config") end end end - - -- get it return description end , values = function (complete, opt) if not complete then return end - -- import + -- imports import("core.platform.platform") import("core.base.hashset") - -- get archs + -- get all architectures local archset = hashset.new() - for _, plat in ipairs(opt.plat and { opt.plat } or platform.plats()) do local archs = platform.archs(plat) if archs then @@ -113,8 +110,6 @@ task("config") end end end - - -- get it return archset:to_array() end } , {'m', "mode", "kv", "release" , "Compile for the given mode." @@ -156,9 +151,22 @@ task("config") , " - sdk/bin" , " - sdk/lib" , " - sdk/include" } - , {nil, "toolchain", "kv", nil, "The Cross Toolchain Name" - , "e.g." - , " - llvm" } + , {nil, "toolchain", "kv", nil, "The Toolchain Name" + , "e.g. " + , " - xmake f --toolchain=clang" + , " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx" + , " - run `xmake show -l toolchains` to get all toolchains" + , values = function (complete, opt) + if complete then + import("core.project.project") + import("core.platform.platform") + local names = table.copy(platform.toolchains()) + for name, _ in pairs(project.toolchains()) do + table.insert(names, name) + end + return names + end + end } -- show language menu options , function () diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index 720eb0351..9472c9b24 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -59,11 +59,6 @@ function main() end end - -- check the global configure - if changed or option.get("clean") then - global.check() - end - -- load and check theme local themename = option.get("theme") if themename then diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 05337e4c8..c8bd2fec7 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -546,7 +546,12 @@ function _instance:extraconf(name, item, key) return value end --- new an scope instance +-- clone a new instance from the current +function _instance:clone() + return _instance.new(self:kind(), self:info(), {interpreter = self:interpreter(), remove_repeat = self._REMOVE_REPEAT, enable_filter = self._ENABLE_FILTER}) +end + +-- new a scope instance function scopeinfo.new(...) return _instance.new(...) end diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index cd42d8ae2..eedb2c9a2 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -646,9 +646,9 @@ end -- e.g. -- -- { --- binary = {"ld", "gc-ld", "dc-ld"} --- , static = {"ar", "gc-ar", "dc-ar"} --- , shared = {"sh", "dc-sh"} +-- binary = {"ld", "gcld", "dcld"} +-- , static = {"ar", "gcar", "dcar"} +-- , shared = {"sh", "dcsh"} -- } -- function language.targetkinds() diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 63270ee15..ea85a605e 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -191,7 +191,6 @@ function main._init() else os.addenv("PATH", os.programdir()) end - return true end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index b69b4f094..d47f0fc4e 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -492,7 +492,7 @@ function _instance:build_envs(lazy_loading) setmetatable(build_envs, { __index = function (tbl, key) local value = config.get(key) if value == nil then - value = platform.get(key, self:plat()) + value = platform.toolconfig(key, self:plat()) end if value == nil then value = platform.tool(key, self:plat()) diff --git a/xmake/core/platform/environment.lua b/xmake/core/platform/environment.lua index acc383f19..f76568cb7 100644 --- a/xmake/core/platform/environment.lua +++ b/xmake/core/platform/environment.lua @@ -23,6 +23,7 @@ local environment = environment or {} -- load modules local os = require("base/os") +local table = require("base/table") local global = require("base/global") local platform_core = require("platform/platform") local sandbox = require("sandbox/sandbox") @@ -32,97 +33,80 @@ local import = require("sandbox/modules/import") -- enter the toolchains environment function environment._enter_toolchains() - -- save the toolchains environment - environment._PATH = os.getenv("PATH") + -- get the current platform + local platform, errors = platform_core.load() + if not platform then + return false, errors + end -- add $programdir/winenv/bin to $path + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") if os.host() == "windows" then os.addenv("PATH", path.join(os.programdir(), "winenv", "bin")) end + + -- add the runenvs of toolchains + for name, values in pairs(platform:runenvs()) do + if not oldenvs[name] then + oldenvs[name] = os.getenv(name) + end + os.addenv(name, table.unpack(table.wrap(values))) + end + environment._OLDENVS_TOOLCHAINS = oldenvs + return true end -- leave the toolchains environment function environment._leave_toolchains() - - -- leave the toolchains environment - os.setenv("PATH", environment._PATH) + local oldenvs = environment._OLDENVS_TOOLCHAINS + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end + return true end -- enter the running environment function environment._enter_run() - - -- save the running environment - environment._PATH = os.getenv("PATH") - environment._LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") + oldenvs.LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") + environment._OLDENVS_RUN = oldenvs + return true end -- leave the running environment function environment._leave_run() - - -- leave the running environment - os.setenv("PATH", environment._PATH) - os.setenv("LD_LIBRARY_PATH", environment._LD_LIBRARY_PATH) + local oldenvs = environment._OLDENVS_RUN + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end + return true end -- enter the environment for the current platform function environment.enter(name) - - -- get the current platform - local platform, errors = platform_core.load() - if not platform then - return false, errors - end - - -- the maps local maps = {toolchains = environment._enter_toolchains, run = environment._enter_run} - - -- enter the common environment local func = maps[name] if func then - func() - end - - -- enter the environment of the given platform - local on_enter = platform:script("environment_enter") - if on_enter then - local ok, errors = sandbox.load(on_enter, platform, name) + local ok, errors = func() if not ok then return false, errors end end - - -- ok return true end -- leave the environment for the current platform function environment.leave(name) - - -- get the current platform - local platform, errors = platform_core.load() - if not platform then - return false, errors - end - - -- leave the environment of the given platform - local on_leave = platform:script("environment_leave") - if on_leave then - local ok, errors = sandbox.load(on_leave, platform, name) - if not ok then - return false, errors - end - end - - -- the maps local maps = {toolchains = environment._leave_toolchains, run = environment._leave_run} - - -- leave the common environment local func = maps[name] if func then - func() + local ok, errors = func() + if not ok then + return false, errors + end end - - -- ok return true end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index bf6734373..eb247f7af 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -28,17 +28,16 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local interpreter = require("base/interpreter") +local toolchain = require("tool/toolchain") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") -local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance -function _instance.new(name, info, rootdir) +function _instance.new(name, info) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info - instance._ROOTDIR = rootdir return instance end @@ -103,6 +102,135 @@ function _instance:archs() return self._INFO:get("archs") end +-- get runenvs of toolchains +function _instance:runenvs() + local runenvs = self._RUNENVS + if not runenvs then + runenvs = {} + for _, toolchain_inst in ipairs(self:toolchains()) do + local toolchain_runenvs = toolchain_inst:get("runenvs") + if toolchain_runenvs then + for name, values in pairs(toolchain_runenvs) do + runenvs[name] = table.join2(table.wrap(runenvs[name]), values) + end + end + end + self._RUNENVS = runenvs + end + return runenvs +end + +-- get the toolchains +function _instance:toolchains(opt) + local toolchains = self._TOOLCHAINS + if not toolchains then + + -- get current valid toolchains from configuration cache + local names = nil + toolchains = {} + if not (opt and opt.all) then + names = config.get("__toolchains") + else + -- get the given toolchain + local toolchain_given = config.get("toolchain") + if toolchain_given then + local toolchain_inst, errors = toolchain.load(toolchain_given) + -- attempt to load toolchain from project + if not toolchain_inst and platform._project() then + toolchain_inst = platform._project().toolchain(toolchain_given) + end + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + toolchain_given = toolchain_inst + end + + -- get the platform toolchains + if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then + names = self._INFO:get("toolchains") + end + end + if names then + for _, name in ipairs(names) do + local toolchain_inst, errors = toolchain.load(name) + -- attempt to load toolchain from project + if not toolchain_inst and platform._project() then + toolchain_inst = platform._project().toolchain(name) + end + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end + end + self._TOOLCHAINS = toolchains + end + return toolchains +end + +-- get the program and name of the given tool kind +function _instance:tool(toolkind) + + -- init tools + local tools = self._TOOLS + if not tools then + tools = {} + self._TOOLS = tools + end + + -- get tool program + local program, toolname + local toolinfo = tools[toolkind] + if toolinfo == nil then + toolinfo = {} + local toolchains = self:toolchains() + for idx, toolchain_inst in ipairs(toolchains) do + program, toolname = toolchain_inst:tool(toolkind) + if program then + toolinfo[1] = program + toolinfo[2] = toolname + break + end + end + tools[toolkind] = toolinfo + else + program = toolinfo[1] + toolname = toolinfo[2] + end + return program, toolname +end + +-- get tool configuration from the toolchains +function _instance:toolconfig(name) + + -- init tool configs + local toolconfigs = self._TOOLCONFIGS + if not toolconfigs then + toolconfigs = {} + self._TOOLCONFIGS = toolconfigs + end + + -- get configuration + local toolconfig = toolconfigs[name] + if toolconfig == nil then + + -- get them from all toolchains + for _, toolchain_inst in ipairs(self:toolchains()) do + local values = toolchain_inst:get(name) + if values then + toolconfig = toolconfig or {} + table.join2(toolconfig, values) + end + end + + -- cache it + toolconfig = toolconfig or false + toolconfigs[name] = toolconfig + end + return toolconfig or nil +end + -- get the platform script function _instance:script(name) return self._INFO:get(name) @@ -125,6 +253,65 @@ function _instance:data_add(name, data) self._DATA[name] = table.unwrap(table.join(self._DATA[name] or {}, data)) end +-- do check +function _instance:check() + + -- check platform + local on_check = self:script("check") + if on_check then + local ok, errors = sandbox.load(on_check, self) + if not ok then + return false, errors + end + end + + -- check toolchains + local toolchains = self:toolchains({all = true}) + local idx = 1 + local num = #toolchains + local standalone = false + local toolchains_valid = {} + while idx <= num do + local toolchain = toolchains[idx] + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then + table.remove(toolchains, idx) + num = num - 1 + else + if toolchain:standalone() then + standalone = true + end + idx = idx + 1 + table.insert(toolchains_valid, toolchain:name()) + end + end + if #toolchains == 0 then + return false, "toolchains not found!" + end + + -- save valid toolchains + config.set("__toolchains", toolchains_valid) + return true +end + +-- get formats +function _instance:formats() + local formats = self._FORMATS + if not formats then + for _, toolchain_inst in ipairs(self:toolchains()) do + formats = toolchain_inst:get("formats") + if formats then + break + end + end + if not formats then + formats = self._INFO:get("formats") + end + self._FORMATS = formats + end + return formats +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -164,6 +351,11 @@ function platform._interpreter() return interp end +-- get project +function platform._project() + return platform._PROJECT +end + -- get platform apis function platform._apis() return @@ -175,21 +367,22 @@ function platform._apis() , "platform.set_hosts" , "platform.set_archs" , "platform.set_installdir" + , "platform.set_toolchains" } , script = { -- platform.on_xxx "platform.on_load" - , "platform.on_config_check" - , "platform.on_global_check" - , "platform.on_environment_enter" - , "platform.on_environment_leave" + , "platform.on_check" + } + , keyvalues = + { + "platform.set_formats" } , dictionary = { -- platform.set_xxx "platform.set_menu" - , "platform.set_formats" } } end @@ -284,13 +477,8 @@ function platform.load(plat) return nil, string.format("the platform %s not found!", plat) end - -- new an instance - local instance, errors = _instance.new(plat, result, interp:rootdir()) - if not instance then - return nil, errors - end - -- save instance to the cache + local instance = _instance.new(plat, result) platform._PLATFORMS[cachekey] = instance return instance end @@ -321,16 +509,14 @@ function platform.tool(toolkind, plat) if not instance then os.raise(errors) end - - -- check it first - local on_check = instance:script("config_check") - if on_check then - on_check(instance, toolkind) - end - -- get it again - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) + -- get it from the platform toolchains + program, toolname = instance:tool(toolkind) + if program then + config.set(toolkind, program, {force = true, readonly = true}) + config.set("__toolname_" .. toolkind, toolname) + config.save() + end end -- contain toolname? parse it, e.g. '[email protected]' @@ -344,6 +530,16 @@ function platform.tool(toolkind, plat) return program, toolname end +-- get the given tool configuration +function platform.toolconfig(name, plat) + local instance, errors = platform.load(plat) + if instance then + return instance:toolconfig(name) + else + os.raise(errors) + end +end + -- get the all platforms function platform.plats() @@ -356,9 +552,7 @@ function platform.plats() local plats = {} local dirs = platform.directories() for _, dir in ipairs(dirs) do - - -- get the platform list - local platpathes = os.match(path.join(dir, "*"), true) + local platpathes = os.dirs(path.join(dir, "*")) if platpathes then for _, platpath in ipairs(platpathes) do if os.isfile(path.join(platpath, "xmake.lua")) then @@ -371,6 +565,31 @@ function platform.plats() return plats end +-- get the all toolchains +function platform.toolchains() + + -- return it directly if exists + if platform._TOOLCHAINS then + return platform._TOOLCHAINS + end + + -- get all toolchains + local toolchains = {} + local dirs = toolchain.directories() + for _, dir in ipairs(dirs) do + local dirs = os.dirs(path.join(dir, "*")) + if dirs then + for _, dir in ipairs(dirs) do + if os.isfile(path.join(dir, "xmake.lua")) then + table.insert(toolchains, path.basename(dir)) + end + end + end + end + platform._TOOLCHAINS = toolchains + return toolchains +end + -- get the platform os function platform.os(plat) return platform.get("os", plat) @@ -384,8 +603,14 @@ end -- get the format of the given target kind for platform function platform.format(targetkind) + -- get platform instance + local instance, errors = platform.load(plat) + if not instance then + os.raise(errors) + end + -- get formats - local formats = platform.get("formats") + local formats = instance:formats() if formats then return formats[targetkind] end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index e900f394f..1c97bdfd4 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -42,10 +42,14 @@ local deprecated_project = require("project/deprecated/project") local package = require("package/package") local platform = require("platform/platform") local environment = require("platform/environment") +local toolchain = require("tool/toolchain") local language = require("language/language") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") +-- register project to platform +platform._PROJECT = project + -- the current os is belong to the given os? function project._api_is_os(interp, ...) @@ -327,6 +331,29 @@ function project._load_rules() return rules end +-- load toolchains +function project._load_toolchains() + + -- load the project file first if has not been loaded? + local ok, errors = project._load() + if not ok then + return nil, errors + end + + -- load the toolchain from the the project file + local results, errors = project._load_scope("toolchain", true, true) + if not results then + return nil, errors + end + + -- make toolchain instances + local toolchains = {} + for toolchain_name, toolchain_info in pairs(results) do + toolchains[toolchain_name] = toolchain.new(toolchain_name, toolchain_info) + end + return toolchains +end + -- load targets function project._load_targets() @@ -680,6 +707,9 @@ function project.interpreter() -- define apis for language interp:api_define(language.apis()) + -- define apis for toolchain + interp:api_define(toolchain.apis()) + -- define apis for project interp:api_define(project.apis()) @@ -924,10 +954,7 @@ end -- get project rules function project.rules() - if not project._RULES then - - -- load rules local rules, errors = project._load_rules() if not rules then os.raise(errors) @@ -937,6 +964,23 @@ function project.rules() return project._RULES end +-- get the given toolchain +function project.toolchain(name) + return project.toolchains()[name] +end + +-- get project toolchains +function project.toolchains() + if not project._TOOLCHAINS then + local toolchains, errors = project._load_toolchains() + if not toolchains then + os.raise(errors) + end + project._TOOLCHAINS = toolchains + end + return project._TOOLCHAINS +end + -- get the given task function project.task(name) return project.tasks()[name] diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua index 4ea5b2745..9141a2d76 100644 --- a/xmake/core/sandbox/modules/import/core/base/global.lua +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -68,31 +68,6 @@ function sandbox_core_base_global.clear() return global.clear() end --- check the configure -function sandbox_core_base_global.check() - - -- check all platforms with the current host - for _, plat in ipairs(table.wrap(platform.plats())) do - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - raise(errors) - end - - -- belong to the current host? - for _, host in ipairs(table.wrap(instance:hosts())) do - if host == os.host() then - local on_check = instance:script("global_check") - if on_check then - on_check(instance) - end - break - end - end - end -end - -- get all options function sandbox_core_base_global.options() return global.options() diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 2961cb67f..d9730f830 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -45,12 +45,17 @@ function sandbox_core_platform.plats() return assert(platform.plats()) end +-- get the all toolchains +function sandbox_core_platform.toolchains() + return assert(platform.toolchains()) +end + -- get the all architectures for the given platform function sandbox_core_platform.archs(plat) return platform.archs(plat) end --- get the current platform configure +-- get the current platform configuration function sandbox_core_platform.get(name, plat) return platform.get(name, plat) end @@ -63,5 +68,10 @@ function sandbox_core_platform.tool(toolkind) return platform.tool(toolkind) end +-- get the current platform tool configuration +function sandbox_core_platform.toolconfig(name, plat) + return platform.toolconfig(name, plat) +end + -- return module return sandbox_core_platform diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 449fac71f..3ea6d3a30 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -116,11 +116,9 @@ function sandbox_core_project_config.check() -- get the current platform local instance, errors = platform.load() if instance then - - -- do check - local on_check = instance:script("config_check") - if on_check then - on_check(instance) + local ok, errors = instance:check() + if not ok then + raise(errors) end else raise(errors) diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index c6796af36..cb7465fcd 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -39,6 +39,8 @@ local import = require("sandbox/modules/import") sandbox_core_project.get = project.get sandbox_core_project.rule = project.rule sandbox_core_project.rules = project.rules +sandbox_core_project.toolchain = project.toolchain +sandbox_core_project.toolchains = project.toolchains sandbox_core_project.target = project.target sandbox_core_project.targets = project.targets sandbox_core_project.option = project.option diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 3c77247c1..042aa5001 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -263,7 +263,7 @@ function builder:_add_flags_from_language(flags, target, getters) end return values end - , platform = platform.get + , platform = platform.toolconfig , target = function (name) -- only for target diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 0c0a1375a..27c81879c 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -47,8 +47,8 @@ function compiler:_add_flags_from_platform(flags, targetkind) if targetkind then local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.get(targetkind .. '.' .. flagkind)) + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind)) end end end @@ -140,7 +140,7 @@ function compiler.load(sourcekind, target) for _, flagkind in ipairs(instance:_flagkinds()) do -- add flags for platform, e.g. gcc.cxflags or cxflags - compiler_tool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) + compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end -- ok diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index ed1f47daa..b3f91a904 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -39,13 +39,13 @@ local compiler = require("tool/compiler") -- add flags from the platform function linker:_add_flags_from_platform(flags, targetkind) - -- attempt to add special lanugage flags first for target kind, e.g. binary.go.gc-ldflags, static.dc-arflags + -- attempt to add special lanugage flags first for target kind, e.g. binary.go.gcldflags, static.dcarflags if targetkind then local toolkind = self:kind() local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.get(targetkind .. '.' .. toolkind .. 'flags') or platform.get(targetkind .. '.' .. flagkind)) + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind)) end end end @@ -57,7 +57,7 @@ function linker:_add_flags_from_linker(flags) local toolkind = self:kind() for _, flagkind in ipairs(self:_flagkinds()) do - -- attempt to add special lanugage flags first, e.g. gc-ldflags, dc-arflags + -- attempt to add special lanugage flags first, e.g. gcldflags, dcarflags table.join2(flags, self:get(toolkind .. 'flags') or self:get(flagkind)) end end @@ -185,9 +185,9 @@ function linker.load(targetkind, sourcekinds, target) local toolname = linkertool:name() for _, flagkind in ipairs(instance:_flagkinds()) do - -- add special lanugage flags first, e.g. go.gc-ldflags or gcc.ldflags or gc-ldflags or ldflags - linkertool:add(toolkind .. 'flags', platform.get(toolname .. '.' .. toolkind .. 'flags') or platform.get(toolkind .. 'flags')) - linkertool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) + -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags + linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags')) + linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end -- ok diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua new file mode 100644 index 000000000..e2220127e --- /dev/null +++ b/xmake/core/tool/toolchain.lua @@ -0,0 +1,383 @@ +--!A cross-toolchain build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file toolchain.lua +-- + +-- define module +local toolchain = toolchain or {} +local _instance = _instance or {} + +-- load modules +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local table = require("base/table") +local global = require("base/global") +local option = require("base/option") +local interpreter = require("base/interpreter") +local config = require("project/config") +local language = require("language/language") +local sandbox = require("sandbox/sandbox") +local sandbox_module = require("sandbox/modules/import/core/sandbox/module") + +-- new an instance +function _instance.new(name, info) + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + return instance +end + +-- get toolchain name +function _instance:name() + return self._NAME +end + +-- get toolchain platform +function _instance:plat() + return config.get("plat") or os.host() +end + +-- get toolchain architecture +function _instance:arch() + return config.get("arch") or os.arch() +end + +-- get toolchain info +function _instance:info() + local arch = self:arch() + local infos = self._INFOS + if not infos then + infos = {} + self._INFOS = infos + end + local info = infos[arch] + if not info then + -- we need multiple info objects for different architectures + info = self._INFO:clone() + infos[arch] = info + end + return info +end + +-- set the value to the toolchain configuration +function _instance:set(name, ...) + self:info():apival_set(name, ...) +end + +-- add the value to the toolchain configuration +function _instance:add(name, ...) + self:info():apival_add(name, ...) +end + +-- get the toolchain configuration +function _instance:get(name) + + -- attempt to get the static configure value + local value = self:info():get(name) + if value ~= nil then + return value + end + + -- lazy loading platform + self:_load() + + -- get other platform info + return self:info():get(name) +end + +-- get toolchain kind +function _instance:kind() + return self:info():get("kind") +end + +-- is standalone toolchain? +function _instance:standalone() + return self:kind() == "standalone" +end + +-- get the program and name of the given tool kind +function _instance:tool(toolkind) + local toolpathes = self:get("toolsets." .. toolkind) + if toolpathes then + for _, toolpath in ipairs(table.wrap(toolpathes)) do + local program, toolname = self:_checktool(toolkind, toolpath) + if program then + return program, toolname + end + end + end +end + +-- get the toolchain script +function _instance:script(name) + return self:info():get(name) +end + +-- get the bin directory +function _instance:bindir() + return config.get("bin") or self:get("bindir") +end + +-- get the sdk directory +function _instance:sdkdir() + return config.get("sdk") or self:get("sdkdir") +end + +-- do load, @note we need load it repeatly for each architectures +function _instance:_load() + local info = self:info() + if not info:get("__loaded") and not info:get("__loading") then + local on_load = info:get("load") + if on_load then + info:set("__loading", true) + local ok, errors = sandbox.load(on_load, self) + info:set("__loading", false) + if not ok then + os.raise(errors) + end + end + info:set("__loaded", true) + end +end + +-- do check, we only check it once for all architectures +function _instance:check() + local checkok = true + if not self._CHECKED then + local on_check = self:info():get("check") + if on_check then + local ok, results_or_errors = sandbox.load(on_check, self) + if ok then + checkok = results_or_errors + else + os.raise(results_or_errors) + end + end + self._CHECKED = true + end + return checkok +end + +-- get the tool description from the tool kind +function _instance:_description(toolkind) + local descriptions = self._DESCRIPTIONS + if not descriptions then + descriptions = + { + cc = "the c compiler", + cxx = "the c++ compiler", + ld = "the linker", + sh = "the shared library linker", + ar = "the static library archiver", + ex = "the static library extractor", + strip = "the symbols stripper", + dsymutil = "the symbols generator", + mm = "the objc compiler", + mxx = "the objc++ compiler", + as = "the assember", + sc = "the swift compiler", + scld = "the swift linker", + scsh = "the swift shared library linker", + gc = "the golang compiler", + gcld = "the golang linker", + gcar = "the golang static library archiver", + dc = "the dlang compiler", + dcld = "the dlang linker", + dcsh = "the dlang shared library linker", + dcar = "the dlang static library archiver", + rc = "the rust compiler", + rcld = "the rust linker", + rcsh = "the rust shared library linker", + rcar = "the rust static library archiver", + cu = "the cuda compiler", + culd = "the cuda linker", + cuccbin = "the cuda host c++ compiler", + } + self._DESCRIPTIONS = descriptions + end + return descriptions[toolkind] +end + +-- check the given tool path +function _instance:_checktool(toolkind, toolpath) + + -- get find_tool + local find_tool = self._find_tool + if not find_tool then + find_tool = sandbox_module.import("lib.detect.find_tool", {anonymous = true}) + self._find_tool = find_tool + end + + -- do filter for toolpath variables, e.g. set_toolsets("cc", "$(env CC)") + local sandbox_inst = sandbox.instance() + if sandbox_inst then + local filter = sandbox_inst:filter() + if filter then + local value = filter:handle(toolpath) + if value and value:trim() ~= "" then + toolpath = value + else + return + end + end + end + + -- find tool program + local program, toolname + local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()}) + if tool then + program = tool.program + toolname = tool.name + end + + -- get tool description from the tool kind + local description = self:_description(toolkind) or ("unknown toolkind " .. toolkind) + + -- trace + if option.get("verbose") then + if program then + utils.cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) + else + utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, toolpath) + end + end + return program, toolname +end + +-- the interpreter +function toolchain._interpreter() + + -- the interpreter has been initialized? return it directly + if toolchain._INTERPRETER then + return toolchain._INTERPRETER + end + + -- init interpreter + local interp = interpreter.new() + assert(interp) + + -- define apis + interp:api_define(toolchain.apis()) + + -- define apis for language + interp:api_define(language.apis()) + + -- save interpreter + toolchain._INTERPRETER = interp + + -- ok? + return interp +end + +-- get toolchain apis +function toolchain.apis() + return + { + values = + { + "toolchain.set_kind" + , "toolchain.set_bindir" + , "toolchain.set_sdkdir" + , "toolchain.set_archs" + } + , keyvalues = + { + -- toolchain.set_xxx + "toolchain.set_formats" + , "toolchain.set_toolsets" + -- toolchain.add_xxx + , "toolchain.add_runenvs" + } + , script = + { + -- toolchain.on_xxx + "toolchain.on_load" + , "toolchain.on_check" + } + } +end + +-- get toolchain directories +function toolchain.directories() + + -- init directories + local dirs = toolchain._DIRS or { path.join(global.directory(), "toolchains") + , path.join(os.programdir(), "toolchains") + } + + -- save directories to cache + toolchain._DIRS = dirs + return dirs +end + +-- load the given toolchain +function toolchain.load(name) + + -- get it directly from cache dirst + toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} + if toolchain._TOOLCHAINS[name] then + return toolchain._TOOLCHAINS[name] + end + + -- find the toolchain script path + local scriptpath = nil + for _, dir in ipairs(toolchain.directories()) do + scriptpath = path.join(dir, name, "xmake.lua") + if os.isfile(scriptpath) then + break + end + end + if not scriptpath or not os.isfile(scriptpath) then + return nil, string.format("the toolchain %s not found!", name) + end + + -- get interpreter + local interp = toolchain._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + return nil, errors + end + + -- load toolchain + local results, errors = interp:make("toolchain", true, false) + if not results and os.isfile(scriptpath) then + return nil, errors + end + + -- check the toolchain name + local result = results[name] + if not result then + return nil, string.format("the toolchain %s not found!", name) + end + + -- save instance to the cache + local instance = _instance.new(name, result) + toolchain._TOOLCHAINS[name] = instance + return instance +end + +-- new toolchain +function toolchain.new(name, info) + return _instance.new(name, info) +end + +-- return module +return toolchain diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 60f36f098..535d652f2 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -28,7 +28,7 @@ language("cuda") set_sourceflags {cu = "cuflags"} -- set target kinds - set_targetkinds {gpucode = "cu-ld", binary = "ld", static = "ar", shared = "sh"} + set_targetkinds {gpucode = "culd", binary = "ld", static = "ar", shared = "sh"} -- set target flags set_targetflags {gpucode = "culdflags", binary = "ldflags", static = "arflags", shared = "shflags"} @@ -140,7 +140,7 @@ language("cuda") {category = "Cross Complation Configuration/Compiler Configuration" } , {nil, "cu", "kv", nil, "The Cuda Compiler" } , {nil, "cu-ccbin", "kv", nil, "The Cuda Host C++ Compiler" } - , {nil, "cu-ld", "kv", nil, "The Cuda Linker" } + , {nil, "culd", "kv", nil, "The Cuda Linker" } , {category = "Cross Complation Configuration/Compiler Flags Configuration" } , {nil, "cuflags", "kv", nil, "The Cuda Compiler Flags" } diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua index 6481381f0..f30706797 100644 --- a/xmake/languages/dlang/xmake.lua +++ b/xmake/languages/dlang/xmake.lua @@ -28,7 +28,7 @@ language("dlang") set_sourceflags {dc = "dcflags"} -- set target kinds - set_targetkinds {binary = "dc-ld", static = "dc-ar", shared = "dc-sh"} + set_targetkinds {binary = "dcld", static = "dcar", shared = "dcsh"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} @@ -113,9 +113,9 @@ language("dlang") , {nil, "dc", "kv", nil, "The Dlang Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "dc-ld", "kv", nil, "The Dlang Linker" } - , {nil, "dc-ar", "kv", nil, "The Dlang Static Library Archiver" } - , {nil, "dc-sh", "kv", nil, "The Dlang Shared Library Linker" } + , {nil, "dcld", "kv", nil, "The Dlang Linker" } + , {nil, "dcar", "kv", nil, "The Dlang Static Library Archiver" } + , {nil, "dcsh", "kv", nil, "The Dlang Shared Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } , {nil, "links", "kv", nil, "The Link Libraries" } diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index 385e43c8b..d78d64e1d 100644 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -28,7 +28,7 @@ language("golang") set_sourceflags {gc = "gcflags"} -- set target kinds - set_targetkinds {binary = "gc-ld", static = "gc-ar"} + set_targetkinds {binary = "gcld", static = "gcar"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags"} @@ -109,7 +109,7 @@ language("golang") , {nil, "go", "kv", nil, "The Golang Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "gc-ld", "kv", nil, "The Golang Linker" } + , {nil, "gcld", "kv", nil, "The Golang Linker" } , {nil, "go-ar", "kv", nil, "The Golang Static Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua index 8afd1ea7a..044ed0111 100644 --- a/xmake/languages/rust/xmake.lua +++ b/xmake/languages/rust/xmake.lua @@ -28,7 +28,7 @@ language("rust") set_sourceflags {rc = "rcflags"} -- set target kinds - set_targetkinds {binary = "rc-ld", static = "rc-ar", shared = "rc-sh"} + set_targetkinds {binary = "rcld", static = "rcar", shared = "rcsh"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} @@ -94,9 +94,9 @@ language("rust") , {nil, "rc", "kv", nil, "The Rust Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "rc-ld", "kv", nil, "The Rust Linker" } - , {nil, "rc-ar", "kv", nil, "The Rust Static Library Archiver" } - , {nil, "rc-sh", "kv", nil, "The Rust Shared Library Linker" } + , {nil, "rcld", "kv", nil, "The Rust Linker" } + , {nil, "rcar", "kv", nil, "The Rust Static Library Archiver" } + , {nil, "rcsh", "kv", nil, "The Rust Shared Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index a3b121a13..3ac1f0b87 100644 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -28,7 +28,7 @@ language("swift") set_sourceflags {sc = "scflags"} -- set target kinds - set_targetkinds {binary = "sc-ld", static = "ar", shared = "sc-sh"} + set_targetkinds {binary = "scld", static = "ar", shared = "scsh"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} @@ -153,8 +153,8 @@ language("swift") , { nil, "sc", "kv", nil, "The Swift Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , { nil, "sc-ld", "kv", nil, "The Swift Linker" } - , { nil, "sc-sh", "kv", nil, "The Swift Shared Library Linker" } + , { nil, "scld", "kv", nil, "The Swift Linker" } + , { nil, "scsh", "kv", nil, "The Swift Shared Library Linker" } , { category = "Cross Complation Configuration/Builtin Flags Configuration" } , { nil, "links", "kv", nil, "The Link Libraries" } diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index eaadb249c..378c68642 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -27,10 +27,10 @@ import("core.project.project") function init(self) -- init arflags - self:set("dc-arflags", "-lib") + self:set("dcarflags", "-lib") -- init shflags - self:set("dc-shflags", "-shared", "-fPIC") + self:set("dcshflags", "-shared", "-fPIC") -- init dcflags for the kind: shared self:set("shared.dcflags", "-fPIC") @@ -134,15 +134,30 @@ end -- make the rpathdir flag function nf_rpathdir(self, dir) - local flag = "-L-rpath=" .. os.args(dir) - if self:has_flags(flag) then - return flag + dir = path.translate(dir) + if self:has_flags("-L-rpath=" .. dir, "ldflags") then + return "-L-rpath=" .. os.args(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" .. os.args(dir:gsub("%$ORIGIN", "@loader_path")) end end -- make the link arguments list function linkargv(self, objectfiles, targetkind, targetfile, flags) - return self:program(), table.join(flags, "-of" .. targetfile, objectfiles) + + -- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib + local flags_extra = {} + if targetkind == "shared" and is_plat("macosx") then + table.insert(flags_extra, "-L-install_name") + table.insert(flags_extra, "-L@rpath/" .. path.filename(targetfile)) + end + + -- init arguments + return self:program(), table.join(flags, flags_extra, "-of" .. targetfile, objectfiles) end -- link the target file diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index 944a14eff..80230ba4f 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -27,7 +27,7 @@ import("core.project.project") function init(self) -- init arflags - self:set("gc-arflags", "grc") + self:set("gcarflags", "grc") -- init the file formats self:set("formats", { static = "$(name).a" }) diff --git a/xmake/modules/core/tools/ld.lua b/xmake/modules/core/tools/ld.lua new file mode 100644 index 000000000..6894d21b8 --- /dev/null +++ b/xmake/modules/core/tools/ld.lua @@ -0,0 +1,99 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file 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 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" + } + + local plat = config.plat() + if plat == "macosx" or plat == "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" .. os.args(path.translate(dir)) +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + + -- init arguments + local argv = table.join("-o", targetfile, objectfiles, flags) + + -- too long arguments for windows? + if is_host("windows") then + opt = opt or {} + local args = os.args(argv, {escape = true}) + if #args > 1024 and not opt.rawargs then + local argsfile = os.tmpfile(args) .. ".args.txt" + io.writefile(argsfile, args) + argv = {"@" .. argsfile} + end + end + return self:program(), argv +end + +-- link the target file +function link(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) +end + diff --git a/xmake/modules/core/tools/ldc2.lua b/xmake/modules/core/tools/ldc2.lua index ef4796156..9cf9fd48b 100644 --- a/xmake/modules/core/tools/ldc2.lua +++ b/xmake/modules/core/tools/ldc2.lua @@ -28,7 +28,7 @@ function init(self) _super.init(self) -- init shflags - self:set("dc-shflags", "-shared") + self:set("dcshflags", "-shared") -- init cxflags for the kind: shared self:set("shared.dcflags", "") diff --git a/xmake/modules/core/tools/llvm_ar.lua b/xmake/modules/core/tools/llvm_ar.lua index b9674ffaf..0d890bd5c 100644 --- a/xmake/modules/core/tools/llvm_ar.lua +++ b/xmake/modules/core/tools/llvm_ar.lua @@ -24,9 +24,6 @@ import("core.tool.compiler") -- init it function init(self) self:set("arflags", "cr") - if is_plat("cross") and is_subhost("windows") then - self:set("formats", { static = "$(name).lib" }) - end end -- make the strip flag diff --git a/xmake/modules/core/tools/nasm.lua b/xmake/modules/core/tools/nasm.lua new file mode 100644 index 000000000..a02091f07 --- /dev/null +++ b/xmake/modules/core/tools/nasm.lua @@ -0,0 +1,139 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file nasm.lua +-- + +-- imports +import("core.base.option") + +-- 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) + + -- the maps + local maps = + { + none = "-w" + } + + -- 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" .. os.args(dir) +end + +-- make the compile arguments list +function _compargv1(self, sourcefile, objectfile, flags) + return self:program(), table.join(flags, "-o", objectfile, sourcefile) +end + +-- compile the source file +function _compile1(self, sourcefile, objectfile, dependinfo, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + local outdata, errdata = try + { + function () + return os.iorunv(_compargv1(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 (option.get("diagnosis") or option.get("warning")) then + errdata = errdata:trim() + if #errdata > 0 then + cprint("${color.warning}%s", errdata) + end + end + end + } + } +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 + diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index 227c6ad43..0ec83c803 100644 --- a/xmake/modules/core/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -27,13 +27,13 @@ import("core.project.project") function init(self) -- init arflags - self:set("rc-arflags", "--crate-type=lib") + self:set("rcarflags", "--crate-type=lib") -- init shflags - self:set("rc-shflags", "--crate-type=dylib") + self:set("rcshflags", "--crate-type=dylib") -- init ldflags - self:set("rc-ldflags", "--crate-type=bin") + self:set("rcldflags", "--crate-type=bin") -- init the file formats self:set("formats", { static = "lib$(name).rlib" }) diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua index a8c22a9ee..6aa5e3f2a 100644 --- a/xmake/modules/detect/sdks/find_mingw.lua +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -33,6 +33,8 @@ function _find_mingwdir(sdkdir) if not sdkdir then if is_host("macosx") then sdkdir = "/usr/local/opt/mingw-w64" + elseif is_host("linux") then + sdkdir = "/usr" end end @@ -54,11 +56,11 @@ function _find_mingw(sdkdir, bindir, cross) -- find mingw root directory sdkdir = _find_mingwdir(sdkdir) if not sdkdir then - return {} + return end -- select cross on macos, e.g x86_64-w64-mingw32- or i686-w64-mingw32- - if is_host("macosx") and not cross then + if is_host("macosx", "linux") and not cross then local arch = config.get("arch") if not arch or arch == "i386" then cross = "i686-*-" diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua index 7dee10690..f0ee66676 100644 --- a/xmake/modules/detect/sdks/find_ndk.lua +++ b/xmake/modules/detect/sdks/find_ndk.lua @@ -101,7 +101,7 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) -- find ndk root directory sdkdir = _find_ndkdir(sdkdir) if not sdkdir then - return {} + return end -- get cross @@ -142,14 +142,11 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) bindir = find_directory("bin", path.join(sdkdir, "toolchains", gcc_toolchain_subdir, "prebuilt", "*")) end if not bindir then - return {} + return end -- find the sdk version local sdkver = ndk_sdkver or _find_ndk_sdkver(sdkdir, bindir, arch) - if not sdkver then - return {} - end -- find the gcc toolchain local gcc_toolchain = find_directory("bin", path.join(sdkdir, "toolchains", gcc_toolchain_subdir, "prebuilt", "*")) @@ -159,9 +156,6 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) -- find the toolchains version local toolchains_ver = ndk_toolchains_ver or _find_ndk_toolchains_ver(gcc_toolchain or bindir) - if not toolchains_ver then - return {} - end -- get ndk version, e.g. r16b, .. local ndkver = nil diff --git a/xmake/modules/detect/tools/find_fasm.lua b/xmake/modules/detect/tools/find_fasm.lua index 5ebf9e699..0b555a406 100644 --- a/xmake/modules/detect/tools/find_fasm.lua +++ b/xmake/modules/detect/tools/find_fasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.norun = true -- find program local program = find_program(opt.program or "fasm", opt) diff --git a/xmake/platforms/windows/load.lua b/xmake/modules/detect/tools/find_ld.lua index 78217e5f1..7b015e043 100644 --- a/xmake/platforms/windows/load.lua +++ b/xmake/modules/detect/tools/find_ld.lua @@ -15,24 +15,32 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file find_ld.lua -- -- imports -import("core.project.config") +import("core.tool.compiler") +import("lib.detect.find_program") --- load it -function main(platform) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_ld() +-- local ar, version = find_ld({program = "ld", version = true}) +-- +-- @endcode +-- +function main(opt) - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x64" and "win64" or "win32") + -- init options + opt = opt or {} + opt.norun = true - -- init flags for dlang - local dc_archs = { x86 = "-m32", x64 = "-m64" } - platform:add("dcflags", dc_archs[arch]) - platform:add("dc-shflags", dc_archs[arch]) - platform:add("dc-ldflags", dc_archs[arch]) + -- find program + return find_program(opt.program or "ld", opt) end diff --git a/xmake/platforms/cygwin/load.lua b/xmake/modules/detect/tools/find_nasm.lua index c101640b5..68936502e 100644 --- a/xmake/platforms/cygwin/load.lua +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -15,32 +15,41 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file find_nasm.lua -- -- imports -import("core.project.config") +import("lib.detect.find_program") +import("lib.detect.find_programver") --- load it -function main(platform) +-- find nasm +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local nasm = find_nasm() +-- local nasm, version = find_nasm({program = "nasm", version = true}) +-- +-- @endcode +-- +function main(opt) - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch - end - end - if archflags then - platform:add("cxflags", archflags) - platform:add("asflags", archflags) - platform:add("ldflags", archflags) - platform:add("shflags", archflags) + -- init options + opt = opt or {} + opt.check = "-v" + + -- find program + local program = find_program(opt.program or "nasm", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) end - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32") + -- ok? + return program, version end - diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua index a74cd8817..201c50841 100644 --- a/xmake/modules/package/manager/conan/install_package.lua +++ b/xmake/modules/package/manager/conan/install_package.lua @@ -30,7 +30,7 @@ import("net.fasturl") function _conan_get_build_env(name, plat) local value = config.get(name) if value == nil then - value = platform.get(name, plat) + value = platform.toolconfig(name, plat) end if value == nil then value = platform.tool(name, plat) diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua index 5c08c6ae0..bf4c30709 100644 --- a/xmake/modules/private/action/trybuild/autotools.lua +++ b/xmake/modules/private/action/trybuild/autotools.lua @@ -39,7 +39,7 @@ end function _get_buildenv(key) local value = config.get(key) if value == nil then - value = platform.get(key, config.plat()) + value = platform.toolconfig(key, config.plat()) end if value == nil then value = platform.tool(key, config.plat()) diff --git a/xmake/modules/private/platform/check_toolchain.lua b/xmake/modules/private/platform/check_toolchain.lua deleted file mode 100644 index 839e6600d..000000000 --- a/xmake/modules/private/platform/check_toolchain.lua +++ /dev/null @@ -1,83 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file check_toolchain.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_tool") - --- check the given tool -function _check_tool(config, toolkind, description, name, cross, pathes, check) - - -- get the program - local program = config.get(toolkind) - if not program then - - -- translate program name to attempt to get `$(env XX)` - name = vformat(name) - if #name == 0 then - return - end - - -- attempt to check it - local toolname = nil - if not program then - local tool = find_tool(name, {program = (cross or "") .. name, pathes = pathes or config.get("bin"), check = check}) - if tool then - program = tool.program - toolname = tool.name - end - end - - -- check ok? - if program then - config.set(toolkind, program) - config.set("__toolname_" .. toolkind, toolname) - config.save() - end - - -- trace - if option.get("verbose") then - if program then - cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) - else - cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) - end - end - end - - -- ok? - return program -end - --- check the toolchain -function main(config, name, toolchain) - for _, toolinfo in ipairs(toolchain.list) do - if type(toolinfo) == "string" then - if _check_tool(config, name, toolchain.description, toolinfo) then - break - end - else - if _check_tool(config, name, toolchain.description, toolinfo.name, toolinfo.cross, toolinfo.pathes, toolinfo.check) then - break - end - end - end -end - diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua deleted file mode 100644 index f199d08ba..000000000 --- a/xmake/platforms/android/config.lua +++ /dev/null @@ -1,155 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_ndk") -import("detect.sdks.find_android_sdk") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the ndk toolchain -function _check_ndk() - local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) - if ndk then - config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global - config.set("bin", ndk.bindir, {force = true, readonly = true}) - config.set("cross", ndk.cross, {force = true, readonly = true}) - config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- check the android sdk -function _check_android_sdk() - local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) - if sdk then - config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- get gcc toolchain bin directory - local gcc_toolchain_bin = nil - local gcc_toolchain = config.get("gcc_toolchain") - if gcc_toolchain then - gcc_toolchain_bin = path.join(gcc_toolchain, "bin") - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local strip = toolchain("the symbols stripper") - local as = toolchain("the assember") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar} - - -- init the c compiler - cc:add({name = "gcc", cross = cross}, "clang") - - -- init the c++ compiler - cxx:add({name = "g++", cross = cross}, "clang++") - - -- init the c preprocessor - cpp:add({name = "gcc -E", cross = cross}, "clang -E") - - -- init the assember - as:add({name = "gcc", cross = cross}, "clang") - - -- init the linker - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add("clang++", "clang") - - -- init the shared library linker - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add("clang++", "clang") - - -- init the static library archiver - ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library index generator - ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("android.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armeabi-v7a") - - -- check android sdk - _check_android_sdk() - - -- check ndk - _check_ndk() - - -- check ld and sh, @note toolchains must be initialized after calling check_ndk() - local toolchains = singleton.get("android.toolchains", _toolchains) - check_toolchain(config, "ld", toolchains.ld) - check_toolchain(config, "sh", toolchains.sh) - end -end - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 45a4eaf8d..27bea1645 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -37,13 +37,23 @@ platform("android") set_archs("armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mip64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "armeabi-v7a") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "ndk", "rust") -- set menu set_menu { diff --git a/xmake/platforms/bsd/config.lua b/xmake/platforms/bsd/config.lua deleted file mode 100644 index 3a4912f78..000000000 --- a/xmake/platforms/bsd/config.lua +++ /dev/null @@ -1,175 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/bsd/load.lua b/xmake/platforms/bsd/load.lua deleted file mode 100644 index e1357e717..000000000 --- a/xmake/platforms/bsd/load.lua +++ /dev/null @@ -1,81 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- cross toolchains? - if config.get("cross") or config.get("bin") or config.get("sdk") then - - -- init linkdirs and includedirs - local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- ok - return - end - - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - end - end - - -- init flags for c/c++ - platform:add("cxflags", archflags, "-I/usr/local/include", "-I/usr/include") - platform:add("ldflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - platform:add("shflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", archflags) - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "elf64" or "elf32") - platform:add("asflags", archflags) - - -- init flags for golang - platform:set("gc-ldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dc-shflags", dc_archs[arch] or "") - platform:add("dc-ldflags", dc_archs[arch] or "") - - -- init flags for rust - platform:set("rc-shflags", "") - platform:set("rc-ldflags", "") -end - diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index 3ea3ed9f6..35f063eb7 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -31,19 +31,26 @@ platform("bsd") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on check global configuration - on_global_check("global") - - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") -- set menu set_menu { diff --git a/xmake/platforms/cross/config.lua b/xmake/platforms/cross/config.lua deleted file mode 100644 index b159cf5c1..000000000 --- a/xmake/platforms/cross/config.lua +++ /dev/null @@ -1,189 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "none") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get llvm toolchains -function _toolchains_llvm() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", "clang") - - -- init the c preprocessor - cpp:add("$(env CPP)", "clang -E") - - -- init the c++ compiler - cxx:add("$(env CXX)", "clang", "clang++") - - -- init the assember - as:add("$(env AS)", "clang") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") - - -- init the static library archiver - ar:add("$(env AR)", "llvm-ar") - - -- init the static library extractor - ex:add("$(env AR)", "llvm-ar") - - -- init the static library index generator - ranlib:add("$(env RANLIB)", "llvm-ranlib") - - -- init the symbols stripper - strip:add("$(env STRIP)", "llvm-strip") - return toolchains -end - --- get toolchains -function _toolchains() - - -- get cross prefix - local cross = config.get("cross") or "" - - -- for llvm toolchains? - if cross == "" and config.get("toolchain") == "llvm" then - return _toolchains_llvm() - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library index generator - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index 31e7f6d95..c5b12eda5 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -28,12 +28,22 @@ platform("cross") set_archs("i386", "x86_64", "armv7", "armv7s", "arm64-v8a", "mips", "mips64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "none") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross") diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua deleted file mode 100644 index 6c963188d..000000000 --- a/xmake/platforms/cygwin/config.lua +++ /dev/null @@ -1,172 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index e43c5e35c..deca581bc 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -31,14 +31,25 @@ platform("cygwin") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dll", binary = "$(name).exe", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.subarch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross", "gcc", "clang", "yasm") diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua deleted file mode 100644 index 2a7f52aa1..000000000 --- a/xmake/platforms/iphoneos/config.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") - - -- init cross - local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cpp = toolchain("the c preprocessor") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 2f6bcf00f..7118846b7 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -31,16 +31,23 @@ platform("iphoneos") set_archs("arm64", "armv7", "armv7s", "i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dylib") + set_formats("symbol", "$(name).dSYM") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "arm64") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on check global configuration - on_global_check("global") - - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "xcode") -- set menu set_menu { diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua deleted file mode 100644 index 489c8d15e..000000000 --- a/xmake/platforms/linux/config.lua +++ /dev/null @@ -1,175 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua deleted file mode 100644 index e1357e717..000000000 --- a/xmake/platforms/linux/load.lua +++ /dev/null @@ -1,81 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- cross toolchains? - if config.get("cross") or config.get("bin") or config.get("sdk") then - - -- init linkdirs and includedirs - local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- ok - return - end - - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - end - end - - -- init flags for c/c++ - platform:add("cxflags", archflags, "-I/usr/local/include", "-I/usr/include") - platform:add("ldflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - platform:add("shflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", archflags) - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "elf64" or "elf32") - platform:add("asflags", archflags) - - -- init flags for golang - platform:set("gc-ldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dc-shflags", dc_archs[arch] or "") - platform:add("dc-ldflags", dc_archs[arch] or "") - - -- init flags for rust - platform:set("rc-shflags", "") - platform:set("rc-ldflags", "") -end - diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 53517239a..a1097565b 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -31,19 +31,26 @@ platform("linux") set_archs("i386", "x86_64", "armv7", "armv7s", "arm64-v8a", "mips", "mips64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on check global configuration - on_global_check("global") - - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") -- set menu set_menu { diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua deleted file mode 100644 index b440146cc..000000000 --- a/xmake/platforms/macosx/config.lua +++ /dev/null @@ -1,164 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init cross - local cross = "xcrun -sdk macosx " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add("clang", "clang++", "gcc", "g++") - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add("clang++", "g++", "clang", "gcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add("clang++", "g++", "clang", "gcc") - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross}, "ar") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}, "strip") - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add("clang", "clang++", "gcc", "g++") - - -- init the swift compiler and linker - sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end -end - diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua deleted file mode 100644 index a9a7ff1cd..000000000 --- a/xmake/platforms/macosx/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = nil - if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" - end - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch) - platform:add("ldflags", "-arch " .. arch) - if target_minver then - platform:add("cxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("mxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - platform:add("cxflags", "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - platform:add("cxflags", "-I/usr/local/include") - platform:add("cxflags", "-I/usr/include") - platform:add("ldflags", "-L/usr/local/lib") - platform:add("ldflags", "-L/usr/lib") - end - platform:add("ldflags", "-stdlib=libc++") - platform:add("ldflags", "-lz") - platform:add("shflags", platform:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm - platform:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") - platform:set("fasm.asflags", "") - platform:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - platform:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-shflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-ldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - -- init flags for golang - platform:set("gc-ldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dc-shflags", dc_archs[arch] or "") - platform:add("dc-ldflags", dc_archs[arch] or "" ) - - -- init flags for rust - platform:set("rc-shflags", "") - platform:set("rc-ldflags", "") -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 452c528db..f643d2c80 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -31,19 +31,26 @@ platform("macosx") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dylib") + set_formats("symbol", "$(name).dSYM") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on check global configuration - on_global_check("global") - - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go") -- set menu set_menu { diff --git a/xmake/platforms/mingw/config.lua b/xmake/platforms/mingw/config.lua deleted file mode 100644 index bbfc6f7f9..000000000 --- a/xmake/platforms/mingw/config.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_mingw") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the mingw toolchain -function _check_mingw() - local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) - if mingw then - config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) - config.set("cross", mingw.cross, {readonly = true, force = true}) - config.set("bin", mingw.bindir, {readonly = true, force = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local mrc = toolchain("the resource compiler") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the resource compiler - mrc:add({name = "windres", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "x86_64") - - -- check mingw - _check_mingw() - end -end - diff --git a/xmake/platforms/mingw/load.lua b/xmake/platforms/mingw/load.lua deleted file mode 100644 index 653527e6d..000000000 --- a/xmake/platforms/mingw/load.lua +++ /dev/null @@ -1,52 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch - end - end - if archflags then - platform:add("cxflags", archflags) - platform:add("asflags", archflags) - platform:add("ldflags", archflags) - platform:add("shflags", archflags) - end - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32") - - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end -end - diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 7b5ad2624..82c2ae07e 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -31,13 +31,24 @@ platform("mingw") set_archs("i386", "x86_64") -- set formats - set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} + set_formats("static", "$(name).lib") + set_formats("object", "$(name).obj") + set_formats("shared", "$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).pdb") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "x86_64") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "mingw") -- set menu set_menu { diff --git a/xmake/platforms/msys/config.lua b/xmake/platforms/msys/config.lua deleted file mode 100644 index f5fd3c0a4..000000000 --- a/xmake/platforms/msys/config.lua +++ /dev/null @@ -1,172 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("msys.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/msys/load.lua b/xmake/platforms/msys/load.lua deleted file mode 100644 index c101640b5..000000000 --- a/xmake/platforms/msys/load.lua +++ /dev/null @@ -1,46 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch - end - end - if archflags then - platform:add("cxflags", archflags) - platform:add("asflags", archflags) - platform:add("ldflags", archflags) - platform:add("shflags", archflags) - end - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32") -end - diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index b3abadbf9..ec73a87ee 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -31,14 +31,25 @@ platform("msys") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dll", binary = "$(name).exe", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.subarch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross", "gcc", "clang", "yasm") diff --git a/xmake/platforms/sdcc/config.lua b/xmake/platforms/sdcc/config.lua deleted file mode 100644 index ad2f14626..000000000 --- a/xmake/platforms/sdcc/config.lua +++ /dev/null @@ -1,114 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "stm8") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} - - -- init the c compiler - cc:add("$(env CC)", "sdcc") - - -- init the c preprocessor - cpp:add("$(env CPP)", "sdcpp") - - -- init the c++ compiler - cxx:add("$(env CXX)", "sdcc") - - -- init the assember - as:add("$(env AS)", "sdcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "sdcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "sdcc") - - -- init the static library archiver - ar:add("$(env AR)", "sdar") - - -- init the static library extractor - ex:add("$(env AR)", "sdar") - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua deleted file mode 100644 index 57504cb60..000000000 --- a/xmake/platforms/watchos/config.lua +++ /dev/null @@ -1,124 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") - local simulator = (arch == "i386") - - -- init cross - local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armv7k") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/watchos/global.lua b/xmake/platforms/watchos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/watchos/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 5c2e2a731..b6d864d0b 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -31,16 +31,23 @@ platform("watchos") set_archs("armv7k", "i386") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dylib") + set_formats("symbol", "$(name).dSYM") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "armv7k") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on check global configuration - on_global_check("global") - - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "xcode") -- set menu set_menu { diff --git a/xmake/platforms/windows/config.lua b/xmake/platforms/windows/config.lua deleted file mode 100644 index 04b92ce65..000000000 --- a/xmake/platforms/windows/config.lua +++ /dev/null @@ -1,139 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("core.platform.environment") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_vstudio") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local mrc = toolchain("the resource compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld} - - -- init the c compiler - cc:add("cl.exe") - - -- init the c++ compiler - cxx:add("cl.exe") - - -- init the resource compiler - mrc:add("rc.exe") - - -- init the assember - local arch = config.get("arch") - if arch and arch:find("64") then - as:add("ml64.exe") - else - as:add("ml.exe") - end - - -- init the linker - ld:add("link.exe") - - -- init the shared library linker - sh:add("link.exe -dll") - - -- init the static library archiver - ar:add("link.exe -lib") - - -- init the static library extractor - ex:add("lib.exe") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("windows.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - environment.enter("toolchains") - check_toolchain(config, name, toolchain) - environment.leave("toolchains") - end - else - - -- check arch - check_arch(config) - - -- check vstudio - local cc = path.basename(config.get("cc") or "cl"):lower() - local cxx = path.basename(config.get("cxx") or "cl"):lower() - local mrc = path.basename(config.get("mrc") or "rc"):lower() - if cc == "cl" or cxx == "cl" or mrc == "rc" then - check_vstudio(config) - end - end -end - diff --git a/xmake/platforms/windows/environment/leave.lua b/xmake/platforms/windows/environment/leave.lua deleted file mode 100644 index 8547cfd66..000000000 --- a/xmake/platforms/windows/environment/leave.lua +++ /dev/null @@ -1,44 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file leave.lua --- - --- leave the given environment -function _leave(platform, name) - local old = platform:data("windows.environment." .. name) - if old then - os.setenv(name, old) - end -end - --- leave the toolchains environment -function _leave_toolchains(platform) - _leave(platform, "path") - _leave(platform, "lib") - _leave(platform, "include") - _leave(platform, "libpath") -end - --- leave environment -function main(platform, name) - local maps = {toolchains = _leave_toolchains} - local func = maps[name] - if func then - func(platform) - end -end diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua deleted file mode 100644 index 9ef580bef..000000000 --- a/xmake/platforms/windows/global.lua +++ /dev/null @@ -1,49 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_arch") -import("private.platform.check_vstudio") - --- clean temporary global configs -function _clean_global() - global.set("arch", nil) - global.set("__vcvarsall", nil) -end - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check arch - check_arch(global) - - -- check vstudio - check_vstudio(global, {try = true}) - - -- clean temporary global configs - _clean_global() -end - diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 43c7acccb..5c29b0e0b 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -31,22 +31,24 @@ platform("windows") set_archs("x86", "x64") -- set formats - set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} + set_formats("static", "$(name).lib") + set_formats("object", "$(name).obj") + set_formats("shared", "$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).pdb") - -- on check project configuration - on_config_check("config") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) - -- on check global configuration - on_global_check("global") - - -- on environment enter - on_environment_enter("environment.enter") - - -- on environment leave - on_environment_leave("environment.leave") - - -- on load - on_load("load") + -- set toolchains + set_toolchains("vs", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "go") -- set menu set_menu { diff --git a/xmake/platforms/macosx/global.lua b/xmake/plugins/show/list.lua index f625eb103..3d44532bb 100644 --- a/xmake/platforms/macosx/global.lua +++ b/xmake/plugins/show/list.lua @@ -15,22 +15,17 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file global.lua +-- @file list.lua -- -- imports -import("core.base.global") -import("private.platform.check_xcode") +import("core.base.option") --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) +-- get all list values +function lists() + local values = {} + for _, filepath in ipairs(os.files(path.join(os.scriptdir(), "lists", "*.lua"))) do + table.insert(values, path.basename(filepath)) end - - -- check xcode - check_xcode(global, true) + return values end - diff --git a/xmake/platforms/linux/global.lua b/xmake/plugins/show/lists/platforms.lua index d74d84943..0f9d2507c 100644 --- a/xmake/platforms/linux/global.lua +++ b/xmake/plugins/show/lists/platforms.lua @@ -15,18 +15,14 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file global.lua +-- @file platforms.lua -- -- imports -import("core.base.global") +import("core.platform.platform") +import(".showlist") --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end +-- show all platforms +function main() + showlist(platform.plats()) end - diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua new file mode 100644 index 000000000..7089fc53f --- /dev/null +++ b/xmake/plugins/show/lists/targets.lua @@ -0,0 +1,35 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file targets.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.platform.platform") +import(".showlist") + +-- show all platforms +function main() + config.load() + local targets = {} + for name, _ in pairs(project.targets()) do + table.insert(targets, name) + end + showlist(targets) +end diff --git a/xmake/platforms/iphoneos/global.lua b/xmake/plugins/show/lists/toolchains.lua index f625eb103..911fd801c 100644 --- a/xmake/platforms/iphoneos/global.lua +++ b/xmake/plugins/show/lists/toolchains.lua @@ -15,22 +15,20 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file global.lua +-- @file toolchains.lua -- -- imports -import("core.base.global") -import("private.platform.check_xcode") +import("core.base.option") +import("core.project.project") +import("core.platform.platform") +import(".showlist") --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) +-- show all toolchains +function main() + local names = table.copy(platform.toolchains()) + for name, _ in pairs(project.toolchains()) do + table.insert(names, name) end - - -- check xcode - check_xcode(global, true) + showlist(names) end - diff --git a/xmake/plugins/show/main.lua b/xmake/plugins/show/main.lua new file mode 100644 index 000000000..816ca30a3 --- /dev/null +++ b/xmake/plugins/show/main.lua @@ -0,0 +1,37 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") + +-- show list +function _show_list(name) + return assert(import("lists." .. name, {try = true, anonymous = true}), "unknown list name(%s)", name)() +end + +-- main entry +function main() + + -- show list? + local listname = option.get("list") + if listname then + return _show_list(listname) + end +end diff --git a/xmake/modules/private/platform/check_arch.lua b/xmake/plugins/show/showlist.lua index 4e67f8ae9..7a7e90b54 100644 --- a/xmake/modules/private/platform/check_arch.lua +++ b/xmake/plugins/show/showlist.lua @@ -15,24 +15,26 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file check_arch.lua +-- @file showlist.lua -- -- imports import("core.base.option") +import("core.base.text") --- check the architecture -function main(config, default) - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", default or os.arch()) - - -- trace - cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) +-- show values +function main(values) + local tbl = {align = 'l', sep = " "} + local row = {} + for _, value in ipairs(values) do + table.insert(row, value) + if #row > 10 then + table.insert(tbl, row) + row = {} + end end + if #row > 0 then + table.insert(tbl, row) + end + print(text.table(tbl)) end - diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua new file mode 100644 index 000000000..180b2140d --- /dev/null +++ b/xmake/plugins/show/xmake.lua @@ -0,0 +1,49 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define task +task("show") + + -- set category + set_category("plugin") + + -- on run + on_run("main") + + -- set menu + set_menu { + -- usage + usage = "xmake show [options] [arguments]" + + -- description + , description = "Show the given project information." + + -- options + , options = + { + {'l', "list" , "kv" , nil , "Show the values list of the given name." + , values = function (complete, opt) + return import("list").lists() + end} + } + } + + + diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua new file mode 100644 index 000000000..944a6bc22 --- /dev/null +++ b/xmake/toolchains/clang/xmake.lua @@ -0,0 +1,72 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("clang") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "clang") + set_toolsets("cxx", "clang", "clang++") + set_toolsets("ld", "clang++", "clang") + set_toolsets("sh", "clang++", "clang") + set_toolsets("ar", "ar") + set_toolsets("ex", "ar") + set_toolsets("strip", "strip") + set_toolsets("mm", "clang") + set_toolsets("mxx", "clang", "clang++") + set_toolsets("as", "clang") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("clang") + end) + + -- on load + on_load(function (toolchain) + + -- get march + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + + -- init flags for c/c++ + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + if not is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", march) + + -- init flags for asm + toolchain:add("asflags", march) + end) diff --git a/xmake/platforms/sdcc/load.lua b/xmake/toolchains/cross/check.lua index 2f44d691e..34b62ccc0 100644 --- a/xmake/platforms/sdcc/load.lua +++ b/xmake/toolchains/cross/check.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,33 +15,31 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file check.lua -- -- imports import("core.project.config") +import("detect.sdks.find_cross_toolchain") --- load it -function main(platform) +-- check the cross toolchain +function main(toolchain) - -- init linkdirs and includedirs + -- is cross? local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end + local bindir = config.get("bin") + local cross = config.get("cross") + if not sdkdir and not bindir and not cross then + return end - -- add port flags for arch - local arch = config.get("arch") - if arch then - platform:add("cxflags", "-m" .. arch) - platform:add("ldflags", "-m" .. arch) + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("cross toolchain not found!") end + return cross_toolchain end - diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua new file mode 100644 index 000000000..1cf211646 --- /dev/null +++ b/xmake/toolchains/cross/xmake.lua @@ -0,0 +1,69 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("cross") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- imports + import("core.project.config") + + -- get cross prefix + local cross = config.get("cross") or "" + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "gcc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "clang", cross .. "g++", cross .. "clang++") + toolchain:set("toolsets", "cpp", cross .. "gcc -E", cross .. "clang -E") + toolchain:set("toolsets", "as", cross .. "gcc", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "ranlib", cross .. "ranlib") + toolchain:set("toolsets", "strip", cross .. "strip") + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + end) diff --git a/xmake/toolchains/cuda/xmake.lua b/xmake/toolchains/cuda/xmake.lua new file mode 100644 index 000000000..884851581 --- /dev/null +++ b/xmake/toolchains/cuda/xmake.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("cuda") + + -- set toolsets + set_toolsets("cu", "nvcc", "clang") + set_toolsets("culd", "nvcc") + set_toolsets("cu-ccbin", "$(env CXX)", "$(env CC)", "clang", "gcc") + diff --git a/xmake/modules/private/platform/toolchain.lua b/xmake/toolchains/dlang/xmake.lua index 7ddf361d6..783530b90 100644 --- a/xmake/modules/private/platform/toolchain.lua +++ b/xmake/toolchains/dlang/xmake.lua @@ -15,24 +15,22 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file toolchain.lua +-- @file xmake.lua -- --- imports -import("core.base.object") - --- init toolchain -local toolchain = toolchain or object {_init = {"description", "list"}} - --- add tool to toolchain list -function toolchain:add(...) - for _, item in ipairs({...}) do - table.insert(self.list, item) - end -end - --- create a toolchain object -function main(description) - return toolchain {description, {}} -end +-- define toolchain +toolchain("dlang") + + -- set toolsets + set_toolsets("dc", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcld", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcsh", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcar", "$(env DC)", "dmd", "ldc2", "gdc") + -- on load + on_load(function (toolchain) + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + toolchain:add("dcflags", march) + toolchain:add("dcshflags", march) + toolchain:add("dcldflags", march) + end) diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua new file mode 100644 index 000000000..f5dda488b --- /dev/null +++ b/xmake/toolchains/envs/xmake.lua @@ -0,0 +1,37 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("envs") + + -- set toolsets + set_toolsets("cc", "$(env CC)") + set_toolsets("cxx", "$(env CXX)") + set_toolsets("ld", "$(env LD)", "$(env CXX)") + set_toolsets("sh", "$(env SH)", "$(env LD)", "$(env CXX)") + set_toolsets("ar", "$(env AR)") + set_toolsets("ex", "$(env EX)", "$(env AR)") + set_toolsets("strip", "$(env STRIP)") + set_toolsets("ranlib","$(env RANLIB)") + set_toolsets("mm", "$(env MM)") + set_toolsets("mxx", "$(env MXX)") + set_toolsets("as", "$(env AS)") + set_toolsets("sc", "$(env SC)") + diff --git a/xmake/toolchains/fasm/xmake.lua b/xmake/toolchains/fasm/xmake.lua new file mode 100644 index 000000000..cf61cc2ab --- /dev/null +++ b/xmake/toolchains/fasm/xmake.lua @@ -0,0 +1,31 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("fasm") + + -- set toolsets + set_toolsets("as", "fasm") + + -- on load + on_load(function (toolchain) + -- reset asflags for fasm + toolchain:add("fasm.asflags", "") + end) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua new file mode 100644 index 000000000..17270aedb --- /dev/null +++ b/xmake/toolchains/gcc/xmake.lua @@ -0,0 +1,72 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("gcc") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "gcc") + set_toolsets("cxx", "gcc", "g++") + set_toolsets("ld", "g++", "gcc") + set_toolsets("sh", "g++", "gcc") + set_toolsets("ar", "ar") + set_toolsets("ex", "ar") + set_toolsets("strip", "strip") + set_toolsets("mm", "gcc") + set_toolsets("mxx", "gcc", "g++") + set_toolsets("as", "gcc") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("gcc") + end) + + -- on load + on_load(function (toolchain) + + -- get march + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + + -- init flags for c/c++ + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + if not is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", march) + + -- init flags for asm + toolchain:add("asflags", march) + end) diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua new file mode 100644 index 000000000..402e5cc04 --- /dev/null +++ b/xmake/toolchains/go/xmake.lua @@ -0,0 +1,33 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("go") + + -- set toolsets + set_toolsets("gc", "$(env GC)", "go", "gccgo") + set_toolsets("gcld", "$(env GC)", "go", "gccgo") + set_toolsets("gcar", "$(env GC)", "go", "gccgo") + + -- on load + on_load(function (toolchain) + toolchain:set("gcldflags", "") + end) + diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua new file mode 100644 index 000000000..04d4d6dec --- /dev/null +++ b/xmake/toolchains/llvm/check.lua @@ -0,0 +1,46 @@ +--!A cross-toolchain build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + + -- get sdk directory + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + if not sdkdir and not bindir then + if is_plat("linux") and os.isfile("/usr/bin/llvm-ar") then + sdkdir = "/usr" + end + end + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("llvm toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua new file mode 100644 index 000000000..53132de83 --- /dev/null +++ b/xmake/toolchains/llvm/xmake.lua @@ -0,0 +1,63 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("llvm") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "clang") + set_toolsets("cxx", "clang", "clang++") + set_toolsets("cpp", "clang -E") + set_toolsets("as", "clang") + set_toolsets("ld", "clang++", "clang") + set_toolsets("sh", "clang++", "clang") + set_toolsets("ar", "llvm-ar") + set_toolsets("ex", "llvm-ar") + set_toolsets("ranlib", "llvm-ranlib") + set_toolsets("strip", "llvm-strip") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + end) diff --git a/xmake/toolchains/mingw/check.lua b/xmake/toolchains/mingw/check.lua new file mode 100644 index 000000000..0bf65a0ce --- /dev/null +++ b/xmake/toolchains/mingw/check.lua @@ -0,0 +1,40 @@ +--!A cross-toolchain build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_mingw") + +-- check the mingw toolchain +function main(toolchain) + local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) + if mingw then + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + config.set("cross", mingw.cross, {readonly = true, force = true}) + config.set("bin", mingw.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --mingw=xxx") + cprint("or - xmake global --mingw=xxx") + raise() + end + return true +end diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua new file mode 100644 index 000000000..10a9b2ffa --- /dev/null +++ b/xmake/toolchains/mingw/xmake.lua @@ -0,0 +1,70 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("mingw") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- imports + import("core.project.config") + + -- get cross + local cross = config.get("cross") or "" + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "gcc") + toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "g++") + toolchain:set("toolsets", "cpp", cross .. "gcc -E") + toolchain:set("toolsets", "as", cross .. "gcc") + toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "ranlib", cross .. "ranlib") + toolchain:set("toolsets", "mrc", cross .. "windres") + + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then + if arch == "x86_64" then archflags = "-m64" + elseif arch == "i386" then archflags = "-m32" + else archflags = "-arch " .. arch + end + end + if archflags then + toolchain:add("cxflags", archflags) + toolchain:add("asflags", archflags) + toolchain:add("ldflags", archflags) + toolchain:add("shflags", archflags) + end + end) diff --git a/xmake/toolchains/nasm/xmake.lua b/xmake/toolchains/nasm/xmake.lua new file mode 100644 index 000000000..fe9beb8b6 --- /dev/null +++ b/xmake/toolchains/nasm/xmake.lua @@ -0,0 +1,36 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("nasm") + + -- set toolsets + set_toolsets("as", "nasm") + + -- on load + on_load(function (toolchain) + if is_plat("macosx") then + toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") + elseif is_plat("linux", "bsd") then + toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") + elseif is_plat("windows", "mingw", "msys", "cygwin") then + toolchain:add("nasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + end + end) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua new file mode 100644 index 000000000..4cd4eea11 --- /dev/null +++ b/xmake/toolchains/ndk/check.lua @@ -0,0 +1,56 @@ +--!A cross-toolchain build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_ndk") +import("detect.sdks.find_android_sdk") + +-- check the ndk toolchain +function _check_ndk() + local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) + if ndk then + config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) + config.set("bin", ndk.bindir, {force = true, readonly = true}) + config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- check the android sdk +function _check_android_sdk() + local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) + if sdk then + config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) + end +end + +-- main entry +function main(toolchain) + _check_android_sdk() + _check_ndk() + return true +end diff --git a/xmake/platforms/android/load.lua b/xmake/toolchains/ndk/load.lua index b0ed21ba3..b2b0ae95f 100644 --- a/xmake/platforms/android/load.lua +++ b/xmake/toolchains/ndk/load.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -21,20 +21,42 @@ -- imports import("core.project.config") --- load it -function main(platform) +-- main entry +function main(toolchain) + + -- get cross + local cross = config.get("cross") or "" + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- set toolsets + toolchain:set("toolsets", "cc", "clang", cross .. "gcc") + toolchain:set("toolsets", "cxx", "clang++", cross .. "g++") + toolchain:set("toolsets", "cpp", "clang -E", cross .. "gcc -E") + toolchain:set("toolsets", "as", "clang", cross .. "gcc") + toolchain:set("toolsets", "ld", "clang++", "clang", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "sh", "clang++", "clang", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "ar", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar") + toolchain:set("toolsets", "ex", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar") + toolchain:set("toolsets", "ranlib", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ranlib") or (cross .. "ranlib")) + toolchain:set("toolsets", "strip", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "strip") or (cross .. "strip")) -- init flags local arm32 = false local arch = config.get("arch") - platform:add("ldflags", "-llog") - platform:add("shflags", "-llog") + toolchain:add("ldflags", "-llog") + toolchain:add("shflags", "-llog") if arch and (arch == "armeabi" or arch == "armeabi-v7a" or arch == "armv5te" or arch == "armv7-a") then -- armv5te/armv7-a are deprecated arm32 = true - platform:add("cxflags", "-mthumb") - platform:add("asflags", "-mthumb") - platform:add("ldflags", "-mthumb") - platform:add("shflags", "-mthumb") + toolchain:add("cxflags", "-mthumb") + toolchain:add("asflags", "-mthumb") + toolchain:add("ldflags", "-mthumb") + toolchain:add("shflags", "-mthumb") end -- use llvm directory? e.g. android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin @@ -62,18 +84,18 @@ function main(platform) , ["mips64"] = "mips64el-none-linux-android" -- removed in ndk r17 } assert(targets[arch], "unknown arch(%s) for android!", arch) - platform:add("cxflags", "-target " .. targets[arch]) - platform:add("asflags", "-target " .. targets[arch]) - platform:add("ldflags", "-target " .. targets[arch]) - platform:add("shflags", "-target " .. targets[arch]) + toolchain:add("cxflags", "-target " .. targets[arch]) + toolchain:add("asflags", "-target " .. targets[arch]) + toolchain:add("ldflags", "-target " .. targets[arch]) + toolchain:add("shflags", "-target " .. targets[arch]) -- add gcc toolchain local gcc_toolchain = config.get("gcc_toolchain") if gcc_toolchain then - platform:add("cxflags", "-gcc-toolchain " .. gcc_toolchain) - platform:add("asflags", "-gcc-toolchain " .. gcc_toolchain) - platform:add("ldflags", "-gcc-toolchain " .. gcc_toolchain) - platform:add("shflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("cxflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("asflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("ldflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("shflags", "-gcc-toolchain " .. gcc_toolchain) end else local march = arch @@ -83,14 +105,14 @@ function main(platform) march = "armv5te" end -- old version ndk - platform:add("cxflags", "-march=" .. march) - platform:add("asflags", "-march=" .. march) - platform:add("ldflags", "-march=" .. march) - platform:add("shflags", "-march=" .. march) + toolchain:add("cxflags", "-march=" .. march) + toolchain:add("asflags", "-march=" .. march) + toolchain:add("ldflags", "-march=" .. march) + toolchain:add("shflags", "-march=" .. march) end -- init cxflags for the target kind: binary - platform:add("binary.cxflags", "-fPIE", "-pie") + toolchain:add("binary.cxflags", "-fPIE", "-pie") -- add flags for the sdk directory of ndk local ndk = config.get("ndk") @@ -148,29 +170,29 @@ function main(platform) , mips = "mips-linux-android" -- removed in ndk r17 , mips64 = "mips64-linux-android" -- removed in ndk r17 } - platform:add("cxflags", "-D__ANDROID_API__=" .. ndk_sdkver) - platform:add("asflags", "-D__ANDROID_API__=" .. ndk_sdkver) - platform:add("cflags", "--sysroot=" .. ndk_sysroot_be_r14) - platform:add("cxxflags","--sysroot=" .. ndk_sysroot_be_r14) - platform:add("asflags", "--sysroot=" .. ndk_sysroot_be_r14) - platform:add("cflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) - platform:add("cxxflags","-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) - platform:add("asflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("cxflags", "-D__ANDROID_API__=" .. ndk_sdkver) + toolchain:add("asflags", "-D__ANDROID_API__=" .. ndk_sdkver) + toolchain:add("cflags", "--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("cxxflags","--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("asflags", "--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("cflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("cxxflags","-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("asflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) else if sysroot_arch then - platform:add("cflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - platform:add("cxxflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - platform:add("asflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("cflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("cxxflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("asflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) end end if sysroot_arch then - platform:add("ldflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - platform:add("shflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("ldflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("shflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) end -- add "-fPIE -pie" to ldflags - platform:add("ldflags", "-fPIE") - platform:add("ldflags", "-pie") + toolchain:add("ldflags", "-fPIE") + toolchain:add("ldflags", "-pie") -- get llvm c++ stl sdk directory local cxxstl_sdkdir_llvmstl = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) @@ -228,65 +250,65 @@ function main(platform) -- add c++ stl include and link directories if toolchains_arch then - platform:add("ldflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) - platform:add("shflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) + toolchain:add("ldflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) + toolchain:add("shflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) end if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then - platform:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) + toolchain:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) if toolchains_arch then - platform:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) + toolchain:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) end local abi_path = path.join(ndk, "sources", "cxx-stl", "llvm-libc++abi") local before_r13 = path.join(abi_path, "libcxxabi") local after_r13 = path.join(abi_path, "include") if os.isdir(before_r13) then - platform:add("cxxflags", "-I" .. before_r13) + toolchain:add("cxxflags", "-I" .. before_r13) elseif os.isdir(after_r13) then - platform:add("cxxflags", "-I" .. after_r13) + toolchain:add("cxxflags", "-I" .. after_r13) end elseif ndk_cxxstl:startswith("gnustl") then - platform:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) + toolchain:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) if toolchains_arch then - platform:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) + toolchain:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) end elseif ndk_cxxstl:startswith("stlport") then - platform:add("cxxflags", format("-I%s/stlport", cxxstl_sdkdir)) + toolchain:add("cxxflags", format("-I%s/stlport", cxxstl_sdkdir)) end -- add c++ stl links if ndk_cxxstl == "c++_static" or ndk_cxxstl == "llvmstl_static" then - platform:add("ldflags", "-lc++_static", "-lc++abi") - platform:add("shflags", "-lc++_static", "-lc++abi") + toolchain:add("ldflags", "-lc++_static", "-lc++abi") + toolchain:add("shflags", "-lc++_static", "-lc++abi") if arm32 then - platform:add("ldflags", "-lunwind", "-latomic") - platform:add("shflags", "-lunwind", "-latomic") + toolchain:add("ldflags", "-lunwind", "-latomic") + toolchain:add("shflags", "-lunwind", "-latomic") end elseif ndk_cxxstl == "c++_shared" or ndk_cxxstl == "llvmstl_shared" then - platform:add("ldflags", "-lc++_shared", "-lc++abi") - platform:add("shflags", "-lc++_shared", "-lc++abi") + toolchain:add("ldflags", "-lc++_shared", "-lc++abi") + toolchain:add("shflags", "-lc++_shared", "-lc++abi") if arm32 then - platform:add("ldflags", "-lunwind", "-latomic") - platform:add("shflags", "-lunwind", "-latomic") + toolchain:add("ldflags", "-lunwind", "-latomic") + toolchain:add("shflags", "-lunwind", "-latomic") end elseif ndk_cxxstl == "gnustl_static" then - platform:add("ldflags", "-lgnustl_static") - platform:add("shflags", "-lgnustl_static") + toolchain:add("ldflags", "-lgnustl_static") + toolchain:add("shflags", "-lgnustl_static") elseif ndk_cxxstl == "gnustl_shared" then - platform:add("ldflags", "-lgnustl_shared") - platform:add("shflags", "-lgnustl_shared") + toolchain:add("ldflags", "-lgnustl_shared") + toolchain:add("shflags", "-lgnustl_shared") elseif ndk_cxxstl == "stlport_static" then - platform:add("ldflags", "-lstlport_static") - platform:add("shflags", "-lstlport_static") + toolchain:add("ldflags", "-lstlport_static") + toolchain:add("shflags", "-lstlport_static") elseif ndk_cxxstl == "stlport_shared" then - platform:add("ldflags", "-lstlport_shared") - platform:add("shflags", "-lstlport_shared") + toolchain:add("ldflags", "-lstlport_shared") + toolchain:add("shflags", "-lstlport_shared") end -- fix 'ld: error: cannot find -lc++' for clang++.exe on r20/windows -- @see https://github.com/xmake-io/xmake/issues/684 if ndkver and ndkver >= 20 and (ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl")) then - platform:add("ldflags", "-nostdlib++") - platform:add("shflags", "-nostdlib++") + toolchain:add("ldflags", "-nostdlib++") + toolchain:add("shflags", "-nostdlib++") end end end @@ -303,18 +325,16 @@ function main(platform) -- init flags for rust if targets_rust[arch] then - platform:add("rcflags", "--target=" .. targets_rust[arch]) + toolchain:add("rcflags", "--target=" .. targets_rust[arch]) end - platform:add("rc-shflags", "-C link-args=\"" .. (table.concat(platform:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) - platform:add("rc-ldflags", "-C link-args=\"" .. (table.concat(platform:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) - local sh = config.get("sh") + toolchain:add("rcshflags", "-C link-args=\"" .. (table.concat(toolchain:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + toolchain:add("rcldflags", "-C link-args=\"" .. (table.concat(toolchain:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + local sh = toolchain:tool("sh") -- @note we cannot use `config.get("sh")`, because we need check sh first if sh then - platform:add("rc-shflags", "-C linker=" .. sh) + toolchain:add("rcshflags", "-C linker=" .. sh) end - local ld = config.get("ld") + local ld = toolchain:tool("ld") if ld then - platform:add("rc-ldflags", "-C linker=" .. ld) + toolchain:add("rcldflags", "-C linker=" .. ld) end end - - diff --git a/xmake/toolchains/ndk/xmake.lua b/xmake/toolchains/ndk/xmake.lua new file mode 100644 index 000000000..931df3753 --- /dev/null +++ b/xmake/toolchains/ndk/xmake.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("ndk") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") diff --git a/xmake/platforms/sdcc/xmake.lua b/xmake/toolchains/rust/xmake.lua index b06094f9f..43684a5bb 100644 --- a/xmake/platforms/sdcc/xmake.lua +++ b/xmake/toolchains/rust/xmake.lua @@ -18,22 +18,17 @@ -- @file xmake.lua -- --- define platform -platform("sdcc") - - -- set hosts - set_hosts("macosx", "linux", "windows") - - -- set archs - set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") - - -- set formats - set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} - - -- on check project configuration - on_config_check("config") +-- define toolchain +toolchain("rust") + + -- set toolsets + set_toolsets("rc", "$(env RC)", "rustc") + set_toolsets("rcld", "$(env RC)", "rustc") + set_toolsets("rcsh", "$(env RC)", "rustc") + set_toolsets("rcar", "$(env RC)", "rustc") -- on load - on_load("load") - - + on_load(function (toolchain) + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "") + end) diff --git a/xmake/platforms/cross/load.lua b/xmake/toolchains/sdcc/check.lua index 2bc56f971..a55f99a76 100644 --- a/xmake/platforms/cross/load.lua +++ b/xmake/toolchains/sdcc/check.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,32 +15,23 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file check.lua -- -- imports import("core.project.config") +import("detect.sdks.find_cross_toolchain") --- load it -function main(platform) - - -- init linkdirs and includedirs +-- check the cross toolchain +function main(toolchain) local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- add bin search library for loading some dependent .dll files windows local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("sdcc toolchain not found!") end + return cross_toolchain end - diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua new file mode 100644 index 000000000..859f0b6d9 --- /dev/null +++ b/xmake/toolchains/sdcc/xmake.lua @@ -0,0 +1,71 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("sdcc") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "sdcc") + set_toolsets("cxx", "sdcc") + set_toolsets("cpp", "sdcpp") + set_toolsets("as", "sdcc") + set_toolsets("ld", "sdcc") + set_toolsets("sh", "sdcc") + set_toolsets("ar", "sdar") + set_toolsets("ex", "sdar") + + -- set archs + set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") + + -- set formats + set_formats("static", "$(name).lib") + set_formats("object", "$(name).rel") + set_formats("binary", "$(name).bin") + set_formats("symbol", "$(name).sym") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add port flags for arch + local arch = get_config("arch") + if arch then + toolchain:add("cxflags", "-m" .. arch) + toolchain:add("ldflags", "-m" .. arch) + end + end) diff --git a/xmake/modules/private/platform/check_vstudio.lua b/xmake/toolchains/vs/check.lua index 6657e43ea..12fac2aa0 100644 --- a/xmake/modules/private/platform/check_vstudio.lua +++ b/xmake/toolchains/vs/check.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,17 +15,17 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file check_vstudio.lua +-- @file check.lua -- -- imports import("core.base.option") +import("core.project.config") import("detect.sdks.find_vstudio") import("lib.detect.find_tool") -import("core.platform.environment") -- attempt to check vs environment -function _check_vsenv(config) +function _check_vsenv() -- have been checked? local vs = config.get("vs") @@ -59,13 +59,19 @@ function _check_vsenv(config) config.set("__vcvarsall", vcvarsall) -- check compiler - environment.enter("toolchains") + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") + oldenvs.LIB = os.getenv("LIB") + os.setenv("PATH", vsenv.path .. ';' .. (oldenvs.PATH or "")) + os.setenv("LIB", vsenv.lib .. ';' .. (oldenvs.LIB or "")) local program = nil local tool = find_tool("cl.exe", {force = true}) if tool then program = tool.program end - environment.leave("toolchains") + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end -- ok? if program then @@ -77,19 +83,12 @@ function _check_vsenv(config) end -- check the visual studio -function main(config, opt) - - -- attempt to check the given vs version first - local vs = _check_vsenv(config) +function _check_vstudio() + local vs = _check_vsenv() if vs then - - -- save it config.set("vs", vs, {readonly = true, force = true}) - - -- trace cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.success}%s", config.get("arch"), vs) else - -- failed cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", config.get("arch")) if not (opt and opt.try) then print("please run:") @@ -98,6 +97,17 @@ function main(config, opt) raise() end end + return vs end +-- main entry +function main() + -- @see https://github.com/xmake-io/xmake/pull/679 + local cc = path.basename(config.get("cc") or "cl"):lower() + local cxx = path.basename(config.get("cxx") or "cl"):lower() + local mrc = path.basename(config.get("mrc") or "rc"):lower() + if cc == "cl" or cxx == "cl" or mrc == "rc" then + return _check_vstudio(config) + end +end diff --git a/xmake/platforms/windows/environment/enter.lua b/xmake/toolchains/vs/load.lua index 827898222..855869a0b 100644 --- a/xmake/platforms/windows/environment/enter.lua +++ b/xmake/toolchains/vs/load.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,25 +15,25 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file enter.lua +-- @file load.lua -- -- imports +import("core.base.option") import("core.project.config") -import("core.base.global") import("detect.sdks.find_vstudio") --- enter the given environment -function _enter(platform, name) +-- add the given vs environment +function _add_vsenv(toolchain, name) -- get vcvarsall - local vcvarsall = config.get("__vcvarsall") or global.get("__vcvarsall") + local vcvarsall = config.get("__vcvarsall") if not vcvarsall then return end -- get arch - local arch = config.get("arch") or global.get("arch") or "" + local arch = config.get("arch") or "" -- get vs environment for the current arch local vsenv = vcvarsall[arch] or {} @@ -58,38 +58,33 @@ function _enter(platform, name) end -- get the pathes for the vs environment - local old = nil local new = vsenv[name] if new then - - -- get the current pathes - old = os.getenv(name) or "" - - -- append the current pathes - new = new .. ";" .. old - - -- update the pathes for the environment - os.setenv(name, new) + toolchain:add("runenvs", name:upper(), path.splitenv(new)) end - - -- save the previous environment - platform:data_set("windows.environment." .. name, old) end --- enter the toolchains environment -function _enter_toolchains(platform) - _enter(platform, "path") - _enter(platform, "lib") - _enter(platform, "include") - _enter(platform, "libpath") -end +-- main entry +function main(toolchain) --- enter environment -function main(platform, name) - local maps = {toolchains = _enter_toolchains} - local func = maps[name] - if func then - func(platform) + -- set toolsets + toolchain:set("toolsets", "cc", "cl.exe") + toolchain:set("toolsets", "cxx", "cl.exe") + toolchain:set("toolsets", "mrc", "rc.exe") + if is_arch("x64") then + toolchain:set("toolsets", "as", "ml64.exe") + else + toolchain:set("toolsets", "as", "ml.exe") end + toolchain:set("toolsets", "ld", "link.exe") + toolchain:set("toolsets", "sh", "link.exe -dll") + toolchain:set("toolsets", "ar", "link.exe -lib") + toolchain:set("toolsets", "ex", "lib.exe") + + -- add vs environments + _add_vsenv(toolchain, "path") + _add_vsenv(toolchain, "lib") + _add_vsenv(toolchain, "include") + _add_vsenv(toolchain, "libpath") end diff --git a/xmake/platforms/bsd/global.lua b/xmake/toolchains/vs/xmake.lua index d74d84943..cc717de9f 100644 --- a/xmake/platforms/bsd/global.lua +++ b/xmake/toolchains/vs/xmake.lua @@ -15,18 +15,17 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file global.lua +-- @file xmake.lua -- --- imports -import("core.base.global") +-- define toolchain +toolchain("vs") --- check it -function main(platform, name) + -- mark as standalone toolchain + set_kind("standalone") - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end + -- check toolchain + on_check("check") + -- load toolchain + on_load("load") diff --git a/xmake/modules/private/platform/check_xcode.lua b/xmake/toolchains/xcode/check.lua index e0188beb4..925db3870 100644 --- a/xmake/modules/private/platform/check_xcode.lua +++ b/xmake/toolchains/xcode/check.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,30 +15,23 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file check_xcode.lua +-- @file check.lua -- -- imports import("core.base.option") +import("core.project.config") import("detect.sdks.find_xcode") --- check the xcode application directory -function main(config, optional) +-- main entry +function main(toolchain) -- find xcode local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) if xcode then - - -- save it (maybe to global) config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - - elseif not optional then - - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --xcode=xxx") - cprint("or - xmake global --xcode=xxx") - raise() + else + return false end -- save target minver @@ -54,5 +47,5 @@ function main(config, optional) end config.set("target_minver", target_minver) end + return true end - diff --git a/xmake/platforms/iphoneos/load.lua b/xmake/toolchains/xcode/load_iphoneos.lua index c41dc19d6..3aeb78672 100644 --- a/xmake/platforms/iphoneos/load.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,14 +15,14 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file load_iphoneos.lua -- -- imports import("core.project.config") --- load it -function main(platform) +-- main entry +function main(toolchain) -- init architecture local arch = config.get("arch") or "arm64" @@ -44,19 +44,19 @@ function main(platform) local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-shflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-ldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua new file mode 100644 index 000000000..5cebd96bb --- /dev/null +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -0,0 +1,78 @@ +--!A cross-toolchain build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_macosx.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end +end diff --git a/xmake/platforms/watchos/load.lua b/xmake/toolchains/xcode/load_watchos.lua index 78e251728..5048f4bb7 100644 --- a/xmake/platforms/watchos/load.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!A cross-toolchain 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. @@ -15,14 +15,14 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file load_watchos.lua -- -- imports import("core.project.config") --- load it -function main(platform) +-- main entry +function main(toolchain) -- init architecture local arch = config.get("arch") @@ -41,19 +41,19 @@ function main(platform) local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-shflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-ldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua new file mode 100644 index 000000000..74462908c --- /dev/null +++ b/xmake/toolchains/xcode/xmake.lua @@ -0,0 +1,76 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("xcode") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load(function (toolchain) + + -- get cross + local cross, arch, simulator + if is_plat("macosx") then + cross = "xcrun -sdk macosx " + elseif is_plat("iphoneos") then + arch = get_config("arch") or os.arch() + simulator = (arch == "i386" or arch == "x86_64") + cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + elseif is_plat("watchos") then + arch = get_config("arch") or os.arch() + simulator = (arch == "i386") + cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " + else + raise("unknown platform for xcode!") + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "strip", cross .. "strip") + toolchain:set("toolsets", "dsymutil", cross .. "dsymutil", "dsymutil") + toolchain:set("toolsets", "mm", cross .. "clang") + toolchain:set("toolsets", "mxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + if arch then + toolchain:set("toolsets", "cpp", cross .. "clang -arch " .. arch .. " -E") + end + if is_plat("macosx") then + toolchain:set("toolsets", "as", cross .. "clang") + elseif simulator then + toolchain:set("toolsets", "as", cross .. "clang") + else + toolchain:set("toolsets", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross) .. "clang") + end + + -- load configurations + import("load_" .. get_config("plat"))(toolchain) + end) diff --git a/xmake/toolchains/yasm/xmake.lua b/xmake/toolchains/yasm/xmake.lua new file mode 100644 index 000000000..a99a15cc6 --- /dev/null +++ b/xmake/toolchains/yasm/xmake.lua @@ -0,0 +1,36 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("yasm") + + -- set toolsets + set_toolsets("as", "yasm") + + -- on load + on_load(function (toolchain) + if is_plat("macosx") then + toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") + elseif is_plat("linux", "bsd") then + toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") + elseif is_plat("windows", "mingw", "msys", "cygwin") then + toolchain:add("yasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + end + end) |
