summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-11 14:46:59 +0800
committerruki <[email protected]>2015-06-11 14:46:59 +0800
commitd81ff2a9fbfefbfd58697f918a879a59e14321c1 (patch)
treee9564abc3e379786725f5785c7079d5b226db166 /xmake/scripts/base
parent2b17a555fd3a5b4711b36a5b5a85b98146e5fa12 (diff)
add option flags to project
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/compiler.lua113
-rw-r--r--xmake/scripts/base/linker.lua66
-rw-r--r--xmake/scripts/base/project.lua1
3 files changed, 125 insertions, 55 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua
index 65daf8afb..f078c598f 100644
--- a/xmake/scripts/base/compiler.lua
+++ b/xmake/scripts/base/compiler.lua
@@ -245,28 +245,73 @@ function compiler.make(module, target, srcfile, objfile)
-- append the includedirs flags from the current project
if module.flag_includedir then
- local includedirs = utils.wrap(target.includedirs)
- for _, includedir in ipairs(includedirs) do
+ for _, includedir in ipairs(utils.wrap(target.includedirs)) do
table.join2(flags, module.flag_includedir(includedir))
end
end
-- append the defines flags from the current project
if module.flag_define then
- local defines = utils.wrap(target.defines)
- for _, define in ipairs(defines) do
+ for _, define in ipairs(utils.wrap(target.defines)) do
table.join2(flags, module.flag_define(define))
end
end
-- append the undefines flags from the current project
if module.flag_undefine then
- local undefines = utils.wrap(target.undefines)
- for _, undefine in ipairs(undefines) do
+ for _, undefine in ipairs(utils.wrap(target.undefines)) do
table.join2(flags, module.flag_undefine(undefine))
end
end
+ -- the options
+ if target.options then
+ for _, name in ipairs(utils.wrap(target.options)) do
+
+ -- get option if be enabled
+ local opt = nil
+ if config.get(name) then opt = config.get("__" .. name) end
+ if nil ~= opt then
+
+ -- append the flags from the option
+ for _, flagname in ipairs(flagnames) do
+ table.join2(flags, compiler._mapflags(module, opt[flagname]))
+ end
+
+ -- append the includedirs flags from the option
+ if module.flag_includedir then
+ for _, includedir in ipairs(utils.wrap(opt.includedirs)) do
+ table.join2(flags, module.flag_includedir(includedir))
+ end
+ end
+
+ -- append the defines flags from the option
+ if module.flag_define then
+
+ local defines = {}
+ if opt.defines then table.join2(defines, opt.defines) end
+ if opt.defines_if_ok then table.join2(defines, opt.defines_if_ok) end
+
+ for _, define in ipairs(defines) do
+ table.join2(flags, module.flag_define(define))
+ end
+ end
+
+ -- append the undefines flags from the option
+ if module.flag_undefine then
+
+ local undefines = {}
+ if opt.undefines then table.join2(undefines, opt.undefines) end
+ if opt.undefines_if_ok then table.join2(undefines, opt.undefines_if_ok) end
+
+ for _, undefine in ipairs(undefines) do
+ table.join2(flags, module.flag_undefine(undefine))
+ end
+ end
+ end
+ end
+ end
+
-- append the flags from the configure
for _, flagname in ipairs(flagnames) do
table.join2(flags, compiler._mapflags(module, config.get(flagname)))
@@ -301,53 +346,53 @@ function compiler.check_include(opt, include, srcpath, objpath)
srcfile:close()
-- get the compiler
- local c = compiler.get(srcpath)
- if not c then return end
+ local module = compiler.get(srcpath)
+ if not module then return end
-- the flag names
- local flagnames = compiler._flagnames(c._NAME)
+ local flagnames = compiler._flagnames(module._NAME)
assert(flagnames)
-- append the common flags
local flags = {}
for _, flagname in ipairs(flagnames) do
- table.join2(flags, c[flagname])
+ table.join2(flags, module[flagname])
end
-- append the option flags
for _, flagname in ipairs(flagnames) do
- table.join2(flags, compiler._mapflags(c, opt[flagname]))
+ table.join2(flags, compiler._mapflags(module, opt[flagname]))
end
-- append the defines flags
- if opt.defines and c.flag_define then
+ if opt.defines and module.flag_define then
local defines = utils.wrap(opt.defines)
for _, define in ipairs(defines) do
- table.join2(flags, c.flag_define(define))
+ table.join2(flags, module.flag_define(define))
end
end
-- append the undefines flags
- if opt.undefines and c.flag_undefine then
+ if opt.undefines and module.flag_undefine then
local undefines = utils.wrap(opt.undefines)
for _, undefine in ipairs(undefines) do
- table.join2(flags, c.flag_undefine(undefine))
+ table.join2(flags, module.flag_undefine(undefine))
end
end
-- append the includedirs flags
- if opt.includedirs and c.flag_includedir then
+ if opt.includedirs and module.flag_includedir then
for _, includedir in ipairs(utils.wrap(opt.includedirs)) do
- table.join2(flags, c.flag_includedir(includedir))
+ table.join2(flags, module.flag_includedir(includedir))
end
end
-- make the compile command
- local cmd = string.format("%s > %s 2>&1", c.command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV)
+ local cmd = string.format("%s > %s 2>&1", module.command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV)
if not cmd then return end
-- execute the compile command
- return c.main(cmd)
+ return module.main(cmd)
end
-- check function for the project option
@@ -361,13 +406,13 @@ function compiler.check_function(opt, interface, srcpath, objpath)
if not srcfile then return end
-- get the compiler
- local c = compiler.get(srcpath)
- if not c then return end
+ local module = compiler.get(srcpath)
+ if not module then return end
-- make includes
local includes = nil
- if c._NAME == "cc" then includes = opt.cincludes
- elseif c._NAME == "cxx" then includes = opt.cxxincludes
+ if module._NAME == "cc" then includes = opt.cincludes
+ elseif module._NAME == "cxx" then includes = opt.cxxincludes
end
if includes then
for _, include in ipairs(utils.wrap(includes)) do
@@ -391,49 +436,49 @@ function compiler.check_function(opt, interface, srcpath, objpath)
srcfile:close()
-- the flag names
- local flagnames = compiler._flagnames(c._NAME)
+ local flagnames = compiler._flagnames(module._NAME)
assert(flagnames)
-- append the common flags
local flags = {}
for _, flagname in ipairs(flagnames) do
- table.join2(flags, c[flagname])
+ table.join2(flags, module[flagname])
end
-- append the option flags
for _, flagname in ipairs(flagnames) do
- table.join2(flags, compiler._mapflags(c, opt[flagname]))
+ table.join2(flags, compiler._mapflags(module, opt[flagname]))
end
-- append the defines flags
- if opt.defines and c.flag_define then
+ if opt.defines and module.flag_define then
local defines = utils.wrap(opt.defines)
for _, define in ipairs(defines) do
- table.join2(flags, c.flag_define(define))
+ table.join2(flags, module.flag_define(define))
end
end
-- append the undefines flags
- if opt.undefines and c.flag_undefine then
+ if opt.undefines and module.flag_undefine then
local undefines = utils.wrap(opt.undefines)
for _, undefine in ipairs(undefines) do
- table.join2(flags, c.flag_undefine(undefine))
+ table.join2(flags, module.flag_undefine(undefine))
end
end
-- append the includedirs flags
- if opt.includedirs and c.flag_includedir then
+ if opt.includedirs and module.flag_includedir then
for _, includedir in ipairs(utils.wrap(opt.includedirs)) do
- table.join2(flags, c.flag_includedir(includedir))
+ table.join2(flags, module.flag_includedir(includedir))
end
end
-- make the compile command
- local cmd = string.format("%s > %s 2>&1", c.command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV)
+ local cmd = string.format("%s > %s 2>&1", module.command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV)
if not cmd then return end
-- execute the compile command
- return c.main(cmd)
+ return module.main(cmd)
end
-- return module: compiler
diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua
index 0cb054821..befab7b7c 100644
--- a/xmake/scripts/base/linker.lua
+++ b/xmake/scripts/base/linker.lua
@@ -136,10 +136,10 @@ function linker.make(module, target, objfiles, targetfile)
local kind = target.kind or ""
-- the flag name
- local flag_name = nil
- if kind == "binary" then flag_name = "ldflags"
- elseif kind == "static" then flag_name = "arflags"
- elseif kind == "shared" then flag_name = "shflags"
+ local flagname = nil
+ if kind == "binary" then flagname = "ldflags"
+ elseif kind == "static" then flagname = "arflags"
+ elseif kind == "shared" then flagname = "shflags"
else
-- error
utils.error("unknown type for linker: %s", kind)
@@ -148,29 +148,55 @@ function linker.make(module, target, objfiles, targetfile)
-- append the common flags from the current linker
local flags = {}
- table.join2(flags, module[flag_name])
+ table.join2(flags, module[flagname])
-- append the target flags from the current project
- table.join2(flags, linker._mapflags(module, target[flag_name]))
+ table.join2(flags, linker._mapflags(module, target[flagname]))
-- append the linkdirs flags from the current project
if module.flag_linkdir then
- local linkdirs = utils.wrap(target.linkdirs)
- for _, linkdir in ipairs(linkdirs) do
+ for _, linkdir in ipairs(utils.wrap(target.linkdirs)) do
table.join2(flags, module.flag_linkdir(linkdir))
end
end
-- append the links flags from the current project
if module.flag_link then
- local links = utils.wrap(target.links)
- for _, link in ipairs(links) do
+ for _, link in ipairs(utils.wrap(target.links)) do
table.join2(flags, module.flag_link(link))
end
end
+ -- the options
+ if target.options then
+ for _, name in ipairs(utils.wrap(target.options)) do
+
+ -- get option if be enabled
+ local opt = nil
+ if config.get(name) then opt = config.get("__" .. name) end
+ if nil ~= opt then
+
+ -- append the flags from the option
+ table.join2(flags, linker._mapflags(module, opt[flagname]))
+
+ -- append the linkdirs flags from the option
+ if module.flag_linkdir then
+ for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do
+ table.join2(flags, module.flag_linkdir(linkdir))
+ end
+ end
+
+ -- append the links flags from the option
+ if module.flag_link then
+ for _, link in ipairs(utils.wrap(opt.links)) do
+ table.join2(flags, module.flag_link(link))
+ end
+ end
+ end
+ end
+ end
-- append the flags from the configure
- table.join2(flags, linker._mapflags(module, config.get(flag_name)))
+ table.join2(flags, linker._mapflags(module, config.get(flagname)))
-- append the strip flags from the current project
table.join2(flags, linker._getflags(module, target.strip, { debug = "-S"
@@ -188,34 +214,34 @@ function linker.check_links(opt, links, objectfile, targetfile)
assert(opt and links and objectfile and targetfile)
-- get the linker
- local l = linker.get("binary")
- assert(l and l.flag_link)
+ local module = linker.get("binary")
+ assert(module and module.flag_link)
-- append the common flags
local flags = {}
- table.join2(flags, l.ldflags)
+ table.join2(flags, module.ldflags)
-- append the option flags
- table.join2(flags, linker._mapflags(l, opt.ldflags))
+ table.join2(flags, linker._mapflags(module, opt.ldflags))
-- append the linkdirs flags
- if opt.linkdirs and l.flag_linkdir then
+ if opt.linkdirs and module.flag_linkdir then
for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do
- table.join2(flags, l.flag_linkdir(linkdir))
+ table.join2(flags, module.flag_linkdir(linkdir))
end
end
-- append the links flags
for _, link in ipairs(utils.wrap(links)) do
- table.join2(flags, l.flag_link(link))
+ table.join2(flags, module.flag_link(link))
end
-- make the compile command
- local cmd = string.format("%s > %s 2>&1", l.command_link(objectfile, targetfile, table.concat(flags, " "):trim()), xmake._NULDEV)
+ local cmd = string.format("%s > %s 2>&1", module.command_link(objectfile, targetfile, table.concat(flags, " "):trim()), xmake._NULDEV)
if not cmd then return end
-- execute the link command
- return l.main(cmd)
+ return module.main(cmd)
end
-- return module: linker
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 79a7007be..39cfa7c42 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -340,7 +340,6 @@ function project._makeconf_for_target(target_name, target)
end
end
-
-- make the tail
file:write("#endif\n")