@@ -31,24 +31,31 @@ use Getopt::Long;
31
31
# thus acting like a filter and passing all other arguments
32
32
# straight through
33
33
my $opt_debug ;
34
+ my $opt_build_type ;
35
+ my $opt_build = 1;
36
+ my $opt_just_print ;
37
+
34
38
Getopt::Long::Configure(" pass_through" );
35
39
GetOptions(
36
40
37
41
# Build MySQL Server and NDB with debug
38
- ' debug' => \$opt_debug ,
42
+ ' debug! ' => \$opt_debug ,
39
43
' with-debug:s' => sub { $opt_debug = 1; },
40
-
44
+ ' build-type=s' => \$opt_build_type ,
45
+ ' build!' => \$opt_build ,
46
+ ' c|just-configure' => sub { $opt_build = 0; },
47
+ ' n|just-print' => \$opt_just_print ,
41
48
) or exit (1);
42
49
43
50
# Find source root directory, assume this script is
44
51
# in <srcroot>/storage/ndb/
45
- my $srcdir = dirname(dirname(dirname(abs_path($0 ))));
46
- die unless -d $srcdir ; # Sanity check that the srcdir exist
52
+ my $opt_srcdir = dirname(dirname(dirname(abs_path($0 ))));
53
+ die unless -d $opt_srcdir ; # Sanity check that the srcdir exist
47
54
if ($^O eq " cygwin" ) {
48
55
# Convert posix path to Windows mixed path since cmake
49
56
# is most likely a windows binary
50
- $srcdir = ` cygpath -m $srcdir ` ;
51
- chomp $srcdir ;
57
+ $opt_srcdir = ` cygpath -m $opt_srcdir ` ;
58
+ chomp $opt_srcdir ;
52
59
}
53
60
54
61
# Check that cmake exists and figure out it's version
@@ -61,7 +68,7 @@ my $cmake_version_id;
61
68
{
62
69
# print "1: $1 2: $2 3: $3\n";
63
70
$cmake_version_id = $1 *10000 + $2 *100 + $3 ;
64
- print " cmake_version_id: $cmake_version_id \n " ;
71
+ # print "cmake_version_id: $cmake_version_id\n";
65
72
}
66
73
die " Could not parse cmake version" unless ($cmake_version_id );
67
74
}
@@ -71,37 +78,244 @@ my $cmake_version_id;
71
78
# Configure
72
79
#
73
80
{
81
+ # Remove old CMakeCache.txt(ignore if not exists) to
82
+ # force fresh configure
83
+ unlink (" CMakeCache.txt" );
84
+
74
85
my @args ;
75
- push (@args , " $srcdir /cmake/configure.pl" );
76
-
77
- # MySQL Server options
78
- push (@args , " --with-ssl" );
86
+
87
+ # Hardcoded options controlling how to build MySQL Server
88
+ push (@args , " -DWITH_SSL=bundled" );
79
89
80
90
if ($opt_debug )
81
91
{
82
- push (@args , " --with-debug " );
83
- push (@args , " --disable-mysql-maintainer-mode " );
92
+ push (@args , " -DWITH_DEBUG=1 " );
93
+ push (@args , " -DMYSQL_MAINTAINER_MODE=0 " );
84
94
}
85
95
86
- # NDB options
87
- push (@args , " --with-plugin-ndbcluster " );
88
- push (@args , " --with-ndb-test " );
96
+ # Hardcoded options controlling how to build NDB
97
+ push (@args , " -DWITH_PLUGIN_NDBCLUSTER=1 " );
98
+ push (@args , " -DWITH_NDB_TEST=1 " );
89
99
90
- cmd($^X, @args , @ARGV );
100
+ # The cmake generator to use
101
+ if ($opt_build_type )
102
+ {
103
+ push (@args , " -G \" $opt_build_type \" " );
104
+ }
105
+
106
+ # Sets installation directory, bindir, libdir, libexecdir etc.
107
+ # The equivalent CMake variables are given without prefix
108
+ # e.g if --prefix is /usr and --bindir is /usr/bin
109
+ # then cmake variable (INSTALL_BINDIR) must be just "bin"
110
+ my $opt_prefix ;
111
+ sub set_installdir
112
+ {
113
+ my ($path , $varname ) = @_ ;
114
+ my $prefix_length = length ($opt_prefix );
115
+ if (($prefix_length > 0) && (index ($path ,$opt_prefix ) == 0))
116
+ {
117
+ # path is under the prefix, remove the prefix and
118
+ # maybe following "/"
119
+ $path = substr ($path , $prefix_length );
120
+ if (length ($path ) > 0)
121
+ {
122
+ my $char = substr ($path , 0, 1);
123
+ if ($char eq " /" )
124
+ {
125
+ $path = substr ($path , 1);
126
+ }
127
+ }
128
+ if (length ($path ) > 0)
129
+ {
130
+ push (@args , " -D$varname =$path " );
131
+ }
132
+ }
133
+ }
134
+
135
+ # Process --configure style arguments which need special conversion
136
+ my $opt_bindir ;
137
+ my $opt_libdir ;
138
+ my $opt_libexecdir ;
139
+ my $opt_includedir ;
140
+ my $opt_with_zlib_dir ;
141
+ my $opt_with_ssl ;
142
+ my $opt_localstatedir ;
143
+ my $opt_mysql_maintainer_mode ;
144
+ my $opt_with_gcov ;
145
+ my $opt_with_comment ;
146
+ my $opt_with_plugins ;
147
+ my $opt_without_plugin ;
148
+ my $opt_extra_charsets ;
149
+ my $opt_with_extra_charsets ;
150
+ Getopt::Long::Configure(" pass_through" );
151
+ GetOptions(
152
+ ' prefix=s' => \$opt_prefix ,
153
+ ' srcdir=s' => \$opt_srcdir ,
154
+ ' bindir=s' => \$opt_bindir ,
155
+ ' libdir=s' => \$opt_libdir ,
156
+ ' libexecdir=s' => \$opt_libexecdir ,
157
+ ' includedir=s' => \$opt_includedir ,
158
+ ' with-zlib-dir=s' => \$opt_with_zlib_dir ,
159
+ ' with-ssl:s' => \$opt_with_ssl ,
160
+ ' localstatedir=s' => \$opt_localstatedir ,
161
+ ' mysql-maintainer-mode=s' => \$opt_mysql_maintainer_mode ,
162
+ ' with-gcov' => \$opt_with_gcov ,
163
+ ' with-comment=s' => \$opt_with_comment ,
164
+ ' with-plugins=s' => \$opt_with_plugins ,
165
+ ' without-plugin=s' => \$opt_without_plugin ,
166
+ ' with-extra-charsets=s' => \$opt_with_extra_charsets ,
167
+ ' extra-charsets=s' => \$opt_extra_charsets ,
168
+ ) or exit (1);
169
+
170
+ if ($opt_prefix )
171
+ {
172
+ push (@args , " -DCMAKE_INSTALL_PREFIX=$opt_prefix " );
173
+ }
174
+ if ($opt_bindir )
175
+ {
176
+ set_installdir($opt_bindir , " INSTALL_BINDIR" );
177
+ }
178
+ if ($opt_libdir )
179
+ {
180
+ set_installdir($opt_libdir , " INSTALL_LIBDIR" );
181
+ }
182
+ if ($opt_libexecdir )
183
+ {
184
+ set_installdir($opt_libexecdir , " INSTALL_SBINDIR" );
185
+ }
186
+ if ($opt_includedir )
187
+ {
188
+ set_installdir($opt_includedir , " INSTALL_INCLUDEDIR" );
189
+ }
190
+ if ($opt_with_zlib_dir )
191
+ {
192
+ $opt_with_zlib_dir = " system"
193
+ if ($opt_with_zlib_dir ne " bundled" );
194
+ push (@args , " -DWITH_ZLIB=$opt_with_zlib_dir " );
195
+ }
196
+ if ($opt_with_ssl )
197
+ {
198
+ push (@args , " -DWITH_SSL=" .($opt_with_ssl ? " yes" : " bundled" ));
199
+ }
200
+ if ($opt_localstatedir )
201
+ {
202
+ push (@args , " -DMYSQL_DATADIR=$opt_localstatedir " );
203
+ }
204
+ if ($opt_mysql_maintainer_mode )
205
+ {
206
+ push (@args , " -DMYSQL_MAINTAINER_MODE=" .
207
+ ($opt_mysql_maintainer_mode =~ / enable/ ? " 1" : " 0" ));
208
+ }
209
+ if ($opt_with_gcov )
210
+ {
211
+ push (@args , " -DENABLE_GCOV=ON" );
212
+ }
213
+ if ($opt_with_comment )
214
+ {
215
+ push (@args , " \" -DWITH_COMMENT=$opt_with_comment \" " );
216
+ }
217
+ if ($opt_with_plugins )
218
+ {
219
+ my @plugins = split (/ ,/ , $opt_with_plugins );
220
+ foreach my $p (@plugins )
221
+ {
222
+ $p =~ s / -/ _/ g ;
223
+ push (@args , " -DWITH_" .uc ($p )." =1" );
224
+ }
225
+ }
226
+ if ($opt_without_plugin )
227
+ {
228
+ push (@args , " -DWITHOUT_" .uc ($opt_without_plugin )." =1" );
229
+ }
230
+ if ($opt_extra_charsets )
231
+ {
232
+ push (@args , " -DWITH_CHARSETS=$opt_extra_charsets " );
233
+ }
234
+ if ($opt_with_extra_charsets )
235
+ {
236
+ push (@args , " -DWITH_EXTRA_CHARSETS=$opt_with_extra_charsets " );
237
+ }
238
+
239
+
240
+ # Default conversion of remaining args in ARGV from
241
+ # 1) --arg -> -DARG=1
242
+ # 2) --arg=value -> -DARG=value
243
+ # 3) arg=value -> environment variable arg=value
244
+ foreach my $option (@ARGV )
245
+ {
246
+ if ($option =~ / ^--/ )
247
+ {
248
+ # Remove leading --
249
+ $option = substr ($option , 2);
250
+
251
+ my @v = split (' =' , $option );
252
+ my $name = shift (@v );
253
+ $name = uc ($name );
254
+ $name =~ s / -/ _/ g ;
255
+ if (@v )
256
+ {
257
+ push (@args , " -D$name =" .join (' =' , @v ));
258
+ }
259
+ else
260
+ {
261
+ push (@args , " -D$name =1" );
262
+ }
263
+ }
264
+ else
265
+ {
266
+
267
+ # This must be environment variable
268
+ my @v = split (' =' , $option );
269
+ my $name = shift (@v );
270
+ if (@v )
271
+ {
272
+ $ENV {$name } = join (' =' , @v );
273
+ }
274
+ else
275
+ {
276
+ die " unhandled argument '$option ' found" ;
277
+ }
278
+ }
279
+ }
280
+
281
+ # The source directory to build from
282
+ die " srcdir already contains CMakeCache.txt, this will not work!"
283
+ if (-f " $opt_srcdir /CMakeCache.txt" );
284
+ push (@args , $opt_srcdir );
285
+
286
+ cmd(" cmake" , @args );
287
+ }
288
+
289
+ if (!$opt_build )
290
+ {
291
+ print " Configuration completed, skipping build(used --no-build)\n " ;
292
+ exit (0);
91
293
}
92
294
295
+
93
296
#
94
297
# Build
95
298
#
96
299
{
97
300
if ($cmake_version_id >= 20800)
98
301
{
99
- # Use the universal "cmake --build <srcdir >" way of building
302
+ # Use the universal "cmake --build <dir >" way of building
100
303
# which is available from cmake 2.8 and works on all platforms
101
304
my @args ;
102
305
push (@args , " --build" );
103
-
104
- push (@args , " $srcdir " );
306
+ push (@args , " ." );
307
+
308
+ if ($^O eq " cygwin" or $^O eq " MSWin32" )
309
+ {
310
+ # Choose to build RelWitDebInfo by default on Windows
311
+ my $config = ' RelWithDebInfo' ;
312
+ if ($opt_debug )
313
+ {
314
+ $config = ' Debug' ;
315
+ }
316
+ push (@args , " --config" );
317
+ push (@args , $config );
318
+ }
105
319
106
320
cmd(" cmake" , @args );
107
321
@@ -112,12 +326,18 @@ my $cmake_version_id;
112
326
die " You need to install cmake with version > 2.8"
113
327
if ($^O eq " cygwin" or $^O eq " MSWin32" );
114
328
115
- cmd(" make -C $srcdir " );
329
+ cmd(" make" );
116
330
}
117
331
}
118
332
119
333
sub cmd {
120
334
my ($cmd , @a )= @_ ;
335
+
336
+ if ($opt_just_print ){
337
+ print " $cmd " , join (' ' , @a ), " \n " ;
338
+ return ;
339
+ }
340
+
121
341
print " compile-cluster: calling '$cmd " , join (' ' , @a ), " '\n " ;
122
342
system ($cmd , @a )
123
343
and print (" command failed: $! \n " )
0 commit comments