#!/usr/bin/perl
# -*- cperl -*-
#
# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##############################################################################
#
# This script reports various configuration settings that may be needed
# when using the MySQL client library.
#
# This script try to match the shell script version as close as possible,
# but in addition being compatible with ActiveState Perl on Windows.
#
# All unrecognized arguments to this script are passed to mysqld.
#
# NOTE: This script will only be used on Windows until solved how to
# handle ws2_32 and other strings inserted that might contain
# several arguments, possibly with spaces in them.
#
# NOTE: This script was deliberately written to be as close to the shell
# script as possible, to make the maintenance of both in parallel
# easier.
#
##############################################################################
use File::Basename;
use Getopt::Long;
use Cwd;
use strict;
my @exclude_cflags =
qw/DDBUG_OFF DSAFE_MUTEX DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS
DEXTRA_DEBUG DHAVE_purify O O[0-9] xO[0-9] W[-A-Za-z]*
Xa xstrconst xc99=none
unroll2 ip mp restrict/;
my @exclude_libs = qw/lmtmalloc static-libcxa i-static static-intel/;
my $cwd = cwd();
my $basedir;
my $socket = '/tmp/mysql.sock';
my $version = '5.5.22';
sub which
{
my $file = shift;
my $IFS = $^O eq "MSWin32" ? ";" : ":";
foreach my $dir ( split($IFS, $ENV{PATH}) )
{
if ( -f "$dir/$file" or -f "$dir/$file.exe" )
{
return "$dir/$file";
}
}
print STDERR "which: no $file in ($ENV{PATH})
";
exit 1;
}
# ----------------------------------------------------------------------
# If we can find the given directory relatively to where mysql_config is
# we should use this instead of the incompiled one.
# This is to ensure that this script also works with the binary MySQL
# version
# ----------------------------------------------------------------------
sub fix_path
{
my $default = shift;
my @dirs = @_;
foreach my $dirname ( @dirs )
{
my $path = "$basedir/$dirname";
if ( -d $path )
{
return $path;
}
}
return $default;
}
sub get_full_path
{
my $file = shift;
# if the file is a symlink, try to resolve it
if ( $^O ne "MSWin32" and -l $file )
{
$file = readlink($file);
}
if ( $file =~ m,^/, )
{
# Do nothing, absolute path
}
elsif ( $file =~ m,/, )
{
# Make absolute, and remove "/./" in path
$file = "$cwd/$file";
$file =~ s,/./,/,g;
}
else
{
# Find in PATH
$file = which($file);
}
return $file;
}
##############################################################################
#
# Form a command line that can handle spaces in paths and arguments
#
##############################################################################
sub quote_options {
my @cmd;
foreach my $opt ( @_ )
{
next unless $opt; # If undefined or empty, just skip
push(@cmd, ""$opt""); # Quote argument
}
return join(" ", @cmd);
}
##############################################################################
#
# Main program
#
##############################################################################
my $me = get_full_path($0);
$basedir = dirname(dirname($me)); # Remove "/bin/mysql_config" part
my $ldata = 'C:/Program Files/MySQL/MySQL Server 5.5/data';
my $execdir = 'C:/Program Files (x86)/MySQL/bin';
my $bindir = 'C:/Program Files (x86)/MySQL/bin';
# ----------------------------------------------------------------------
# If installed, search for the compiled in directory first (might be "lib64")
# ----------------------------------------------------------------------
my $pkglibdir = fix_path('C:/Program Files (x86)/MySQL/lib',"libmysql/relwithdebinfo",
"libmysql/release","libmysql/debug","lib/mysql","lib");
my $pkgincludedir = fix_path('C:/Program Files (x86)/MySQL/include', "include/mysql", "include");
# Assume no argument with space in it
my @ldflags = split(" ",'');
my $port;
if ( '0' == 0 ) {
$port = 0;
} else {
$port = '3306';
}
# ----------------------------------------------------------------------
# Create options
# We intentionally add a space to the beginning and end of lib strings, simplifies replace later
# ----------------------------------------------------------------------
my (@lib_opts,@lib_r_opts,@lib_e_opts);
if ( $^O eq "MSWin32" )
{
my $linkpath = "$pkglibdir";
# user32 is only needed for debug or embedded
my @winlibs = ("wsock32.lib","advapi32.lib","user32.lib");
@lib_opts = ("$linkpath/mysqlclient.lib",@winlibs);
@lib_r_opts = @lib_opts;
@lib_e_opts = ("$linkpath/mysqlserver.lib",@winlibs);
}
else
{
my $linkpath = "-L$pkglibdir";
@lib_opts = ($linkpath,"-lmysqlclient");
@lib_r_opts = ($linkpath,"-lmysqlclient_r");
@lib_e_opts = ($linkpath,"-lmysqld");
}
my $flags;
$flags->{libs} =
[@ldflags,@lib_opts,'','ws2_32 Secur32 ','',''];
$flags->{libs_r} =
[@ldflags,@lib_r_opts,'','ws2_32 ',''];
$flags->{embedded_libs} =
[@ldflags,@lib_e_opts,'','','ws2_32 ','',''];
$flags->{include} = ["-I$pkgincludedir"];
$flags->{cflags} = [@{$flags->{include}},split(" ",'/MT /Zi /O2 /Ob1 /D NDEBUG -DDBUG_OFF')];
# ----------------------------------------------------------------------
# Remove some options that a client doesn't have to care about
# FIXME until we have a --cxxflags, we need to remove -Xa
# and -xstrconst to make --cflags usable for Sun Forte C++
# ----------------------------------------------------------------------
my $filter = join("|", @exclude_cflags);
my @tmp = @{$flags->{cflags}}; # Copy the flag list
$flags->{cflags} = []; # Clear it
foreach my $cflag ( @tmp )
{
push(@{$flags->{cflags}}, $cflag) unless $cflag =~ m/^($filter)$/o;
}
# Same for --libs(_r)
$filter = join("|", @exclude_libs);
foreach my $lib_type ( "libs","libs_r","embedded_libs" )
{
my @tmp = @{$flags->{$lib_type}}; # Copy the flag list
$flags->{$lib_type} = []; # Clear it
foreach my $lib ( @tmp )
{
push(@{$flags->{$lib_type}}, $lib) unless $lib =~ m/^($filter)$/o;
}
}
my $include = quote_options(@{$flags->{include}});
my $cflags = quote_options(@{$flags->{cflags}});
my $libs = quote_options(@{$flags->{libs}});
my $libs_r = quote_options(@{$flags->{libs_r}});
my $embedded_libs = quote_options(@{$flags->{embedded_libs}});
##############################################################################
#
# Usage information, output if no option is given
#
##############################################################################
sub usage
{
print sub { print "$include
" },
"libs" => sub { print "$libs
" },
"libs_r" => sub { print "$libs_r
" },
"socket" => sub { print "$socket
" },
"port" => sub { print "$port
" },
"version" => sub { print "$version
" },
"embedded-libs|embedded|libmysqld-libs" =>
sub { print "$embedded_libs
" },
) or usage();
exit 0
#! / ระบบควบคุมเวอร์ชัน/ช่อง/ภาษาเพิร์ล#- * - cperl- * -## ลิขสิทธิ์ (c) 2007, 2010, Oracle และ/หรือบริษัทในเครือ สงวนลิขสิทธิ์ทั้งหมด## โปรแกรมนี้เป็นโปรแกรมซอฟต์แวร์ฟรี คุณสามารถเผยแพร่ซ้ำ และ/หรือปรับเปลี่ยน#ได้ภายใต้เงื่อนไขการอนุญาตตามที่เผยแพร่โดยสาธารณะทั่วไปของกนู#มูลนิธิซอฟต์แวร์ฟรี รุ่น 2 ใบอนุญาต## โปรแกรมกระจายในหวังว่า มันจะเป็นประโยชน์#แต่ไม่มีการรับประกันใด ๆ ไม่ มีแม้แต่การรับประกันโดยนัยของ# สินค้าหรือออกกำลังกายสำหรับวัตถุประสงค์เฉพาะ ดู# สัญญาอนุญาตสาธารณะทั่วไป GNU สำหรับรายละเอียดเพิ่มเติม## คุณควรได้รับสำเนาของสัญญาอนุญาตสาธารณะทั่วไปของกนูใน#กับโปรแกรมนี้ ถ้า ไม่ เขียนซอฟต์แวร์ฟรี# มูลนิธิ Inc., 51 เซนต์แฟรงคลิน 5 ชั้น Boston, MA 02110-1301 สหรัฐอเมริกา################################################################################ สคริปต์รายงานค่าต่าง ๆ ที่อาจมีความจำเป็น#เมื่อใช้ไลบรารีของไคลเอ็นต์ MySQL## ลองนี้สคริปต์ให้ตรงกับรุ่นใกล้เคียงที่สุด สคริปต์เชลล์#แต่นอกจากนี้ มีการเข้ากันได้กับภาษาเพิร์ล ActiveState บน Windows## ทั้งหมดละเลยจัดการอาร์กิวเมนต์สคริปต์นี้จะผ่านไป mysqld## หมายเหตุ: สคริปต์นี้จะใช้ได้เฉพาะกับ Windows จนกว่าแก้ไขวิธีการ#หมายเลขอ้างอิง ws2_32 และสายอักขระอื่นแทรกที่อาจประกอบด้วย#หลายอาร์กิวเมนต์ อาจ มีช่องว่างในการ## หมายเหตุ: สคริปต์นี้ได้ตั้งใจเขียนให้ใกล้เคียงกับ shell#สคริปต์เป็น เพื่อให้การรักษาทั้งสองอย่างควบคู่กัน#ได้ง่ายขึ้น###############################################################################ใช้ File::Basenameใช้ Getopt::Longใช้ Cwdใช้เข้มงวด@exclude_cflags ของฉัน = qw DSAFE_MUTEX DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS DDBUG_OFF เวียดโซ DEXTRA_DEBUG DHAVE_purify O O [0-9] [0-9] W [ซดีซา ---z] * Xa xstrconst xc99 =ไม่มี unroll2 ip mp จำกัด /;@exclude_libs ของฉัน = qw/lmtmalloc คง libcxa i-คงสถิต-intel /;$cwd ของฉัน = cwd()$basedir ของฉัน$socket ของฉัน = ' / tmp/mysql.sock';$version ของฉัน = '5.5.22'ย่อยซึ่ง{ $file ของฉัน =กะ $IFS ของฉัน = $^ O eq "MSWin32" ";" : ":"; foreach $dir ของฉัน (แยก ($IFS, $ENV {พาธ})) { ถ้า (-f " $dir/$file " หรือ -f "$dir/$file.exe") { กลับ " $dir/$file "; } } พิมพ์ STDERR "ซึ่ง: ไม่ $file ใน ($ENV {พาธ})
"; ออก 1}# ----------------------------------------------------------------------#ถ้าเราสามารถค้นหาไดเรกทอรีที่กำหนดค่อนข้างจะอยู่ที่ mysql_config#เราควรใช้นี้แทนของ incompiled หนึ่ง# นี่คือเพื่อให้แน่ใจว่า สคริปต์นี้ยังทำงานร่วมกับ MySQL แบบไบนารีรุ่น## ----------------------------------------------------------------------fix_path ย่อย{ $default ของฉัน =กะ @dirs ของฉัน =@_; foreach $dirname ของฉัน (@dirs) { $path ของฉัน = " $basedir/$dirname "; ถ้า (-d $path) { $path กลับ } } $default กลับ}get_full_path ย่อย{ $file ของฉัน =กะ #ถ้าแฟ้ม symlink พยายามที่จะแก้ไข ถ้า ($^ O ne "MSWin32" และ -l $file) { $file = readlink($file) } ถ้า ($file = ~ m, ^ /,) { # อะไร เส้นทางแบบสัมบูรณ์ } elsif ($file = ~ m, /,) { ทำแน่นอน และเอา " / . / " ในเส้นทาง $file = " $cwd/$file "; $file = ~ s, / /, /, g } อื่น { # ค้นหาในเส้นทาง $file = which($file) } $file กลับ}################################################################################ แบบบรรทัดคำสั่งที่สามารถจัดการกับช่องว่างในเส้นทางและอาร์กิวเมนต์###############################################################################{quote_options ย่อย @cmd ของฉัน foreach (@_) $opt ของฉัน { ถัดไปเว้นแต่ $opt # ถ้าไม่ได้กำหนด หรือเปล่า เพียงข้าม ผลักดัน (@cmd, ""$opt""); # อาร์กิวเมนต์อ้างอิง } กลับเข้าร่วม ("", @cmd);}################################################################################ หลักโปรแกรม###############################################################################$me ของฉัน = get_full_path($0)$basedir = dirname(dirname($me)) # เอาส่วน"ช่อง/mysql_config"$ldata ของฉัน = ' C: / โปรแกรม แฟ้ม/MySQL/MySQL Server 5.5/ข้อมูล ';$execdir ของฉัน = ' C: / แฟ้มโปรแกรม (x 86) / MySQL/ช่อง ';$bindir ของฉัน = ' C: / แฟ้มโปรแกรม (x 86) / MySQL/ช่อง ';# ----------------------------------------------------------------------# ถ้าติดตั้ง ค้นหาไดเรกทอรีที่คอมไพล์ในครั้งแรก (อาจจะ "lib64")# ----------------------------------------------------------------------$pkglibdir ของฉัน = fix_path('C:/Program Files (x86)/MySQL/lib "," libmysql/relwithdebinfo" "ปล่อย libmysql" "บัก libmysql" "lib/mysql", "lib");$pkgincludedir ของฉัน = fix_path('C:/Program Files (x86)/MySQL/รวม "," รวม/mysql" "รวม");# รับอาร์กิวเมนต์ไม่ มีพื้นที่ใน@ldflags ของฉัน =แยก (" );$port ของฉันถ้า ('0' == 0) { $port = 0} {อื่น $port = '3306'}# ----------------------------------------------------------------------# สร้างตัวเลือก #เราตั้งใจให้เว้นวรรคเพื่อเริ่มต้นและจุดสิ้นสุดของสตริงการ lib ช่วยให้ง่ายแทนที่ในภายหลัง# ----------------------------------------------------------------------ฉัน (@lib_opts, @lib_r_opts, @lib_e_opts);ถ้า ($^ O eq "MSWin32"){ $linkpath ของฉัน = "$pkglibdir" # user32 เท่าที่จำเป็นสำหรับการดีบัก หรือฝังตัว @winlibs ของฉัน = ("wsock32.lib","advapi32.lib","user32.lib"); @lib_opts = ("$linkpath/mysqlclient.lib",@winlibs); @lib_r_opts = @lib_opts @lib_e_opts = ("$linkpath/mysqlserver.lib",@winlibs);}อื่น{ $linkpath ของฉัน = "-L$ pkglibdir "; @lib_opts = ($linkpath, "-lmysqlclient "); @lib_r_opts = ($linkpath, "-lmysqlclient_r "); @lib_e_opts = ($linkpath, "-lmysqld ");}$flags ของฉัน$flags -> {libs } = [@ldflags, @lib_opts นิ้ว 'ws2_32 Secur32' ];$flags -> {libs_r } = [@ldflags, @lib_r_opts นิ้ว 'ws2_32' ];$flags -> {embedded_libs } = [@ldflags, @lib_e_opts นิ้ว นิ้ว 'ws2_32' ];$flags -> {รวม} = ["-ฉัน $pkgincludedir "];$flags -> {cflags } = [@{ $flags -> {รวม} }, แบ่ง ("", " /MT /Zi /O2 /Ob1 /D NDEBUG-DDBUG_OFF')];# ----------------------------------------------------------------------# ลบตัวเลือกบางตัวที่ลูกค้าไม่ต้องสนใจ# FIXME จนกว่าเรามี - cxxflags ที่เราต้องการเอาออก - Xa# และ - xstrconst เพื่อให้ - cflags ใช้ c ++แดดฟอร์เต้# ----------------------------------------------------------------------$filter ของฉัน =รวม (" | ", @exclude_cflags);@tmp ของฉัน = @{$flags -> {cflags } }; # สำเนารายการสถานะ$flags -> {cflags } =[]; #ยกเลิกเลือกforeach $cflag ของฉัน (@tmp){ ผลักดัน (@{$flags -> {cflags } }, $cflag) นอกจาก $cflag = ~ m / ^ /o$ ($filter)}# เหมือนกัน--libs(_r)$filter =รวม (" | ", @exclude_libs);foreach $lib_type ของฉัน ("libs", "libs_r", "embedded_libs"){ @tmp ของฉัน = @{$flags -> {$lib_type } }; # สำเนารายการสถานะ $flags -> {$lib_type } =[]; #ยกเลิกเลือก foreach $lib ของฉัน (@tmp) { ผลักดัน (@{$flags -> {$lib_type } }, $lib) นอกจาก $lib = ~ m / ^ /o$ ($filter) }}$include ของฉัน = quote_options (@{ $flags -> {รวม} });$cflags ของฉัน = quote_options (@{$flags -> {cflags } });$libs ของฉัน = quote_options (@{$flags -> {libs } });$libs_r ของฉัน = quote_options (@{$flags -> {libs_r } });$embedded_libs ของฉัน = quote_options (@{$flags -> {embedded_libs } });################################################################################ การใช้ข้อมูล แสดงผลถ้าเลือกไม่ได้###############################################################################ใช้ย่อย{ พิมพ์ <การใช้งาน: $0 [เลือก]ตัวเลือก: -cflags [$cflags] -รวม [$include] -libs [$libs] -libs_r [$libs_r] -ซ็อกเก็ต [$socket] -พอร์ต [$port] -รุ่น [$version] -libmysqld-libs [$embedded_libs]EOF ออก 1}@ARGV หรือ usage()################################################################################ รับตัวเลือก และแสดงผลค่า###############################################################################GetOptions ( "cflags" = > ย่อย {พิมพ์ "$cflags
" }, "รวม" = > ย่อย {พิมพ์ "$include
" }, "libs" = > ย่อย {พิมพ์ "$libs
" }, "libs_r" = > ย่อย {พิมพ์ "$libs_r
" }, "หนวด" = > ย่อย {พิมพ์ "$socket
" }, "พอร์ต" = > ย่อย {พิมพ์ "$port
" }, "รุ่น" = > ย่อย {พิมพ์ "$version
" }, "ฝัง-libs|embedded|libmysqld-libs" = > ย่อย {พิมพ์ "$embedded_libs
" }, ) หรือ usage()ออกจาก 0
การแปล กรุณารอสักครู่..
