summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-01 21:38:02 +0800
committerruki <[email protected]>2017-06-01 21:38:02 +0800
commita04665a2adccd7c46faf2aa9aae2f33cba8fac39 (patch)
treee406d3684818c2798c22e689fc3eb739b3a1c427
parent6ac56a31d36fb151e50f7158da12d56f32a2e2aa (diff)
compile the microsoft resource file
-rw-r--r--xmake/core/language/language.lua2
-rw-r--r--xmake/languages/c++/xmake.lua2
-rw-r--r--xmake/languages/msrc/api.lua48
-rw-r--r--xmake/languages/msrc/load.lua38
-rw-r--r--xmake/languages/msrc/xmake.lua71
-rw-r--r--xmake/platforms/windows/check.lua1
-rw-r--r--xmake/tools/rc.lua149
7 files changed, 309 insertions, 2 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index 278d59a3e..c860b1a2a 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -585,7 +585,7 @@ function language.linkerinfos_of(targetkind, sourcekinds)
for name, instance in pairs(languages) do
for _, mixingkind in ipairs(table.wrap(instance:mixingkinds())) do
local targetflags = instance:targetflags()
- for _targetkind, linkerkind in pairs(instance:targetkinds()) do
+ for _targetkind, linkerkind in pairs(table.wrap(instance:targetkinds())) do
-- init linker info
linkerinfos[_targetkind] = linkerinfos[_targetkind] or {}
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index ca18654cd..e061f06e9 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -38,7 +38,7 @@ language("c++")
set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
-- set mixing kinds
- set_mixingkinds("cc", "cxx", "as")
+ set_mixingkinds("cc", "cxx", "as", "mrc")
-- on load
on_load("load")
diff --git a/xmake/languages/msrc/api.lua b/xmake/languages/msrc/api.lua
new file mode 100644
index 000000000..23934db76
--- /dev/null
+++ b/xmake/languages/msrc/api.lua
@@ -0,0 +1,48 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file api.lua
+--
+
+-- get apis
+function apis()
+
+ -- init apis
+ _g.values =
+ {
+ -- target.add_xxx
+ "target.add_mrcflags"
+ -- option.add_xxx
+ , "option.add_mrcflags"
+ }
+ _g.pathes =
+ {
+ -- target.add_xxx
+ "target.add_includedirs"
+ -- option.add_xxx
+ , "option.add_includedirs"
+ }
+
+ -- ok
+ return _g
+end
+
+
diff --git a/xmake/languages/msrc/load.lua b/xmake/languages/msrc/load.lua
new file mode 100644
index 000000000..4eb290d07
--- /dev/null
+++ b/xmake/languages/msrc/load.lua
@@ -0,0 +1,38 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file load.lua
+--
+
+-- imports
+import("api")
+
+-- load it
+function main()
+
+ -- init apis
+ _g.apis = api.apis()
+
+ -- ok
+ return _g
+end
+
+
diff --git a/xmake/languages/msrc/xmake.lua b/xmake/languages/msrc/xmake.lua
new file mode 100644
index 000000000..9bcfcc488
--- /dev/null
+++ b/xmake/languages/msrc/xmake.lua
@@ -0,0 +1,71 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define language
+language("msrc")
+
+ -- set source file kinds
+ set_sourcekinds {mrc = ".rc"}
+
+ -- set source file flags
+ set_sourceflags {mrc = "mrcflags"}
+
+ -- set mixing kinds
+ set_mixingkinds("mrc")
+
+ -- on load
+ on_load("load")
+
+ -- set name flags
+ set_nameflags
+ {
+ object =
+ {
+ "config.includedirs"
+ , "target.defines"
+ , "target.undefines"
+ , "target.includedirs"
+ , "option.defines"
+ , "option.undefines"
+ , "option.defines_if_ok"
+ , "option.undefines_if_ok"
+ , "platform.includedirs"
+ , "platform.defines"
+ , "platform.undefines"
+ }
+ }
+
+ -- set menu
+ set_menu {
+ config =
+ {
+ { }
+ , {nil, "mrc", "kv", nil, "The Microsoft Resource Compiler" }
+ , {nil, "mrcflags", "kv", nil, "The Microsoft Resource Flags" }
+
+ , { }
+ , {nil, "includedirs","kv", nil, "The Include Search Directories" }
+ }
+ }
+
diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua
index f74fbb42e..8218ffd3a 100644
--- a/xmake/platforms/windows/check.lua
+++ b/xmake/platforms/windows/check.lua
@@ -121,6 +121,7 @@ function _toolchains(config)
-- insert c/c++ tools to toolchains
checker.toolchain_insert(toolchains, "cc", "", "cl.exe", "the c compiler")
checker.toolchain_insert(toolchains, "cxx", "", "cl.exe", "the c++ compiler")
+ checker.toolchain_insert(toolchains, "mrc", "", "rc.exe", "the resource compiler")
checker.toolchain_insert(toolchains, "ld", "", "link.exe", "the linker")
checker.toolchain_insert(toolchains, "ar", "", "link.exe -lib", "the static library archiver")
checker.toolchain_insert(toolchains, "sh", "", "link.exe -dll", "the shared library linker")
diff --git a/xmake/tools/rc.lua b/xmake/tools/rc.lua
new file mode 100644
index 000000000..eb2d5fa05
--- /dev/null
+++ b/xmake/tools/rc.lua
@@ -0,0 +1,149 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file rc.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.project")
+
+-- init it
+function init(shellname, kind)
+
+ -- save the shell name
+ _g.shellname = shellname or "rc.exe"
+
+ -- save kind
+ _g.kind = kind
+
+ -- init features
+ _g.features =
+ {
+ ["object:sources"] = false
+ }
+end
+
+-- get the property
+function get(name)
+
+ -- get it
+ return _g[name]
+end
+
+-- make the define flag
+function nf_define(macro)
+
+ -- make it
+ return "-d" .. macro:gsub("\"", "\\\"")
+end
+
+-- make the undefine flag
+function nf_undefine(macro)
+
+ -- make it
+ return "-u" .. macro
+end
+
+-- make the includedir flag
+function nf_includedir(dir)
+
+ -- make it
+ return "-I" .. dir
+end
+
+-- make the complie command
+function _compcmd1(sourcefile, objectfile, flags)
+
+ -- make it
+ return format("%s %s -Fo%s %s", _g.shellname, flags, objectfile, sourcefile)
+end
+
+-- complie the source file
+function _compile1(sourcefile, objectfile, incdepfile, flags)
+
+ -- ensure the object directory
+ os.mkdir(path.directory(objectfile))
+
+ -- compile it
+ try
+ {
+ function ()
+ local outdata, errdata = os.iorun(_compcmd1(sourcefile, objectfile, flags))
+ return (outdata or "") .. (errdata or "")
+ end,
+ catch
+ {
+ function (errors)
+
+ -- compiling errors
+ os.raise(errors)
+ end
+ },
+ finally
+ {
+ function (ok, warnings)
+
+ -- print some warnings
+ if warnings and #warnings > 0 and option.get("verbose") then
+ cprint("${yellow}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
+ end
+ end
+ }
+ }
+end
+
+-- make the complie command
+function compcmd(sourcefiles, objectfile, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) ~= "table", "'object:sources' not support!")
+
+ -- for only single source file
+ return _compcmd1(sourcefiles, objectfile, flags)
+end
+
+-- complie the source file
+function compile(sourcefiles, objectfile, incdepfile, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) ~= "table", "'object:sources' not support!")
+
+ -- for only single source file
+ _compile1(sourcefiles, objectfile, incdepfile, flags)
+end
+
+-- check the given flags
+function check(flags)
+
+ -- make an stub source file
+ local objectfile = os.tmpfile() .. ".res"
+ local sourcefile = os.tmpfile() .. ".rc"
+ io.writefile(sourcefile, "#define RESID 1")
+
+ -- check it
+ os.run("%s -fo%s %s", _g.shellname, objectfile, sourcefile)
+
+ -- remove files
+ os.rm(objectfile)
+ os.rm(sourcefile)
+end
+