diff options
| author | ruki <[email protected]> | 2015-06-12 12:30:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-12 12:30:56 +0800 |
| commit | 99b9eb72c8db9854311fc0b5a79e07f8cae85242 (patch) | |
| tree | 837868dffc057d9a987ac4dc0592d98b015563c2 /xmake/scripts | |
| parent | 1678ef146c122b8a38a4485262f43b816230aa0f (diff) | |
modify platform and probe toolchains
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_config.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/action/_global.lua | 13 | ||||
| -rw-r--r-- | xmake/scripts/platform/android/android.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/platform/android/prober.lua | 40 | ||||
| -rw-r--r-- | xmake/scripts/platform/iphoneos/iphoneos.lua | 41 | ||||
| -rw-r--r-- | xmake/scripts/platform/iphoneos/prober.lua | 92 | ||||
| -rw-r--r-- | xmake/scripts/platform/iphonesimulator/iphonesimulator.lua | 41 | ||||
| -rw-r--r-- | xmake/scripts/platform/iphonesimulator/prober.lua | 92 | ||||
| -rw-r--r-- | xmake/scripts/platform/linux/prober.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/platform/macosx/macosx.lua | 45 | ||||
| -rw-r--r-- | xmake/scripts/platform/macosx/prober.lua | 93 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/prober.lua | 61 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/cl.lua | 56 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/link.lua | 56 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/nmake.lua | 56 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/windows.lua | 77 | ||||
| -rw-r--r-- | xmake/scripts/tools/gcc.lua | 2 |
17 files changed, 536 insertions, 236 deletions
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua index 417d6ec36..13916114a 100644 --- a/xmake/scripts/action/_config.lua +++ b/xmake/scripts/action/_config.lua @@ -125,7 +125,8 @@ function _config.menu() , function () return project.menu() end , {} - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } + , {nil, "make", "kv", "auto", "Set the make path." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } , {} , {nil, "cross", "kv", nil, "The cross toolchains prefix" diff --git a/xmake/scripts/action/_global.lua b/xmake/scripts/action/_global.lua index c2b7a956b..2ae54483c 100644 --- a/xmake/scripts/action/_global.lua +++ b/xmake/scripts/action/_global.lua @@ -62,18 +62,19 @@ function _global.menu() -- options , options = { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." - , " --ccache=[y|n]" } + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + , {nil, "make", "kv", "auto", "Set the make path." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." + , " --ccache=[y|n]" } , {} -- the options for all platforms , function () return platform.menu("global") end , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } } } end diff --git a/xmake/scripts/platform/android/android.lua b/xmake/scripts/platform/android/android.lua index 629f07886..4774b79b5 100644 --- a/xmake/scripts/platform/android/android.lua +++ b/xmake/scripts/platform/android/android.lua @@ -43,7 +43,7 @@ function android.make(configs) -- init the toolchains configs.tools = {} - configs.tools.make = "make" + configs.tools.make = config.get("make") configs.tools.ccache = config.get("__ccache") configs.tools.cc = config.get("cc") configs.tools.cxx = config.get("cxx") diff --git a/xmake/scripts/platform/android/prober.lua b/xmake/scripts/platform/android/prober.lua index 37cd18877..45f4c23ea 100644 --- a/xmake/scripts/platform/android/prober.lua +++ b/xmake/scripts/platform/android/prober.lua @@ -55,11 +55,11 @@ end function prober._probe_ndk_sdkver(configs) -- ok? - local ndk_sdkver = config.get("ndk_sdkver") + local ndk_sdkver = configs.get("ndk_sdkver") if ndk_sdkver then return true end -- get the ndk - local ndk = config.get("ndk") + local ndk = configs.get("ndk") if ndk then -- match all sdk directories @@ -95,6 +95,26 @@ function prober._probe_ndk_sdkver(configs) return true end +-- probe the make +function prober._probe_make(configs) + + -- ok? + local make = configs.get("make") + if make then return true end + + -- probe the make path + make = tools.probe("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"}) + + -- probe ok? update it + if make then configs.set("make", make) end + + -- trace + utils.verbose("checking for the make ... %s", utils.ifelse(make, make, "no")) + + -- ok + return true +end + -- probe the ccache function prober._probe_ccache(configs) @@ -133,23 +153,23 @@ function prober._probe_toolpath(configs, kind, cross, name, description) assert(kind) -- get the cross - cross = config.get("cross") or cross + cross = configs.get("cross") or cross -- attempt to get it from the given cross toolchains local toolpath = nil - local toolchains = config.get("toolchains") + local toolchains = configs.get("toolchains") if toolchains then - toolpath = tools.probe(cross .. (config.get(kind) or name), toolchains) + toolpath = tools.probe(cross .. (configs.get(kind) or name), toolchains) end -- attempt to get it directly from the configure if not toolpath then - toolpath = config.get(kind) + toolpath = configs.get(kind) end -- attempt to get it from the ndk if not toolpath then - local ndk = config.get("ndk") + local ndk = configs.get("ndk") if ndk then -- match all toolchains @@ -174,7 +194,7 @@ function prober._probe_toolpath(configs, kind, cross, name, description) return true end --- probe the compiler +-- probe the toolchains function prober._probe_toolchains(configs) -- done @@ -192,6 +212,7 @@ function prober.config() -- call all probe functions utils.call( { prober._probe_arch + , prober._probe_make , prober._probe_ccache , prober._probe_ndk_sdkver , prober._probe_toolchains} @@ -204,7 +225,8 @@ end function prober.global() -- call all probe functions - utils.call( { prober._probe_ccache + utils.call( { prober._probe_make + , prober._probe_ccache , prober._probe_ndk_sdkver} , nil , global) diff --git a/xmake/scripts/platform/iphoneos/iphoneos.lua b/xmake/scripts/platform/iphoneos/iphoneos.lua index 3d8538e2a..30d6f049e 100644 --- a/xmake/scripts/platform/iphoneos/iphoneos.lua +++ b/xmake/scripts/platform/iphoneos/iphoneos.lua @@ -43,24 +43,35 @@ function iphoneos.make(configs) -- init the toolchains configs.tools = {} - configs.tools.make = "make" + configs.tools.make = config.get("make") configs.tools.ccache = config.get("__ccache") - configs.tools.cc = config.get("cc") or "xcrun -sdk iphoneos clang" - configs.tools.cxx = config.get("cxx") or "xcrun -sdk iphoneos clang++" - 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 "xcrun -sdk iphoneos clang++" - configs.tools.ar = config.get("ar") or "xcrun -sdk iphoneos ar" - configs.tools.sh = config.get("sh") or "xcrun -sdk iphoneos clang++" + configs.tools.cc = config.get("cc") + configs.tools.cxx = config.get("cxx") + configs.tools.mm = config.get("mm") + configs.tools.mxx = config.get("mxx") + configs.tools.ld = config.get("ld") + configs.tools.ar = config.get("ar") + configs.tools.sh = config.get("sh") - -- init xcode sdk directory - configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS" .. config.get("xcode_sdkver") .. ".sdk" + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then archflags = "-arch " .. arch end + configs.cxflags = { archflags } + configs.mxflags = { archflags } + configs.asflags = { archflags } + configs.ldflags = { archflags } + configs.shflags = { archflags } - -- init flags - configs.cxflags = "-isysroot " .. configs.xcode_sdkdir - configs.mxflags = "-isysroot " .. configs.xcode_sdkdir - configs.ldflags = "-isysroot " .. configs.xcode_sdkdir - configs.shflags = "-isysroot " .. configs.xcode_sdkdir + -- init flags for the xcode sdk directory + local xcode_sdkdir = config.get("__xcode_sdkdir") + if xcode_sdkdir then + table.insert(configs.cxflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.asflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.mxflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.ldflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.shflags, "-isysroot " .. xcode_sdkdir) + end end diff --git a/xmake/scripts/platform/iphoneos/prober.lua b/xmake/scripts/platform/iphoneos/prober.lua index e62b4d39f..00b59b205 100644 --- a/xmake/scripts/platform/iphoneos/prober.lua +++ b/xmake/scripts/platform/iphoneos/prober.lua @@ -45,7 +45,7 @@ function prober._probe_arch(configs) configs.set("arch", "armv7") -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) -- ok return true @@ -84,10 +84,10 @@ function prober._probe_xcode(configs) configs.set("xcode_dir", xcode_dir) -- trace - utils.verbose("checking the Xcode application directory ... %s", xcode_dir) + utils.verbose("checking for the Xcode application directory ... %s", xcode_dir) else -- failed - utils.error("checking the Xcode application directory ... no") + utils.error("checking for the Xcode application directory ... no") utils.error(" - xmake config --xcode_dir=xxx") utils.error("or - xmake global --xcode_dir=xxx") return false @@ -126,11 +126,17 @@ function prober._probe_xcode_sdkver(configs) -- save it configs.set("xcode_sdkver", xcode_sdkver) + -- save the xcode sdk directory + local xcode_dir = configs.get("xcode_dir") + if xcode_dir then + configs.set("__xcode_sdkdir", xcode_dir .. "/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS" .. xcode_sdkver .. ".sdk") + end + -- trace - utils.verbose("checking the Xcode SDK version for %s ... %s", configs.get("plat"), xcode_sdkver) + utils.verbose("checking for the Xcode SDK version for %s ... %s", configs.get("plat"), xcode_sdkver) else -- failed - utils.error("checking the Xcode SDK version for %s ... no", configs.get("plat")) + utils.error("checking for the Xcode SDK version for %s ... no", configs.get("plat")) utils.error(" - xmake config --xcode_sdkver=xxx") utils.error("or - xmake global --xcode_sdkver=xxx") return false @@ -140,6 +146,26 @@ function prober._probe_xcode_sdkver(configs) return true end +-- probe the make +function prober._probe_make(configs) + + -- ok? + local make = configs.get("make") + if make then return true end + + -- probe the make path + make = tools.probe("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"}) + + -- probe ok? update it + if make then configs.set("make", make) end + + -- trace + utils.verbose("checking for the make ... %s", utils.ifelse(make, make, "no")) + + -- ok + return true +end + -- probe the ccache function prober._probe_ccache(configs) @@ -171,6 +197,57 @@ function prober._probe_ccache(configs) return true end +-- probe the tool path +function prober._probe_toolpath(configs, kind, cross, name, description) + + -- check + assert(kind) + + -- get the cross + cross = configs.get("cross") or cross + + -- attempt to get it from the given cross toolchains + local toolpath = nil + local toolchains = configs.get("toolchains") + if toolchains then + toolpath = tools.probe(cross .. (configs.get(kind) or name), toolchains) + end + + -- attempt to get it directly from the configure + if not toolpath then + toolpath = configs.get(kind) + end + + -- attempt to run it directly + if not toolpath then + toolpath = tools.probe(cross .. name) + 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 toolchains +function prober._probe_toolchains(configs) + + -- done + if not prober._probe_toolpath(configs, "cc", "xcrun -sdk iphoneos ", "clang", "the c compiler") then return false end + if not prober._probe_toolpath(configs, "cxx", "xcrun -sdk iphoneos ", "clang++", "the c++ compiler") then return false end + if not prober._probe_toolpath(configs, "mm", "xcrun -sdk iphoneos ", "clang", "the objc compiler") then return false end + if not prober._probe_toolpath(configs, "mxx", "xcrun -sdk iphoneos ", "clang++", "the objc++ compiler") then return false end + if not prober._probe_toolpath(configs, "as", "xcrun -sdk iphoneos ", "clang", "the assember") then return false end + if not prober._probe_toolpath(configs, "ld", "xcrun -sdk iphoneos ", "clang++", "the linker") then return false end + if not prober._probe_toolpath(configs, "ar", "xcrun -sdk iphoneos ", "ar", "the static library linker") then return false end + if not prober._probe_toolpath(configs, "sh", "xcrun -sdk iphoneos ", "clang++", "the shared library linker") then return false end + return true +end + -- probe the project configure function prober.config() @@ -178,7 +255,9 @@ function prober.config() utils.call( { prober._probe_arch , prober._probe_xcode , prober._probe_xcode_sdkver - , prober._probe_ccache} + , prober._probe_make + , prober._probe_ccache + , prober._probe_toolchains} , nil , config) @@ -189,6 +268,7 @@ function prober.global() -- call all probe functions utils.call( { prober._probe_xcode + , prober._probe_make , prober._probe_ccache} , nil , global) diff --git a/xmake/scripts/platform/iphonesimulator/iphonesimulator.lua b/xmake/scripts/platform/iphonesimulator/iphonesimulator.lua index 5189eb9ed..8cf3e4ea4 100644 --- a/xmake/scripts/platform/iphonesimulator/iphonesimulator.lua +++ b/xmake/scripts/platform/iphonesimulator/iphonesimulator.lua @@ -43,24 +43,35 @@ function iphonesimulator.make(configs) -- init the toolchains configs.tools = {} - configs.tools.make = "make" + configs.tools.make = config.get("make") configs.tools.ccache = config.get("__ccache") - configs.tools.cc = config.get("cc") or "xcrun -sdk iphonesimulator clang" - configs.tools.cxx = config.get("cxx") or "xcrun -sdk iphonesimulator clang++" - 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 "xcrun -sdk iphonesimulator clang++" - configs.tools.ar = config.get("ar") or "xcrun -sdk iphonesimulator ar" - configs.tools.sh = config.get("sh") or "xcrun -sdk iphonesimulator clang++" + configs.tools.cc = config.get("cc") + configs.tools.cxx = config.get("cxx") + configs.tools.mm = config.get("mm") + configs.tools.mxx = config.get("mxx") + configs.tools.ld = config.get("ld") + configs.tools.ar = config.get("ar") + configs.tools.sh = config.get("sh") - -- init xcode sdk directory - configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" .. config.get("xcode_sdkver") .. ".sdk" + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then archflags = "-arch " .. arch end + configs.cxflags = { archflags } + configs.mxflags = { archflags } + configs.asflags = { archflags } + configs.ldflags = { archflags } + configs.shflags = { archflags } - -- init flags - configs.cxflags = "-isysroot " .. configs.xcode_sdkdir - configs.mxflags = "-isysroot " .. configs.xcode_sdkdir - configs.ldflags = "-isysroot " .. configs.xcode_sdkdir - configs.shflags = "-isysroot " .. configs.xcode_sdkdir + -- init flags for the xcode sdk directory + local xcode_sdkdir = config.get("__xcode_sdkdir") + if xcode_sdkdir then + table.insert(configs.cxflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.asflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.mxflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.ldflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.shflags, "-isysroot " .. xcode_sdkdir) + end end diff --git a/xmake/scripts/platform/iphonesimulator/prober.lua b/xmake/scripts/platform/iphonesimulator/prober.lua index 9d48d5f15..7760f7fdb 100644 --- a/xmake/scripts/platform/iphonesimulator/prober.lua +++ b/xmake/scripts/platform/iphonesimulator/prober.lua @@ -45,7 +45,7 @@ function prober._probe_arch(configs) configs.set("arch", "i386") -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) -- ok return true @@ -84,10 +84,10 @@ function prober._probe_xcode(configs) configs.set("xcode_dir", xcode_dir) -- trace - utils.verbose("checking the Xcode application directory ... %s", xcode_dir) + utils.verbose("checking for the Xcode application directory ... %s", xcode_dir) else -- failed - utils.error("checking the Xcode application directory ... no") + utils.error("checking for the Xcode application directory ... no") utils.error(" - xmake config --xcode_dir=xxx") utils.error("or - xmake global --xcode_dir=xxx") return false @@ -126,11 +126,17 @@ function prober._probe_xcode_sdkver(configs) -- save it configs.set("xcode_sdkver", xcode_sdkver) + -- save the xcode sdk directory + local xcode_dir = configs.get("xcode_dir") + if xcode_dir then + configs.set("__xcode_sdkdir", xcode_dir .. "/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" .. xcode_sdkver .. ".sdk") + end + -- trace - utils.verbose("checking the Xcode SDK version for %s ... %s", configs.get("plat"), xcode_sdkver) + utils.verbose("checking for the Xcode SDK version for %s ... %s", configs.get("plat"), xcode_sdkver) else -- failed - utils.error("checking the Xcode SDK version for %s ... no", configs.get("plat")) + utils.error("checking for the Xcode SDK version for %s ... no", configs.get("plat")) utils.error(" - xmake config --xcode_sdkver=xxx") utils.error("or - xmake global --xcode_sdkver=xxx") return false @@ -140,6 +146,26 @@ function prober._probe_xcode_sdkver(configs) return true end +-- probe the make +function prober._probe_make(configs) + + -- ok? + local make = configs.get("make") + if make then return true end + + -- probe the make path + make = tools.probe("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"}) + + -- probe ok? update it + if make then configs.set("make", make) end + + -- trace + utils.verbose("checking for the make ... %s", utils.ifelse(make, make, "no")) + + -- ok + return true +end + -- probe the ccache function prober._probe_ccache(configs) @@ -171,6 +197,57 @@ function prober._probe_ccache(configs) return true end +-- probe the tool path +function prober._probe_toolpath(configs, kind, cross, name, description) + + -- check + assert(kind) + + -- get the cross + cross = configs.get("cross") or cross + + -- attempt to get it from the given cross toolchains + local toolpath = nil + local toolchains = configs.get("toolchains") + if toolchains then + toolpath = tools.probe(cross .. (configs.get(kind) or name), toolchains) + end + + -- attempt to get it directly from the configure + if not toolpath then + toolpath = configs.get(kind) + end + + -- attempt to run it directly + if not toolpath then + toolpath = tools.probe(cross .. name) + 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 toolchains +function prober._probe_toolchains(configs) + + -- done + if not prober._probe_toolpath(configs, "cc", "xcrun -sdk iphonesimulator ", "clang", "the c compiler") then return false end + if not prober._probe_toolpath(configs, "cxx", "xcrun -sdk iphonesimulator ", "clang++", "the c++ compiler") then return false end + if not prober._probe_toolpath(configs, "mm", "xcrun -sdk iphonesimulator ", "clang", "the objc compiler") then return false end + if not prober._probe_toolpath(configs, "mxx", "xcrun -sdk iphonesimulator ", "clang++", "the objc++ compiler") then return false end + if not prober._probe_toolpath(configs, "as", "xcrun -sdk iphonesimulator ", "clang", "the assember") then return false end + if not prober._probe_toolpath(configs, "ld", "xcrun -sdk iphonesimulator ", "clang++", "the linker") then return false end + if not prober._probe_toolpath(configs, "ar", "xcrun -sdk iphonesimulator ", "ar", "the static library linker") then return false end + if not prober._probe_toolpath(configs, "sh", "xcrun -sdk iphonesimulator ", "clang++", "the shared library linker") then return false end + return true +end + -- probe the project configure function prober.config() @@ -178,7 +255,9 @@ function prober.config() utils.call( { prober._probe_arch , prober._probe_xcode , prober._probe_xcode_sdkver - , prober._probe_ccache} + , prober._probe_make + , prober._probe_ccache + , prober._probe_toolchains} , nil , config) end @@ -188,6 +267,7 @@ function prober.global() -- call all probe functions utils.call( { prober._probe_xcode + , prober._probe_make , prober._probe_ccache} , nil , global) diff --git a/xmake/scripts/platform/linux/prober.lua b/xmake/scripts/platform/linux/prober.lua index 772c0ee66..9f18ccd15 100644 --- a/xmake/scripts/platform/linux/prober.lua +++ b/xmake/scripts/platform/linux/prober.lua @@ -45,7 +45,7 @@ function prober._probe_arch(configs) configs.set("arch", xmake._ARCH) -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) -- ok return true diff --git a/xmake/scripts/platform/macosx/macosx.lua b/xmake/scripts/platform/macosx/macosx.lua index 5bdc6f1f3..5adeb0e6a 100644 --- a/xmake/scripts/platform/macosx/macosx.lua +++ b/xmake/scripts/platform/macosx/macosx.lua @@ -43,24 +43,39 @@ function macosx.make(configs) -- init the toolchains configs.tools = {} - configs.tools.make = "make" + configs.tools.make = config.get("make") configs.tools.ccache = config.get("__ccache") - configs.tools.cc = config.get("cc") or "xcrun -sdk macosx clang" - configs.tools.cxx = config.get("cxx") or "xcrun -sdk macosx clang++" - 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 "xcrun -sdk macosx clang++" - configs.tools.ar = config.get("ar") or "xcrun -sdk macosx ar" - configs.tools.sh = config.get("sh") or "xcrun -sdk macosx clang++" + configs.tools.cc = config.get("cc") + configs.tools.cxx = config.get("cxx") + configs.tools.mm = config.get("mm") + configs.tools.mxx = config.get("mxx") + configs.tools.ld = config.get("ld") + configs.tools.ar = config.get("ar") + configs.tools.sh = config.get("sh") - -- init xcode sdk directory - configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. config.get("xcode_sdkver") .. ".sdk" + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then + if arch == "x64" then archflags = "-m64" + elseif arch == "x86" then archflags = "-m32" + end + end + configs.cxflags = { archflags } + configs.mxflags = { archflags } + configs.asflags = { archflags } + configs.ldflags = { archflags } + configs.shflags = { archflags } - -- init flags - configs.cxflags = "-isysroot " .. configs.xcode_sdkdir - configs.mxflags = "-isysroot " .. configs.xcode_sdkdir - configs.ldflags = "-isysroot " .. configs.xcode_sdkdir - configs.shflags = "-isysroot " .. configs.xcode_sdkdir + -- init flags for the xcode sdk directory + local xcode_sdkdir = config.get("__xcode_sdkdir") + if xcode_sdkdir then + table.insert(configs.cxflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.asflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.mxflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.ldflags, "-isysroot " .. xcode_sdkdir) + table.insert(configs.shflags, "-isysroot " .. xcode_sdkdir) + end end diff --git a/xmake/scripts/platform/macosx/prober.lua b/xmake/scripts/platform/macosx/prober.lua index 32e059269..ddf2b7e4c 100644 --- a/xmake/scripts/platform/macosx/prober.lua +++ b/xmake/scripts/platform/macosx/prober.lua @@ -45,7 +45,7 @@ function prober._probe_arch(configs) configs.set("arch", xmake._ARCH) -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) -- ok return true @@ -84,10 +84,10 @@ function prober._probe_xcode(configs) configs.set("xcode_dir", xcode_dir) -- trace - utils.verbose("checking the Xcode application directory ... %s", xcode_dir) + utils.verbose("checking for the Xcode application directory ... %s", xcode_dir) else -- failed - utils.error("checking the Xcode application directory ... no") + utils.error("checking for the Xcode application directory ... no") utils.error(" - xmake config --xcode_dir=xxx") utils.error("or - xmake global --xcode_dir=xxx") return false @@ -125,12 +125,18 @@ function prober._probe_xcode_sdkver(configs) -- save it configs.set("xcode_sdkver", xcode_sdkver) - + + -- save the xcode sdk directory + local xcode_dir = configs.get("xcode_dir") + if xcode_dir then + configs.set("__xcode_sdkdir", xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk") + end + -- trace - utils.verbose("checking the Xcode SDK version for %s ... %s", configs.get("plat"), xcode_sdkver) + utils.verbose("checking for the Xcode SDK version for %s ... %s", configs.get("plat"), xcode_sdkver) else -- failed - utils.error("checking the Xcode SDK version for %s ... no", configs.get("plat")) + utils.error("checking for the Xcode SDK version for %s ... no", configs.get("plat")) utils.error(" - xmake config --xcode_sdkver=xxx") utils.error("or - xmake global --xcode_sdkver=xxx") return false @@ -140,6 +146,26 @@ function prober._probe_xcode_sdkver(configs) return true end +-- probe the make +function prober._probe_make(configs) + + -- ok? + local make = configs.get("make") + if make then return true end + + -- probe the make path + make = tools.probe("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"}) + + -- probe ok? update it + if make then configs.set("make", make) end + + -- trace + utils.verbose("checking for the make ... %s", utils.ifelse(make, make, "no")) + + -- ok + return true +end + -- probe the ccache function prober._probe_ccache(configs) @@ -171,6 +197,57 @@ function prober._probe_ccache(configs) return true end +-- probe the tool path +function prober._probe_toolpath(configs, kind, cross, name, description) + + -- check + assert(kind) + + -- get the cross + cross = configs.get("cross") or cross + + -- attempt to get it from the given cross toolchains + local toolpath = nil + local toolchains = configs.get("toolchains") + if toolchains then + toolpath = tools.probe(cross .. (configs.get(kind) or name), toolchains) + end + + -- attempt to get it directly from the configure + if not toolpath then + toolpath = configs.get(kind) + end + + -- attempt to run it directly + if not toolpath then + toolpath = tools.probe(cross .. name) + 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 toolchains +function prober._probe_toolchains(configs) + + -- done + if not prober._probe_toolpath(configs, "cc", "xcrun -sdk macosx ", "clang", "the c compiler") then return false end + if not prober._probe_toolpath(configs, "cxx", "xcrun -sdk macosx ", "clang++", "the c++ compiler") then return false end + if not prober._probe_toolpath(configs, "mm", "xcrun -sdk macosx ", "clang", "the objc compiler") then return false end + if not prober._probe_toolpath(configs, "mxx", "xcrun -sdk macosx ", "clang++", "the objc++ compiler") then return false end + if not prober._probe_toolpath(configs, "as", "xcrun -sdk macosx ", "clang", "the assember") then return false end + if not prober._probe_toolpath(configs, "ld", "xcrun -sdk macosx ", "clang++", "the linker") then return false end + if not prober._probe_toolpath(configs, "ar", "xcrun -sdk macosx ", "ar", "the static library linker") then return false end + if not prober._probe_toolpath(configs, "sh", "xcrun -sdk macosx ", "clang++", "the shared library linker") then return false end + return true +end + -- probe the project configure function prober.config() @@ -178,7 +255,9 @@ function prober.config() utils.call( { prober._probe_arch , prober._probe_xcode , prober._probe_xcode_sdkver - , prober._probe_ccache} + , prober._probe_make + , prober._probe_ccache + , prober._probe_toolchains} , nil , config) end diff --git a/xmake/scripts/platform/windows/prober.lua b/xmake/scripts/platform/windows/prober.lua index c8e466b5a..764669a27 100644 --- a/xmake/scripts/platform/windows/prober.lua +++ b/xmake/scripts/platform/windows/prober.lua @@ -28,6 +28,8 @@ local utils = require("base/utils") local string = require("base/string") local config = require("base/config") local global = require("base/global") +local tools = require("tools/tools") +local platform = require("platform/platform") -- define module: prober local prober = prober or {} @@ -45,7 +47,7 @@ function prober._probe_arch(configs) configs.set("arch", xmake._ARCH) -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) -- ok return true @@ -94,10 +96,10 @@ function prober._probe_vs_version(configs) configs.set("vs", vs) -- trace - utils.verbose("checking the Microsoft Visual Studio version ... %s", vs) + utils.verbose("checking for the Microsoft Visual Studio version ... %s", vs) else -- failed - utils.error("checking the Microsoft Visual Studio version ... no") + utils.error("checking for the Microsoft Visual Studio version ... no") utils.error(" - xmake config --vs=xxx") utils.error("or - xmake global --vs=xxx") return false @@ -195,13 +197,64 @@ function prober._probe_vs_path(configs) return true end +-- probe the tool path +function prober._probe_toolpath(configs, kind, name, description) + + -- check + assert(kind) + + -- attempt to get it directly from the configure + local toolpath = configs.get(kind) + if toolpath then return true end + + -- attempt to run it directly first + if not toolpath and os.execute(string.format("%s nul > %s 2>&1", name, xmake._NULDEV)) ~= 0x7f00 then + toolpath = name + 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 toolchains +function prober._probe_toolchains(configs) + + -- the windows module + local windows = platform.module() + assert(windows) + + -- enter envirnoment + windows.enter() + + -- done + if not prober._probe_toolpath(configs, "cc", "cl.exe", "the c compiler") then return false end + if not prober._probe_toolpath(configs, "cxx", "cl.exe", "the c++ compiler") then return false end + if not prober._probe_toolpath(configs, "ld", "link.exe", "the linker") then return false end + if not prober._probe_toolpath(configs, "ar", "link.exe", "the static library linker") then return false end + if not prober._probe_toolpath(configs, "sh", "link.exe", "the shared library linker") then return false end + if not prober._probe_toolpath(configs, "make", "nmake.exe", "the make") then return false end + + -- leave envirnoment + windows.leave() + + -- ok + return true +end + -- probe the project configure function prober.config() -- call all probe functions utils.call( { prober._probe_arch , prober._probe_vs_version - , prober._probe_vs_path} + , prober._probe_vs_path + , prober._probe_toolchains} , nil , config) end diff --git a/xmake/scripts/platform/windows/tools/cl.lua b/xmake/scripts/platform/windows/tools/cl.lua index 879264e68..5ede4a0b0 100644 --- a/xmake/scripts/platform/windows/tools/cl.lua +++ b/xmake/scripts/platform/windows/tools/cl.lua @@ -27,43 +27,7 @@ local cl = cl or {} local utils = require("base/utils") local string = require("base/string") local config = require("base/config") - --- enter the given environment -function cl._enter(name) - - -- check - assert(name) - - -- get the pathes for the vs environment - local old = nil - local new = config.get("__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) - end - - -- return the previous environment - return old; -end - --- leave the given environment -function cl._leave(name, old) - - -- check - assert(name) - - -- restore the previous environment - if old then - os.setenv(name, old) - end -end +local platform = require("platform/platform") -- init the compiler function cl.init(self, name) @@ -146,20 +110,18 @@ end -- the main function function cl.main(self, cmd) - -- enter the vs environment - local pathes = cl._enter("path") - local libs = cl._enter("lib") - local includes = cl._enter("include") - local libpathes = cl._enter("libpath") + -- the windows module + local windows = platform.module() + assert(windows) + + -- enter envirnoment + windows.enter() -- execute it local ok = os.execute(cmd) - -- leave the vs environment - cl._leave("path", pathes) - cl._leave("lib", libs) - cl._leave("include", includes) - cl._leave("libpath", libpathes) + -- leave envirnoment + windows.leave() -- ok? return utils.ifelse(ok == 0, true, false) diff --git a/xmake/scripts/platform/windows/tools/link.lua b/xmake/scripts/platform/windows/tools/link.lua index ad1086ba5..4c8d59aaa 100644 --- a/xmake/scripts/platform/windows/tools/link.lua +++ b/xmake/scripts/platform/windows/tools/link.lua @@ -27,43 +27,7 @@ local link = link or {} local utils = require("base/utils") local string = require("base/string") local config = require("base/config") - --- enter the given environment -function link._enter(name) - - -- check - assert(name) - - -- get the pathes for the vs environment - local old = nil - local new = config.get("__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) - end - - -- return the previous environment - return old; -end - --- leave the given environment -function link._leave(name, old) - - -- check - assert(name) - - -- restore the previous environment - if old then - os.setenv(name, old) - end -end +local platform = require("platform/platform") -- init the compiler function link.init(self, name) @@ -134,20 +98,18 @@ end -- the main function function link.main(self, cmd) - -- enter the vs environment - local pathes = link._enter("path") - local libs = link._enter("lib") - local includes = link._enter("include") - local libpathes = link._enter("libpath") + -- the windows module + local windows = platform.module() + assert(windows) + + -- enter envirnoment + windows.enter() -- execute it local ok = os.execute(cmd) - -- leave the vs environment - link._leave("path", pathes) - link._leave("lib", libs) - link._leave("include", includes) - link._leave("libpath", libpathes) + -- leave envirnoment + windows.leave() -- ok? return utils.ifelse(ok == 0, true, false) diff --git a/xmake/scripts/platform/windows/tools/nmake.lua b/xmake/scripts/platform/windows/tools/nmake.lua index 7d42dc706..f84f9ee6f 100644 --- a/xmake/scripts/platform/windows/tools/nmake.lua +++ b/xmake/scripts/platform/windows/tools/nmake.lua @@ -26,47 +26,11 @@ local path = require("base/path") local utils = require("base/utils") local string = require("base/string") local config = require("base/config") +local platform = require("platform/platform") -- define module: nmake local nmake = nmake or {} --- enter the given environment -function nmake._enter(name) - - -- check - assert(name) - - -- get the pathes for the vs environment - local old = nil - local new = config.get("__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) - end - - -- return the previous environment - return old; -end - --- leave the given environment -function nmake._leave(name, old) - - -- check - assert(name) - - -- restore the previous environment - if old then - os.setenv(name, old) - end -end - -- the init function function nmake.init(self, name) @@ -81,11 +45,12 @@ end -- the main function function nmake.main(self, mkfile, target) - -- enter the vs environment - local pathes = nmake._enter("path") - local libs = nmake._enter("lib") - local includes = nmake._enter("include") - local libpathes = nmake._enter("libpath") + -- the windows module + local windows = platform.module() + assert(windows) + + -- enter envirnoment + windows.enter() -- make command local cmd = nil @@ -98,11 +63,8 @@ function nmake.main(self, mkfile, target) -- done local ok = os.execute(cmd) - -- leave the vs environment - nmake._leave("path", pathes) - nmake._leave("lib", libs) - nmake._leave("include", includes) - nmake._leave("libpath", libpathes) + -- leave envirnoment + windows.leave() -- ok? return utils.ifelse(ok == 0, true, false) diff --git a/xmake/scripts/platform/windows/windows.lua b/xmake/scripts/platform/windows/windows.lua index a3d80c49a..573699d9a 100644 --- a/xmake/scripts/platform/windows/windows.lua +++ b/xmake/scripts/platform/windows/windows.lua @@ -24,14 +24,73 @@ local windows = windows or {} -- load modules +local os = require("base/os") local config = require("base/config") -- init host -windows._HOST = "windows" +windows._HOST = "windows" -- init architectures -windows._ARCHS = {"x86", "x64"} +windows._ARCHS = {"x86", "x64"} +-- enter the given environment +function windows._enter(name) + + -- check + assert(name) + + -- get the pathes for the vs environment + local old = nil + local new = config.get("__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) + end + + -- return the previous environment + return old; +end + +-- leave the given environment +function windows._leave(name, old) + + -- check + assert(name) + + -- restore the previous environment + if old then + os.setenv(name, old) + end +end + +-- enter environment +function windows.enter() + + -- enter the vs environment + windows._pathes = windows._enter("path") + windows._libs = windows._enter("lib") + windows._includes = windows._enter("include") + windows._libpathes = windows._enter("libpath") + +end + +-- leave environment +function windows.leave() + + -- leave the vs environment + windows._leave("path", windows._pathes) + windows._leave("lib", windows._libs) + windows._leave("include", windows._includes) + windows._leave("libpath", windows._libpathes) + +end -- make configure function windows.make(configs) @@ -43,13 +102,13 @@ function windows.make(configs) configs.formats.binary = {"", ".exe"} -- init the toolchains - configs.tools = {} - configs.tools.make = "nmake" - configs.tools.cc = config.get("cc") or "cl" - configs.tools.cxx = config.get("cxx") or "cl" - configs.tools.ld = config.get("ld") or "link" - configs.tools.ar = config.get("ar") or "link" - configs.tools.sh = config.get("sh") or "link" + configs.tools = {} + configs.tools.make = config.get("make") + configs.tools.cc = config.get("cc") + configs.tools.cxx = config.get("cxx") + configs.tools.ld = config.get("ld") + configs.tools.ar = config.get("ar") + configs.tools.sh = config.get("sh") end diff --git a/xmake/scripts/tools/gcc.lua b/xmake/scripts/tools/gcc.lua index 8a5e40ff3..e54442f9a 100644 --- a/xmake/scripts/tools/gcc.lua +++ b/xmake/scripts/tools/gcc.lua @@ -74,6 +74,8 @@ function gcc.init(self, name) -- suppress warning for the ccache bug if name:find("clang") and config.get("ccache") then + self.cxflags = self.cxflags or {} + self.mxflags = self.mxflags or {} table.join2(self.cxflags, "-Qunused-arguments") table.join2(self.mxflags, "-Qunused-arguments") end |
