~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to win/configure.js

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Configure.js
 
2
//
 
3
// Copyright (C) 2006 MySQL AB
 
4
// 
 
5
// This program is free software; you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation; version 2 of the License.
 
8
// 
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
ForReading = 1;
 
19
ForWriting = 2;
 
20
ForAppending = 8;
 
21
 
 
22
try 
 
23
{
 
24
    var fso = new ActiveXObject("Scripting.FileSystemObject");
 
25
 
 
26
    var args = WScript.Arguments
 
27
    
 
28
    // read in the Unix configure.in file
 
29
    var configureInTS = fso.OpenTextFile("configure.in", ForReading);
 
30
    var configureIn = configureInTS.ReadAll();
 
31
    configureInTS.Close();
 
32
    var default_comment = "Source distribution";
 
33
    var default_port = GetValue(configureIn, "MYSQL_TCP_PORT_DEFAULT");
 
34
    var actual_port = 0;
 
35
 
 
36
    var configfile = fso.CreateTextFile("win\\configure.data", true);
 
37
    for (i=0; i < args.Count(); i++)
 
38
    {
 
39
        var parts = args.Item(i).split('=');
 
40
        switch (parts[0])
 
41
        {
 
42
            case "CYBOZU":
 
43
            case "EMBED_MANIFESTS":
 
44
            case "EXTRA_DEBUG":
 
45
            case "WITH_EMBEDDED_SERVER":
 
46
            case "WITHOUT_MARIA_TEMP_TABLES":
 
47
                    configfile.WriteLine("SET (" + args.Item(i) + " TRUE)");
 
48
                    break;
 
49
            case "MYSQL_SERVER_SUFFIX":
 
50
            case "MYSQLD_EXE_SUFFIX":
 
51
                    configfile.WriteLine("SET (" + parts[0] + " \""
 
52
                                         + parts[1] + "\")");
 
53
                    break;
 
54
            case "COMPILATION_COMMENT":
 
55
                    default_comment = parts[1];
 
56
                    break;
 
57
            case "MYSQL_TCP_PORT":
 
58
                    actual_port = parts[1];
 
59
                    break;
 
60
        }
 
61
    }
 
62
 
 
63
    if (actual_port == 0)
 
64
        {
 
65
       // if we actually defaulted (as opposed to the pathological case of
 
66
       // --with-tcp-port=<MYSQL_TCP_PORT_DEFAULT> which might in theory
 
67
       // happen if whole batch of servers was built from a script), set
 
68
       // the default to zero to indicate that; we don't lose information
 
69
       // that way, because 0 obviously indicates that we can get the
 
70
       // default value from MYSQL_TCP_PORT. this seems really evil, but
 
71
       // testing for MYSQL_TCP_PORT==MYSQL_TCP_PORT_DEFAULT would make a
 
72
       // a port of MYSQL_TCP_PORT_DEFAULT magic even if the builder did not
 
73
       // intend it to mean "use the default, in fact, look up a good default
 
74
       // from /etc/services if you can", but really, really meant 3306 when
 
75
       // they passed in 3306. When they pass in a specific value, let them
 
76
       // have it; don't second guess user and think we know better, this will
 
77
       // just make people cross.  this makes the the logic work like this
 
78
       // (which is complicated enough):
 
79
       // 
 
80
       // - if a port was set during build, use that as a default.
 
81
       // 
 
82
       // - otherwise, try to look up a port in /etc/services; if that fails,
 
83
       //   use MYSQL_TCP_PORT_DEFAULT (at the time of this writing 3306)
 
84
       // 
 
85
       // - allow the MYSQL_TCP_PORT environment variable to override that.
 
86
       // 
 
87
       // - allow command-line parameters to override all of the above.
 
88
       // 
 
89
       // the top-most MYSQL_TCP_PORT_DEFAULT is read from win/configure.js,
 
90
       // so don't mess with that.
 
91
           actual_port = default_port;
 
92
           default_port = 0;
 
93
        }
 
94
 
 
95
    configfile.WriteLine("SET (COMPILATION_COMMENT \"" +
 
96
                         default_comment + "\")");
 
97
 
 
98
    configfile.WriteLine("SET (PROTOCOL_VERSION \"" +
 
99
                         GetValue(configureIn, "PROTOCOL_VERSION") + "\")");
 
100
    configfile.WriteLine("SET (DOT_FRM_VERSION \"" +
 
101
                         GetValue(configureIn, "DOT_FRM_VERSION") + "\")");
 
102
    configfile.WriteLine("SET (MYSQL_TCP_PORT_DEFAULT \"" + default_port + "\")");
 
103
    configfile.WriteLine("SET (MYSQL_TCP_PORT \"" + actual_port + "\")");
 
104
    configfile.WriteLine("SET (MYSQL_UNIX_ADDR \"" +
 
105
                         GetValue(configureIn, "MYSQL_UNIX_ADDR_DEFAULT") + "\")");
 
106
    var version = GetVersion(configureIn);
 
107
    configfile.WriteLine("SET (VERSION \"" + version + "\")");
 
108
    configfile.WriteLine("SET (MYSQL_BASE_VERSION \"" +
 
109
                         GetBaseVersion(version) + "\")");
 
110
    configfile.WriteLine("SET (MYSQL_VERSION_ID \"" +
 
111
                         GetVersionId(version) + "\")");
 
112
    var engineOptions = ParsePlugins();
 
113
    for (option in engineOptions)
 
114
    {
 
115
       configfile.WriteLine("SET(" + engineOptions[option] + " TRUE)");
 
116
    }
 
117
    configfile.Close();
 
118
    
 
119
    fso = null;
 
120
 
 
121
    WScript.Echo("done!");
 
122
}
 
123
catch (e)
 
124
{
 
125
    WScript.Echo("Error: " + e.description);
 
126
}
 
127
 
 
128
function GetValue(str, key)
 
129
{
 
130
    var pos = str.indexOf(key+'=');
 
131
    if (pos == -1) return null;
 
132
    pos += key.length + 1;
 
133
    var end = str.indexOf("\n", pos);
 
134
    if (str.charAt(pos) == "\"")
 
135
        pos++;
 
136
    if (str.charAt(end-1) == "\"")
 
137
        end--;
 
138
    return str.substring(pos, end);    
 
139
}
 
140
 
 
141
function GetVersion(str)
 
142
{
 
143
    var key = "AC_INIT([MySQL Server], [";
 
144
    var pos = str.indexOf(key);
 
145
    if (pos == -1) return null;
 
146
    pos += key.length;
 
147
    var end = str.indexOf("]", pos);
 
148
    if (end == -1) return null;
 
149
    return str.substring(pos, end);
 
150
}
 
151
 
 
152
function GetBaseVersion(version)
 
153
{
 
154
    var dot = version.indexOf(".");
 
155
    if (dot == -1) return null;
 
156
    dot = version.indexOf(".", dot+1);
 
157
    if (dot == -1) dot = version.length;
 
158
    return version.substring(0, dot);
 
159
}
 
160
 
 
161
function GetVersionId(version)
 
162
{
 
163
    var dot = version.indexOf(".");
 
164
    if (dot == -1) return null;
 
165
    var major = parseInt(version.substring(0, dot), 10);
 
166
    
 
167
    dot++;
 
168
    var nextdot = version.indexOf(".", dot);
 
169
    if (nextdot == -1) return null;
 
170
    var minor = parseInt(version.substring(dot, nextdot), 10);
 
171
    dot = nextdot+1;
 
172
    
 
173
    var stop = version.indexOf("-", dot);
 
174
    if (stop == -1) stop = version.length;
 
175
    var build = parseInt(version.substring(dot, stop), 10);
 
176
    
 
177
    var id = major;
 
178
    if (minor < 10)
 
179
        id += '0';
 
180
    id += minor;
 
181
    if (build < 10)
 
182
        id += '0';
 
183
    id += build;
 
184
    return id;
 
185
}
 
186
 
 
187
function PluginConfig(isGroup, include)
 
188
{
 
189
    this.isGroup = isGroup;
 
190
    this.include = include;
 
191
}
 
192
 
 
193
 
 
194
// Parse command line arguments specific to plugins (aka storage engines).
 
195
//
 
196
// --with-plugin-PLUGIN, --with-plugins=group,  --with-plugins=PLUGIN[,PLUGIN...]
 
197
// --without-plugin-PLUGIN is supported.
 
198
//
 
199
// Legacy option WITH_<PLUGIN>_STORAGE_ENGINE is supported as well.
 
200
// The function returns string array with elements like WITH_SOME_STORAGE_ENGINE 
 
201
// or WITHOUT_SOME_STORAGE_ENGINE.
 
202
//
 
203
// This function handles groups, for example effect of specifying --with-plugins=max 
 
204
// is the same as --with-plugins==archive,federated,falcon,innobase...
 
205
 
 
206
function ParsePlugins()
 
207
{
 
208
 
 
209
    var config = new Array();  
 
210
 
 
211
    config["DEFAULT"] = new PluginConfig(true,true);
 
212
    
 
213
    // Parse command line parameters
 
214
    for (i=0; i< WScript.Arguments.length;i++)
 
215
    {
 
216
        var option = WScript.Arguments.Item(i);
 
217
        var match = /WITH_(\w+)_STORAGE_ENGINE/.exec(option);
 
218
        if (match == null)
 
219
            match = /--with-plugin-(\w+)/.exec(option);
 
220
        if (match != null)
 
221
        {
 
222
            config[match[1].toUpperCase()] =  new PluginConfig(false,true);
 
223
            continue;
 
224
        }
 
225
 
 
226
        match = /WITHOUT_(\w+)_STORAGE_ENGINE/.exec(option);
 
227
        if (match == null)
 
228
            match = /--without-plugin-(\w+)/.exec(option);
 
229
    
 
230
        if (match != null)
 
231
        {
 
232
            config[match[1].toUpperCase()] =  
 
233
                new PluginConfig(false,false);
 
234
            continue;
 
235
        }
 
236
        
 
237
        match = /--with-plugins=([\w,\-_]+)/.exec(option);
 
238
        if(match != null)
 
239
        {
 
240
        
 
241
            var plugins  = match[1].split(",");
 
242
            for(var key in plugins)
 
243
            {
 
244
                config[plugins[key].toUpperCase()] = 
 
245
                    new PluginConfig(null,true);
 
246
            }
 
247
            continue;
 
248
        }
 
249
        match = /--without-plugins=([\w,\-_]+)/.exec(option);
 
250
        if(match != null)
 
251
        {
 
252
            var plugins = match[1].split(",");
 
253
            for(var key in plugins)
 
254
                config[plugins[key].toUpperCase()] =
 
255
                    new PluginConfig(null, false);
 
256
            continue;
 
257
        }
 
258
    }
 
259
    
 
260
    // Read plugin definitions, find out groups plugins belong to.
 
261
    var fc = new Enumerator(fso.GetFolder("storage").SubFolders);
 
262
    for (;!fc.atEnd(); fc.moveNext())
 
263
    {
 
264
        var subfolder = fc.item();
 
265
        var name =  subfolder.name.toUpperCase();
 
266
        
 
267
        // Handle case where storage engine  was already specified by name in 
 
268
        // --with-plugins or --without-plugins.
 
269
        if (config[name] != undefined)
 
270
        {
 
271
            config[name].isGroup = false;
 
272
            continue;
 
273
        }
 
274
        config[name] = new PluginConfig(false,null);
 
275
        
 
276
        // Handle groups. For each plugin, find out which group it belongs to
 
277
        // If this group was specified on command line for inclusion/exclusion,
 
278
        // then include/exclude the plugin.
 
279
        filename  = subfolder +"\\plug.in";
 
280
        if (fso.FileExists(filename))
 
281
        {
 
282
            var content = fso.OpenTextFile(filename, ForReading).ReadAll();
 
283
            var match = 
 
284
              /MYSQL_STORAGE_ENGINE([ ]*)[\(]([^\)]+)[\)]/.exec(content);
 
285
            if (match== null)
 
286
                continue;
 
287
            match = /\[[\w,\-_]+\][\s]?\)/.exec(match[0]);
 
288
            if (match == null)
 
289
                continue;
 
290
            groups = match[0].split(/[\,\(\)\[\] ]/);
 
291
            for (var key in groups)
 
292
            {
 
293
                var group = groups[key].toUpperCase();
 
294
                if (config[group] != undefined)
 
295
                {
 
296
                    config[group].isGroup = true;
 
297
                    if (config[group].include != null)
 
298
                    {
 
299
                        config[name].include = config[group].include;
 
300
                        break;
 
301
                    }
 
302
                }
 
303
            }
 
304
        }
 
305
    }
 
306
    
 
307
    var arr = new Array();
 
308
    for(key in config)
 
309
    {
 
310
        var eng = config[key];
 
311
        if(eng.isGroup != undefined && !eng.isGroup     && eng.include != undefined)
 
312
        {
 
313
            if (fso.FolderExists("storage\\"+key) || key=="PARTITION")
 
314
            {
 
315
                arr[arr.length] = eng.include? 
 
316
                    "WITH_"+key+"_STORAGE_ENGINE":"WITHOUT_"+key+"_STORAGE_ENGINE";
 
317
            }
 
318
        }
 
319
    }
 
320
    return arr;
 
321
}