summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-04-28 21:36:34 +0800
committerruki <[email protected]>2018-04-28 21:36:34 +0800
commitd94f0728facb33a2cddebb19b8a9c953f6cdde06 (patch)
treeb265f55d1c9ed98342c80ab750aeb4e07e8a05fe
parent4277a46cfdc23dc8d840400048eda256d8e5d1e9 (diff)
impl load umdf rule
-rw-r--r--tests/projects/wdk/umdf/echo/xmake.lua14
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_path.lua2
-rw-r--r--xmake/rules/wdk/load.lua91
-rw-r--r--xmake/rules/wdk/xmake.lua40
4 files changed, 123 insertions, 24 deletions
diff --git a/tests/projects/wdk/umdf/echo/xmake.lua b/tests/projects/wdk/umdf/echo/xmake.lua
index 3dd38ee62..e946a868f 100644
--- a/tests/projects/wdk/umdf/echo/xmake.lua
+++ b/tests/projects/wdk/umdf/echo/xmake.lua
@@ -2,23 +2,27 @@
-- add modes: debug and release
add_rules("mode.debug", "mode.release")
+-- enable unicode
+add_defines("_UNICODE", "UNICODE")
+
-- add target
target("echo")
+ set_default(false)
-- add rules
- add_rules("wdk.driver.umdf")
+ add_rules("wdk.umdf.driver")
-- add files
add_files("driver/*.c")
+ -- add includedirs
+ add_includedirs("exe")
+
-- add target
target("app")
- -- add deps
- add_deps("echo")
-
-- add rules
- add_rules("wdk.binary")
+ add_rules("wdk.umdf.binary")
-- add files
add_files("exe/*.cpp")
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
index 10f844752..0532a1bf8 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
@@ -37,7 +37,7 @@ function sandbox_lib_detect_find_path._find(filedir, name)
-- path exists?
for _, p in ipairs(os.filedirs(path.join(filedir, name))) do
- return filedir
+ return path.directory(p)
end
end
diff --git a/xmake/rules/wdk/load.lua b/xmake/rules/wdk/load.lua
new file mode 100644
index 000000000..cce968f3e
--- /dev/null
+++ b/xmake/rules/wdk/load.lua
@@ -0,0 +1,91 @@
+--!A cross-platform 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file load.lua
+--
+
+-- imports
+import("core.project.config")
+import("lib.detect.find_path")
+
+-- load for umdf
+function _load_for_umdf(target, wdk, arch, kind)
+
+ -- add defines
+ target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL")
+ target:add("defines", "UMDF_VERSION_MINOR=15", "UMDF_VERSION_MAJOR=2", "UMDF_USING_NTSTATUS")
+ if arch == "x64" then
+ target:add("defines", "_WIN64", "_AMD64_", "AMD64")
+ end
+
+ -- add include directories
+ target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um"))
+ local includedir = find_path("wdf.h", path.join(wdk.includedir, "wdf", "umdf", "**"))
+ if includedir then
+ target:add("includedirs", includedir)
+ end
+
+ -- add link directories
+ target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch))
+ for _, dir in ipairs(os.dirs(path.join(wdk.libdir, "wdf", "umdf", arch, "*"))) do
+ target:add("linkdirs", dir)
+ break
+ end
+
+ -- add links
+ if kind == "shared" then
+ target:add("links", "WdfDriverStubUm")
+ end
+ target:add("links", "ntdll", "OneCoreUAP", "mincore", "ucrt")
+ target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib")
+end
+
+-- load for kmdf
+function _load_for_kmdf(target, opt)
+end
+
+-- the main entry
+function main(target, opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- get wdk
+ local wdk = target:data("wdk")
+
+ -- get arch
+ local arch = config.arch()
+
+ -- set kind
+ if opt.kind then
+ target:set("kind", opt.kind)
+ end
+
+ -- load for umdf
+ if opt.mode == "umdf" then
+ _load_for_umdf(target, wdk, arch, kind)
+ end
+
+ -- load for kmdf
+ if opt.mode == "kmdf" then
+ _load_for_kmdf(target, wdk, arch, kind)
+ end
+end
diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua
index c3cf6af73..21aaae2cb 100644
--- a/xmake/rules/wdk/xmake.lua
+++ b/xmake/rules/wdk/xmake.lua
@@ -42,41 +42,45 @@ rule("wdk.env")
end)
-- define rule: umdf driver
-rule("wdk.driver.umdf")
+rule("wdk.umdf.driver")
-- add rules
add_deps("wdk.env")
-- on load
on_load(function (target)
+ import("load")(target, {kind = "shared", mode = "umdf"})
+ end)
- -- imports
- import("core.project.config")
-
- -- get wdk
- local wdk = target:data("wdk")
+-- define rule: umdf binary
+rule("wdk.umdf.binary")
- -- set kind: shared library
- target:set("kind", "shared")
+ -- add rules
+ add_deps("wdk.env")
- -- add link directories
- target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", config.arch()))
- target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", config.arch(), "2.0"))
-
- -- add include directories
- target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um"))
- target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", "2.0"))
+ -- on load
+ on_load(function (target)
+ import("load")(target, {kind = "binary", mode = "umdf"})
end)
-- define rule: kmdf driver
-rule("wdk.driver.kmdf")
+rule("wdk.kmdf.driver")
-- add rules
add_deps("wdk.env")
--- define rule: binary
-rule("wdk.binary")
+ -- on load
+ on_load(function (target)
+ import("load")(target, {kind = "shared", mode = "kmdf"})
+ end)
+
+-- define rule: kmdf binary
+rule("wdk.kmdf.binary")
-- add rules
add_deps("wdk.env")
+ -- on load
+ on_load(function (target)
+ import("load")(target, {kind = "binary", mode = "kmdf"})
+ end)