diff options
| author | ruki <[email protected]> | 2018-05-11 00:44:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-10 22:25:32 +0800 |
| commit | e43926b47af1b535d066dabe0bde86317cf85648 (patch) | |
| tree | 7969df770ae8dae92e7686cd6d77b41d2591f89a | |
| parent | 6cf4df42c737fc71012c68a0943edc0bf30c3649 (diff) | |
seperate qt and wdk rules
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.c | 407 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.h | 34 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.man | 101 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.rc | 1 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/xmake.lua | 13 | ||||
| -rw-r--r-- | xmake/rules/qt/env/load.lua (renamed from xmake/rules/qt/load.lua) | 0 | ||||
| -rw-r--r-- | xmake/rules/qt/env/xmake.lua | 348 | ||||
| -rw-r--r-- | xmake/rules/qt/moc/moc.lua (renamed from xmake/rules/qt/moc.lua) | 0 | ||||
| -rw-r--r-- | xmake/rules/qt/moc/xmake.lua | 107 | ||||
| -rw-r--r-- | xmake/rules/qt/qrc/xmake.lua | 115 | ||||
| -rw-r--r-- | xmake/rules/qt/ui/xmake.lua | 92 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 269 | ||||
| -rw-r--r-- | xmake/rules/wdk/env/load.lua (renamed from xmake/rules/wdk/load.lua) | 0 | ||||
| -rw-r--r-- | xmake/rules/wdk/env/xmake.lua | 43 | ||||
| -rw-r--r-- | xmake/rules/wdk/inf/xmake.lua | 89 | ||||
| -rw-r--r-- | xmake/rules/wdk/man/xmake.lua | 66 | ||||
| -rw-r--r-- | xmake/rules/wdk/tracewpp/xmake.lua | 124 | ||||
| -rw-r--r-- | xmake/rules/wdk/xmake.lua | 192 |
18 files changed, 1544 insertions, 457 deletions
diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.c b/tests/projects/wdk/kmdf/perfcounters/kcs.c new file mode 100644 index 000000000..9996addcb --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.c @@ -0,0 +1,407 @@ +/*++
+
+Copyright (c) Microsoft Corporation. All rights reserved.
+
+ THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
+ PURPOSE.
+
+Module Name:
+
+ kcs.c
+
+Abstract:
+
+ This module contains sample code to demonstrate how to provide
+ counter data from a kernel driver.
+
+Environment:
+
+ Kernel mode only.
+
+--*/
+
+
+#include <wdm.h>
+#include "kcs.h"
+#include "kcsCounters.h"
+
+#pragma code_seg("PAGE")
+
+DRIVER_INITIALIZE DriverEntry;
+DRIVER_UNLOAD KcsUnload;
+
+NTSTATUS
+KcsAddGeometricInstance (
+ _In_ PPCW_BUFFER Buffer,
+ _In_ PCWSTR Name,
+ _In_ ULONG MinimalValue,
+ _In_ ULONG Amplitude
+ )
+
+/*++
+
+Routine Description:
+
+ This utility function adds instance to the callback buffer.
+
+Arguments:
+
+ Buffer - Data will be returned in this buffer.
+
+ Name - Name of instances to be added.
+
+ MinimalValue - Minimum value of the wave.
+
+ Amplitude - Amplitude of the wave.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ ULONG Index;
+ LARGE_INTEGER Timestamp;
+ UNICODE_STRING UnicodeName;
+ GEOMETRIC_WAVE_VALUES Values;
+
+ PAGED_CODE();
+
+ KeQuerySystemTime(&Timestamp);
+
+ Index = (Timestamp.QuadPart / 10000000) % 10;
+
+ Values.Triangle = MinimalValue + Amplitude * abs(5 - Index) / 5;
+ Values.Square = MinimalValue + Amplitude * (Index < 5);
+
+ RtlInitUnicodeString(&UnicodeName, Name);
+
+ return KcsAddGeometricWave(Buffer, &UnicodeName, 0, &Values);
+}
+
+NTSTATUS NTAPI
+KcsGeometricWaveCallback (
+ _In_ PCW_CALLBACK_TYPE Type,
+ _In_ PPCW_CALLBACK_INFORMATION Info,
+ _In_opt_ PVOID Context
+ )
+
+/*++
+
+Routine Description:
+
+ This function returns the list of counter instances and counter data.
+
+Arguments:
+
+ Type - Request type.
+
+ Info - Buffer for returned data.
+
+ Context - Not used.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ NTSTATUS Status;
+ UNICODE_STRING UnicodeName;
+
+ UNREFERENCED_PARAMETER(Context);
+
+ PAGED_CODE();
+
+ switch (Type) {
+ case PcwCallbackEnumerateInstances:
+
+ //
+ // Instances are being enumerated, so we add them without values.
+ //
+
+ RtlInitUnicodeString(&UnicodeName, L"Small Wave");
+ Status = KcsAddGeometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ RtlInitUnicodeString(&UnicodeName, L"Medium Wave");
+ Status = KcsAddGeometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ RtlInitUnicodeString(&UnicodeName, L"Large Wave");
+ Status = KcsAddGeometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ break;
+
+ case PcwCallbackCollectData:
+
+ //
+ // Add values for 3 instances of Geometric Wave Counter Set.
+ //
+
+ Status = KcsAddGeometricInstance(Info->CollectData.Buffer,
+ L"Small Wave",
+ 40,
+ 20);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ Status = KcsAddGeometricInstance(Info->CollectData.Buffer,
+ L"Medium Wave",
+ 30,
+ 40);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ Status = KcsAddGeometricInstance(Info->CollectData.Buffer,
+ L"Large Wave",
+ 20,
+ 60);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ break;
+ }
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+KcsAddTrignometricInstance (
+ _In_ PPCW_BUFFER Buffer,
+ _In_ PCWSTR Name,
+ _In_ ULONG MinimalValue,
+ _In_ ULONG Amplitude
+ )
+
+/*++
+
+Routine Description:
+
+ This utility function adds instance to the callback buffer.
+
+Arguments:
+
+ Buffer - Data will be returned in this buffer.
+
+ Name - Name of instances to be added.
+
+ MinimalValue - Minimum value of the wave.
+
+ Amplitude - Amplitude of the wave.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ double Angle;
+ KFLOATING_SAVE FloatSave;
+ NTSTATUS Status;
+ LARGE_INTEGER Timestamp;
+ UNICODE_STRING UnicodeName;
+ TRIGNOMETRIC_WAVE_VALUES Values;
+
+ PAGED_CODE();
+
+ Status = KeSaveFloatingPointState(&FloatSave);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ KeQuerySystemTime(&Timestamp);
+
+ Angle = (double)(Timestamp.QuadPart / 400000) * (22/7) / 180;
+
+ Values.Constant = MinimalValue;
+ Values.Cosine = (ULONG)(MinimalValue + Amplitude * cos(Angle));
+ Values.Sine = (ULONG)(MinimalValue + Amplitude * sin(Angle));
+
+ KeRestoreFloatingPointState(&FloatSave);
+
+ //
+ // Add instance name & values to the caller's buffer.
+ //
+
+ RtlInitUnicodeString(&UnicodeName, Name);
+
+ return KcsAddTrignometricWave(Buffer, &UnicodeName, 0, &Values);
+}
+
+NTSTATUS NTAPI
+KcsTrignometricWaveCallback (
+ _In_ PCW_CALLBACK_TYPE Type,
+ _In_ PPCW_CALLBACK_INFORMATION Info,
+ _In_opt_ PVOID Context
+ )
+
+/*++
+
+Routine Description:
+
+ This function returns the list of counter instances and counter data.
+
+Arguments:
+
+ Type - Request type.
+
+ Info - Buffer for returned data.
+
+ Context - Not used.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ NTSTATUS Status;
+ UNICODE_STRING UnicodeName;
+
+ UNREFERENCED_PARAMETER(Context);
+
+ PAGED_CODE();
+
+ switch (Type) {
+ case PcwCallbackEnumerateInstances:
+ RtlInitUnicodeString(&UnicodeName, L"default");
+ Status = KcsAddTrignometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ break;
+
+ case PcwCallbackCollectData:
+
+ //
+ // Add values for Single Instance of Trignometirc Wave Counter Set.
+ //
+
+ return KcsAddTrignometricInstance(Info->CollectData.Buffer,
+ L"default",
+ 50,
+ 30);
+ }
+
+ return STATUS_SUCCESS;
+}
+
+VOID
+KcsUnload (
+ _In_ PDRIVER_OBJECT DriverObject
+ )
+
+/*++
+
+Routine Description:
+
+ This function unregisters countersets
+
+Arguments:
+
+ DriverObject - Not used.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+ UNREFERENCED_PARAMETER(DriverObject);
+
+ PAGED_CODE();
+
+ //
+ // Unregister Countersets.
+ //
+
+ KcsUnregisterGeometricWave();
+ KcsUnregisterTrignometricWave();
+}
+
+NTSTATUS
+DriverEntry (
+ _In_ PDRIVER_OBJECT DriverObject,
+ _In_ PUNICODE_STRING RegistryPath
+ )
+
+/*++
+
+Routine Description:
+
+ This function registers countersets on initial loading of the driver.
+
+Arguments:
+
+ DriverObject - Supplies the driver object of the driver being loaded.
+
+ RegistryPath - Not used.
+
+Return Value:
+
+ NTSTATUS indicating if driver was properly loaded.
+
+--*/
+
+{
+ NTSTATUS Status;
+
+ UNREFERENCED_PARAMETER(RegistryPath);
+
+ PAGED_CODE();
+
+ //
+ // Register Countersets.
+ //
+
+ Status = KcsRegisterGeometricWave(KcsGeometricWaveCallback, NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ Status = KcsRegisterTrignometricWave(KcsTrignometricWaveCallback, NULL);
+ if (!NT_SUCCESS(Status)) {
+ KcsUnregisterTrignometricWave();
+ return Status;
+ }
+
+ //
+ // Success path - set up unload routine and return success.
+ //
+
+ DriverObject->DriverUnload = KcsUnload;
+
+ return STATUS_SUCCESS;
+}
+
diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.h b/tests/projects/wdk/kmdf/perfcounters/kcs.h new file mode 100644 index 000000000..f575b816d --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.h @@ -0,0 +1,34 @@ +/*++
+
+Copyright (c) Microsoft Corporation. All rights reserved.
+
+ THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
+ PURPOSE.
+
+Module Name:
+
+ kcs.h
+
+Abstract:
+
+ This module contains sample code to demonstrate how to provide
+ counter data from a kernel driver.
+
+Environment:
+
+ Kernel mode only.
+
+--*/
+
+typedef struct _GEOMETRIC_WAVE_VALUES {
+ ULONG Square;
+ ULONG Triangle;
+} GEOMETRIC_WAVE_VALUES, *PGEOMETRIC_WAVE_VALUES;
+
+typedef struct _TRIGNOMETRIC_WAVE_VALUES {
+ ULONG Constant;
+ ULONG Cosine;
+ ULONG Sine;
+} TRIGNOMETRIC_WAVE_VALUES, *PTRIGNOMETRIC_WAVE_VALUES;
\ No newline at end of file diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.man b/tests/projects/wdk/kmdf/perfcounters/kcs.man new file mode 100644 index 000000000..a5a16ffbd --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.man @@ -0,0 +1,101 @@ +<instrumentationManifest + xmlns="http://schemas.microsoft.com/win/2004/08/events" + xmlns:trace="http://schemas.microsoft.com/win/2004/08/events/trace" + xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" + > + <instrumentation> + <counters + xmlns="http://schemas.microsoft.com/win/2005/12/counters" + xmlns:auto-ns1="http://schemas.microsoft.com/win/2004/08/events" + schemaVersion="1.1" + > + <provider callback = "custom" + applicationIdentity = "Kcs.sys" + providerType = "kernelMode" + providerName = "KernelCountersSample" + providerGuid = "{d2ffffff-965a-4cf9-9c07-fe25378c2a23}"> + <counterSet guid = "{d2ffffff-c923-4794-b696-70577630b5cf}" + uri = "Microsoft.Wdk.Samples.Kcs.GeometricWave" + name = "Geometric Waves" + description = "This counter set displays a Triangle and a Square wave" + symbol = "GeometricWave" + instances = "multipleAggregate" + > + <structs> + <struct name="GeometricWaveValues" type="GEOMETRIC_WAVE_VALUES"/> + </structs> + <counter id = "1" + uri = "Microsoft.Wdk.Samples.Kcs.GeometricWave.Triangle" + name = "Triangle" + struct = "GeometricWaveValues" + field = "Triangle" + description = "This counter displays triangle wave" + aggregate = "avg" + type = "perf_counter_rawcount" + detailLevel = "standard"> + </counter> + + <counter id = "2" + uri = "Microsoft.Wdk.Samples.Kcs.GeometricWave.Square" + name = "Square Wave" + struct = "GeometricWaveValues" + field = "Square" + description = "This counter displays Square Wave" + aggregate = "avg" + type = "perf_counter_rawcount" + detailLevel = "standard"> + </counter> + </counterSet> + <counterSet guid = "{ffffffff-eaa6-45ba-bf6d-4c7cb0d6ef73}" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave" + name = "Trignometric Waves" + description = "This counter set displays a sine, cosine and a constant wave" + symbol = "TrignometricWave" + instances = "single"> + <structs> + <struct name="TrignometricWaveValues" type="TRIGNOMETRIC_WAVE_VALUES"/> + </structs> + <counter id = "1" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave.Sine" + name = "Sine Wave" + description = "This counter displays Sine Wave" + struct = "TrignometricWaveValues" + field = "Sine" + type = "perf_counter_rawcount" + detailLevel = "standard"> + <counterAttributes> + <counterAttribute name = "reference" /> + </counterAttributes> + </counter> + <counter id = "2" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave.Cosine" + name = "Cosine Wave" + description = "This counter displays Cosine Wave" + struct = "TrignometricWaveValues" + field = "Cosine" + type = "perf_counter_rawcount" + detailLevel = "standard"> + <counterAttributes> + <counterAttribute name = "reference" /> + </counterAttributes> + </counter> + <counter id = "3" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave.Constant" + name = "Constant Value" + description = "This counter displays Constant Value" + struct = "TrignometricWaveValues" + field = "Constant" + type = "perf_counter_rawcount" + detailLevel = "standard"> + <counterAttributes> + <counterAttribute name = "reference" /> + </counterAttributes> + </counter> + </counterSet> + </provider> + </counters> + </instrumentation> +</instrumentationManifest>
\ No newline at end of file diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.rc b/tests/projects/wdk/kmdf/perfcounters/kcs.rc new file mode 100644 index 000000000..7ebb6b97b --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.rc @@ -0,0 +1 @@ +#include "kcsCounters.rc"
diff --git a/tests/projects/wdk/kmdf/perfcounters/xmake.lua b/tests/projects/wdk/kmdf/perfcounters/xmake.lua new file mode 100644 index 000000000..3e6e0bb63 --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/xmake.lua @@ -0,0 +1,13 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +-- add target +target("kcs") + + -- add rules + add_rules("wdk.kmdf.driver") + + -- add files + add_files("*.c", "*.rc", "*.man") + diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/env/load.lua index f1373b711..f1373b711 100644 --- a/xmake/rules/qt/load.lua +++ b/xmake/rules/qt/env/load.lua diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua new file mode 100644 index 000000000..5f5b43520 --- /dev/null +++ b/xmake/rules/qt/env/xmake.lua @@ -0,0 +1,348 @@ +--!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 xmake.lua +-- + +-- define rule: environment +rule("qt.env") + + -- on load + on_load(function (target) + import("detect.sdks.find_qt") + if not target:data("qt") then + target:data_set("qt", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!")) + end + end) + + -- before run + before_run(function (target) + local qt = target:data("qt") + if qt and (is_plat("windows") or (is_plat("mingw") and is_host("windows"))) then + os.addenv("PATH", qt.bindir) + end + end) + + -- clean files + after_clean(function (target) + for _, file in ipairs(target:data("qt.cleanfiles")) do + os.rm(file) + end + target:data_set("qt.cleanfiles", nil) + end) + +-- define rule: *.ui +rule("qt.ui") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".ui") + + -- on load + on_load(function (target) + + -- get uic + local uic = path.join(target:data("qt").bindir, is_host("windows") and "uic.exe" or "uic") + assert(uic and os.isexec(uic), "uic not found!") + + -- save uic + target:data_set("qt.uic", uic) + end) + + -- before build file + before_build_file(function (target, sourcefile_ui, opt) + + -- imports + import("core.base.option") + import("core.project.config") + import("core.project.depend") + + -- get uic + local uic = target:data("qt.uic") + + -- get c++ header file for ui + local headerfile_ui = path.join(config.buildir(), ".qt", "ui", target:name(), "ui_" .. path.basename(sourcefile_ui) .. ".h") + local headerfile_dir = path.directory(headerfile_ui) + + -- add includedirs + target:add("includedirs", path.absolute(headerfile_dir, os.projectdir())) + + -- add clean files + target:data_add("qt.cleanfiles", headerfile_ui) + + -- need build this object? + local dependfile = target:dependfile(headerfile_ui) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(headerfile_ui)}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.ui %s", opt.progress, sourcefile_ui) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.ui %s", opt.progress, sourcefile_ui) + end + + -- ensure ui header file directory + if not os.isdir(headerfile_dir) then + os.mkdir(headerfile_dir) + end + + -- compile ui + os.vrunv(uic, {sourcefile_ui, "-o", headerfile_ui}) + + -- update files and values to the dependent file + dependinfo.files = {sourcefile_ui} + depend.save(dependinfo, dependfile) + end) + +-- define rule: moc +rule("qt.moc") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".h") + + -- on load + on_load(function (target) + + -- get moc + local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") + assert(moc and os.isexec(moc), "moc not found!") + + -- save moc + target:data_set("qt.moc", moc) + end) + + -- on build file + on_build_file(function (target, headerfile_moc, opt) + + -- imports + import("moc") + import("core.base.option") + import("core.project.config") + import("core.tool.compiler") + import("core.project.depend") + + -- get c++ source file for moc + local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp") + + -- get object file + local objectfile = target:objectfile(sourcefile_moc) + + -- load compiler + local compinst = compiler.load("cxx", {target = target}) + + -- get compile flags + local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc}) + + -- add objectfile + table.insert(target:objectfiles(), objectfile) + + -- add clean files + target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile}) + + -- load dependent info + local dependfile = target:dependfile(objectfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + + -- need build this object? + local depvalues = {compinst:program(), compflags} + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.moc %s", opt.progress, headerfile_moc) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.moc %s", opt.progress, headerfile_moc) + end + + -- generate c++ source file for moc + moc.generate(target, headerfile_moc, sourcefile_moc) + + -- trace + if option.get("verbose") then + print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) + end + + -- compile c++ source file for moc + dependinfo.files = {} + compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags}) + + -- update files and values to the dependent file + dependinfo.values = depvalues + table.insert(dependinfo.files, headerfile_moc) + depend.save(dependinfo, dependfile) + end) + +-- define rule: *.qrc +rule("qt.qrc") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".qrc") + + -- on load + on_load(function (target) + + -- get rcc + local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc") + assert(rcc and os.isexec(rcc), "rcc not found!") + + -- save rcc + target:data_set("qt.rcc", rcc) + end) + + -- on build file + on_build_file(function (target, sourcefile_qrc, opt) + + -- imports + import("core.base.option") + import("core.project.config") + import("core.project.depend") + import("core.tool.compiler") + + -- get rcc + local rcc = target:data("qt.rcc") + + -- get c++ source file for qrc + local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp") + local sourcefile_dir = path.directory(sourcefile_cpp) + + -- get object file + local objectfile = target:objectfile(sourcefile_cpp) + + -- load compiler + local compinst = compiler.load("cxx", {target = target}) + + -- get compile flags + local compflags = compinst:compflags({target = target, sourcefile = sourcefile_cpp}) + + -- add objectfile + table.insert(target:objectfiles(), objectfile) + + -- add clean files + target:data_add("qt.cleanfiles", {sourcefile_cpp, objectfile}) + + -- load dependent info + local dependfile = target:dependfile(objectfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + + -- need build this object? + local depvalues = {compinst:program(), compflags} + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) + end + + -- ensure the source file directory + if not os.isdir(sourcefile_dir) then + os.mkdir(sourcefile_dir) + end + + -- compile qrc + os.vrunv(rcc, {"-name", "qml", sourcefile_qrc, "-o", sourcefile_cpp}) + + -- trace + if option.get("verbose") then + print(compinst:compcmd(sourcefile_cpp, objectfile, {compflags = compflags})) + end + + -- compile c++ source file for qrc + dependinfo.files = {} + compinst:compile(sourcefile_cpp, objectfile, {dependinfo = dependinfo, compflags = compflags}) + + -- update files and values to the dependent file + dependinfo.values = depvalues + table.insert(dependinfo.files, sourcefile_qrc) + depend.save(dependinfo, dependfile) + end) + +-- define rule: qt static library +rule("qt.static") + + -- add rules + add_deps("qt.qrc", "qt.ui", "qt.moc") + + -- on load + on_load(function (target) + import("load")(target, {kind = "static", frameworks = {"QtCore"}}) + end) + +-- define rule: qt shared library +rule("qt.shared") + + -- add rules + add_deps("qt.qrc", "qt.ui", "qt.moc") + + -- on load + on_load(function (target) + import("load")(target, {kind = "shared", frameworks = {"QtCore"}}) + end) + +-- define rule: qt console +rule("qt.console") + + -- add rules + add_deps("qt.qrc", "qt.ui", "qt.moc") + + -- on load + on_load(function (target) + import("load")(target, {kind = "binary", frameworks = {"QtCore"}}) + end) + +-- define rule: qt application +rule("qt.application") + + -- add rules + add_deps("qt.qrc", "qt.ui", "qt.moc") + + -- on load + on_load(function (target) + + -- load common flags to target + import("load")(target, {kind = "binary", frameworks = {"QtGui", "QtQml", "QtNetwork", "QtCore"}}) + + -- add -subsystem:windows for windows platform + if is_plat("windows") then + target:add("defines", "_WINDOWS") + target:add("ldflags", "-subsystem:windows", "-entry:mainCRTStartup", {force = true}) + elseif is_plat("mingw") then + target:add("defines", "_WINDOWS") + target:add("ldflags", "-Wl,-subsystem:windows", "-Wl,-entry:mainCRTStartup", {force = true}) + end + end) + diff --git a/xmake/rules/qt/moc.lua b/xmake/rules/qt/moc/moc.lua index 22fb3b311..22fb3b311 100644 --- a/xmake/rules/qt/moc.lua +++ b/xmake/rules/qt/moc/moc.lua diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua new file mode 100644 index 000000000..aad6cab1c --- /dev/null +++ b/xmake/rules/qt/moc/xmake.lua @@ -0,0 +1,107 @@ +--!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 xmake.lua +-- + +-- define rule: moc +rule("qt.moc") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".h") + + -- on load + on_load(function (target) + + -- get moc + local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") + assert(moc and os.isexec(moc), "moc not found!") + + -- save moc + target:data_set("qt.moc", moc) + end) + + -- on build file + on_build_file(function (target, headerfile_moc, opt) + + -- imports + import("moc") + import("core.base.option") + import("core.project.config") + import("core.tool.compiler") + import("core.project.depend") + + -- get c++ source file for moc + local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp") + + -- get object file + local objectfile = target:objectfile(sourcefile_moc) + + -- load compiler + local compinst = compiler.load("cxx", {target = target}) + + -- get compile flags + local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc}) + + -- add objectfile + table.insert(target:objectfiles(), objectfile) + + -- add clean files + target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile}) + + -- load dependent info + local dependfile = target:dependfile(objectfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + + -- need build this object? + local depvalues = {compinst:program(), compflags} + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.moc %s", opt.progress, headerfile_moc) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.moc %s", opt.progress, headerfile_moc) + end + + -- generate c++ source file for moc + moc.generate(target, headerfile_moc, sourcefile_moc) + + -- trace + if option.get("verbose") then + print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) + end + + -- compile c++ source file for moc + dependinfo.files = {} + compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags}) + + -- update files and values to the dependent file + dependinfo.values = depvalues + table.insert(dependinfo.files, headerfile_moc) + depend.save(dependinfo, dependfile) + end) + diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua new file mode 100644 index 000000000..03c17be4e --- /dev/null +++ b/xmake/rules/qt/qrc/xmake.lua @@ -0,0 +1,115 @@ +--!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 xmake.lua +-- + +-- define rule: *.qrc +rule("qt.qrc") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".qrc") + + -- on load + on_load(function (target) + + -- get rcc + local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc") + assert(rcc and os.isexec(rcc), "rcc not found!") + + -- save rcc + target:data_set("qt.rcc", rcc) + end) + + -- on build file + on_build_file(function (target, sourcefile_qrc, opt) + + -- imports + import("core.base.option") + import("core.project.config") + import("core.project.depend") + import("core.tool.compiler") + + -- get rcc + local rcc = target:data("qt.rcc") + + -- get c++ source file for qrc + local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp") + local sourcefile_dir = path.directory(sourcefile_cpp) + + -- get object file + local objectfile = target:objectfile(sourcefile_cpp) + + -- load compiler + local compinst = compiler.load("cxx", {target = target}) + + -- get compile flags + local compflags = compinst:compflags({target = target, sourcefile = sourcefile_cpp}) + + -- add objectfile + table.insert(target:objectfiles(), objectfile) + + -- add clean files + target:data_add("qt.cleanfiles", {sourcefile_cpp, objectfile}) + + -- load dependent info + local dependfile = target:dependfile(objectfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + + -- need build this object? + local depvalues = {compinst:program(), compflags} + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) + end + + -- ensure the source file directory + if not os.isdir(sourcefile_dir) then + os.mkdir(sourcefile_dir) + end + + -- compile qrc + os.vrunv(rcc, {"-name", "qml", sourcefile_qrc, "-o", sourcefile_cpp}) + + -- trace + if option.get("verbose") then + print(compinst:compcmd(sourcefile_cpp, objectfile, {compflags = compflags})) + end + + -- compile c++ source file for qrc + dependinfo.files = {} + compinst:compile(sourcefile_cpp, objectfile, {dependinfo = dependinfo, compflags = compflags}) + + -- update files and values to the dependent file + dependinfo.values = depvalues + table.insert(dependinfo.files, sourcefile_qrc) + depend.save(dependinfo, dependfile) + end) + diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua new file mode 100644 index 000000000..b00ede129 --- /dev/null +++ b/xmake/rules/qt/ui/xmake.lua @@ -0,0 +1,92 @@ +--!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 xmake.lua +-- + +-- define rule: *.ui +rule("qt.ui") + + -- add rule: qt environment + add_deps("qt.env") + + -- set extensions + set_extensions(".ui") + + -- on load + on_load(function (target) + + -- get uic + local uic = path.join(target:data("qt").bindir, is_host("windows") and "uic.exe" or "uic") + assert(uic and os.isexec(uic), "uic not found!") + + -- save uic + target:data_set("qt.uic", uic) + end) + + -- before build file + before_build_file(function (target, sourcefile_ui, opt) + + -- imports + import("core.base.option") + import("core.project.config") + import("core.project.depend") + + -- get uic + local uic = target:data("qt.uic") + + -- get c++ header file for ui + local headerfile_ui = path.join(config.buildir(), ".qt", "ui", target:name(), "ui_" .. path.basename(sourcefile_ui) .. ".h") + local headerfile_dir = path.directory(headerfile_ui) + + -- add includedirs + target:add("includedirs", path.absolute(headerfile_dir, os.projectdir())) + + -- add clean files + target:data_add("qt.cleanfiles", headerfile_ui) + + -- need build this object? + local dependfile = target:dependfile(headerfile_ui) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(headerfile_ui)}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.ui %s", opt.progress, sourcefile_ui) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.ui %s", opt.progress, sourcefile_ui) + end + + -- ensure ui header file directory + if not os.isdir(headerfile_dir) then + os.mkdir(headerfile_dir) + end + + -- compile ui + os.vrunv(uic, {sourcefile_ui, "-o", headerfile_ui}) + + -- update files and values to the dependent file + dependinfo.files = {sourcefile_ui} + depend.save(dependinfo, dependfile) + end) + diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index 5f5b43520..8fb9ed36d 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -22,275 +22,6 @@ -- @file xmake.lua -- --- define rule: environment -rule("qt.env") - - -- on load - on_load(function (target) - import("detect.sdks.find_qt") - if not target:data("qt") then - target:data_set("qt", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!")) - end - end) - - -- before run - before_run(function (target) - local qt = target:data("qt") - if qt and (is_plat("windows") or (is_plat("mingw") and is_host("windows"))) then - os.addenv("PATH", qt.bindir) - end - end) - - -- clean files - after_clean(function (target) - for _, file in ipairs(target:data("qt.cleanfiles")) do - os.rm(file) - end - target:data_set("qt.cleanfiles", nil) - end) - --- define rule: *.ui -rule("qt.ui") - - -- add rule: qt environment - add_deps("qt.env") - - -- set extensions - set_extensions(".ui") - - -- on load - on_load(function (target) - - -- get uic - local uic = path.join(target:data("qt").bindir, is_host("windows") and "uic.exe" or "uic") - assert(uic and os.isexec(uic), "uic not found!") - - -- save uic - target:data_set("qt.uic", uic) - end) - - -- before build file - before_build_file(function (target, sourcefile_ui, opt) - - -- imports - import("core.base.option") - import("core.project.config") - import("core.project.depend") - - -- get uic - local uic = target:data("qt.uic") - - -- get c++ header file for ui - local headerfile_ui = path.join(config.buildir(), ".qt", "ui", target:name(), "ui_" .. path.basename(sourcefile_ui) .. ".h") - local headerfile_dir = path.directory(headerfile_ui) - - -- add includedirs - target:add("includedirs", path.absolute(headerfile_dir, os.projectdir())) - - -- add clean files - target:data_add("qt.cleanfiles", headerfile_ui) - - -- need build this object? - local dependfile = target:dependfile(headerfile_ui) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(headerfile_ui)}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.qt.ui %s", opt.progress, sourcefile_ui) - else - cprint("${green}[%02d%%]:${clear} compiling.qt.ui %s", opt.progress, sourcefile_ui) - end - - -- ensure ui header file directory - if not os.isdir(headerfile_dir) then - os.mkdir(headerfile_dir) - end - - -- compile ui - os.vrunv(uic, {sourcefile_ui, "-o", headerfile_ui}) - - -- update files and values to the dependent file - dependinfo.files = {sourcefile_ui} - depend.save(dependinfo, dependfile) - end) - --- define rule: moc -rule("qt.moc") - - -- add rule: qt environment - add_deps("qt.env") - - -- set extensions - set_extensions(".h") - - -- on load - on_load(function (target) - - -- get moc - local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") - assert(moc and os.isexec(moc), "moc not found!") - - -- save moc - target:data_set("qt.moc", moc) - end) - - -- on build file - on_build_file(function (target, headerfile_moc, opt) - - -- imports - import("moc") - import("core.base.option") - import("core.project.config") - import("core.tool.compiler") - import("core.project.depend") - - -- get c++ source file for moc - local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp") - - -- get object file - local objectfile = target:objectfile(sourcefile_moc) - - -- load compiler - local compinst = compiler.load("cxx", {target = target}) - - -- get compile flags - local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc}) - - -- add objectfile - table.insert(target:objectfiles(), objectfile) - - -- add clean files - target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile}) - - -- load dependent info - local dependfile = target:dependfile(objectfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local depvalues = {compinst:program(), compflags} - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.qt.moc %s", opt.progress, headerfile_moc) - else - cprint("${green}[%02d%%]:${clear} compiling.qt.moc %s", opt.progress, headerfile_moc) - end - - -- generate c++ source file for moc - moc.generate(target, headerfile_moc, sourcefile_moc) - - -- trace - if option.get("verbose") then - print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) - end - - -- compile c++ source file for moc - dependinfo.files = {} - compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags}) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.insert(dependinfo.files, headerfile_moc) - depend.save(dependinfo, dependfile) - end) - --- define rule: *.qrc -rule("qt.qrc") - - -- add rule: qt environment - add_deps("qt.env") - - -- set extensions - set_extensions(".qrc") - - -- on load - on_load(function (target) - - -- get rcc - local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc") - assert(rcc and os.isexec(rcc), "rcc not found!") - - -- save rcc - target:data_set("qt.rcc", rcc) - end) - - -- on build file - on_build_file(function (target, sourcefile_qrc, opt) - - -- imports - import("core.base.option") - import("core.project.config") - import("core.project.depend") - import("core.tool.compiler") - - -- get rcc - local rcc = target:data("qt.rcc") - - -- get c++ source file for qrc - local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp") - local sourcefile_dir = path.directory(sourcefile_cpp) - - -- get object file - local objectfile = target:objectfile(sourcefile_cpp) - - -- load compiler - local compinst = compiler.load("cxx", {target = target}) - - -- get compile flags - local compflags = compinst:compflags({target = target, sourcefile = sourcefile_cpp}) - - -- add objectfile - table.insert(target:objectfiles(), objectfile) - - -- add clean files - target:data_add("qt.cleanfiles", {sourcefile_cpp, objectfile}) - - -- load dependent info - local dependfile = target:dependfile(objectfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - - -- need build this object? - local depvalues = {compinst:program(), compflags} - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) - else - cprint("${green}[%02d%%]:${clear} compiling.qt.qrc %s", opt.progress, sourcefile_qrc) - end - - -- ensure the source file directory - if not os.isdir(sourcefile_dir) then - os.mkdir(sourcefile_dir) - end - - -- compile qrc - os.vrunv(rcc, {"-name", "qml", sourcefile_qrc, "-o", sourcefile_cpp}) - - -- trace - if option.get("verbose") then - print(compinst:compcmd(sourcefile_cpp, objectfile, {compflags = compflags})) - end - - -- compile c++ source file for qrc - dependinfo.files = {} - compinst:compile(sourcefile_cpp, objectfile, {dependinfo = dependinfo, compflags = compflags}) - - -- update files and values to the dependent file - dependinfo.values = depvalues - table.insert(dependinfo.files, sourcefile_qrc) - depend.save(dependinfo, dependfile) - end) - -- define rule: qt static library rule("qt.static") diff --git a/xmake/rules/wdk/load.lua b/xmake/rules/wdk/env/load.lua index 6d78ecf7a..6d78ecf7a 100644 --- a/xmake/rules/wdk/load.lua +++ b/xmake/rules/wdk/env/load.lua diff --git a/xmake/rules/wdk/env/xmake.lua b/xmake/rules/wdk/env/xmake.lua new file mode 100644 index 000000000..53d2e942e --- /dev/null +++ b/xmake/rules/wdk/env/xmake.lua @@ -0,0 +1,43 @@ +--!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 xmake.lua +-- + +-- define rule: environment +rule("wdk.env") + + -- on load + on_load(function (target) + import("detect.sdks.find_wdk") + if not target:data("wdk") then + target:data_set("wdk", assert(find_wdk(nil, {verbose = true}), "WDK not found!")) + end + end) + + -- clean files + after_clean(function (target) + for _, file in ipairs(target:data("wdk.cleanfiles")) do + os.rm(file) + end + target:data_set("wdk.cleanfiles", nil) + end) + diff --git a/xmake/rules/wdk/inf/xmake.lua b/xmake/rules/wdk/inf/xmake.lua new file mode 100644 index 000000000..3cec2660b --- /dev/null +++ b/xmake/rules/wdk/inf/xmake.lua @@ -0,0 +1,89 @@ +--!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 xmake.lua +-- + +-- define rule: *.inf +rule("wdk.inf") + + -- add rule: wdk environment + add_deps("wdk.env") + + -- set extensions + set_extensions(".inf", ".inx") + + -- on load + on_load(function (target) + + -- imports + import("core.project.config") + + -- get arch + local arch = assert(config.arch(), "arch not found!") + + -- get stampinf + local stampinf = path.join(target:data("wdk").bindir, arch, is_host("windows") and "stampinf.exe" or "stampinf") + assert(stampinf and os.isexec(stampinf), "stampinf not found!") + + -- save uic + target:data_set("wdk.stampinf", stampinf) + end) + + -- on build file + on_build_file(function (target, sourcefile, opt) + + -- imports + import("core.base.option") + import("core.project.depend") + + -- the target file + local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".inf") + + -- add clean files + target:data_add("wdk.cleanfiles", targetfile) + + -- need build this object? + local dependfile = target:dependfile(targetfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile)}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.wdk.inf %s", opt.progress, sourcefile) + else + cprint("${green}[%02d%%]:${clear} compiling.wdk.inf %s", opt.progress, sourcefile) + end + + -- get stampinf + local stampinf = target:data("wdk.stampinf") + + -- update the timestamp + os.cp(sourcefile, targetfile) + os.vrunv(stampinf, {"-d", "*", "-a", is_arch("x64") and "arm64" or "x86", "-v", "*", "-f", targetfile}, {wildcards = false}) + + -- update files and values to the dependent file + dependinfo.files = {sourcefile} + depend.save(dependinfo, dependfile) + end) + diff --git a/xmake/rules/wdk/man/xmake.lua b/xmake/rules/wdk/man/xmake.lua new file mode 100644 index 000000000..e8d4ec045 --- /dev/null +++ b/xmake/rules/wdk/man/xmake.lua @@ -0,0 +1,66 @@ +--!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 xmake.lua +-- + +-- define rule: *.man +rule("wdk.man") + + -- add rule: wdk environment + add_deps("wdk.env") + + -- set extensions + set_extensions(".man") + + -- on load + on_load(function (target) + + -- imports + import("core.project.config") + + -- get arch + local arch = assert(config.arch(), "arch not found!") + + -- get ctrpp + local ctrpp = path.join(target:data("wdk").bindir, arch, is_host("windows") and "ctrpp.exe" or "ctrpp") + assert(ctrpp and os.isexec(ctrpp), "ctrpp not found!") + + -- save uic + target:data_set("wdk.ctrpp", ctrpp) + end) + + -- before build file + before_build_file(function (target, sourcefile, opt) + + -- imports + import("core.base.option") + import("core.project.depend") + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.wdk.man %s", opt.progress, sourcefile) + else + cprint("${green}[%02d%%]:${clear} compiling.wdk.man %s", opt.progress, sourcefile) + end + + end) + diff --git a/xmake/rules/wdk/tracewpp/xmake.lua b/xmake/rules/wdk/tracewpp/xmake.lua new file mode 100644 index 000000000..5acb72308 --- /dev/null +++ b/xmake/rules/wdk/tracewpp/xmake.lua @@ -0,0 +1,124 @@ +--!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 xmake.lua +-- + +-- define rule: tracewpp +rule("wdk.tracewpp") + + -- add rule: wdk environment + add_deps("wdk.env") + + -- on load + on_load(function (target) + + -- imports + import("core.project.config") + + -- get wdk + local wdk = target:data("wdk") + + -- get arch + local arch = assert(config.arch(), "arch not found!") + + -- get tracewpp + local tracewpp = path.join(wdk.bindir, arch, is_host("windows") and "tracewpp.exe" or "tracewpp") + assert(tracewpp and os.isexec(tracewpp), "tracewpp not found!") + + -- save tracewpp + target:data_set("wdk.tracewpp", tracewpp) + + -- save output directory + target:data_set("wdk.tracewpp.outputdir", path.join(config.buildir(), ".wpp", config.get("mode") or "generic", config.get("arch") or os.arch(), target:name())) + + -- save config directory + target:data_set("wdk.tracewpp.configdir", path.join(wdk.bindir, wdk.sdkver, "WppConfig", "Rev1")) + end) + + -- before build file + before_build_file(function (target, sourcefile, opt) + + -- imports + import("core.base.option") + import("core.project.depend") + + -- get tracewpp + local tracewpp = target:data("wdk.tracewpp") + + -- get outputdir + local outputdir = target:data("wdk.tracewpp.outputdir") + + -- get configdir + local configdir = target:data("wdk.tracewpp.configdir") + + -- init args + local args = {} + if target:rule("wdk.kmdf.driver") then + table.insert(args, "-km") + table.insert(args, "-gen:{km-WdfDefault.tpl}*.tmh") + end + local flags = target:values("wdk.tracewpp.flags") + if flags then + table.join2(args, flags) + end + table.insert(args, "-cfgdir:" .. configdir) + table.insert(args, "-odir:" .. outputdir) + table.insert(args, sourcefile) + + -- add includedirs + target:add("includedirs", outputdir) + + -- add clean files + target:data_add("wdk.cleanfiles", outputdir) + + -- need build this object? + local targetfile = path.join(outputdir, path.basename(sourcefile) .. ".tmh") + local dependfile = target:dependfile(targetfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile), values = args}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.wdk.tracewpp %s", opt.progress, sourcefile) + else + cprint("${green}[%02d%%]:${clear} compiling.wdk.tracewpp %s", opt.progress, sourcefile) + end + + -- ensure the output directory + if not os.isdir(outputdir) then + os.mkdir(outputdir) + end + + -- remove the previous target file first + os.tryrm(targetfile) + + -- generate the *.tmh file + os.vrunv(tracewpp, args, {wildcards = false}) + + -- update files and values to the dependent file + dependinfo.files = {sourcefile} + dependinfo.values = args + depend.save(dependinfo, dependfile) + end) + diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua index 8f51862e9..402cd1c64 100644 --- a/xmake/rules/wdk/xmake.lua +++ b/xmake/rules/wdk/xmake.lua @@ -22,195 +22,11 @@ -- @file xmake.lua -- --- define rule: environment -rule("wdk.env") - - -- on load - on_load(function (target) - import("detect.sdks.find_wdk") - if not target:data("wdk") then - target:data_set("wdk", assert(find_wdk(nil, {verbose = true}), "WDK not found!")) - end - end) - - -- clean files - after_clean(function (target) - for _, file in ipairs(target:data("wdk.cleanfiles")) do - os.rm(file) - end - target:data_set("wdk.cleanfiles", nil) - end) - --- define rule: *.inf -rule("wdk.inf") - - -- add rule: wdk environment - add_deps("wdk.env") - - -- set extensions - set_extensions(".inf", ".inx") - - -- on load - on_load(function (target) - - -- imports - import("core.project.config") - - -- get arch - local arch = assert(config.arch(), "arch not found!") - - -- get stampinf - local stampinf = path.join(target:data("wdk").bindir, arch, is_host("windows") and "stampinf.exe" or "stampinf") - assert(stampinf and os.isexec(stampinf), "stampinf not found!") - - -- save uic - target:data_set("wdk.stampinf", stampinf) - end) - - -- on build file - on_build_file(function (target, sourcefile, opt) - - -- imports - import("core.base.option") - import("core.project.depend") - - -- the target file - local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".inf") - - -- add clean files - target:data_add("wdk.cleanfiles", targetfile) - - -- need build this object? - local dependfile = target:dependfile(targetfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile)}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.wdk.inf %s", opt.progress, sourcefile) - else - cprint("${green}[%02d%%]:${clear} compiling.wdk.inf %s", opt.progress, sourcefile) - end - - -- get stampinf - local stampinf = target:data("wdk.stampinf") - - -- update the timestamp - os.cp(sourcefile, targetfile) - os.vrunv(stampinf, {"-d", "*", "-a", is_arch("x64") and "arm64" or "x86", "-v", "*", "-f", targetfile}, {wildcards = false}) - - -- update files and values to the dependent file - dependinfo.files = {sourcefile} - depend.save(dependinfo, dependfile) - end) - --- define rule: tracewpp -rule("wdk.tracewpp") - - -- add rule: wdk environment - add_deps("wdk.env") - - -- on load - on_load(function (target) - - -- imports - import("core.project.config") - - -- get wdk - local wdk = target:data("wdk") - - -- get arch - local arch = assert(config.arch(), "arch not found!") - - -- get tracewpp - local tracewpp = path.join(wdk.bindir, arch, is_host("windows") and "tracewpp.exe" or "tracewpp") - assert(tracewpp and os.isexec(tracewpp), "tracewpp not found!") - - -- save tracewpp - target:data_set("wdk.tracewpp", tracewpp) - - -- save output directory - target:data_set("wdk.tracewpp.outputdir", path.join(config.buildir(), ".wpp", config.get("mode") or "generic", config.get("arch") or os.arch(), target:name())) - - -- save config directory - target:data_set("wdk.tracewpp.configdir", path.join(wdk.bindir, wdk.sdkver, "WppConfig", "Rev1")) - end) - - -- before build file - before_build_file(function (target, sourcefile, opt) - - -- imports - import("core.base.option") - import("core.project.depend") - - -- get tracewpp - local tracewpp = target:data("wdk.tracewpp") - - -- get outputdir - local outputdir = target:data("wdk.tracewpp.outputdir") - - -- get configdir - local configdir = target:data("wdk.tracewpp.configdir") - - -- init args - local args = {} - if target:rule("wdk.kmdf.driver") then - table.insert(args, "-km") - table.insert(args, "-gen:{km-WdfDefault.tpl}*.tmh") - end - local flags = target:values("wdk.tracewpp.flags") - if flags then - table.join2(args, flags) - end - table.insert(args, "-cfgdir:" .. configdir) - table.insert(args, "-odir:" .. outputdir) - table.insert(args, sourcefile) - - -- add includedirs - target:add("includedirs", outputdir) - - -- add clean files - target:data_add("wdk.cleanfiles", outputdir) - - -- need build this object? - local targetfile = path.join(outputdir, path.basename(sourcefile) .. ".tmh") - local dependfile = target:dependfile(targetfile) - local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) - if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile), values = args}) then - return - end - - -- trace progress info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.wdk.tracewpp %s", opt.progress, sourcefile) - else - cprint("${green}[%02d%%]:${clear} compiling.wdk.tracewpp %s", opt.progress, sourcefile) - end - - -- ensure the output directory - if not os.isdir(outputdir) then - os.mkdir(outputdir) - end - - -- remove the previous target file first - os.tryrm(targetfile) - - -- generate the *.tmh file - os.vrunv(tracewpp, args, {wildcards = false}) - - -- update files and values to the dependent file - dependinfo.files = {sourcefile} - dependinfo.values = args - depend.save(dependinfo, dependfile) - end) - -- define rule: umdf driver rule("wdk.umdf.driver") -- add rules - add_deps("wdk.inf") + add_deps("wdk.inf", "wdk.man") -- on load on_load(function (target) @@ -221,7 +37,7 @@ rule("wdk.umdf.driver") rule("wdk.umdf.binary") -- add rules - add_deps("wdk.inf") + add_deps("wdk.inf", "wdk.man") -- on load on_load(function (target) @@ -232,7 +48,7 @@ rule("wdk.umdf.binary") rule("wdk.kmdf.driver") -- add rules - add_deps("wdk.inf") + add_deps("wdk.inf", "wdk.man") -- on load on_load(function (target) @@ -243,7 +59,7 @@ rule("wdk.kmdf.driver") rule("wdk.kmdf.binary") -- add rules - add_deps("wdk.inf") + add_deps("wdk.inf", "wdk.man") -- on load on_load(function (target) |
