|
| 1 | +#!/usr/bin/perl |
| 2 | +# -*- cperl -*- |
| 3 | +# |
| 4 | +# Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation; version 2 of the License. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with this program; if not, write to the Free Software |
| 17 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + |
| 19 | +############################################################################## |
| 20 | +# |
| 21 | +# This script reports various configuration settings that may be needed |
| 22 | +# when using the MySQL client library. |
| 23 | +# |
| 24 | +# This script try to match the shell script version as close as possible, |
| 25 | +# but in addition being compatible with ActiveState Perl on Windows. |
| 26 | +# |
| 27 | +# All unrecognized arguments to this script are passed to mysqld. |
| 28 | +# |
| 29 | +# NOTE: This script will only be used on Windows until solved how to |
| 30 | +# handle -lpthread -lm -lcrypt -ldl -laio and other strings inserted that might contain |
| 31 | +# several arguments, possibly with spaces in them. |
| 32 | +# |
| 33 | +# NOTE: This script was deliberately written to be as close to the shell |
| 34 | +# script as possible, to make the maintenance of both in parallel |
| 35 | +# easier. |
| 36 | +# |
| 37 | +############################################################################## |
| 38 | + |
| 39 | +use File::Basename; |
| 40 | +use Getopt::Long; |
| 41 | +use Cwd; |
| 42 | +use strict; |
| 43 | + |
| 44 | +my @exclude_cflags = |
| 45 | + qw/DDBUG_OFF DSAFE_MUTEX DFORCE_INIT_OF_VARS |
| 46 | + DEXTRA_DEBUG DHAVE_purify O O[0-9] xO[0-9] W[-A-Za-z]* |
| 47 | + unroll2 ip mp restrict/; |
| 48 | + |
| 49 | +my @exclude_libs = qw/lmtmalloc static-libcxa i-static static-intel/; |
| 50 | + |
| 51 | +my $cwd = cwd(); |
| 52 | +my $basedir; |
| 53 | + |
| 54 | +my $socket = '/tmp/mysql.sock'; |
| 55 | +my $version = '5.6.31'; |
| 56 | + |
| 57 | +sub which |
| 58 | +{ |
| 59 | + my $file = shift; |
| 60 | + |
| 61 | + my $IFS = $^O eq "MSWin32" ? ";" : ":"; |
| 62 | + |
| 63 | + foreach my $dir ( split($IFS, $ENV{PATH}) ) |
| 64 | + { |
| 65 | + if ( -f "$dir/$file" or -f "$dir/$file.exe" ) |
| 66 | + { |
| 67 | + return "$dir/$file"; |
| 68 | + } |
| 69 | + } |
| 70 | + print STDERR "which: no $file in ($ENV{PATH})\n"; |
| 71 | + exit 1; |
| 72 | +} |
| 73 | + |
| 74 | +# ---------------------------------------------------------------------- |
| 75 | +# If we can find the given directory relatively to where mysql_config is |
| 76 | +# we should use this instead of the incompiled one. |
| 77 | +# This is to ensure that this script also works with the binary MySQL |
| 78 | +# version |
| 79 | +# ---------------------------------------------------------------------- |
| 80 | + |
| 81 | +sub fix_path |
| 82 | +{ |
| 83 | + my $default = shift; |
| 84 | + my @dirs = @_; |
| 85 | + |
| 86 | + foreach my $dirname ( @dirs ) |
| 87 | + { |
| 88 | + my $path = "$basedir/$dirname"; |
| 89 | + if ( -d $path ) |
| 90 | + { |
| 91 | + return $path; |
| 92 | + } |
| 93 | + } |
| 94 | + return $default; |
| 95 | +} |
| 96 | + |
| 97 | +sub get_full_path |
| 98 | +{ |
| 99 | + my $file = shift; |
| 100 | + |
| 101 | + # if the file is a symlink, try to resolve it |
| 102 | + if ( $^O ne "MSWin32" and -l $file ) |
| 103 | + { |
| 104 | + $file = readlink($file); |
| 105 | + } |
| 106 | + |
| 107 | + if ( $file =~ m,^/, ) |
| 108 | + { |
| 109 | + # Do nothing, absolute path |
| 110 | + } |
| 111 | + elsif ( $file =~ m,/, ) |
| 112 | + { |
| 113 | + # Make absolute, and remove "/./" in path |
| 114 | + $file = "$cwd/$file"; |
| 115 | + $file =~ s,/\./,/,g; |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + # Find in PATH |
| 120 | + $file = which($file); |
| 121 | + } |
| 122 | + |
| 123 | + return $file; |
| 124 | +} |
| 125 | + |
| 126 | +############################################################################## |
| 127 | +# |
| 128 | +# Form a command line that can handle spaces in paths and arguments |
| 129 | +# |
| 130 | +############################################################################## |
| 131 | + |
| 132 | +sub quote_options { |
| 133 | + my @cmd; |
| 134 | + foreach my $opt ( @_ ) |
| 135 | + { |
| 136 | + next unless $opt; # If undefined or empty, just skip |
| 137 | + push(@cmd, "\"$opt\""); # Quote argument |
| 138 | + } |
| 139 | + return join(" ", @cmd); |
| 140 | +} |
| 141 | + |
| 142 | +############################################################################## |
| 143 | +# |
| 144 | +# Main program |
| 145 | +# |
| 146 | +############################################################################## |
| 147 | + |
| 148 | +my $me = get_full_path($0); |
| 149 | +$basedir = dirname(dirname($me)); # Remove "/bin/mysql_config" part |
| 150 | + |
| 151 | +my $ldata = '/home/som/comp_test/data'; |
| 152 | +my $execdir = '/home/som/comp_test/bin'; |
| 153 | +my $bindir = '/home/som/comp_test/bin'; |
| 154 | + |
| 155 | +# ---------------------------------------------------------------------- |
| 156 | +# If installed, search for the compiled in directory first (might be "lib64") |
| 157 | +# ---------------------------------------------------------------------- |
| 158 | + |
| 159 | +my $pkglibdir = fix_path('/home/som/comp_test/lib',"libmysql/relwithdebinfo", |
| 160 | + "libmysql/release","libmysql/debug","lib/mysql","lib"); |
| 161 | + |
| 162 | +my $pkgincludedir = fix_path('/home/som/comp_test/include', "include/mysql", "include"); |
| 163 | + |
| 164 | +# Assume no argument with space in it |
| 165 | +my @ldflags = split(" ",''); |
| 166 | + |
| 167 | +my $port; |
| 168 | +if ( '0' == 0 ) { |
| 169 | + $port = 0; |
| 170 | +} else { |
| 171 | + $port = '3306'; |
| 172 | +} |
| 173 | + |
| 174 | +# ---------------------------------------------------------------------- |
| 175 | +# Create options |
| 176 | +# We intentionally add a space to the beginning and end of lib strings, simplifies replace later |
| 177 | +# ---------------------------------------------------------------------- |
| 178 | + |
| 179 | +my (@lib_opts,@lib_r_opts,@lib_e_opts); |
| 180 | +if ( $^O eq "MSWin32" ) |
| 181 | +{ |
| 182 | + my $linkpath = "$pkglibdir"; |
| 183 | + # user32 is only needed for debug or embedded |
| 184 | + my @winlibs = ("wsock32.lib","advapi32.lib","user32.lib"); |
| 185 | + @lib_opts = ("$linkpath/mysqlclient.lib",@winlibs); |
| 186 | + @lib_r_opts = @lib_opts; |
| 187 | + @lib_e_opts = ("$linkpath/mysqlserver.lib",@winlibs); |
| 188 | +} |
| 189 | +else |
| 190 | +{ |
| 191 | + my $linkpath = "-L$pkglibdir "; |
| 192 | + @lib_opts = ($linkpath,"-lmysqlclient"); |
| 193 | + @lib_r_opts = ($linkpath,"-lmysqlclient_r"); |
| 194 | + @lib_e_opts = ($linkpath,"-lmysqld"); |
| 195 | +} |
| 196 | + |
| 197 | +my $flags; |
| 198 | +$flags->{libs} = |
| 199 | + [@ldflags,@lib_opts,'',' -lpthread -lm -ldl ','','']; |
| 200 | +$flags->{libs_r} = |
| 201 | + [@ldflags,@lib_r_opts,'',' -lpthread -lm -lcrypt -ldl -laio ','']; |
| 202 | +$flags->{embedded_libs} = |
| 203 | + [@ldflags,@lib_e_opts,'','',' -lpthread -lm -lcrypt -ldl -laio ','','']; |
| 204 | + |
| 205 | +$flags->{include} = ["-I$pkgincludedir"]; |
| 206 | +$flags->{cflags} = [@{$flags->{include}},split(" ",' -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF')]; |
| 207 | +$flags->{cxxflags}= [@{$flags->{include}},split(" ",' -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF')]; |
| 208 | + |
| 209 | +# ---------------------------------------------------------------------- |
| 210 | +# Remove some options that a client doesn't have to care about |
| 211 | +# ---------------------------------------------------------------------- |
| 212 | + |
| 213 | +my $filter = join("|", @exclude_cflags); |
| 214 | +my @tmp = @{$flags->{cflags}}; # Copy the flag list |
| 215 | +$flags->{cflags} = []; # Clear it |
| 216 | +foreach my $cflag ( @tmp ) |
| 217 | +{ |
| 218 | + push(@{$flags->{cflags}}, $cflag) unless $cflag =~ m/^($filter)$/o; |
| 219 | +} |
| 220 | +@tmp = @{$flags->{cxxflags}}; # Copy the flag list |
| 221 | +$flags->{cxxflags} = []; # Clear it |
| 222 | +foreach my $cxxflag ( @tmp ) |
| 223 | +{ |
| 224 | + push(@{$flags->{cxxflags}}, $cxxflag) unless $cxxflag =~ m/^($filter)$/o; |
| 225 | +} |
| 226 | + |
| 227 | +# Same for --libs(_r) |
| 228 | +$filter = join("|", @exclude_libs); |
| 229 | +foreach my $lib_type ( "libs","libs_r","embedded_libs" ) |
| 230 | +{ |
| 231 | + my @tmp = @{$flags->{$lib_type}}; # Copy the flag list |
| 232 | + $flags->{$lib_type} = []; # Clear it |
| 233 | + foreach my $lib ( @tmp ) |
| 234 | + { |
| 235 | + push(@{$flags->{$lib_type}}, $lib) unless $lib =~ m/^($filter)$/o; |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +my $include = quote_options(@{$flags->{include}}); |
| 240 | +my $cflags = quote_options(@{$flags->{cflags}}); |
| 241 | +my $cxxflags= quote_options(@{$flags->{cxxflags}}); |
| 242 | +my $libs = quote_options(@{$flags->{libs}}); |
| 243 | +my $libs_r = quote_options(@{$flags->{libs_r}}); |
| 244 | +my $embedded_libs = quote_options(@{$flags->{embedded_libs}}); |
| 245 | + |
| 246 | +############################################################################## |
| 247 | +# |
| 248 | +# Usage information, output if no option is given |
| 249 | +# |
| 250 | +############################################################################## |
| 251 | + |
| 252 | +sub usage |
| 253 | +{ |
| 254 | + print <<EOF; |
| 255 | +Usage: $0 [OPTIONS] |
| 256 | +Options: |
| 257 | + --cflags [$cflags] |
| 258 | + --cxxflags [$cxxflags] |
| 259 | + --include [$include] |
| 260 | + --libs [$libs] |
| 261 | + --libs_r [$libs_r] |
| 262 | + --socket [$socket] |
| 263 | + --port [$port] |
| 264 | + --version [$version] |
| 265 | + --libmysqld-libs [$embedded_libs] |
| 266 | +EOF |
| 267 | + exit 1; |
| 268 | +} |
| 269 | + |
| 270 | +@ARGV or usage(); |
| 271 | + |
| 272 | +############################################################################## |
| 273 | +# |
| 274 | +# Get options and output the values |
| 275 | +# |
| 276 | +############################################################################## |
| 277 | + |
| 278 | +GetOptions( |
| 279 | + "cflags" => sub { print "$cflags\n" }, |
| 280 | + "cxxflags"=> sub { print "$cxxflags\n" }, |
| 281 | + "include" => sub { print "$include\n" }, |
| 282 | + "libs" => sub { print "$libs\n" }, |
| 283 | + "libs_r" => sub { print "$libs_r\n" }, |
| 284 | + "socket" => sub { print "$socket\n" }, |
| 285 | + "port" => sub { print "$port\n" }, |
| 286 | + "version" => sub { print "$version\n" }, |
| 287 | + "embedded-libs|embedded|libmysqld-libs" => |
| 288 | + sub { print "$embedded_libs\n" }, |
| 289 | + ) or usage(); |
| 290 | + |
| 291 | +exit 0 |
0 commit comments