diff options
| author | ruki <[email protected]> | 2015-06-02 10:12:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-02 10:12:47 +0800 |
| commit | bf6315e4e63270175eb27d9ab73dc98f3408cea8 (patch) | |
| tree | a30eb35c334883b1a7e01479c0ffdf614807cab5 /xmake/scripts | |
| parent | f6177ffb405aa474e5d8e8af787778bd8ed8439c (diff) | |
append config and target flags
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/compiler/compiler.lua | 67 | ||||
| -rw-r--r-- | xmake/scripts/linker/linker.lua | 46 |
3 files changed, 81 insertions, 36 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 808ff819c..1a3bbbbe6 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -145,7 +145,7 @@ function makefile._make_object(file, target, srcfile, objfile) -- make body file:write(string.format("\t@echo [%s]: compiling %s\n", config.get("mode"), srcfile)) file:write(string.format("\t@xmake l mkdir %s\n", path.directory(objfile))) - file:write(string.format("\t@%s\n", c:make(filetype, srcfile, objfile, ""))) + file:write(string.format("\t@%s\n", c:make(target, filetype, srcfile, objfile))) -- make tail file:write("\n") @@ -218,7 +218,7 @@ function makefile._make_target(file, name, target) -- make body file:write(string.format("\t@echo [%s]: linking %s\n", config.get("mode"), path.filename(targetfile))) file:write(string.format("\t@xmake l mkdir %s\n", path.directory(targetfile))) - file:write(string.format("\t@%s\n", l:make(target.kind, objfiles, targetfile, ""))) + file:write(string.format("\t@%s\n", l:make(target, objfiles, targetfile))) -- make tail file:write("\n") diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/compiler/compiler.lua index 7b52bd951..a4c5c59b7 100644 --- a/xmake/scripts/compiler/compiler.lua +++ b/xmake/scripts/compiler/compiler.lua @@ -59,35 +59,66 @@ function compiler._mapflags(self, flags) end -- make the compile command -function compiler._make(self, filetype, srcfile, objfile, flags) +function compiler._make(self, target, filetype, srcfile, objfile) -- check - assert(self and filetype); + assert(self and target and filetype); -- the configure local configs = self._CONFIGS assert(configs) - -- get the common flags string for the current compiler - local flags_common = nil - if filetype == "cc" then flags_common = configs.cflags - elseif filetype == "cxx" then flags_common = configs.cxxflags - elseif filetype == "mm" then flags_common = configs.mflags - elseif filetype == "mxx" then flags_common = configs.mxxflags - elseif filetype == "as" then flags_common = configs.asflags + -- the flag names + local flag_names = nil + if filetype == "cc" then flag_names = { "cxflags", "cflags" } + elseif filetype == "cxx" then flag_names = { "cxflags", "cxxflags" } + elseif filetype == "mm" then flag_names = { "mxflags", "mflags" } + elseif filetype == "mxx" then flag_names = { "mxflags", "mxxflags" } + elseif filetype == "as" then flag_names = { "asflags" } + -- error + utils.error("unknown filetype for compiler: %s", filetype) + return end - flags_common = flags_common or "" - -- map flags - flags = compiler._mapflags(self, utils.wrap(flags)) - assert(flags) - - -- make flags string - flags = table.concat(flags) - assert(flags) + -- get the common flags from the current compiler + local flags_common = "" + for _, flag_name in ipairs(flag_names) do + flags_common = string.format("%s %s", flags_common, configs[flag_name] or "") + end + + -- get the target flags from the current project + local flags_target = "" + for _, flag_name in ipairs(flag_names) do + + -- get flags + local flags = target[flag_name] + if flags then + flags = table.concat(compiler._mapflags(self, utils.wrap(flags)), " ") + end + + -- append flags + flags_target = string.format("%s %s", flags_target, flags or "") + end + + -- get the config flags + local flags_config = "" + for _, flag_name in ipairs(flag_names) do + + -- get flags + local flags = config.get(flag_name) + if flags then + flags = table.concat(compiler._mapflags(self, utils.wrap(flags)), " ") + end + + -- append flags + flags_config = string.format("%s %s", flags_config, flags or "") + end + + -- make the flags string + local flags = string.format("%s %s %s", flags_common, flags_target, flags_config) -- get it - return self._make(configs, srcfile, objfile, flags_common .. " " .. flags) + return self._make(configs, srcfile, objfile, flags) end -- load the given compiler diff --git a/xmake/scripts/linker/linker.lua b/xmake/scripts/linker/linker.lua index d2e4ec9ec..22b4c5ea1 100644 --- a/xmake/scripts/linker/linker.lua +++ b/xmake/scripts/linker/linker.lua @@ -58,33 +58,47 @@ function linker._mapflags(self, flags) end -- make the command -function linker._make(self, kind, objfiles, targetfile, flags) +function linker._make(self, target, objfiles, targetfile) -- check - assert(self and self._make) + assert(self and self._make and target) -- the configure local configs = self._CONFIGS assert(configs) - -- get the common flags string for the current linker - local flags_common = nil - if kind == "binary" then flags_common = configs.ldflags - elseif kind == "static" then flags_common = configs.arflags - elseif kind == "shared" then flags_common = configs.shflags + -- the target kind + 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" + else + -- error + utils.error("unknown type for linker: %s", kind) + return end - flags_common = flags_common or "" - -- map flags - flags = linker._mapflags(self, utils.wrap(flags)) - assert(flags) - - -- make flags string - flags = table.concat(flags) - assert(flags) + -- get the common flags from the current linker + local flags_common = configs[flag_name] or "" + + -- get the target flags from the current project + local flags_target = target[flag_name] or "" + flags_target = table.concat(linker._mapflags(self, utils.wrap(flags_target)), " ") + assert(flags_target) + + -- get the config flags + local flags_config = config.get(flag_name) or "" + flags_config = table.concat(linker._mapflags(self, utils.wrap(flags_config)), " ") + assert(flags_config) + + -- make the flags string + local flags = string.format("%s %s %s", flags_common, flags_target, flags_config) -- make it - return self._make(configs, table.concat(objfiles), targetfile, flags_common .. " " .. flags) + return self._make(configs, table.concat(objfiles, " "), targetfile, flags) end -- load the given linker |
