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
98
99
|
using Posix;
namespace Wixl {
static bool version;
static bool verbose;
static bool preproc;
static string output;
[CCode (array_length = false, array_null_terminated = true)]
static string[] files;
[CCode (array_length = false, array_null_terminated = true)]
static string[] defines;
[CCode (array_length = false, array_null_terminated = true)]
static string[] includedirs;
private const OptionEntry[] options = {
{ "version", 0, 0, OptionArg.NONE, ref version, N_("Display version number"), null },
{ "verbose", 'v', 0, OptionArg.NONE, ref verbose, N_("Verbose output"), null },
{ "output", 'o', 0, OptionArg.FILENAME, ref output, N_("Output file"), null },
{ "define", 'D', 0, OptionArg.STRING_ARRAY, ref defines, N_("Define variable"), null },
{ "includedir", 'I', 0, OptionArg.STRING_ARRAY, ref includedirs, N_("Include directory"), null },
{ "only-preproc", 'E', 0, OptionArg.NONE, ref preproc, N_("Stop after the preprocessing stage"), null },
{ "", 0, 0, OptionArg.FILENAME_ARRAY, ref files, null, N_("INPUT_FILE...") },
{ null }
};
int main (string[] args) {
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (Config.GETTEXT_PACKAGE);
GLib.Environment.set_application_name (Config.PACKAGE_NAME);
var parameter_string = _("- a msi building tool");
var opt_context = new OptionContext (parameter_string);
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
try {
opt_context.parse (ref args);
} catch (OptionError.BAD_VALUE err) {
GLib.stdout.printf (opt_context.get_help (true, null));
exit (1);
} catch (OptionError error) {
warning (error.message);
}
if (version) {
GLib.stdout.printf ("%s\n", Config.PACKAGE_VERSION);
exit (0);
}
if (files.length < 1) {
GLib.stderr.printf (_("Please specify input files.\n"));
exit (1);
}
if (output == null && !preproc) {
if (files[0].has_suffix (".wxs"))
output = files[0].slice (0, -4) + ".msi";
else {
GLib.stderr.printf (_("Please specify the output file.\n"));
exit (1);
}
}
try {
var builder = new WixBuilder (includedirs);
foreach (var d in defines) {
var def = d.split ("=", 2);
var name = def[0];
var value = def.length == 2 ? def[1] : "1";
builder.define_variable (name, value);
}
foreach (var arg in files) {
if (verbose)
print ("Loading %s...\n", arg);
var file = File.new_for_commandline_arg (arg);
builder.load_file (file, preproc);
builder.add_path (file.get_parent ().get_path ());
}
if (preproc)
return 0;
if (verbose)
print ("Building %s...\n", output);
var msi = builder.build ();
msi.build (output);
} catch (GLib.Error error) {
printerr (error.message + "\n");
return 1;
}
return 0;
}
} // Wixl
|