diff options
| author | ruki <[email protected]> | 2018-11-12 22:38:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-12 09:52:19 +0800 |
| commit | 377840c51da27c07f9d94caf458f99eb197798e3 (patch) | |
| tree | 3561bdbbc9b7a82b06cc68494e3a9f0f52bd5f2d | |
| parent | f372a5c5cf20e9a7deaa99cdb9d2c14b5aec7755 (diff) | |
improve platform
| -rw-r--r-- | xmake/core/base/table.lua | 15 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 54 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 14 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 10 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 82 |
5 files changed, 81 insertions, 94 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 6ee3544a1..de024ff2b 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -264,18 +264,13 @@ end -- unwrap object if be only one function table.unwrap(object) - - -- check - assert(object) - - -- unwrap it - if type(object) == "table" and table.getn(object) == 1 then - for _, v in pairs(object) do - return v + if type(object) == "table" then + if #object == 1 then + return object[1] + elseif #object == 0 then + return end end - - -- ok return object end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index a0b9cad98..dc16bf0d4 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -51,53 +51,40 @@ function _instance.new(name, info, rootdir) return instance end --- get the platform configure -function _instance:get(name) - - -- the info - local info = self._INFO - - -- get if from info first - local value = info[name] - if value ~= nil then - return value - end - - -- load _g - if self._g == nil and info.load ~= nil then - - -- load it - local ok, results = sandbox.load(info.load) - if not ok then - os.raise(results) - end +-- set the value to the platform info +function _instance:set(name, ...) + self._INFO[name] = table.unwrap(table.unique({...})) +end - -- save _g - self._g = results - end +-- add the value to the platform info +function _instance:add(name, ...) + local info = table.wrap(self._INFO[name]) + self._INFO[name] = table.unwrap(table.unique(table.join(info, ...))) +end - -- get it from _g - return self._g[name] +-- get the platform configure +function _instance:get(name) + return self._INFO[name] end -- get the platform os function _instance:os() - return self._INFO.os + return self:get("os") end -- get the platform menu function _instance:menu() - return self._INFO.menu + return self:get("menu") end -- get the platform hosts function _instance:hosts() - return self._INFO.hosts + return self:get("hosts") end -- get the platform archs function _instance:archs() - return self._INFO.archs + return self:get("archs") end -- the directories of platform @@ -217,6 +204,15 @@ function platform.load(plat) return nil, errors end + -- do load + local on_load = instance:get("load") + if on_load then + local ok, errors = sandbox.load(on_load, instance) + if not ok then + return nil, errors + end + end + -- save instance to the cache platform._PLATFORMS[plat] = instance diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 34334bf95..99f965a0a 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -48,15 +48,17 @@ end function compiler:_addflags_from_platform(flags, targetkind) -- add flags - local toolkind = self:kind() + local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - -- add flags for platform - table.join2(flags, platform.get(flagkind)) + -- add flags for platform, e.g. gcc.cxflags or cxflags + local toolflags = platform.get(toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.get(flagkind)) - -- add flags for platform and the given taget kind - if targetkind ~= nil and platform.get(targetkind) ~= nil then - table.join2(flags, platform.get(targetkind)[flagkind]) + -- add flags for platform with the given target kind, e.g. binary.gcc.cxflags or binary.cxflags + if targetkind then + local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.get(targetkind .. '.' .. flagkind)) end end end diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 2cfc20fdf..363e7ad30 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -45,15 +45,17 @@ function linker:_addflags_from_platform(flags, targetkind) -- add flags local toolkind = self:kind() + local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - -- attempt to add special lanugage flags first, .e.g gc-ldflags, dc-arflags - table.join2(flags, platform.get(toolkind .. 'flags') or platform.get(flagkind)) + -- attempt to add special lanugage flags first, e.g. go.gc-ldflags or gcc.ldflags or gc-ldflags or ldflags + local toolflags = platform.get(toolname .. '.' .. toolkind .. 'flags') or platform.get(toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.get(toolkind .. 'flags') or platform.get(flagkind)) -- attempt to add special lanugage flags first for target kind, .e.g gc-ldflags, dc-arflags if targetkind then - local targetflags = platform.get(targetkind) or {} - table.join2(flags, targetflags[toolkind .. 'flags'] or targetflags[flagkind]) + 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)) end end end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 8d9ae97c4..d917585df 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -26,7 +26,7 @@ import("core.project.config") -- load it -function main() +function main(platform) -- init flags for architecture local arch = config.get("arch") or os.arch() @@ -41,77 +41,69 @@ function main() end -- init flags for c/c++ - _g.cxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0" } - _g.ldflags = { "-arch " .. arch } + platform:add("cxflags", "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0") + platform:add("ldflags", "-arch " .. arch) if target_minver then - table.insert(_g.ldflags, "-mmacosx-version-min=" .. target_minver) + platform:add("ldflags", "-mmacosx-version-min=" .. target_minver) end if xcode_sdkdir then - table.insert(_g.cxflags, "-isysroot " .. xcode_sdkdir) - table.insert(_g.ldflags, "-isysroot " .. xcode_sdkdir) + platform:add("cxflags", "-isysroot " .. xcode_sdkdir) + platform:add("ldflags", "-isysroot " .. xcode_sdkdir) else - table.insert(_g.cxflags, "-I/usr/local/include") - table.insert(_g.cxflags, "-I/usr/include") - table.insert(_g.ldflags, "-L/usr/local/lib") - table.insert(_g.ldflags, "-L/usr/lib") + 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 - table.insert(_g.ldflags, "-stdlib=libc++") - table.insert(_g.ldflags, "-lz") - _g.shflags = table.copy(_g.ldflags) + platform:add("ldflags", "-stdlib=libc++") + platform:add("ldflags", "-lz") + platform:add("shflags", platform:get("ldflags")) - -- init flags for objc/c++ (with _g.ldflags and _g.shflags) - _g.mxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0" } + -- init flags for objc/c++ (with ldflags and shflags) + platform:add("mxflags", "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0") if xcode_sdkdir then - table.insert(_g.mxflags, "-isysroot " .. xcode_sdkdir) + platform:add("mxflags", "-isysroot " .. xcode_sdkdir) end -- init flags for asm - local as = config.get("as") - if as == "yasm" then - _g.asflags = { "-f", arch == "x86_64" and "macho64" or "macho32" } - elseif as == "fasm" then - _g.asflags = {} - else - _g.asflags = { "-arch " .. arch } - if xcode_sdkdir then - table.insert(_g.asflags, "-isysroot " .. xcode_sdkdir) - end + 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 - _g.scflags = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } - _g["sc-shflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } - _g["sc-ldflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + 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 - _g["gc-ldflags"] = {} + platform:set("gc-ldflags", "") -- init flags for dlang local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - _g.dcflags = { dc_archs[arch] or "" } - _g["dc-shflags"] = { dc_archs[arch] or "" } - _g["dc-ldflags"] = { dc_archs[arch] or "" } + 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 - _g["rc-shflags"] = {} - _g["rc-ldflags"] = {} + platform:set("rc-shflags", "") + platform:set("rc-ldflags", "") -- init flags for cuda local cu_archs = { i386 = "-m32 -Xcompiler -arch -Xcompiler i386", x86_64 = "-m64 -Xcompiler -arch -Xcompiler x86_64" } - _g.cuflags = {cu_archs[arch] or ""} - _g["cu-shflags"] = {cu_archs[arch] or ""} - _g["cu-ldflags"] = {cu_archs[arch] or ""} + platform:add("cuflags", cu_archs[arch] or "") + platform:add("cu-shflags", cu_archs[arch] or "") + platform:add("cu-ldflags", cu_archs[arch] or "") local cuda_dir = config.get("cuda") if cuda_dir then - table.insert(_g.cuflags, "-I" .. os.args(path.join(cuda_dir, "include"))) - table.insert(_g["cu-ldflags"], "-L" .. os.args(path.join(cuda_dir, "lib"))) - table.insert(_g["cu-shflags"], "-L" .. os.args(path.join(cuda_dir, "lib"))) - table.insert(_g["cu-ldflags"], "-Xlinker -rpath -Xlinker " .. os.args(path.join(cuda_dir, "lib"))) + platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) + platform:add("cu-ldflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) + platform:add("cu-shflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) + platform:add("cu-ldflags", "-Xlinker -rpath -Xlinker " .. os.args(path.join(cuda_dir, "lib"))) end - - -- ok - return _g end |
