diff options
| author | ruki <[email protected]> | 2016-07-09 15:08:28 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-09 15:08:28 +0800 |
| commit | 9feb387e4e4e6694b2c9ac3de4d517fb4c4ae44a (patch) | |
| tree | 9581332e5365025b5663c3c48f223a9dfd6f415c | |
| parent | 460030d64886772601749b874f06fe536f1d3fd5 (diff) | |
fix install directory and modify compiler and linker interfaces
| -rwxr-xr-x | xmake/actions/build/builder.lua | 35 | ||||
| -rwxr-xr-x | xmake/actions/install/xmake.lua | 4 | ||||
| -rwxr-xr-x | xmake/actions/uninstall/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 16 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/linker.lua | 16 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 21 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 29 | ||||
| -rw-r--r-- | xmake/platforms/installer.lua | 28 | ||||
| -rwxr-xr-x | xmake/plugins/project/makefile.lua | 2 | ||||
| -rw-r--r-- | xmake/tools/ar.lua | 14 | ||||
| -rwxr-xr-x | xmake/tools/cl.lua | 30 | ||||
| -rwxr-xr-x | xmake/tools/gcc.lua | 52 | ||||
| -rwxr-xr-x | xmake/tools/link.lua | 40 | ||||
| -rwxr-xr-x | xmake/tools/ml.lua | 30 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua | 19 |
15 files changed, 241 insertions, 100 deletions
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua index 8264e4476..b10e76bbe 100755 --- a/xmake/actions/build/builder.lua +++ b/xmake/actions/build/builder.lua @@ -91,31 +91,30 @@ function _build_object(target, index) return _build_object_for_static(target, sourcefile, objectfile, percent) end - -- make command - local command = compiler.compcmd(sourcefile, objectfile, target) - -- uses ccache local ccache = nil if config.get("ccache") then ccache = tool.shellname("ccache") end - if ccache then - command = ccache:append(command, " ") - end -- trace print("[%02d%%]: %scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) -- trace verbose info if option.get("verbose") then + + -- make command + local command = compiler.compcmd(sourcefile, objectfile, target) + if ccache then + command = ccache:append(command, " ") + end + + -- trace print(command) end - -- create directory if not exists - os.mkdir(path.directory(objectfile)) - - -- run cmd with coroutine - os.corun(command) + -- complie it and enable multitasking + compiler.compile(sourcefile, objectfile, target, true) end -- make objects for the given target @@ -205,23 +204,19 @@ function _build_target(target) end end - -- make the command for linking target - local targetfile = target:targetfile() - local command = linker.linkcmd(objectfiles, targetfile, target) + -- the target file + local targetfile = target:targetfile() -- trace print("[%02d%%]: linking.$(mode) %s", _g.targetindex * 100 / _g.targetcount, path.filename(targetfile)) -- trace verbose info if option.get("verbose") then - print(command) + print(linker.linkcmd(objectfiles, targetfile, target)) end - -- create directory if not exists - os.mkdir(path.directory(targetfile)) - - -- run command - os.run(command) + -- link it + linker.link(objectfiles, targetfile, target) end -- make the given target diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua index d2160490e..11fdd1270 100755 --- a/xmake/actions/install/xmake.lua +++ b/xmake/actions/install/xmake.lua @@ -43,10 +43,10 @@ task("install") -- options , options = { - {'o', "installdir", "kv", nil, "Set the install directory." } + {'o', "installdir", "kv", nil, "Set the install directory." } , {} - , {nil, "target", "v", "all", "Install the given target." } + , {nil, "target", "v", "all", "Install the given target." } } }) diff --git a/xmake/actions/uninstall/xmake.lua b/xmake/actions/uninstall/xmake.lua index b4ef7e8d4..881dc8274 100755 --- a/xmake/actions/uninstall/xmake.lua +++ b/xmake/actions/uninstall/xmake.lua @@ -43,7 +43,10 @@ task("uninstall") -- options , options = { - {nil, "target", "v", "all", "Install the given target." } + {nil, "installdir", "kv", nil, "Set the install directory." } + + , {} + , {nil, "target", "v", "all", "Uninstall the given target." } } }) diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index bf231f7b4..71059ad16 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -41,5 +41,21 @@ function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target) return instance:compcmd(sourcefile, objectfile, target) end +-- compile source file +function sandbox_core_tool_compiler.compile(sourcefile, objectfile, target, multitasking) + + -- get the compiler instance + local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) + if not instance then + raise(errors) + end + + -- compile it + local ok, errors = instance:compile(sourcefile, objectfile, target, multitasking) + if not ok then + raise(errors) + end +end + -- return module return sandbox_core_tool_compiler diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index 9f42a04e7..5f9a32f96 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -41,5 +41,21 @@ function sandbox_core_tool_linker.linkcmd(objectfiles, targetfile, target) return instance:linkcmd(objectfiles, targetfile, target) end +-- link target file +function sandbox_core_tool_linker.link(objectfiles, targetfile, target) + + -- get the linker instance + local instance, errors = linker.load(target:get("kind")) + if not instance then + raise(errors) + end + + -- link it + local ok, errors = instance:link(objectfiles, targetfile, target) + if not ok then + raise(errors) + end +end + -- return module return sandbox_core_tool_linker diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 7d867a6d2..da4e284fd 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -308,10 +308,10 @@ function compiler:_addflags_from_compiler(flags, kind) end -- get the compiler kind of the source file -function compiler.kind_of_file(srcfile) +function compiler.kind_of_file(sourcefile) -- get the source file type - local filetype = path.extension(srcfile) + local filetype = path.extension(sourcefile) if not filetype then return nil end @@ -398,8 +398,21 @@ function compiler:get(name) return self:_tool().get(name) end +-- compile the source file +function compiler:compile(sourcefile, objectfile, target, multitasking) + + -- get flags + local flags = nil + if target then + flags = self:_flags(target) + end + + -- compile it + return sandbox.load(self:_tool().compile, sourcefile, objectfile, flags or "", multitasking) +end + -- get the compile command -function compiler:compcmd(srcfile, objfile, target) +function compiler:compcmd(sourcefile, objectfile, target) -- get flags local flags = nil @@ -408,7 +421,7 @@ function compiler:compcmd(srcfile, objfile, target) end -- get it - return self:_tool().compcmd(srcfile, objfile, flags or "") + return self:_tool().compcmd(sourcefile, objectfile, flags or "") end -- make the define flag diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index e0959702c..41ce9bfd3 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -195,7 +195,7 @@ function linker:_addflags_from_target(flags, target) -- add the links flags for _, link in ipairs(table.wrap(target:get("links"))) do - table.join2(flags, self:link(link)) + table.join2(flags, self:linklib(link)) end -- for target options? @@ -214,7 +214,7 @@ function linker:_addflags_from_target(flags, target) -- add the links flags from the option for _, link in ipairs(table.wrap(opt:get("links"))) do - table.join2(flags, self:link(link)) + table.join2(flags, self:linklib(link)) end end end @@ -238,7 +238,7 @@ function linker:_addflags_from_platform(flags) -- add the links flags for _, link in ipairs(table.wrap(platform.get("links"))) do - table.join2(flags, self:link(link)) + table.join2(flags, self:linklib(link)) end end @@ -332,8 +332,21 @@ function linker:get(name) return self:_tool().get(name) end +-- link the target file +function linker:link(objectfiles, targetfile, target) + + -- get flags + local flags = nil + if target then + flags = self:_flags(target) + end + + -- get it + return sandbox.load(self:_tool().link, table.concat(table.wrap(objectfiles), " "), targetfile, flags or "") +end + -- get the link command -function linker:linkcmd(objfiles, targetfile, target) +function linker:linkcmd(objectfiles, targetfile, target) -- get flags local flags = nil @@ -342,14 +355,14 @@ function linker:linkcmd(objfiles, targetfile, target) end -- get it - return self:_tool().linkcmd(table.concat(table.wrap(objfiles), " "), targetfile, flags or "") + return self:_tool().linkcmd(table.concat(table.wrap(objectfiles), " "), targetfile, flags or "") end --- make the link flag -function linker:link(lib) +-- make the linklib flag +function linker:linklib(lib) -- make it - return self:_tool().link(lib) + return self:_tool().linklib(lib) end -- make the linkdir flag diff --git a/xmake/platforms/installer.lua b/xmake/platforms/installer.lua index 52df1985f..a7ff96b9f 100644 --- a/xmake/platforms/installer.lua +++ b/xmake/platforms/installer.lua @@ -26,11 +26,11 @@ import("core.base.option") -- install binary function install_binary_on_unix(target) - -- the output directory - local outputdir = option.get("outputdir") or "/usr/local" + -- the install directory + local installdir = option.get("installdir") or "/usr/local" -- the binary directory - local binarydir = path.join(outputdir, "bin") + local binarydir = path.join(installdir, "bin") -- make the binary directory os.mkdir(binarydir) @@ -42,14 +42,14 @@ end -- install library function install_library_on_unix(target) - -- the output directory - local outputdir = option.get("outputdir") or "/usr/local" + -- the install directory + local installdir = option.get("installdir") or "/usr/local" -- the library directory - local librarydir = path.join(outputdir, "lib") + local librarydir = path.join(installdir, "lib") -- the include directory - local includedir = path.join(outputdir, "include") + local includedir = path.join(installdir, "include") -- make the library directory os.mkdir(librarydir) @@ -83,11 +83,11 @@ end -- uninstall binary function uninstall_binary_on_unix(target) - -- the output directory - local outputdir = option.get("outputdir") or "/usr/local" + -- the install directory + local installdir = option.get("installdir") or "/usr/local" -- the binary directory - local binarydir = path.join(outputdir, "bin") + local binarydir = path.join(installdir, "bin") -- remove the target file os.rm(path.join(binarydir, path.filename(target:targetfile()))) @@ -96,14 +96,14 @@ end -- uninstall library function uninstall_library_on_unix(target) - -- the output directory - local outputdir = option.get("outputdir") or "/usr/local" + -- the install directory + local installdir = option.get("installdir") or "/usr/local" -- the library directory - local librarydir = path.join(outputdir, "lib") + local librarydir = path.join(installdir, "lib") -- the include directory - local includedir = path.join(outputdir, "include") + local includedir = path.join(installdir, "include") -- remove the target file os.rm(path.join(librarydir, path.filename(target:targetfile()))) diff --git a/xmake/plugins/project/makefile.lua b/xmake/plugins/project/makefile.lua index b3bbe58b2..405441368 100755 --- a/xmake/plugins/project/makefile.lua +++ b/xmake/plugins/project/makefile.lua @@ -140,7 +140,7 @@ function _make_target(makefile, target) makefile:print("") -- make the command - local command = linker.linkcmd(target:objectfiles, targetfile, target) + local command = linker.linkcmd(target:objectfiles(), targetfile, target) -- make body makefile:print("\t@echo linking.$(mode) %s", path.filename(targetfile)) diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua index 6445c332b..79d3cdc58 100644 --- a/xmake/tools/ar.lua +++ b/xmake/tools/ar.lua @@ -44,8 +44,8 @@ function get(name) return _g[name] end --- make the link flag -function link(lib) +-- make the linklib flag +function linklib(lib) end -- make the linkdir flag @@ -59,6 +59,16 @@ function linkcmd(objectfiles, targetfile, flags) return format("%s %s %s %s", _g.shellname, flags, targetfile, objectfiles) end +-- link the target file +function link(objectfiles, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(objectfiles, targetfile, flags)) +end + -- extract the static library to object directory function extract(libraryfile, objectdir) diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua index 70acc34e1..d9a145f8b 100755 --- a/xmake/tools/cl.lua +++ b/xmake/tools/cl.lua @@ -105,10 +105,24 @@ function includedir(dir) end -- make the complie command -function compcmd(srcfile, objfile, flags) +function compcmd(sourcefile, objectfile, flags) -- make it - return format("%s -c %s -Fo%s %s", _g.shellname, flags, objfile, srcfile) + return format("%s -c %s -Fo%s %s", _g.shellname, flags, objectfile, sourcefile) +end + +-- complie the source file +function compile(sourcefile, objectfile, flags, multitasking) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + if multitasking then + os.corun(compcmd(sourcefile, objectfile, flags)) + else + os.run(compcmd(sourcefile, objectfile, flags)) + end end -- run command @@ -122,15 +136,15 @@ end function check(flags) -- make an stub source file - local objfile = path.join(os.tmpdir(), "xmake.cl.obj") - local srcfile = path.join(os.tmpdir(), "xmake.cl.c") - io.write(srcfile, "int main(int argc, char** argv)\n{return 0;}") + local objectfile = path.join(os.tmpdir(), "xmake.cl.obj") + local sourcefile = path.join(os.tmpdir(), "xmake.cl.c") + io.write(sourcefile, "int main(int argc, char** argv)\n{return 0;}") -- check it - os.run("%s -c %s -Fo%s %s", _g.shellname, ifelse(flags, flags, ""), objfile, srcfile) + os.run("%s -c %s -Fo%s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile) -- remove files - os.rm(objfile) - os.rm(srcfile) + os.rm(objectfile) + os.rm(sourcefile) end diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua index ff8d144d3..9b81c456c 100755 --- a/xmake/tools/gcc.lua +++ b/xmake/tools/gcc.lua @@ -87,8 +87,8 @@ function includedir(dir) return "-I" .. dir end --- make the link flag -function link(lib) +-- make the linklib flag +function linklib(lib) -- make it return "-l" .. lib @@ -101,18 +101,42 @@ function linkdir(dir) return "-L" .. dir end --- make the complie command -function compcmd(srcfile, objfile, flags) +-- make the link command +function linkcmd(objectfiles, targetfile, flags) -- make it - return format("%s -c %s -o %s %s", _g.shellname, flags, objfile, srcfile) + return format("%s -o %s %s %s", _g.shellname, targetfile, objectfiles, flags) end --- make the link command -function linkcmd(objfiles, targetfile, flags) +-- make the complie command +function compcmd(sourcefile, objectfile, flags) -- make it - return format("%s -o %s %s %s", _g.shellname, targetfile, objfiles, flags) + return format("%s -c %s -o %s %s", _g.shellname, flags, objectfile, sourcefile) +end + +-- link the target file +function link(objectfiles, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(objectfiles, targetfile, flags)) +end + +-- complie the source file +function compile(sourcefile, objectfile, flags, multitasking) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + if multitasking then + os.corun(compcmd(sourcefile, objectfile, flags)) + else + os.run(compcmd(sourcefile, objectfile, flags)) + end end -- run command @@ -126,17 +150,17 @@ end function check(flags) -- make an stub source file - local objfile = path.join(os.tmpdir(), "xmake.gcc.o") - local srcfile = path.join(os.tmpdir(), "xmake.gcc.c" .. ifelse(_g.kind == "cxx", "pp", "")) + local objectfile = path.join(os.tmpdir(), "xmake.gcc.o") + local sourcefile = path.join(os.tmpdir(), "xmake.gcc.c" .. ifelse(_g.kind == "cxx", "pp", "")) -- make stub code - io.write(srcfile, "int main(int argc, char** argv)\n{return 0;}") + io.write(sourcefile, "int main(int argc, char** argv)\n{return 0;}") -- check it - os.run("%s -c %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objfile, srcfile) + os.run("%s -c %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile) -- remove files - os.rm(objfile) - os.rm(srcfile) + os.rm(objectfile) + os.rm(sourcefile) end diff --git a/xmake/tools/link.lua b/xmake/tools/link.lua index ee3c23972..85c97fb95 100755 --- a/xmake/tools/link.lua +++ b/xmake/tools/link.lua @@ -69,8 +69,8 @@ function get(name) return _g[name] end --- make the link flag -function link(lib) +-- make the linklib flag +function linklib(lib) -- make it return lib .. ".lib" @@ -84,15 +84,15 @@ function linkdir(dir) end -- make the link command -function linkcmd(objfiles, targetfile, flags) +function linkcmd(objectfiles, targetfile, flags) -- make it - local cmd = format("%s %s -out:%s %s", _g.shellname, flags, targetfile, objfiles) + local cmd = format("%s %s -out:%s %s", _g.shellname, flags, targetfile, objectfiles) -- too long? if #cmd > 4096 then local argfile = targetfile .. ".arg" - io.printf(argfile, "%s -out:%s %s", flags, targetfile, objfiles) + io.printf(argfile, "%s -out:%s %s", flags, targetfile, objectfiles) cmd = format("%s @%s", _g.shellname, argfile) end @@ -100,6 +100,16 @@ function linkcmd(objfiles, targetfile, flags) return cmd end +-- link the target file +function link(objectfiles, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(objectfiles, targetfile, flags)) +end + -- run command function run(...) @@ -111,24 +121,24 @@ end function check(flags) -- make an stub source file - local exefile = path.join(os.tmpdir(), "xmake.cl.exe") - local objfile = path.join(os.tmpdir(), "xmake.cl.obj") - local srcfile = path.join(os.tmpdir(), "xmake.cl.c") + local binaryfile = path.join(os.tmpdir(), "xmake.cl.exe") + local objectfile = path.join(os.tmpdir(), "xmake.cl.obj") + local sourcefile = path.join(os.tmpdir(), "xmake.cl.c") -- main entry if flags and flags:lower():find("subsystem:windows") then - io.write(srcfile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}") + io.write(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}") else - io.write(srcfile, "int main(int argc, char** argv)\n{return 0;}") + io.write(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end -- check it - os.run("cl -c -Fo%s %s", objfile, srcfile) - os.run("%s %s -out:%s %s", _g.shellname, ifelse(flags, flags, ""), exefile, objfile) + os.run("cl -c -Fo%s %s", objectfile, sourcefile) + os.run("%s %s -out:%s %s", _g.shellname, ifelse(flags, flags, ""), binaryfile, objectfile) -- remove files - os.rm(objfile) - os.rm(srcfile) - os.rm(exefile) + os.rm(objectfile) + os.rm(sourcefile) + os.rm(binaryfile) end diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua index f705dd509..02e37d0df 100755 --- a/xmake/tools/ml.lua +++ b/xmake/tools/ml.lua @@ -96,10 +96,24 @@ function includedir(dir) end -- make the complie command -function compcmd(srcfile, objfile, flags) +function compcmd(sourcefile, objectfile, flags) -- make it - return format("%s -c %s -Fo%s %s", _g.shellname, flags, objfile, srcfile) + return format("%s -c %s -Fo%s %s", _g.shellname, flags, objectfile, sourcefile) +end + +-- complie the source file +function compile(sourcefile, objectfile, flags, multitasking) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + if multitasking then + os.corun(compcmd(sourcefile, objectfile, flags)) + else + os.run(compcmd(sourcefile, objectfile, flags)) + end end -- run command @@ -113,15 +127,15 @@ end function check(flags) -- make an stub source file - local objfile = path.join(os.tmpdir(), "xmake.ml.obj") - local srcfile = path.join(os.tmpdir(), "xmake.ml.asm") - io.write(srcfile, "end") + local objectfile = path.join(os.tmpdir(), "xmake.ml.obj") + local sourcefile = path.join(os.tmpdir(), "xmake.ml.asm") + io.write(sourcefile, "end") -- check it - os.run("%s -c %s -Fo%s %s", _g.shellname, ifelse(flags, flags, ""), objfile, srcfile) + os.run("%s -c %s -Fo%s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile) -- remove files - os.rm(objfile) - os.rm(srcfile) + os.rm(objectfile) + os.rm(sourcefile) end diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua index 466f90f72..cb391b0f8 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -74,10 +74,24 @@ function get(name) end -- make the compile command -function compcmd(srcfile, objfile, flags) +function compcmd(sourcefile, objectfile, flags) -- make it - return format("%s -c %s -o %s %s", _g.shellname, flags, objfile, srcfile) + return format("%s -c %s -o %s %s", _g.shellname, flags, objectfile, sourcefile) +end + +-- complie the source file +function compile(sourcefile, objectfile, flags, multitasking) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + if multitasking then + os.corun(compcmd(sourcefile, objectfile, flags)) + else + os.run(compcmd(sourcefile, objectfile, flags)) + end end -- make the includedir flag @@ -113,5 +127,4 @@ function check(flags) -- check it os.run("%s -h", _g.shellname) - end |
