summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-13 13:24:11 +0800
committerruki <[email protected]>2017-02-13 13:24:25 +0800
commita2b7b07658824d024f8d54bc73f4687c34179e49 (patch)
tree551241653204748e743efdb991b43ddf2b2c2654
parentcf57859f07fedb0611bd543c7b6fae4199de151d (diff)
remove some interfaces for go tool and add test for go
-rwxr-xr-xtests/static_library_go/src/main.go7
-rwxr-xr-xtests/static_library_go/src/test.go12
-rwxr-xr-xtests/static_library_go/src/test/add.go6
-rwxr-xr-xtests/static_library_go/src/test/sub.go6
-rwxr-xr-xtests/static_library_go/xmake.lua50
-rwxr-xr-xtests/tests3
-rwxr-xr-xxmake/languages/asm/xmake.lua4
-rwxr-xr-xxmake/languages/c++/xmake.lua4
-rwxr-xr-xxmake/languages/golang/xmake.lua10
-rwxr-xr-xxmake/languages/objc++/xmake.lua4
-rw-r--r--xmake/tools/ar.lua5
-rwxr-xr-xxmake/tools/go.lua80
-rwxr-xr-xxmake/tools/link.lua5
-rwxr-xr-xxmake/tools/ml.lua20
-rw-r--r--xmake/tools/swiftc.lua5
15 files changed, 139 insertions, 82 deletions
diff --git a/tests/static_library_go/src/main.go b/tests/static_library_go/src/main.go
new file mode 100755
index 000000000..f2b477453
--- /dev/null
+++ b/tests/static_library_go/src/main.go
@@ -0,0 +1,7 @@
+package main
+
+func main() {
+
+ Run()
+}
+
diff --git a/tests/static_library_go/src/test.go b/tests/static_library_go/src/test.go
new file mode 100755
index 000000000..cf10523f9
--- /dev/null
+++ b/tests/static_library_go/src/test.go
@@ -0,0 +1,12 @@
+package main
+
+import (
+ "fmt"
+ "module"
+)
+
+func Run() {
+
+ fmt.Printf("add: %d\n", module.Add(1, 2));
+ fmt.Printf("sub: %d\n", module.Sub(1, 2));
+}
diff --git a/tests/static_library_go/src/test/add.go b/tests/static_library_go/src/test/add.go
new file mode 100755
index 000000000..98ffef600
--- /dev/null
+++ b/tests/static_library_go/src/test/add.go
@@ -0,0 +1,6 @@
+package module
+
+func Add(a int, b int) int {
+ return a + b;
+}
+
diff --git a/tests/static_library_go/src/test/sub.go b/tests/static_library_go/src/test/sub.go
new file mode 100755
index 000000000..a24a9abb7
--- /dev/null
+++ b/tests/static_library_go/src/test/sub.go
@@ -0,0 +1,6 @@
+package module
+
+func Sub(a int, b int) int {
+ return a - b;
+}
+
diff --git a/tests/static_library_go/xmake.lua b/tests/static_library_go/xmake.lua
new file mode 100755
index 000000000..a614fe00b
--- /dev/null
+++ b/tests/static_library_go/xmake.lua
@@ -0,0 +1,50 @@
+-- the debug mode
+if is_mode("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if is_mode("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+target("module")
+
+ -- set kind
+ set_kind("static")
+
+ -- add files
+ add_files("src/test/*.go")
+
+-- add target
+target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add deps
+ add_deps("module")
+
+ -- add files
+ add_files("src/*.go")
+
+ -- add links
+ add_links("module")
+
+ -- add link directory
+ add_linkdirs("$(buildir)")
+
diff --git a/tests/tests b/tests/tests
index d437635b0..b5f16fef7 100755
--- a/tests/tests
+++ b/tests/tests
@@ -48,6 +48,9 @@ build "./tests/console_c++"
build "./tests/static_library_c++"
build "./tests/shared_library_c++"
+# build for go
+build "./tests/console_go"
+
# merge object
build "./tests/merge_object"
diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua
index 8cda73bde..19ee1d9ff 100755
--- a/xmake/languages/asm/xmake.lua
+++ b/xmake/languages/asm/xmake.lua
@@ -99,6 +99,10 @@ language("asm")
, {nil, "asflags", "kv", nil, "The Assembler Flags" }
, {}
+ , {nil, "ld", "kv", nil, "The Linker" }
+ , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
+
+ , {}
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 0678cbe71..0ddb6a60b 100755
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -105,6 +105,10 @@ language("c++")
, {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" }
, {}
+ , {nil, "ld", "kv", nil, "The Linker" }
+ , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
+
+ , {}
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua
index 8ae77c1f4..0705f92e9 100755
--- a/xmake/languages/golang/xmake.lua
+++ b/xmake/languages/golang/xmake.lua
@@ -35,7 +35,7 @@ language("golang")
set_targetkinds {binary = "go", static = "go", shared = "go"}
-- set target flags
- set_targetflags {binary = "goflags", static = "goflags", shared = "goflags"}
+ set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
-- on load
on_load("load")
@@ -84,6 +84,14 @@ language("golang")
config =
{
{}
+ , {nil, "go", "kv", nil, "The Golang Compiler" }
+ , {nil, "goflags", "kv", nil, "The Golang Compiler Flags" }
+
+ , {}
+ , {nil, "ld", "kv", nil, "The Linker" }
+ , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
+
+ , {}
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index 0919a8d7c..e94dd97ab 100755
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -113,6 +113,10 @@ language("objc++")
, {nil, "mxxflags", "kv", nil, "The Objc++ Compiler Flags" }
, {}
+ , {nil, "ld", "kv", nil, "The Linker" }
+ , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
+
+ , {}
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua
index 3c9c681d0..802b53860 100644
--- a/xmake/tools/ar.lua
+++ b/xmake/tools/ar.lua
@@ -60,11 +60,6 @@ function strip(level)
return maps[level] or ""
end
--- make the symbol flag
-function symbol(level)
- return ""
-end
-
-- make the archive command
function archivecmd(objectfiles, targetfile, flags)
diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua
index cb14e931b..c81a0c206 100755
--- a/xmake/tools/go.lua
+++ b/xmake/tools/go.lua
@@ -37,6 +37,8 @@ function init(shellname, kind)
-- save the kind
_g.kind = kind
+ -- init arflags
+ _g.arflags = { "grcP" }
end
-- get the property
@@ -46,59 +48,18 @@ function get(name)
return _g[name]
end
--- make the strip flag
-function nf_strip(level)
- return ""
-end
-
--- make the symbol flag
-function nf_symbol(level)
- return ""
-end
-
--- make the warning flag
-function nf_warning(level)
- return ""
-end
-
--- make the optimize flag
-function nf_optimize(level)
- return ""
-end
-
--- make the vector extension flag
-function nf_vectorext(extension)
- return ""
-end
-
--- make the language flag
-function nf_language(stdname)
- return ""
-end
-
--- make the define flag
-function nf_define(macro)
- return ""
-end
-
--- make the undefine flag
-function nf_undefine(macro)
- return ""
-end
-
-- make the includedir flag
function nf_includedir(dir)
- return ""
-end
--- make the link flag
-function nf_link(lib)
- return ""
+ -- make it
+ return "-I " .. dir
end
-- make the linkdir flag
function nf_linkdir(dir)
- return ""
+
+ -- make it
+ return "-L " .. dir
end
-- make the link command
@@ -115,6 +76,23 @@ function compcmd(sourcefile, objectfile, flags)
return format("%s tool compile %s -o %s %s", _g.shellname, flags, objectfile, sourcefile)
end
+-- make the archive command
+function archivecmd(objectfiles, targetfile, flags)
+
+ -- make it
+ return format("%s tool pack %s %s %s", _g.shellname, flags, targetfile, objectfiles)
+end
+
+-- archive the library file
+function archive(objectfiles, targetfile, flags)
+
+ -- ensure the target directory
+ os.mkdir(path.directory(targetfile))
+
+ -- link it
+ os.run(archivecmd(objectfiles, targetfile, flags))
+end
+
-- link the target file
function link(objectfiles, targetfile, flags)
@@ -135,6 +113,16 @@ function compile(sourcefile, objectfile, incdepfile, flags)
os.run(compcmd(sourcefile, objectfile, flags))
end
+-- archive the library file
+function archive(objectfiles, targetfile, flags)
+
+ -- ensure the target directory
+ os.mkdir(path.directory(targetfile))
+
+ -- link it
+ os.run(archivecmd(objectfiles, targetfile, flags))
+end
+
-- check the given flags
function check(flags)
diff --git a/xmake/tools/link.lua b/xmake/tools/link.lua
index c7e9096bf..ecd00190e 100755
--- a/xmake/tools/link.lua
+++ b/xmake/tools/link.lua
@@ -71,11 +71,6 @@ function get(name)
return _g[name]
end
--- make the strip flag
-function nf_strip(level)
- return ""
-end
-
-- make the symbol flag
function nf_symbol(level, target)
diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua
index f32b5b361..372a84ac4 100755
--- a/xmake/tools/ml.lua
+++ b/xmake/tools/ml.lua
@@ -64,11 +64,6 @@ function get(name)
return _g[name]
end
--- make the symbol flag
-function nf_symbol(level)
- return ""
-end
-
-- make the warning flag
function nf_warning(level)
@@ -86,21 +81,6 @@ function nf_warning(level)
return maps[level] or ""
end
--- make the optimize flag
-function nf_optimize(level)
- return ""
-end
-
--- make the vector extension flag
-function nf_vectorext(extension)
- return ""
-end
-
--- make the language flag
-function nf_language(stdname)
- return ""
-end
-
-- make the define flag
function nf_define(macro)
diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua
index 5b4823416..266c64cf4 100644
--- a/xmake/tools/swiftc.lua
+++ b/xmake/tools/swiftc.lua
@@ -144,11 +144,6 @@ function nf_vectorext(extension)
return maps[extension] or ""
end
--- make the language flag
-function nf_language(stdname)
- return ""
-end
-
-- make the includedir flag
function nf_includedir(dir)