diff options
| author | ruki <[email protected]> | 2015-06-12 10:45:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-12 10:45:14 +0800 |
| commit | 1678ef146c122b8a38a4485262f43b816230aa0f (patch) | |
| tree | ad6ff2cef9e9f50726f04dc1cafe135aaa26a26d /xmake/scripts | |
| parent | c2e614548b92821c8396e2a2e9f06afeb97cc7bd (diff) | |
probe and compile for android
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/platform/android/android.lua | 29 | ||||
| -rw-r--r-- | xmake/scripts/platform/android/prober.lua | 114 | ||||
| -rw-r--r-- | xmake/scripts/tools/gcc.lua | 51 | ||||
| -rw-r--r-- | xmake/scripts/tools/tools.lua | 10 |
5 files changed, 162 insertions, 46 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index 53d5a2e5d..f0c71053f 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -371,13 +371,13 @@ function compiler.get(srcfile) -- invalid compiler if not module.command_compile then - return nil, string.format("invalid compiler: %s", platform.tool(kind)) + return nil, string.format("invalid compiler: %s", path.filename(platform.tool(kind))) end -- save kind module._KIND = kind else - return nil, string.format("not found compiler: %s", platform.tool(kind)) + return nil, string.format("unknown compiler: %s", path.filename(platform.tool(kind))) end -- ok? diff --git a/xmake/scripts/platform/android/android.lua b/xmake/scripts/platform/android/android.lua index fe1c14cb7..629f07886 100644 --- a/xmake/scripts/platform/android/android.lua +++ b/xmake/scripts/platform/android/android.lua @@ -45,13 +45,28 @@ function android.make(configs) configs.tools = {} configs.tools.make = "make" configs.tools.ccache = config.get("__ccache") - configs.tools.cc = config.get("cc") or "arm-linux-androideabi-gcc" - configs.tools.cxx = config.get("cxx") or "arm-linux-androideabi-g++" - configs.tools.mm = config.get("mm") or configs.tools.cc - configs.tools.mxx = config.get("mxx") or configs.tools.cxx - configs.tools.ld = config.get("ld") or "arm-linux-androideabi-g++" - configs.tools.ar = config.get("ar") or "arm-linux-androideabi-ar" - configs.tools.sh = config.get("sh") or "arm-linux-androideabi-g++" + configs.tools.cc = config.get("cc") + configs.tools.cxx = config.get("cxx") + configs.tools.as = config.get("as") + configs.tools.ld = config.get("ld") + configs.tools.ar = config.get("ar") + configs.tools.sh = config.get("sh") + + -- init flags + configs.cxflags = { "-march=" .. config.get("arch") } + configs.asflags = { "-march=" .. config.get("arch") } + configs.ldflags = { "-march=" .. config.get("arch"), "-llog" } + configs.shflags = { "-march=" .. config.get("arch"), "-llog" } + + -- add flags for the sdk directory of ndk + local ndk_sdkdir = config.get("__ndk_sdkdir") + if ndk_sdkdir then + ndk_sdkdir = path.translate(ndk_sdkdir) + table.insert(configs.cxflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + table.insert(configs.asflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + table.insert(configs.ldflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + table.insert(configs.shflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + end end diff --git a/xmake/scripts/platform/android/prober.lua b/xmake/scripts/platform/android/prober.lua index 5ecf1731b..37cd18877 100644 --- a/xmake/scripts/platform/android/prober.lua +++ b/xmake/scripts/platform/android/prober.lua @@ -45,7 +45,51 @@ function prober._probe_arch(configs) configs.set("arch", "armv7-a") -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) + + -- ok + return true +end + +-- probe the sdk version for ndk +function prober._probe_ndk_sdkver(configs) + + -- ok? + local ndk_sdkver = config.get("ndk_sdkver") + if ndk_sdkver then return true end + + -- get the ndk + local ndk = config.get("ndk") + if ndk then + + -- match all sdk directories + local sdkdirs = os.match(ndk .. "/platforms/android-*", true) + if sdkdirs then + + -- get the max version + local version_maxn = 0 + for _, sdkdir in ipairs(sdkdirs) do + local filename = path.filename(sdkdir) + local version, count = filename:gsub("android%-", "") + if count > 0 then + version = tonumber(version) + if version > version_maxn then version_maxn = version end + end + end + + -- save the version + if version_maxn > 0 then ndk_sdkver = version_maxn end + end + end + + -- probe ok? update it + if ndk_sdkver > 0 then + configs.set("ndk_sdkver", ndk_sdkver) + configs.set("__ndk_sdkdir", string.format("%s/platforms/android-%d", ndk, ndk_sdkver)) + end + + -- trace + utils.verbose("checking for the SDK version of NDK ... %s", string.format("android-%d", ndk_sdkver)) -- ok return true @@ -82,12 +126,75 @@ function prober._probe_ccache(configs) return true end +-- probe the toolchains +function prober._probe_toolpath(configs, kind, cross, name, description) + + -- check + assert(kind) + + -- get the cross + cross = config.get("cross") or cross + + -- attempt to get it from the given cross toolchains + local toolpath = nil + local toolchains = config.get("toolchains") + if toolchains then + toolpath = tools.probe(cross .. (config.get(kind) or name), toolchains) + end + + -- attempt to get it directly from the configure + if not toolpath then + toolpath = config.get(kind) + end + + -- attempt to get it from the ndk + if not toolpath then + local ndk = config.get("ndk") + if ndk then + + -- match all toolchains + toolchains = os.match(string.format("%s/toolchains/arm-linux-androideabi-**/prebuilt/*/bin/%s%s", ndk, cross, name)) + if toolchains then + for _, filepath in ipairs(toolchains) do + -- probe the tool path + toolpath = tools.probe(cross .. name, path.directory(filepath)) + if toolpath then break end + end + end + end + end + + -- probe ok? update it + if toolpath then configs.set(kind, toolpath) end + + -- trace + utils.verbose("checking for %s (%s) ... %s", description, kind, utils.ifelse(toolpath, path.filename(toolpath), "no")) + + -- ok + return true +end + +-- probe the compiler +function prober._probe_toolchains(configs) + + -- done + if not prober._probe_toolpath(configs, "cc", "arm-linux-androideabi-", "gcc", "the c compiler") then return false end + if not prober._probe_toolpath(configs, "cxx", "arm-linux-androideabi-", "g++", "the c++ compiler") then return false end + if not prober._probe_toolpath(configs, "as", "arm-linux-androideabi-", "gcc", "the assember") then return false end + if not prober._probe_toolpath(configs, "ld", "arm-linux-androideabi-", "g++", "the linker") then return false end + if not prober._probe_toolpath(configs, "ar", "arm-linux-androideabi-", "ar", "the static library linker") then return false end + if not prober._probe_toolpath(configs, "sh", "arm-linux-androideabi-", "g++", "the shared library linker") then return false end + return true +end + -- probe the project configure function prober.config() -- call all probe functions utils.call( { prober._probe_arch - , prober._probe_ccache} + , prober._probe_ccache + , prober._probe_ndk_sdkver + , prober._probe_toolchains} , nil , config) @@ -97,7 +204,8 @@ end function prober.global() -- call all probe functions - utils.call( prober._probe_ccache + utils.call( { prober._probe_ccache + , prober._probe_ndk_sdkver} , nil , global) end diff --git a/xmake/scripts/tools/gcc.lua b/xmake/scripts/tools/gcc.lua index cc94a1ab5..8a5e40ff3 100644 --- a/xmake/scripts/tools/gcc.lua +++ b/xmake/scripts/tools/gcc.lua @@ -57,40 +57,19 @@ function gcc.init(self, name) -- save name self._NAME = name or "gcc" - -- the architecture - local arch = config.get("arch") - assert(arch) - - -- init flags for architecture - local flags_arch = "" - if arch == "x86" then flags_arch = "-m32" - elseif arch == "x64" then flags_arch = "-m64" - else flags_arch = "-arch " .. arch - end - - -- init cxflags - self.cxflags = { flags_arch } - -- init mxflags - self.mxflags = { flags_arch - , "-fmessage-length=0" - , "-pipe" - , "-fpascal-strings" - , "\"-DIBOutlet=__attribute__((iboutlet))\"" - , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" - , "\"-DIBAction=void)__attribute__((ibaction)\""} - - -- init asflags - self.asflags = { flags_arch } - - -- init ldflags - self.ldflags = { flags_arch } + self.mxflags = { "-fmessage-length=0" + , "-pipe" + , "-fpascal-strings" + , "\"-DIBOutlet=__attribute__((iboutlet))\"" + , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" + , "\"-DIBAction=void)__attribute__((ibaction)\""} -- init shflags if name:find("clang") then - self.shflags = { flags_arch, "-dynamiclib" } + self.shflags = { "-dynamiclib" } else - self.shflags = { flags_arch, "-shared -Wl,-soname" } + self.shflags = { "-shared -Wl,-soname" } end -- suppress warning for the ccache bug @@ -102,9 +81,19 @@ function gcc.init(self, name) -- init flags map self.mapflags = { + -- vectorexts + ["-mmmx"] = self._check + , ["-msse$"] = self._check + , ["-msse2"] = self._check + , ["-msse3"] = self._check + , ["-mssse3"] = self._check + , ["-mavx$"] = self._check + , ["-mavx2"] = self._check + , ["-mfpu=.*"] = self._check + -- others - ["-ftrapv"] = self._check - , ["-fsanitize=address"] = self._check + , ["-ftrapv"] = self._check + , ["-fsanitize=address"] = self._check } end diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua index 9add7310c..3dafcd749 100644 --- a/xmake/scripts/tools/tools.lua +++ b/xmake/scripts/tools/tools.lua @@ -147,7 +147,7 @@ function tools.load(name, root) end -- load script - local script = loadfile(toolpath) + local script, errors = loadfile(toolpath) if script then -- load tool @@ -163,6 +163,10 @@ function tools.load(name, root) -- ok? return tool + else + utils.error(errors) + utils.error("load %s failed!", toolpath) + assert(false) end end @@ -184,13 +188,13 @@ function tools.probe(name, dirs) -- attempt to get it from the given directories if dirs then - for _, dir in ipairs(dirs) do + for _, dir in ipairs(utils.wrap(dirs)) do -- probe it local toolpath = tools._probe(dir, name) -- ok? - if toolpath then + if toolpath and os.execute(string.format("%s > %s 2>&1", toolpath, xmake._NULDEV)) ~= 0x7f00 then return toolpath end end |
