~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to scripts/mysql_config.pl.in

  • Committer: Brian Aker
  • Date: 2008-07-08 21:36:11 UTC
  • mfrom: (77.1.34 codestyle)
  • Revision ID: brian@tangent.org-20080708213611-b0k2zy8eldttqct3
Merging up Monty's changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
# -*- cperl -*-
3
 
#
4
 
# Copyright (C) 2007 MySQL AB
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 @LIBS@ 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 DSAFEMALLOC USAFEMALLOC DSAFE_MUTEX
46
 
     DPEDANTIC_SAFEMALLOC DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS
47
 
     DEXTRA_DEBUG DHAVE_purify O O[0-9] xO[0-9] W[-A-Za-z]*
48
 
     Xa xstrconst xc99=none
49
 
     unroll2 ip mp restrict/;
50
 
 
51
 
my @exclude_libs = qw/lmtmalloc static-libcxa i-static static-intel/;
52
 
 
53
 
my $cwd = cwd();
54
 
my $basedir;
55
 
 
56
 
my $socket  = '@MYSQL_UNIX_ADDR@';
57
 
my $version = '@VERSION@';
58
 
 
59
 
sub which
60
 
{
61
 
  my $file = shift;
62
 
 
63
 
  my $IFS = $^O eq "MSWin32" ? ";" : ":";
64
 
 
65
 
  foreach my $dir ( split($IFS, $ENV{PATH}) )
66
 
  {
67
 
    if ( -f "$dir/$file" or -f "$dir/$file.exe" )
68
 
    {
69
 
      return "$dir/$file";
70
 
    }
71
 
  }
72
 
  print STDERR "which: no $file in ($ENV{PATH})\n";
73
 
  exit 1;
74
 
}
75
 
 
76
 
# ----------------------------------------------------------------------
77
 
# If we can find the given directory relatively to where mysql_config is
78
 
# we should use this instead of the incompiled one.
79
 
# This is to ensure that this script also works with the binary MySQL
80
 
# version
81
 
# ----------------------------------------------------------------------
82
 
 
83
 
sub fix_path
84
 
{
85
 
  my $default = shift;
86
 
  my @dirs = @_;
87
 
 
88
 
  foreach my $dirname ( @dirs )
89
 
  {
90
 
    my $path = "$basedir/$dirname";
91
 
    if ( -d $path )
92
 
    {
93
 
      return $path;
94
 
    }
95
 
  }
96
 
  return $default;
97
 
}
98
 
 
99
 
sub get_full_path
100
 
{
101
 
  my $file = shift;
102
 
 
103
 
  # if the file is a symlink, try to resolve it
104
 
  if ( $^O ne "MSWin32" and -l $file )
105
 
  {
106
 
    $file = readlink($file);
107
 
  }
108
 
 
109
 
  if ( $file =~ m,^/, )
110
 
  {
111
 
    # Do nothing, absolute path
112
 
  }
113
 
  elsif ( $file =~ m,/, )
114
 
  {
115
 
    # Make absolute, and remove "/./" in path
116
 
    $file = "$cwd/$file";
117
 
    $file =~ s,/\./,/,g;
118
 
  }
119
 
  else
120
 
  {
121
 
    # Find in PATH
122
 
    $file = which($file);
123
 
  }
124
 
 
125
 
  return $file;
126
 
}
127
 
 
128
 
##############################################################################
129
 
#
130
 
#  Form a command line that can handle spaces in paths and arguments
131
 
#
132
 
##############################################################################
133
 
 
134
 
sub quote_options {
135
 
  my @cmd;
136
 
  foreach my $opt ( @_ )
137
 
  {
138
 
    next unless $opt;           # If undefined or empty, just skip
139
 
    push(@cmd, "\"$opt\"");       # Quote argument
140
 
  }
141
 
  return join(" ", @cmd);
142
 
}
143
 
 
144
 
##############################################################################
145
 
#
146
 
#  Main program
147
 
#
148
 
##############################################################################
149
 
 
150
 
my $me = get_full_path($0);
151
 
$basedir = dirname(dirname($me)); # Remove "/bin/mysql_config" part
152
 
 
153
 
my $ldata   = '@localstatedir@';
154
 
my $execdir = '@libexecdir@';
155
 
my $bindir  = '@bindir@';
156
 
 
157
 
# ----------------------------------------------------------------------
158
 
# If installed, search for the compiled in directory first (might be "lib64")
159
 
# ----------------------------------------------------------------------
160
 
 
161
 
my $pkglibdir = fix_path('@pkglibdir@',"libmysql/relwithdebinfo",
162
 
                         "libmysql/release","libmysql/debug","lib/mysql","lib");
163
 
 
164
 
my $pkgincludedir = fix_path('@pkgincludedir@', "include/mysql", "include");
165
 
 
166
 
# Assume no argument with space in it
167
 
my @ldflags = split(" ",'@LDFLAGS@');
168
 
 
169
 
my $port;
170
 
if ( '@MYSQL_TCP_PORT_DEFAULT@' == 0 ) {
171
 
  $port = 0;
172
 
} else {
173
 
  $port = '@MYSQL_TCP_PORT@';
174
 
}
175
 
 
176
 
# ----------------------------------------------------------------------
177
 
# Create options 
178
 
# We intentionally add a space to the beginning and end of lib strings, simplifies replace later
179
 
# ----------------------------------------------------------------------
180
 
 
181
 
my (@lib_opts,@lib_r_opts,@lib_e_opts);
182
 
if ( $^O eq "MSWin32" )
183
 
{
184
 
  my $linkpath   = "$pkglibdir";
185
 
  # user32 is only needed for debug or embedded
186
 
  my @winlibs = ("wsock32.lib","advapi32.lib","user32.lib");
187
 
  @lib_opts   = ("$linkpath/mysqlclient.lib",@winlibs);
188
 
  @lib_r_opts = @lib_opts;
189
 
  @lib_e_opts = ("$linkpath/mysqlserver.lib",@winlibs);
190
 
}
191
 
else
192
 
{
193
 
  my $linkpath   = "-L$pkglibdir";
194
 
  @lib_opts   = ($linkpath,"-lmysqlclient");
195
 
  @lib_r_opts = ($linkpath,"-lmysqlclient_r");
196
 
  @lib_e_opts = ($linkpath,"-lmysqld");
197
 
}
198
 
 
199
 
my $flags;
200
 
$flags->{libs} =
201
 
  [@ldflags,@lib_opts,'@openssl_libs@','@STATIC_NSS_FLAGS@'];
202
 
$flags->{libs_r} =
203
 
  [@ldflags,@lib_r_opts,'@LIBS@','@openssl_libs@'];
204
 
$flags->{embedded_libs} =
205
 
  [@ldflags,@lib_e_opts,'@LIBS@','@WRAPLIBS@','@innodb_system_libs@','@openssl_libs@'];
206
 
 
207
 
$flags->{include} = ["-I$pkgincludedir"];
208
 
$flags->{cflags}  = [@{$flags->{include}},split(" ",'@CFLAGS@')];
209
 
 
210
 
# ----------------------------------------------------------------------
211
 
# Remove some options that a client doesn't have to care about
212
 
# FIXME until we have a --cxxflags, we need to remove -Xa
213
 
#       and -xstrconst to make --cflags usable for Sun Forte C++
214
 
# ----------------------------------------------------------------------
215
 
 
216
 
my $filter = join("|", @exclude_cflags);
217
 
my @tmp = @{$flags->{cflags}};          # Copy the flag list
218
 
$flags->{cflags} = [];                  # Clear it
219
 
foreach my $cflag ( @tmp )
220
 
{
221
 
  push(@{$flags->{cflags}}, $cflag) unless $cflag =~ m/^($filter)$/o;
222
 
}
223
 
 
224
 
# Same for --libs(_r)
225
 
$filter = join("|", @exclude_libs);
226
 
foreach my $lib_type ( "libs","libs_r","embedded_libs" )
227
 
{
228
 
  my @tmp = @{$flags->{$lib_type}};          # Copy the flag list
229
 
  $flags->{$lib_type} = [];                  # Clear it
230
 
  foreach my $lib ( @tmp )
231
 
  {
232
 
    push(@{$flags->{$lib_type}}, $lib) unless $lib =~ m/^($filter)$/o;
233
 
  }
234
 
}
235
 
 
236
 
my $include =       quote_options(@{$flags->{include}});
237
 
my $cflags  =       quote_options(@{$flags->{cflags}});
238
 
my $libs    =       quote_options(@{$flags->{libs}});
239
 
my $libs_r  =       quote_options(@{$flags->{libs_r}});
240
 
my $embedded_libs = quote_options(@{$flags->{embedded_libs}});
241
 
 
242
 
##############################################################################
243
 
#
244
 
#  Usage information, output if no option is given
245
 
#
246
 
##############################################################################
247
 
 
248
 
sub usage
249
 
{
250
 
  print <<EOF;
251
 
Usage: $0 [OPTIONS]
252
 
Options:
253
 
        --cflags         [$cflags]
254
 
        --include        [$include]
255
 
        --libs           [$libs]
256
 
        --libs_r         [$libs_r]
257
 
        --socket         [$socket]
258
 
        --port           [$port]
259
 
        --version        [$version]
260
 
        --libmysqld-libs [$embedded_libs]
261
 
EOF
262
 
  exit 1;
263
 
}
264
 
 
265
 
@ARGV or usage();
266
 
 
267
 
##############################################################################
268
 
#
269
 
#  Get options and output the values
270
 
#
271
 
##############################################################################
272
 
 
273
 
GetOptions(
274
 
           "cflags"  => sub { print "$cflags\n" },
275
 
           "include" => sub { print "$include\n" },
276
 
           "libs"    => sub { print "$libs\n" },
277
 
           "libs_r"  => sub { print "$libs_r\n" },
278
 
           "socket"  => sub { print "$socket\n" },
279
 
           "port"    => sub { print "$port\n" },
280
 
           "version" => sub { print "$version\n" },
281
 
           "embedded-libs|embedded|libmysqld-libs" =>
282
 
             sub { print "$embedded_libs\n" },
283
 
           ) or usage();
284
 
 
285
 
exit 0