summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-21 17:05:03 +0800
committerruki <[email protected]>2017-02-21 17:05:03 +0800
commit1d192697c6464f2b9509050f01f89ed18f651046 (patch)
treeb742e1834cc65fa9f01564ea65ffaca9cc49a61a
parent60bce69c3f3be74e0de627d337b9b39e24aa45b8 (diff)
add static library test for dlang
-rw-r--r--tests/static_library_dlang/src/interfaces.d9
-rw-r--r--tests/static_library_dlang/src/main.d8
-rwxr-xr-xtests/static_library_dlang/xmake.lua53
-rw-r--r--xmake/platforms/macosx/check.lua2
-rwxr-xr-xxmake/tools/dmd.lua30
5 files changed, 91 insertions, 11 deletions
diff --git a/tests/static_library_dlang/src/interfaces.d b/tests/static_library_dlang/src/interfaces.d
new file mode 100644
index 000000000..3386c9124
--- /dev/null
+++ b/tests/static_library_dlang/src/interfaces.d
@@ -0,0 +1,9 @@
+extern(C) int add(int a, int b)
+{
+ return a + b;
+}
+
+extern(C) int sub(int a, int b)
+{
+ return a - b;
+}
diff --git a/tests/static_library_dlang/src/main.d b/tests/static_library_dlang/src/main.d
new file mode 100644
index 000000000..3137de217
--- /dev/null
+++ b/tests/static_library_dlang/src/main.d
@@ -0,0 +1,8 @@
+import std.stdio;
+import interfaces;
+
+void main()
+{
+ printf("add: %d\n", interfaces.add(1, 1));
+ printf("sub: %d\n", interfaces.sub(2, 1));
+}
diff --git a/tests/static_library_dlang/xmake.lua b/tests/static_library_dlang/xmake.lua
new file mode 100755
index 000000000..1fd0d1ee9
--- /dev/null
+++ b/tests/static_library_dlang/xmake.lua
@@ -0,0 +1,53 @@
+-- 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("interfaces")
+
+ -- set kind
+ set_kind("static")
+
+ -- add files
+ add_files("src/interfaces.d")
+
+-- add target
+target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add deps
+ add_deps("interfaces")
+
+ -- add files
+ add_files("src/main.d")
+
+ -- add links
+ add_links("interfaces")
+
+ -- add link directory
+ add_linkdirs("$(buildir)")
+
+ -- add include directory
+ add_includedirs("$(projectdir)/src")
+
diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua
index eec29c9c3..888bde335 100644
--- a/xmake/platforms/macosx/check.lua
+++ b/xmake/platforms/macosx/check.lua
@@ -93,7 +93,7 @@ function _check_toolchains(config)
checker.check_toolchain(config, "dd-sh", "", "dmd", "the dlang shared library linker")
checker.check_toolchain(config, "dd-sh", "", "ldc2", "the dlang shared library linker")
checker.check_toolchain(config, "dd-sh", "", "gdc", "the dlang shared library linker")
- checker.check_toolchain(config, "dd-id", "", "dmd", "the dlang linker")
+ checker.check_toolchain(config, "dd-ld", "", "dmd", "the dlang linker")
checker.check_toolchain(config, "dd-ld", "", "ldc2", "the dlang linker")
checker.check_toolchain(config, "dd-ld", "", "gdc", "the dlang linker")
diff --git a/xmake/tools/dmd.lua b/xmake/tools/dmd.lua
index f0f3a2373..8329e1a3c 100755
--- a/xmake/tools/dmd.lua
+++ b/xmake/tools/dmd.lua
@@ -37,6 +37,16 @@ function init(shellname, kind)
-- save the kind
_g.kind = kind
+ -- init arflags
+ _g["dd-arflags"] = { "-lib" }
+
+ -- init shflags
+ _g["dd-shflags"] = { "-shared", "-fPIC" }
+
+ -- init dflags for the kind: shared
+ _g.shared = {}
+ _g.shared.dflags = {"-fPIC"}
+
-- init features
_g.features =
{
@@ -55,28 +65,28 @@ end
function nf_includedir(dir)
-- make it
- return ""
+ return "-I" .. dir
+end
+
+-- make the link flag
+function nf_link(lib)
+
+ -- make it
+ return "-L-l" .. lib
end
-- make the linkdir flag
function nf_linkdir(dir)
-- make it
- return ""
+ return "-L-L" .. dir
end
-- make the link command
function linkcmd(objectfiles, targetkind, targetfile, flags)
- -- kinds
- local kinds =
- {
- static = " -lib"
- , shared = " -shared"
- }
-
-- make it
- return format("%s%s %s -of%s %s", _g.shellname, kinds[targetkind] or "", flags, targetfile, objectfiles)
+ return format("%s %s -of%s %s", _g.shellname, flags, targetfile, objectfiles)
end
-- link the target file