1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
--!A cross-platform build utility based on Lua
--
-- Licensed 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-present, Xmake Open Source Community.
--
-- @author ruki
-- @file xmake.lua
--
-- define rule: package *.cab
rule("wdk.package.cab")
-- on package
on_package(function (target)
-- imports
import("core.base.option")
import("core.project.config")
import("lib.detect.find_program")
-- the output directory
local outputdir = path.join(option.get("outputdir") or config.builddir(), "drivers", target:name())
local mode = config.mode()
if mode then
outputdir = path.join(outputdir, mode)
end
local arch = config.arch()
if arch then
outputdir = path.join(outputdir, arch)
end
-- the package file
local packagefile = path.join(outputdir, target:name() .. ".cab")
-- the .ddf file
local ddfile = os.tmpfile(target:targetfile()) .. ".ddf"
-- trace progress info
if option.get("verbose") then
cprint("${dim magenta}packaging %s", packagefile)
else
cprint("${magenta}packaging %s", packagefile)
end
-- get makecab
local makecab = find_program("makecab", {check = "/?"})
assert(makecab and os.isexec(makecab), "makecab not found!")
-- make .ddf file
local file = io.open(ddfile, "w")
if file then
file:print("; %s.ddf", target:name())
file:print(";")
file:print(".OPTION EXPLICIT ; Generate errors")
file:print(".Set CabinetFileCountThreshold=0")
file:print(".Set FolderFileCountThreshold=0")
file:print(".Set FolderSizeThreshold=0")
file:print(".Set MaxCabinetSize=0")
file:print(".Set MaxDiskFileCount=0")
file:print(".Set MaxDiskSize=0")
file:print(".Set CompressionType=MSZIP")
file:print(".Set Cabinet=on")
file:print(".Set Compress=on")
file:print(";Specify file name for new cab file")
file:print(".Set CabinetNameTemplate=%s.cab", target:name())
file:print("; Specify the subdirectory for the files. ")
file:print("; Your cab file should not have files at the root level,")
file:print("; and each driver package must be in a separate subfolder.")
file:print(".Set DiskDirectoryTemplate=%s", outputdir)
file:print(";Specify files to be included in cab file")
local infile = target:data("wdk.sign.inf")
if infile and os.isfile(infile) then
file:print(path.absolute(infile))
end
file:print(path.absolute(target:targetfile()))
file:close()
end
-- make .cab
os.vrunv(makecab, {"/f", ddfile})
-- save this package file for signing (wdk.sign.* rules)
target:data_set("wdk.sign.cab", packagefile)
end)
|