summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-05 16:08:19 +0800
committerruki <[email protected]>2016-05-05 16:08:19 +0800
commit64cf81d6ddf726e3230b4fab852e4eb0b75c378d (patch)
tree341fa416034a0aa5c23aa17c513a7dcf85cb12b2
parentf68de1b816bd631634a82d6cd8c8ea4636961a54 (diff)
reimpl build objects
-rwxr-xr-xxmake/actions/build/builder.lua98
-rwxr-xr-xxmake/actions/build/main.lua6
-rwxr-xr-xxmake/actions/config/main.lua1
-rw-r--r--xmake/core/project/target.lua24
-rw-r--r--xmake/core/sandbox/modules/os.lua8
-rw-r--r--xmake/core/sandbox/modules/utils.lua4
-rwxr-xr-xxmake/plugins/makefile/makefile.lua20
7 files changed, 126 insertions, 35 deletions
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua
index 4113b8ef7..e2b453765 100755
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/builder.lua
@@ -35,32 +35,118 @@ function _target(targetname)
return assert(project.target(targetname), "unknown target: %s", targetname)
end
+-- make the object for the *.[o|obj] source file
+function _make_object_for_object(target, srcfile, objfile)
+end
+
+-- make the object for the *.[a|lib] source file
+function _make_object_for_static(target, srcfile, objfile)
+end
+
+-- make object
+function _make_object(target, sourcefile, objectfile)
+
+ -- get the source file type
+ local filetype = path.extension(sourcefile):lower()
+
+ -- make the object for the *.o/obj source makefile
+ if filetype == ".o" or filetype == ".obj" then
+ return _make_object_for_object(target, sourcefile, objectfile)
+ -- make the object for the *.[a|lib] source file
+ elseif filetype == ".a" or filetype == ".lib" then
+ return _make_object_for_static(target, sourcefile, objectfile)
+ end
+
+ -- make command
+ local ccache = tool.shellname("ccache")
+ local compiler = target:compiler(sourcefile)
+ local cmd = compiler:command(target, sourcefile, objectfile)
+ if ccache then
+ cmd = ccache:append(cmd, " ")
+ end
+
+ -- trace
+ print("%scompiling.$(mode) %s", ifelse(ccache, "ccache ", ""), sourcefile)
+
+ -- trace verbose info
+ if option.get("verbose") then
+ print(cmd)
+ end
+
+ -- create directory if not exists
+ os.mkdir(path.directory(objectfile))
+
+ -- run cmd
+ os.run(cmd)
+end
+
+-- make objects for the given target
+function _make_objects(target)
+
+ -- make all objects
+ local i = 1
+ local objectfiles = target:objectfiles()
+ local sourcefiles = target:sourcefiles()
+ for _, objectfile in ipairs(objectfiles) do
+
+ -- make object
+ _make_object(target, sourcefiles[i], objectfile)
+
+ -- next
+ i = i + 1
+ end
+end
+
-- make the given target
function _make_target(target)
+ -- trace
+ print("building.$(mode) %s", target:name())
+
+ -- make objects
+ _make_objects(target)
+
+ -- make target
+ -- ...
+end
+
+-- make the given target and deps
+function _make_target_and_deps(target)
+
+ -- this target have been finished?
+ if _g.finished[target:name()] then
+ return
+ end
+
-- make for all dependent targets
for _, depname in ipairs(target:get("deps")) do
- _make_target(_target(depname))
+ _make_target_and_deps(_target(depname))
end
- -- trace
- print("make target: %s", target:name())
+ -- make target
+ _make_target(target)
+
+ -- finished
+ _g.finished[target:name()] = true
end
-- make
function make(targetname)
- -- make all targets
+ -- init finished states
+ _g.finished = {}
+
+ -- for all?
if targetname == "all" then
-- make all targets
for _, target in pairs(project.targets()) do
- _make_target(target)
+ _make_target_and_deps(target)
end
else
-- make target
- _make_target(_target(targetname))
+ _make_target_and_deps(_target(targetname))
end
end
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index d690bb303..22bb87af4 100755
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -112,10 +112,8 @@ function main()
function ()
-- make
--- builder.make(targetname or "all")
-
- -- make from makefile
- builder.make_from_makefile(targetname or "all")
+ builder.make(targetname or "all")
+-- builder.make_from_makefile(targetname or "all")
end,
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 8e335f887..0dc4174af 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -28,7 +28,6 @@ import("core.project.project")
import("core.platform.platform")
import("core.project.cache")
import("config_h")
-import("makefile")
-- filter option
function _option_filter(name)
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index ef170fa4f..710a9804c 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -158,6 +158,11 @@ function target:sourcefiles()
-- check
assert(self)
+ -- cached? return it directly
+ if self._SOURCEFILES then
+ return self._SOURCEFILES
+ end
+
-- get files
local files = self:get("files")
@@ -207,6 +212,9 @@ function target:sourcefiles()
-- remove repeat files
sourcefiles = table.unique(sourcefiles)
+ -- cache it
+ self._SOURCEFILES = sourcefiles
+
-- ok?
return sourcefiles
end
@@ -217,6 +225,11 @@ function target:objectfiles()
-- check
assert(self)
+ -- cached? return it directly
+ if self._OBJECTFILES then
+ return self._OBJECTFILES
+ end
+
-- get the object directory
local objectdir = self:objectdir()
assert(objectdir and type(objectdir) == "string")
@@ -256,6 +269,9 @@ function target:objectfiles()
end
+ -- cache it
+ self._OBJECTFILES = objectfiles
+
-- ok?
return objectfiles
end
@@ -266,6 +282,11 @@ function target:headerfiles()
-- check
assert(self)
+ -- cached? return it directly
+ if self._HEADERFILES then
+ return self._HEADERFILES[1], self._HEADERFILES[2]
+ end
+
-- no headers?
local headers = self:get("headers")
if not headers then return end
@@ -307,6 +328,9 @@ function target:headerfiles()
end
end
+ -- cache it
+ self._HEADERFILES = {srcheaders, dstheaders}
+
-- ok?
return srcheaders, dstheaders
end
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 0a25c46b9..030e0c851 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -113,10 +113,11 @@ function sandbox_os.mkdir(dir)
dir = vformat(dir)
-- done
- if not os.mkdir(dir) then
- os.raise("create directory: %s failed!", dir)
+ if not os.isdir(dir) then
+ if not os.mkdir(dir) then
+ os.raise("create directory: %s failed!", dir)
+ end
end
-
end
-- remove directory
@@ -134,7 +135,6 @@ function sandbox_os.rmdir(dir)
os.raise("remove directory: %s failed!", dir)
end
end
-
end
-- get the current directory
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index d419c257e..877234602 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -45,14 +45,14 @@ function sandbox_utils.print(format, ...)
end
-- done
- return io.write(vformat(format, ...) .. "\n")
+ io.write(vformat(format, ...) .. "\n")
end
-- printf with the builtin variables
function sandbox_utils.printf(format, ...)
-- done
- return io.write(vformat(format, ...))
+ io.write(vformat(format, ...))
end
-- assert
diff --git a/xmake/plugins/makefile/makefile.lua b/xmake/plugins/makefile/makefile.lua
index 6079ae3a0..691d50816 100755
--- a/xmake/plugins/makefile/makefile.lua
+++ b/xmake/plugins/makefile/makefile.lua
@@ -56,24 +56,8 @@ end
-- make the object for the *.[a|lib] source file
function _make_object_for_static(makefile, target, srcfile, objfile)
- -- make command
- local cmd = format("xmake l -P %s -f %s dispatcher ex extract %s %s > %s 2>&1", xmake._PROJECT_DIR, xmake._PROJECT_FILE, srcmakefile:encode(), objmakefile:encode(), makefile._LOGFILE)
-
- -- make head
- makefile:printf("%s:", objfile)
-
- -- make dependence
- makefile:print(" %s", srcfile)
-
- -- make body
- makefile:print("\t@echo inserting.$(mode) %s", srcfile)
- makefile:print("\t@xmake l %$(VERBOSE) verbose \"%s\"", cmd:encode())
- makefile:print("\t@xmake l rmdir %s\n", path.directory(objfile))
- makefile:print("\t@%s", cmd)
-
- -- make tail
- makefile:print("")
-
+ -- not supported
+ raise("source file: %s not supported!", srcfile)
end
-- make the object