summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-05-07 22:55:32 +0800
committerruki <[email protected]>2018-05-07 11:33:16 +0800
commite257d701fc71e8d75b31485cfa6b71967f180a43 (patch)
treed867f7d55fe2da785530622e7f4a24184657227f
parent6300b045a734b9d5d1f81d154365c5c4b73a650d (diff)
improve dependent files
-rw-r--r--xmake/actions/build/kinds/object.lua18
-rw-r--r--xmake/actions/clean/main.lua4
-rw-r--r--xmake/core/project/target.lua64
-rw-r--r--xmake/plugins/project/makefile/makefile.lua2
4 files changed, 48 insertions, 40 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 37707a0ae..592f78a9c 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -138,7 +138,7 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache)
-- get the object and source with the given index
local sourcefile = sourcebatch.sourcefiles[index]
local objectfile = sourcebatch.objectfiles[index]
- local incdepfile = sourcebatch.incdepfiles[index]
+ local dependfile = sourcebatch.dependfiles[index]
local sourcekind = sourcebatch.sourcekind
-- calculate percent
@@ -154,8 +154,8 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache)
-- get dependent info
local depinfo = {}
- if not buildinfo.rebuild and os.isfile(incdepfile) then
- depinfo = io.load(incdepfile) or {}
+ if not buildinfo.rebuild and os.isfile(dependfile) then
+ depinfo = io.load(dependfile) or {}
end
-- load compiler instance
@@ -207,7 +207,7 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache)
depinfo.flags = compflags
-- save the dependent info
- io.save(incdepfile, depinfo)
+ io.save(dependfile, depinfo)
end
-- build each objects from the given source batch
@@ -238,7 +238,7 @@ function _build_single_object(target, buildinfo, sourcekind, sourcebatch, jobs,
-- get source and object files
local sourcefiles = sourcebatch.sourcefiles
local objectfiles = sourcebatch.objectfiles
- local incdepfiles = sourcebatch.incdepfiles
+ local dependfiles = sourcebatch.dependfiles
-- trace percent info
for index, sourcefile in ipairs(sourcefiles) do
@@ -263,7 +263,7 @@ function _build_single_object(target, buildinfo, sourcekind, sourcebatch, jobs,
buildinfo.modified[target:name()] = true
-- complie them
- compiler.compile(sourcefiles, objectfiles, {incdepfiles = incdepfiles, target = target, sourcekind = sourcekind})
+ compiler.compile(sourcefiles, objectfiles, {dependfiles = dependfiles, target = target, sourcekind = sourcekind})
-- update object index
_g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles
@@ -279,14 +279,14 @@ function _build_pcheaderfiles(target, buildinfo)
local pcheaderfile = target:pcheaderfile(langkind)
if pcheaderfile then
- -- init sourcefile, objectfile and incdepfile
+ -- init sourcefile, objectfile and dependfile
local sourcefile = pcheaderfile
local objectfile = target:pcoutputfile(langkind)
- local incdepfile = objectfile .. ".d"
+ local dependfile = objectfile .. ".d"
local sourcekind = language.langkinds()[langkind]
-- init source batch
- local sourcebatch = {sourcekind = sourcekind, sourcefiles = {sourcefile}, objectfiles = {objectfile}, incdepfiles = {incdepfile}}
+ local sourcebatch = {sourcekind = sourcekind, sourcefiles = {sourcefile}, objectfiles = {objectfile}, dependfiles = {dependfile}}
-- build this precompiled header
_build_object(target, buildinfo, 1, sourcebatch, false)
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 130458280..dd785aa15 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -87,8 +87,8 @@ function _on_clean_target(target)
-- remove the object files
_remove(target:objectfiles())
- -- remove the incdep files
- _remove(target:incdepfiles())
+ -- remove the depend files
+ _remove(target:dependfiles())
-- remove the header files
local _, dstheaders = target:headerfiles()
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 18e97cee4..c2dd7e24f 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -418,7 +418,7 @@ function target:objectdir()
-- the object directory
local objectdir = self:get("objectdir")
if not objectdir then
- objectdir = path.join(config.buildir(), ".objs")
+ objectdir = path.join(config.buildir(), ".objs", self:name())
end
-- append mode sub-directory
@@ -439,7 +439,24 @@ end
-- get the dependent files directory
function target:dependir()
- return path.join(config.buildir(), ".deps", config.get("mode") or "generic", config.get("arch") or os.arch(), self:name())
+
+ -- init the dependent directory
+ local dependir = path.join(config.buildir(), ".deps", self:name())
+
+ -- append mode sub-directory
+ local mode = config.get("mode")
+ if mode then
+ dependir = path.join(dependir, mode)
+ end
+
+ -- append arch sub-directory
+ local arch = config.get("arch")
+ if arch then
+ dependir = path.join(dependir, arch)
+ end
+
+ -- ok?
+ return dependir
end
-- get the target dependent file
@@ -707,10 +724,6 @@ function target:objectfile(sourcefile)
-- translate: [lib]xxx*.[a|lib] => xxx/*.[o|obj] object file
sourcefile = sourcefile:gsub(target.filename("([%w%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1/*")
- -- get the object directory
- local objectdir = self:objectdir()
- assert(objectdir and type(objectdir) == "string")
-
-- translate path
--
-- .e.g
@@ -731,7 +744,7 @@ function target:objectfile(sourcefile)
-- make object file
-- full file name(not base) to avoid name-clash of object file
- return path.join(objectdir, self:name(), sourcedir, target.filename(path.filename(sourcefile), "object"))
+ return path.join(self:objectdir(), sourcedir, target.filename(path.filename(sourcefile), "object"))
end
-- get the object files
@@ -826,35 +839,36 @@ function target:headerfiles(outputdir)
return srcheaders, dstheaders
end
--- get incdep file from object file
-function target:incdepfile(objectfile)
- return path.join(path.directory(objectfile), path.basename(objectfile) .. ".d")
+-- get depend file from object file
+function target:dependfile(objectfile)
+ local depentfile = path.join(self:dependir(), path.relative(objectfile, self:objectdir()))
+ return path.join(path.directory(depentfile), path.basename(depentfile) .. ".d")
end
-- get the dependent include files
-function target:incdepfiles()
+function target:dependfiles()
-- get source batches
local sourcebatches, modified = self:sourcebatches()
-- cached? return it directly
- if self._INCDEPFILES and not modified then
- return self._INCDEPFILES
+ if self._DEPENDFILES and not modified then
+ return self._DEPENDFILES
end
- -- get incdep files from source batches
- local incdepfiles = {}
+ -- get dependent files from source batches
+ local dependfiles = {}
for sourcekind, sourcebatch in pairs(self:sourcebatches()) do
if not sourcebatch.rulename then
- table.join2(incdepfiles, sourcebatch.incdepfiles)
+ table.join2(dependfiles, sourcebatch.dependfiles)
end
end
-- cache it
- self._INCDEPFILES = incdepfiles
+ self._DEPENDFILES = dependfiles
-- ok?
- return incdepfiles
+ return dependfiles
end
-- get the kinds of sourcefiles
@@ -990,24 +1004,18 @@ function target:sourcebatches()
-- insert single object file for all source files
sourcebatch.objectfiles = self:objectfile(path.join(path.directory(sourcefile), "__" .. sourcekind))
- -- insert single incdep file for all source files
- sourcebatch.incdepfiles = self:incdepfile(sourcebatch.objectfiles)
+ -- insert single dependent file for all source files
+ sourcebatch.dependfiles = self:dependfile(sourcebatch.objectfiles)
else
-- insert object files for each source files
sourcebatch.objectfiles = {}
- sourcebatch.incdepfiles = {}
+ sourcebatch.dependfiles = {}
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
-
- -- get object file from this source file
local objectfile = self:objectfile(sourcefile)
-
- -- add object file to this batch
table.insert(sourcebatch.objectfiles, objectfile)
-
- -- add incdep file to this batch
- table.insert(sourcebatch.incdepfiles, self:incdepfile(objectfile))
+ table.insert(sourcebatch.dependfiles, self:dependfile(objectfile))
end
end
end
diff --git a/xmake/plugins/project/makefile/makefile.lua b/xmake/plugins/project/makefile/makefile.lua
index 953a985ae..762d9dc19 100644
--- a/xmake/plugins/project/makefile/makefile.lua
+++ b/xmake/plugins/project/makefile/makefile.lua
@@ -208,7 +208,7 @@ function _make_single_object(makefile, target, sourcekind, sourcebatch, sourcefl
-- get source and object files
local sourcefiles = sourcebatch.sourcefiles
local objectfiles = sourcebatch.objectfiles
- local incdepfiles = sourcebatch.incdepfiles
+ local dependfiles = sourcebatch.dependfiles
-- get program
local program = platform.tool(sourcekind)