diff options
| author | ruki <[email protected]> | 2016-04-23 20:02:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-23 20:02:18 +0800 |
| commit | 48a228f6bb2e4870bf0e4952c0c752ddeae72219 (patch) | |
| tree | 933c64e6834ef2d5a05ebd52eaffb210737b9033 | |
| parent | 31e930871e159dc022ddd1f7a326fcc120e2fb00 (diff) | |
add iphoneos platform
| -rw-r--r-- | xmake/core/_xmake_main.lua | 1 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 2 | ||||
| -rw-r--r-- | xmake/core/platform/checker.lua | 84 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 67 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/try.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 1 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/checker.lua | 35 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/checker.lua | 91 | ||||
| -rwxr-xr-x | xmake/platforms/iphoneos/xmake.lua | 127 | ||||
| -rw-r--r-- | xmake/platforms/macosx/checker.lua | 3 | ||||
| -rwxr-xr-x | xmake/platforms/macosx/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/tools/lipo.lua | 54 |
16 files changed, 401 insertions, 86 deletions
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 754baa3e9..77e27f9e8 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -30,6 +30,7 @@ xmake._VERSION = _VERSION xmake._PROGRAM_DIR = _PROGRAM_DIR xmake._PROJECT_DIR = _PROJECT_DIR xmake._CORE_DIR = _PROGRAM_DIR .. "/core" +xmake._TOOLS_DIR = _PROGRAM_DIR .. "/tools" xmake._PACKAGES_DIR = _PROGRAM_DIR .. "/packages" xmake._TEMPLATES_DIR = _PROGRAM_DIR .. "/templates" xmake._PROJECT_FILE = "xmake.lua" diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 746947bd9..c69b06196 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -223,7 +223,7 @@ function table._dump(self, exclude, level) io.write("<userdata>") else -- error - print("error: invalid object type: %s", type(self)) + print(string.format("error: invalid object type: %s", type(self))) return false end diff --git a/xmake/core/platform/checker.lua b/xmake/core/platform/checker.lua index 52bff4f48..5a03bc132 100644 --- a/xmake/core/platform/checker.lua +++ b/xmake/core/platform/checker.lua @@ -32,16 +32,6 @@ local global = require("project/global") local sandbox = require("sandbox/sandbox") local platform = require("platform/platform") --- the directories of checker -function checker._directories(plat) - - -- the directories - return { path.join(path.join(config.directory(), "platforms"), plat) - , path.join(path.join(global.directory(), "platforms"), plat) - , path.join(path.join(xmake._PROGRAM_DIR, "platforms"), plat) - } -end - -- check the list function checker._checklist(funclist, ...) @@ -62,62 +52,14 @@ end -- load the given checker from the given platform function checker.load(plat) - -- check - assert(plat) - - -- get it directly from cache dirst - checker._CHECKERS = checker._CHECKERS or {} - if checker._CHECKERS[plat] then - return checker._CHECKERS[plat] + -- load platform + local instance, errors = platform.load(plat) + if not instance then + return nil, errors end - -- find the checker script path - local scriptpath = nil - for _, dir in ipairs(checker._directories(plat)) do - - -- find this directory - scriptpath = path.join(dir, "checker.lua") - if os.isfile(scriptpath) then - break - end - - end - - -- not exists? - if not scriptpath or not os.isfile(scriptpath) then - return nil, string.format("the checker of %s not found!", plat) - end - - -- load script - local script, errors = loadfile(scriptpath) - if script then - - -- make sandbox instance with the given script - local instance, errors = sandbox.new(script, nil, path.directory(scriptpath)) - if not instance then - return nil, errors - end - - -- import the module - local module, errors = instance:import() - if not module then - return nil, errors - end - - -- init the module - if module.init then - module.init() - end - - -- save tool to the cache - checker._CHECKERS[plat] = module - - -- ok? - return module - end - - -- failed - return nil, errors + -- get checker + return instance:checker() end -- check the project or global configure @@ -150,14 +92,20 @@ function checker.check(name) -- check all platforms with the current host for _, plat in ipairs(table.wrap(platform.plats())) do - -- load the checker module - local module, errors = checker.load(plat) - if not module then + -- load platform + local instance, errors = platform.load(plat) + if not instance then return false, errors end -- belong to the current host? - if module.get("host") == xmake._HOST then + if instance:host() == xmake._HOST then + + -- get the checker module + local module, errors = instance:checker() + if not module then + return false, errors + end -- check it local ok, errors = checker._checklist(module.get("global"), global) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index c17509558..66593b678 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -35,14 +35,15 @@ local config = require("project/config") local global = require("project/global") -- new an instance -function _instance.new(name, info) +function _instance.new(name, info, rootdir) -- new an instance local instance = table.inherit(_instance) - -- save name and info - instance._NAME = name - instance._INFO = info + -- init instance + instance._NAME = name + instance._INFO = info + instance._ROOTDIR = rootdir -- ok return instance @@ -76,6 +77,59 @@ function _instance:archs() return self._INFO.archs end +-- get the checker +function _instance:checker() + + -- return it directly if cached + if self._CHECKER then + return self._CHECKER + end + + -- get checker + if not self._INFO.checker then + return nil, string.format("the checker of %s not found!", self._NAME) + end + + -- get the script path + local scriptpath = path.join(self._ROOTDIR, self._INFO.checker .. ".lua") + + -- not exists? + if not scriptpath or not os.isfile(scriptpath) then + return nil, string.format("the checker of %s not found!", self._NAME) + end + + -- load script + local script, errors = loadfile(scriptpath) + if script then + + -- make sandbox instance with the given script + local instance, errors = sandbox.new(script, nil, self._ROOTDIR) + if not instance then + return nil, errors + end + + -- import the module + local module, errors = instance:import() + if not module then + return nil, errors + end + + -- init the module + if module.init then + module.init() + end + + -- save tool to the cache + self._CHECKER = module + + -- ok? + return module + end + + -- failed + return nil, errors +end + -- get the platform configure function _instance:get(name) @@ -138,6 +192,9 @@ function platform._interpreter() -- register api: set_platform_menu() interp:api_register_set_values("platform", "platform", "menu") + -- register api: set_platform_checker() + interp:api_register_set_values("platform", "platform", "checker") + -- register api: on_platform_load() interp:api_register_on_script("platform", "platform", "load") @@ -191,7 +248,7 @@ function platform.load(plat) end -- new an instance - local instance, errors = _instance.new(plat, results[plat]) + local instance, errors = _instance.new(plat, results[plat], platform._interpreter():rootdir()) if not instance then return nil, errors end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index fc4f3c195..98dca8bc7 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -166,6 +166,13 @@ function sandbox_os.tmpfile() return os.tmpname() end +-- get the tools directory +function sandbox_os.toolsdir() + + -- get it + return xmake._TOOLS_DIR +end + -- get the program directory function sandbox_os.programdir() diff --git a/xmake/core/sandbox/modules/try.lua b/xmake/core/sandbox/modules/try.lua index 3e21a39df..8a6771e4f 100644 --- a/xmake/core/sandbox/modules/try.lua +++ b/xmake/core/sandbox/modules/try.lua @@ -21,6 +21,7 @@ -- -- load modules +local utils = require("base/utils") local table = require("base/table") local string = require("base/string") local option = require("base/option") @@ -107,8 +108,11 @@ function sandbox_try.try(block) -- run the finally function if funcs and funcs.finally then - funcs.finally() + funcs.finally(utils.ifelse(ok, errors, nil)) end + + -- ok? + return utils.ifelse(ok, errors, nil) end -- return module diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 2d7fcbbaf..c4da87b05 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -59,7 +59,6 @@ function sandbox._traceback(errors) -- get debug info local info = debug.getinfo(level, "Sln") - table.dump(info) -- end? if not info then diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 701983411..b76eaf743 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -272,7 +272,7 @@ function compiler:_addflags_from_platform(flags) -- add flags for _, flagname in ipairs(self:_flagnames()) do - table.join2(flags, self:_mapflags(platform.get(flagname))) + table.join2(flags, platform.get(flagname)) end -- add the includedirs flags diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 8d878a7d7..73f08bad0 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -229,7 +229,7 @@ end function linker:_addflags_from_platform(flags) -- add flags - table.join2(flags, self:_mapflags(platform.get(self:_flagname()))) + table.join2(flags, platform.get(self:_flagname())) -- add the linkdirs flags for _, linkdir in ipairs(table.wrap(platform.get("linkdirs"))) do diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index a6d077de5..2c8ef6ee0 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -117,7 +117,7 @@ function tool._load(shellname) -- find the tool script path local toolpath = nil - local toolname = path.basename(shellname) + local toolname = path.filename(shellname) for _, dir in ipairs(tool._directories()) do -- find this directory diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua index cd0383782..a36845f21 100644 --- a/xmake/platforms/checker.lua +++ b/xmake/platforms/checker.lua @@ -30,12 +30,24 @@ function check_arch(config) local arch = config.get("arch") if not arch then + -- the default architecture + local archs = + { + macosx = os.arch() + , linux = os.arch() + , windows = os.arch() + , iphoneos = "armv7" + , iphonesimulator = os.arch() + , watchos = "armv7" + , watchsimulator = os.arch() + , android = "armv7-a" + } + -- init the default architecture - config.set("arch", os.arch()) + config.set("arch", archs[config.get("plat")]) -- trace print("checking for the architecture ... %s", config.get("arch")) - end end @@ -199,7 +211,7 @@ function check_ccache(config) end -- check the toolchain -function check_toolchain(config, kind, cross, name, description) +function check_toolchain(config, kind, cross, name, description, check) -- get the tool path local toolpath = config.get(kind) @@ -208,6 +220,23 @@ function check_toolchain(config, kind, cross, name, description) -- get the cross cross = config.get("cross") or cross + -- check it using the custom script + if not toolpath and check then + + -- check it + try + { + function () + + -- check it + check(cross .. name) + + -- ok + toolpath = cross .. name + end + } + end + -- attempt to get it from the given cross toolchains local toolchains = config.get("toolchains") if not toolpath and toolchains then diff --git a/xmake/platforms/iphoneos/checker.lua b/xmake/platforms/iphoneos/checker.lua new file mode 100644 index 000000000..f79b0ee55 --- /dev/null +++ b/xmake/platforms/iphoneos/checker.lua @@ -0,0 +1,91 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file checker.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the as +function _check_as(shellname) + + -- make an empty tmp.S + local tmpfile = os.tmpfile() .. ".S" + io.write(tmpfile, "") + + -- check it + os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile) + + -- remove this tmp.S + os.rm(tmpfile) +end + +-- check the toolchains +function _check_toolchains(config) + + -- done + checker.check_toolchain(config, "cc", "xcrun -sdk iphoneos ", "clang", "the c compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk iphoneos ", "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk iphoneos ", "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", "xcrun -sdk iphoneos ", "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk iphoneos ", "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk iphoneos ", "clang", "the objc++ compiler") + checker.check_toolchain(config, "as", path.join(os.toolsdir(), "gas-preprocessor.pl xcrun -sdk iphoneos "), "clang", "the assember", _check_as) + checker.check_toolchain(config, "ld", "xcrun -sdk iphoneos ", "clang++", "the linker") + checker.check_toolchain(config, "ld", "xcrun -sdk iphoneos ", "clang", "the linker") + checker.check_toolchain(config, "ar", "xcrun -sdk iphoneos ", "ar", "the static library linker") + checker.check_toolchain(config, "sh", "xcrun -sdk iphoneos ", "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", "xcrun -sdk iphoneos ", "clang", "the shared library linker") + checker.check_toolchain(config, "sc", "xcrun -sdk iphoneos ", "swiftc", "the swift compiler") + checker.check_toolchain(config, "lipo", "xcrun -sdk iphoneos ", "lipo", "the universal files creater") +end + +-- init it +function init() + + -- init the check list of config + _g.config = + { + checker.check_arch + , checker.check_xcode + , checker.check_xcode_sdkver + , checker.check_target_minver + , checker.check_make + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_xcode + , checker.check_ccache + } + +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua new file mode 100755 index 000000000..56547a5af --- /dev/null +++ b/xmake/platforms/iphoneos/xmake.lua @@ -0,0 +1,127 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define platform +platform("iphoneos") + + -- set os + set_platform_os("ios") + + -- set hosts + set_platform_hosts("macosx") + + -- set archs + set_platform_archs("armv7", "armv7s", "arm64") + + -- set checker + set_platform_checker("checker") + + -- on load + on_platform_load(function () + + -- imports + import("core.project.config") + + -- init the file formats + _g.formats = {} + _g.formats.static = {"lib", ".a"} + _g.formats.object = {"", ".o"} + _g.formats.shared = {"lib", ".dylib"} + + -- init the tools + _g.tools = {} + _g.tools.make = config.get("make") + _g.tools.ccache = config.get("__ccache") + _g.tools.cc = config.get("cc") + _g.tools.cxx = config.get("cxx") + _g.tools.mm = config.get("mm") + _g.tools.mxx = config.get("mxx") + _g.tools.ld = config.get("ld") + _g.tools.as = config.get("as") + _g.tools.ar = config.get("ar") + _g.tools.sh = config.get("sh") + _g.tools.ex = config.get("ar") + _g.tools.sc = config.get("sc") + _g.tools.lipo = config.get("lipo") + + -- init flags for architecture + local arch = config.get("arch") + local target_minver = config.get("target_minver") + _g.cxflags = { "-arch " .. arch, "-miphoneos-version-min=" .. target_minver } + _g.mxflags = { "-arch " .. arch, "-miphoneos-version-min=" .. target_minver } + _g.asflags = { "-arch " .. arch, "-miphoneos-version-min=" .. target_minver } + _g.ldflags = { "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", "-miphoneos-version-min=" .. target_minver } + _g.shflags = { "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", "-miphoneos-version-min=" .. target_minver } + _g.scflags = { format("-target %s-apple-ios%s", arch, target_minver) } + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode_dir") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS" .. xcode_sdkver .. ".sdk" + insert(_g.cxflags, "-isysroot " .. xcode_sdkdir) + insert(_g.asflags, "-isysroot " .. xcode_sdkdir) + insert(_g.mxflags, "-isysroot " .. xcode_sdkdir) + insert(_g.ldflags, "-isysroot " .. xcode_sdkdir) + insert(_g.shflags, "-isysroot " .. xcode_sdkdir) + insert(_g.scflags, "-sdk " .. xcode_sdkdir) + + -- save swift link directory for tools + config.set("__swift_linkdirs", xcode_dir .. "/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos") + + end) + + -- set menu + set_platform_menu({ + config = + { + {} + , {nil, "mm", "kv", nil, "the objc compiler" } + , {nil, "mxx", "kv", nil, "the objc++ compiler" } + , {nil, "mflags", "kv", nil, "the objc compiler flags" } + , {nil, "mxflags", "kv", nil, "the objc/c++ compiler flags" } + , {nil, "mxxflags", "kv", nil, "the objc++ compiler flags" } + , {} + , {nil, "xcode_dir", "kv", "auto", "the xcode application directory" } + , {nil, "xcode_sdkver", "kv", "auto", "the sdk version for xcode" } + , {nil, "target_minver", "kv", "auto", "the target minimal version" } + , {} + , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" } + , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } + , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } + } + + , global = + { + {} + , {nil, "xcode_dir", "kv", "auto", "the xcode application directory" } + , {} + , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" } + , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } + , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } + } + }) + + + + + + diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua index 544363732..f39b28ff5 100644 --- a/xmake/platforms/macosx/checker.lua +++ b/xmake/platforms/macosx/checker.lua @@ -47,9 +47,6 @@ end -- init it function init() - -- init host - _g.host = "macosx" - -- init the check list of config _g.config = { diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 922ca3165..19b1fb4a3 100755 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -33,7 +33,7 @@ platform("macosx") set_platform_archs("i386", "x86_64") -- set checker --- set_platform_checker("checker") + set_platform_checker("checker") -- on load on_platform_load(function () @@ -55,6 +55,7 @@ platform("macosx") _g.tools.cxx = config.get("cxx") _g.tools.mm = config.get("mm") _g.tools.mxx = config.get("mxx") + _g.tools.as = config.get("as") _g.tools.ld = config.get("ld") _g.tools.ar = config.get("ar") _g.tools.sh = config.get("sh") diff --git a/xmake/tools/lipo.lua b/xmake/tools/lipo.lua new file mode 100644 index 000000000..6a08e0fb7 --- /dev/null +++ b/xmake/tools/lipo.lua @@ -0,0 +1,54 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file lipo.lua +-- + +-- imports +import("core.base.option") + +-- init it +function init(shellname) + + -- save name + _g.shellname = shellname or "lipo" + +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + +-- run command +function run(...) + + -- run it + os.run(...) +end + +-- check the given flags +function check(flags) + + -- check it + os.run("xcrun -find lipo") +end + |
