1#!/usr/bin/env perl 2 3# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 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-1335 USA 17 18use strict; 19use Cwd 'abs_path'; 20use File::Basename; 21 22my $cmakeargs = ""; 23 24# Find source root directory 25# Assume this script is in <srcroot>/cmake 26my $srcdir = dirname(dirname(abs_path($0))); 27my $cmake_install_prefix=""; 28my $just_print= 0; 29 30# Sets installation directory, bindir, libdir, libexecdir etc 31# the equivalent CMake variables are given without prefix 32# e.g if --prefix is /usr and --bindir is /usr/bin 33# then cmake variable (INSTALL_BINDIR) must be just "bin" 34 35sub set_installdir 36{ 37 my($path, $varname) = @_; 38 my $prefix_length = length($cmake_install_prefix); 39 if (($prefix_length > 0) && (index($path,$cmake_install_prefix) == 0)) 40 { 41 # path is under the prefix, so remove the prefix and maybe following "/" 42 $path = substr($path, $prefix_length); 43 if(length($path) > 0) 44 { 45 my $char = substr($path, 0, 1); 46 if($char eq "/") 47 { 48 $path= substr($path, 1); 49 } 50 } 51 if(length($path) > 0) 52 { 53 $cmakeargs = $cmakeargs." -D".$varname."=".$path; 54 } 55 } 56} 57 58# CMake understands CC and CXX env.variables correctly, if they contain 1 or 2 tokens 59# e.g CXX=gcc and CXX="ccache gcc" are ok. However it could have a problem if there 60# (recognizing gcc) with more tokens ,e.g CXX="ccache gcc --pipe". 61# The problem is simply fixed by splitting compiler and flags, e.g 62# CXX="ccache gcc --pipe" => CXX=ccache gcc CXXFLAGS=--pipe 63 64sub check_compiler 65{ 66 my ($varname, $flagsvarname) = @_; 67 my @tokens = split(/ /,$ENV{$varname}); 68 if($#tokens >= 2) 69 { 70 $ENV{$varname} = $tokens[0]." ".$tokens[1]; 71 my $flags; 72 73 for(my $i=2; $i<=$#tokens; $i++) 74 { 75 $flags= $flags." ".$tokens[$i]; 76 } 77 if(defined $ENV{$flagsvarname}) 78 { 79 $flags = $flags." ".$ENV{$flagsvarname}; 80 } 81 $ENV{$flagsvarname}=$flags; 82 print("$varname=$ENV{$varname}\n"); 83 print("$flagsvarname=$ENV{$flagsvarname}\n"); 84 } 85} 86 87check_compiler("CC", "CFLAGS"); 88check_compiler("CXX", "CXXFLAGS"); 89 90foreach my $option (@ARGV) 91{ 92 if (substr ($option, 0, 2) eq "--") 93 { 94 $option = substr($option, 2); 95 } 96 else 97 { 98 # This must be environment variable 99 my @v = split('=', $option); 100 my $name = shift(@v); 101 if(@v) 102 { 103 $ENV{$name} = join('=', @v); 104 } 105 next; 106 } 107 if($option =~ /srcdir/) 108 { 109 $srcdir = substr($option,7); 110 next; 111 } 112 if($option =~ /help/) 113 { 114 system("cmake ${srcdir} -LH"); 115 exit(0); 116 } 117 if ($option =~ /print/) 118 { 119 $just_print=1; 120 next; 121 } 122 if($option =~ /with-plugins=/) 123 { 124 my @plugins= split(/,/, substr($option,13)); 125 foreach my $p (@plugins) 126 { 127 $p =~ s/-/_/g; 128 $cmakeargs = $cmakeargs." -DWITH_".uc($p)."=AUTO"; 129 } 130 next; 131 } 132 if($option =~ /with-extra-charsets=/) 133 { 134 my $charsets= substr($option,20); 135 $cmakeargs = $cmakeargs." -DWITH_EXTRA_CHARSETS=".$charsets; 136 next; 137 } 138 if($option =~ /without-plugin=/ || $option =~ /without-plugin-/) 139 { 140 $cmakeargs = $cmakeargs." -DPLUGIN_".uc(substr($option,15))."=NO"; 141 next; 142 } 143 if($option =~ /with-plugin-(.*)=(.*)/) 144 { 145 $cmakeargs = $cmakeargs." -DPLUGIN_".uc($1)."=".uc($2); 146 next; 147 } 148 if($option =~ /without-wsrep/) 149 { 150 $cmakeargs = $cmakeargs." -DWITH_WSREP=OFF"; 151 next; 152 } 153 if($option =~ /with-zlib-dir=bundled/) 154 { 155 $cmakeargs = $cmakeargs." -DWITH_ZLIB=bundled"; 156 next; 157 } 158 if($option =~ /with-zlib-dir=/) 159 { 160 $cmakeargs = $cmakeargs." -DWITH_ZLIB=system"; 161 next; 162 } 163 if($option =~ /with-libevent=/) 164 { 165 $cmakeargs = $cmakeargs." -DWITH_LIBEVENT=system"; 166 next; 167 } 168 if($option =~ /with-libevent/) 169 { 170 $cmakeargs = $cmakeargs." -DWITH_LIBEVENT=bundled"; 171 next; 172 } 173 if($option =~ /with-ssl=yes/) 174 { 175 $cmakeargs = $cmakeargs." -DWITH_SSL=yes"; 176 next; 177 } 178 if($option =~ /with-ssl=system/) 179 { 180 $cmakeargs = $cmakeargs." -DWITH_SSL=system"; 181 next; 182 } 183 if($option =~ /with-ssl$/) 184 { 185 $cmakeargs = $cmakeargs." -DWITH_SSL=bundled"; 186 next; 187 } 188 if($option =~ /with-debug/) 189 { 190 $cmakeargs = $cmakeargs." -DCMAKE_BUILD_TYPE=Debug -DSECURITY_HARDENED=OFF"; 191 next; 192 } 193 if($option =~ /with-(.*)=(.*)/) 194 { 195 $cmakeargs = $cmakeargs. " -DWITH_" . uc($1) . "=" . uc($2); 196 next; 197 } 198 if($option =~ /without-(.*)=(.*)/) 199 { 200 $cmakeargs = $cmakeargs. " -DWITHOUT_" . uc($1) . "=" . uc($2); 201 next; 202 } 203 if($option =~ /prefix=/) 204 { 205 $cmake_install_prefix= substr($option, 7); 206 $cmakeargs = $cmakeargs." -DCMAKE_INSTALL_PREFIX=".$cmake_install_prefix; 207 next; 208 } 209 if($option =~/bindir=/) 210 { 211 set_installdir(substr($option,7), "INSTALL_BINDIR"); 212 next; 213 } 214 if($option =~/libdir=/) 215 { 216 set_installdir(substr($option,7), "INSTALL_LIBDIR"); 217 next; 218 } 219 if($option =~/libexecdir=/) 220 { 221 set_installdir(substr($option,11), "INSTALL_SBINDIR"); 222 next; 223 } 224 if($option =~/includedir=/) 225 { 226 set_installdir(substr($option,11), "INSTALL_INCLUDEDIR"); 227 next; 228 } 229 if ($option =~ /extra-charsets=all/) 230 { 231 $cmakeargs = $cmakeargs." -DWITH_CHARSETS=all"; 232 next; 233 } 234 if ($option =~ /extra-charsets=complex/) 235 { 236 $cmakeargs = $cmakeargs." -DWITH_CHARSETS=complex"; 237 next; 238 } 239 if ($option =~ /localstatedir=/) 240 { 241 $cmakeargs = $cmakeargs." -DMYSQL_DATADIR=".substr($option,14); 242 next; 243 } 244 if ($option =~ /mysql-maintainer-mode/) 245 { 246 $cmakeargs = $cmakeargs." -DMYSQL_MAINTAINER_MODE=" . 247 ($option =~ /enable/ ? "1" : "0"); 248 next; 249 } 250 if ($option =~ /with-comment=/) 251 { 252 $cmakeargs = $cmakeargs." \"-DWITH_COMMENT=".substr($option,13)."\""; 253 next; 254 } 255 if ($option =~ /with-gcov/) 256 { 257 $cmakeargs = $cmakeargs." -DENABLE_GCOV=ON"; 258 next; 259 } 260 if ($option =~ /with-max-indexes=/) 261 { 262 $cmakeargs = $cmakeargs." -DMAX_INDEXES=".substr($option, 17); 263 next; 264 } 265 if ($option =~ /verbose/) 266 { 267 $cmakeargs = $cmakeargs." -DCMAKE_VERBOSE_MAKEFILE=1"; 268 next; 269 } 270 if ($option =~ /with-client-ldflags/) 271 { 272 print("configure.pl : ignoring $option\n"); 273 next; 274 } 275 if ($option =~ /with-mysqld-ldflags=/) 276 { 277 print("configure.pl : ignoring $option\n"); 278 next; 279 } 280 if ($option =~ /with-client-ldflags/) 281 { 282 print("configure.pl : ignoring $option\n"); 283 next; 284 } 285 if ($option =~ /with-mysqld-ldflags=/) 286 { 287 print("configure.pl : ignoring $option\n"); 288 next; 289 } 290 291 $option = uc($option); 292 $option =~ s/-/_/g; 293 $cmakeargs = $cmakeargs." -D".$option."=1"; 294} 295 296print("configure.pl : calling cmake $srcdir $cmakeargs\n"); 297exit(0) if ($just_print); 298unlink("CMakeCache.txt"); 299my $rc = system("cmake $srcdir $cmakeargs"); 300exit($rc); 301