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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
//
// install.js - Windows Configuration
//
// (C) 2003-2008 Anope Team
// Contact us at team@anope.org
//
// This program is free but copyrighted software; see the file COPYING for
// details.
//
// Based on the original code of Epona by Lara.
// Based on the original code of Services by Andy Church.
//
// $Id$
//
var anopeVersion = "Unknown";
var vMaj, vMin, vPat, vBuild, vExtra;
var installerResponses = new Array();
var installerQuestions = [
{
'question' : [
'In what directory do you want Anope to be installed?'
],
'short' : 'Install directory:',
'default_answer' : '',
'store_answer' : function(answer) {
if (!answer) {
WScript.Echo("You must give a directory!\n");
return false;
}
if (!fso.FolderExists(answer)) {
if (fso.FileExists(answer)) {
WScript.Echo(answer + " exists, but is not a directory!\n");
return false;
}
WScript.Echo(answer + " does not exist. Create it ([yes]/no)?\n");
var inputValue = InstallerInput().toLowerCase();
if (!inputValue) {
inputValue = 'yes';
}
if (inputValue != 'no') {
fso.CreateFolder(answer);
}
}
else if (fso.FileExists(answer + '\\include\\services.h')) {
WScript.Echo("You cannot use the Anope source directory as a target directory.\n");
return false;
}
installerResponses['Install Directory'] = answer.replace(/\\/g, '/');
return true;
},
'cmake_argument' : function() {
return '-DINSTDIR:STRING=' + installerResponses['Install Directory'];
}
},
{
'question' : [
'Would you like to build using NMake instead of using Visual Studio?',
'NOTE: If you decide to use NMake, you must be in an environment where',
' NMake can function, such as the Visual Studio command line.',
' If you say yes to this while not in an environment that can run',
' NMake, it can cause the CMake configuration to enter an endless',
' loop.'
],
'short' : 'Use NMake?',
'options' : [
'yes',
'no'
],
'default_answer' : 'no',
'store_answer' : function(answer) {
installerResponses['Use NMake'] = answer;
return true;
},
'cmake_argument' : function() {
if (installerResponses['Use NMake'] == 'yes') return '-G"NMake Makefiles"';
else return '';
}
},
{
'question' : [
'Would you like to build a debug version of Anope?'
],
'short' : 'Build debug?',
'options' : [
'yes',
'no'
],
'default_answer' : 'no',
'store_answer' : function(answer) {
installerResponses['Debug'] = answer;
return true;
},
'cmake_argument' : function() {
if (installerResponses['Debug'] == 'msvc') return '';
else if (installerResponses['Debug'] == 'yes') return '-DCMAKE_BUILD_TYPE:STRING=DEBUG';
else return '-DCMAKE_BUILD_TYPE:STRING=RELEASE';
}
},
{
'question' : [
'Are you using Visual Studio 2008? If you are, you need to answer yes',
'to this question, otherwise CMake will not function properly.'
],
'short' : 'Using Visual Studio 2008?',
'options' : [
'yes',
'no'
],
'default_answer' : 'no',
'store_answer' : function(answer) {
installerResponses['Visual Studio 2008'] = answer;
return true;
},
'cmake_argument' : function() {
if (installerResponses['Visual Studio 2008'] == 'yes') return '-G"Visual Studio 9 2008"';
else return '';
}
},
];
var bannerReplacements = [
{
'findtext' : /CURVER/g,
'replacement' : function() { FindAnopeVersion(); return anopeVersion; }
},
{
'findtext' : / For more options type SOURCE_DIR\/Config --help/g,
'replacement' : function() { return ''; }
}
];
var ScriptPath = WScript.ScriptFullName.substr(0, WScript.ScriptFullName.length - WScript.ScriptName.length);
var fso = WScript.CreateObject('Scripting.FileSystemObject');
var x, y, z;
if (fso.FileExists(ScriptPath + '.BANNER')) {
var bannerStream = fso.OpenTextFile(ScriptPath + '.BANNER');
var bannerText = bannerStream.ReadAll();
bannerStream.close();
for (x in bannerReplacements) {
var thisReplacement = bannerReplacements[x];
bannerText = bannerText.replace(thisReplacement['findtext'], thisReplacement['replacement']);
}
WScript.Echo(bannerText + "\n");
}
else {
WScript.Echo("ERROR: Cannot find banner file!\n");
}
WScript.Echo('Press Enter to Begin...');
InstallerInput();
WScript.Echo('');
for (x in installerQuestions) {
var thisQuestion = installerQuestions[x];
var validResponse = false;
var validOpts = new Array();
if (thisQuestion.short == 'Build debug?' && installerResponses['Use NMake'] == 'no') {
installerResponses['Debug'] = 'msvc';
continue;
}
if (thisQuestion.short == 'Using Visual Studio 2008?' && installerResponses['Debug'] != 'msvc') {
installerResponses['Visual Studio 2008'] = 'no';
continue;
}
while (!validResponse) {
for (y in thisQuestion.question) {
var qLine = thisQuestion.question[y];
WScript.Echo(qLine);
}
WScript.Echo('');
var choiceLine = '';
if (thisQuestion.options) {
for (y in thisQuestion.options) {
choiceLine += thisQuestion.options[y] + ', ';
validOpts[thisQuestion.options[y]] = true;
}
choiceLine = choiceLine.substring(0, choiceLine.length - 2);
WScript.Echo('Available Options: ' + choiceLine);
}
if (thisQuestion.default_answer) WScript.Echo('Default Answer: ' + thisQuestion.default_answer + "\n");
WScript.Echo(thisQuestion.short);
var inputValue = InstallerInput().toLowerCase();
if (!inputValue) {
inputValue = thisQuestion.default_answer;
}
if (choiceLine && !validOpts[inputValue]) {
WScript.Echo("ERROR: Invalid option '" + inputValue + "'\n");
}
else if (thisQuestion.store_answer(inputValue)) {
validResponse = true;
}
}
WScript.Echo('');
}
WScript.Echo("\nAnope will be compiled with the following options:\n");
for (x in installerResponses) {
var thisResponse = installerResponses[x];
WScript.Echo("\t" + x + ":\t\t[" + thisResponse.toUpperCase() + "]");
}
WScript.Echo("\tAnope Version:\t\t\t" + anopeVersion);
WScript.Echo("\nTo continue, please press Enter...");
InstallerInput();
var cmake = 'cmake';
for (x in installerQuestions) {
var thisQuestion = installerQuestions[x];
cmake += ' ' + thisQuestion.cmake_argument();
}
cmake += ' "' + ScriptPath + '"';
WScript.Echo(cmake + "\n");
var shell = WScript.CreateObject('WScript.Shell');
var cmake_shell = shell.exec('%comspec% /c ' + cmake);
while (!cmake_shell.StdOut.AtEndOfStream) {
var strLine = cmake_shell.StdOut.ReadLine();
WScript.Echo(strLine);
}
if (installerResponses['Use NMake'] == 'yes') WScript.Echo("\nTo compile Anope, run 'nmake'. To install, run 'nmake install'.\n");
else WScript.Echo("\nTo compile Anope, open Anope.sln and build the solution. To install,\ndo a build on the INSTALL project.\n");
WScript.Echo("If you update Anope, you should run this script again to ensure\nall available options are set.\n");
// -----------------------------------------------------------------
// Functions
function FindAnopeVersion() {
if (!fso.FileExists(ScriptPath + 'version.log')) {
anopeVersion = 'Unknown';
return;
}
var versionLog = fso.OpenTextFile(ScriptPath + 'version.log');
while (!versionLog.atEndOfStream) {
var versionLine = versionLog.readline();
var thisMatch = versionLine.replace('\n', '');
while (thisMatch.match(/\"/g)) {
thisMatch = thisMatch.replace('"', '');
}
versionLine = thisMatch;
if (versionLine.match(/VERSION_MAJOR=/g)) {
vMaj = versionLine.replace('VERSION_MAJOR=', '');
continue;
}
if (versionLine.match(/VERSION_MINOR=/g)) {
vMin = versionLine.replace('VERSION_MINOR=', '');
continue;
}
if (versionLine.match(/VERSION_PATCH=/g)) {
vPat = versionLine.replace('VERSION_PATCH=', '');
continue;
}
if (versionLine.match(/VERSION_EXTRA=/g)) {
vExtra = versionLine.replace('VERSION_EXTRA=', '');
continue;
}
if (versionLine.match(/VERSION_BUILD=/g)) {
vBuild = versionLine.replace('VERSION_BUILD=', '');
continue;
}
}
versionLog.close();
anopeVersion = vMaj + '.' + vMin + '.' + vPat + '.' + vBuild + vExtra;
return;
}
function InstallerInput() {
var input = WScript.StdIn.Readline();
return input;
}
|