summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-16 23:05:56 +0800
committerruki <[email protected]>2020-03-16 12:35:40 +0800
commit545cace2e633a3232a7f4565ee596b8114b44942 (patch)
tree4240ba6343a8bc52c6bf1002ec4a8b1608ebfada
parent76e2096c698142f07f3db817fc1a229c931cc274 (diff)
add sdcc platform
-rw-r--r--xmake/core/platform/platform.lua13
-rw-r--r--xmake/core/project/target.lua17
-rw-r--r--xmake/modules/core/tools/sdar.lua3
-rw-r--r--xmake/modules/core/tools/sdcc.lua3
-rw-r--r--xmake/platforms/sdcc/config.lua114
-rw-r--r--xmake/platforms/sdcc/load.lua40
-rw-r--r--xmake/platforms/sdcc/xmake.lua39
7 files changed, 194 insertions, 35 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 580645248..5952a0033 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -312,7 +312,6 @@ end
function platform.tool(toolkind, plat)
-- attempt to get program from config first
- local checked = false
local program = config.get(toolkind)
local toolname = config.get("__toolname_" .. toolkind)
if program == nil then
@@ -332,7 +331,6 @@ function platform.tool(toolkind, plat)
-- get it again
program = config.get(toolkind)
toolname = config.get("__toolname_" .. toolkind)
- checked = true
end
-- contain toolname? parse it, e.g. '[email protected]'
@@ -343,17 +341,6 @@ function platform.tool(toolkind, plat)
program = program:sub(pos + 1)
end
end
-
- -- not checked? we check it now
- if program and not checked then
- local tool = sandbox_module.import("lib.detect.find_tool", {anonymous = true})(toolname or program, {program = program})
- if tool and tool.program and tool.program ~= program then
- program = tool.program
- config.set(toolkind, program, {force = true, readonly = true})
- end
- end
-
- -- ok
return program, toolname
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 198295e36..60b323d54 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1051,24 +1051,9 @@ function _instance:objectfile(sourcefile, sourcekind)
end
relativedir = relativedir:gsub("%.%.", "__")
- -- get object format from the compiler
- local objectformat
- if sourcekind then
- self._OBJECTFORMATS = self._OBJECTFORMATS or {}
- objectformat = self._OBJECTFORMATS[sourcekind]
- if objectformat == nil then
- local compinst = compiler.load(sourcekind, self)
- if compinst then
- objectformat = compinst:format("object")
- self._OBJECTFORMATS[sourcekind] = objectformat or false
- end
- end
- objectformat = objectformat or nil
- end
-
-- make object file
-- full file name(not base) to avoid name-clash of object file
- return path.join(self:objectdir(), relativedir, target.filename(path.filename(sourcefile), "object", objectformat))
+ return path.join(self:objectdir(), relativedir, target.filename(path.filename(sourcefile), "object"))
end
-- get the object files
diff --git a/xmake/modules/core/tools/sdar.lua b/xmake/modules/core/tools/sdar.lua
index 3548772f1..ba991e780 100644
--- a/xmake/modules/core/tools/sdar.lua
+++ b/xmake/modules/core/tools/sdar.lua
@@ -26,9 +26,6 @@ function init(self)
-- init flags
self:set("arflags", "-cr")
-
- -- init the file formats
- self:set("formats", {static = "$(name).lib"})
end
-- make the strip flag
diff --git a/xmake/modules/core/tools/sdcc.lua b/xmake/modules/core/tools/sdcc.lua
index 8fb1af30a..c5f720b3f 100644
--- a/xmake/modules/core/tools/sdcc.lua
+++ b/xmake/modules/core/tools/sdcc.lua
@@ -31,9 +31,6 @@ function init(self)
-- init cxflags for the kind: shared
self:set("shared.cxflags", "-fPIC")
- -- init the file formats
- self:set("formats", {object = "$(name).rel"})
-
-- init flags map
self:set("mapflags",
{
diff --git a/xmake/platforms/sdcc/config.lua b/xmake/platforms/sdcc/config.lua
new file mode 100644
index 000000000..ad2f14626
--- /dev/null
+++ b/xmake/platforms/sdcc/config.lua
@@ -0,0 +1,114 @@
+--!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/sdcc/load.lua b/xmake/platforms/sdcc/load.lua
new file mode 100644
index 000000000..896d73a7f
--- /dev/null
+++ b/xmake/platforms/sdcc/load.lua
@@ -0,0 +1,40 @@
+--!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 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
+end
+
diff --git a/xmake/platforms/sdcc/xmake.lua b/xmake/platforms/sdcc/xmake.lua
new file mode 100644
index 000000000..c43e241ed
--- /dev/null
+++ b/xmake/platforms/sdcc/xmake.lua
@@ -0,0 +1,39 @@
+--!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 platform
+platform("sdcc")
+
+ -- set hosts
+ set_hosts("macosx", "linux", "windows")
+
+ -- set archs
+ set_archs("stm8")
+
+ -- set formats
+ set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name)", symbol = "$(name).sym"}
+
+ -- on check project configuration
+ on_config_check("config")
+
+ -- on load
+ on_load("load")
+
+