summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-30 20:49:02 +0800
committerruki <[email protected]>2017-06-30 20:49:02 +0800
commite588531d2ba580d3b9289aa18015a5f89f676423 (patch)
tree2d123ab26a1c8b274d25d33ec5ac4670b519e958
parent51d62ade38f46d3900991374852ecb3d4541692a (diff)
add option:add and remove some unused codes
-rw-r--r--xmake/core/project/option.lua57
-rw-r--r--xmake/core/sandbox/modules/import/core/project/option.lua40
-rw-r--r--xmake/core/tool/linker.lua9
-rw-r--r--xmake/languages/c++/api.lua71
4 files changed, 64 insertions, 113 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 93be29349..6ecf0c397 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -175,11 +175,20 @@ end
-- get the option info
function option:get(infoname)
-
- -- get it
return self._INFO[infoname]
end
+-- add the value to the option info
+function option:add(name_or_info, ...)
+ if type(name_or_info) == "string" then
+ self._INFO[name_or_info] = table.unique(table.join2(table.wrap(self._INFO[name_or_info]), ...))
+ elseif type(name_or_info) == "table" and #name_or_info == 0 then
+ for name, info in pairs(name_or_info) do
+ self:add(name, info)
+ end
+ end
+end
+
-- get option deps
function option:deps()
-- TODO in the future
@@ -188,23 +197,17 @@ end
-- save the option info to the cache
function option:save()
-
- -- save it
option._cache():set(self:name(), self._INFO)
option._cache():flush()
end
-- clear the option info for cache
function option:clear()
-
- -- clear it
option._cache():set(self:name(), nil)
end
-- get the option name
function option:name()
-
- -- get it
return self._NAME
end
@@ -229,43 +232,5 @@ function option.load(name)
return instance
end
--- get the kinds of sourcefiles
-function option:sourcekinds()
-
- -- cached? return it directly
- if self._SOURCEKINDS then
- return self._SOURCEKINDS
- end
-
- -- ok?
- return {"cc", "cxx"}
-end
-
--- get function name and check code
---
--- sigsetjmp
--- sigsetjmp((void*)0, 0)
--- sigsetjmp{sigsetjmp((void*)0, 0);}
--- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);}
---
-function option.checkinfo(checkinfo)
-
- -- parse name and code
- local name, code = string.match(checkinfo, "(.+){(.+)}")
- if code == nil then
- local pos = checkinfo:find("%(")
- if pos then
- name = checkinfo:sub(1, pos - 1)
- code = checkinfo
- else
- name = checkinfo
- code = string.format("volatile void* p%s = (void*)&%s;", name, name)
- end
- end
-
- -- ok
- return name:trim(), code
-end
-
-- return module
return option
diff --git a/xmake/core/sandbox/modules/import/core/project/option.lua b/xmake/core/sandbox/modules/import/core/project/option.lua
deleted file mode 100644
index be9cb810f..000000000
--- a/xmake/core/sandbox/modules/import/core/project/option.lua
+++ /dev/null
@@ -1,40 +0,0 @@
---!The Make-like Build Utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2017, TBOOX Open Source Group.
---
--- @author ruki
--- @file option.lua
---
-
--- define module
-local sandbox_core_project_option = sandbox_core_project_option or {}
-
--- load modules
-local option = require("project/option")
-local raise = require("sandbox/modules/raise")
-
--- parse checkinfo
-function sandbox_core_project_option.checkinfo(checkinfo)
-
- -- parse it
- return option.checkinfo(checkinfo)
-end
-
--- return module
-return sandbox_core_project_option
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 6b3ec05d5..e1d091edb 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -59,12 +59,12 @@ function linker:_addflags_from_platform(flags, targetkind)
end
-- add flags from the compiler
-function linker:_addflags_from_compiler(flags, targetkind, sourcekinds)
+function linker:_addflags_from_compiler(flags, targetkind)
-- make flags
local flags_of_compiler = {}
local toolkind = self:kind()
- for _, sourcekind in ipairs(table.wrap(sourcekinds)) do
+ for _, sourcekind in ipairs(self._SOURCEKINDS) do
-- load compiler
local instance, errors = compiler.load(sourcekind)
@@ -164,6 +164,9 @@ function linker.load(targetkind, sourcekinds)
-- init target kind
instance._TARGETKIND = targetkind
+ -- init source kinds
+ instance._SOURCEKINDS = sourcekinds
+
-- init flag kinds
instance._FLAGKINDS = {linkerinfo.linkerflag}
@@ -238,7 +241,7 @@ function linker:linkflags(opt)
-- add flags from the compiler
if target then
- self:_addflags_from_compiler(flags, targetkind, target:sourcekinds())
+ self:_addflags_from_compiler(flags, targetkind)
end
-- add flags from the linker
diff --git a/xmake/languages/c++/api.lua b/xmake/languages/c++/api.lua
index 8937ddf74..d116fdeac 100644
--- a/xmake/languages/c++/api.lua
+++ b/xmake/languages/c++/api.lua
@@ -22,34 +22,57 @@
-- @file api.lua
--
--- imports
-import("core.project.option")
+-- get function name and function info
+--
+-- sigsetjmp
+-- sigsetjmp((void*)0, 0)
+-- sigsetjmp{sigsetjmp((void*)0, 0);}
+-- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);}
+--
+function _funcinfo(func)
+
+ -- parse name and code
+ local name, code = string.match(func, "(.+){(.+)}")
+ if code == nil then
+ local pos = func:find("%(")
+ if pos then
+ name = func:sub(1, pos - 1)
+ code = func
+ else
+ name = func
+ code = string.format("volatile void* p%s = (void*)&%s;", name, name)
+ end
+ end
+
+ -- ok
+ return name:trim(), code
+end
-- add c function
-function _api_add_cfunc(interp, module, alias, links, includes, checkinfo)
+function _api_add_cfunc(interp, module, alias, links, includes, func)
- -- parse the check code
- local checkname, checkcode = option.checkinfo(checkinfo)
+ -- parse the function info
+ local funcname, funccode = _funcinfo(func)
-- make the option name
local name = nil
if module ~= nil then
- name = format("__%s_%s", module, checkname)
+ name = format("__%s_%s", module, funcname)
else
- name = format("__%s", checkname)
+ name = format("__%s", funcname)
end
-- uses the alias name
if alias ~= nil then
- checkname = alias
+ funcname = alias
end
-- make the option define
local define = nil
if module ~= nil then
- define = format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
+ define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper())
else
- define = format("$(prefix)_HAVE_%s", checkname:upper())
+ define = format("$(prefix)_HAVE_%s", funcname:upper())
end
-- save the current scope
@@ -58,7 +81,7 @@ function _api_add_cfunc(interp, module, alias, links, includes, checkinfo)
-- check option
interp:api_call("option", name)
interp:api_call("set_category", "cfuncs")
- interp:api_call("add_cfuncs", checkinfo)
+ interp:api_call("add_cfuncs", func)
if links then interp:api_call("add_links", links) end
if includes then interp:api_call("add_cincludes", includes) end
interp:api_call("add_defines_h_if_ok", define)
@@ -74,36 +97,36 @@ end
function _api_add_cfuncs(interp, module, links, includes, ...)
-- done
- for _, checkinfo in ipairs({...}) do
- _api_add_cfunc(interp, module, nil, links, includes, checkinfo)
+ for _, func in ipairs({...}) do
+ _api_add_cfunc(interp, module, nil, links, includes, func)
end
end
-- add c++ function
-function _api_add_cxxfunc(interp, module, alias, links, includes, checkinfo)
+function _api_add_cxxfunc(interp, module, alias, links, includes, func)
- -- parse the check code
- local checkname, checkcode = option.checkinfo(checkinfo)
+ -- parse the function info
+ local funcname, funccode = _funcinfo(func)
-- make the option name
local name = nil
if module ~= nil then
- name = format("__%s_%s", module, checkname)
+ name = format("__%s_%s", module, funcname)
else
- name = format("__%s", checkname)
+ name = format("__%s", funcname)
end
-- uses the alias name
if alias ~= nil then
- checkname = alias
+ funcname = alias
end
-- make the option define
local define = nil
if module ~= nil then
- define = format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
+ define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper())
else
- define = format("$(prefix)_HAVE_%s", checkname:upper())
+ define = format("$(prefix)_HAVE_%s", funcname:upper())
end
-- save the current scope
@@ -112,7 +135,7 @@ function _api_add_cxxfunc(interp, module, alias, links, includes, checkinfo)
-- check option
interp:api_call("option", name)
interp:api_call("set_category", "cxxfuncs")
- interp:api_call("add_cxxfuncs", checkinfo)
+ interp:api_call("add_cxxfuncs", func)
if links then interp:api_call("add_links", links) end
if includes then interp:api_call("add_cxxincludes", includes) end
interp:api_call("add_defines_h_if_ok", define)
@@ -128,8 +151,8 @@ end
function _api_add_cxxfuncs(interp, module, links, includes, ...)
-- done
- for _, checkinfo in ipairs({...}) do
- _api_add_cxxfunc(interp, module, nil, links, includes, checkinfo)
+ for _, func in ipairs({...}) do
+ _api_add_cxxfunc(interp, module, nil, links, includes, func)
end
end