mysql_config.pl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #!/usr/bin/perl
  2. # -*- cperl -*-
  3. #
  4. # Copyright (c) 2007, 2017, 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. # This script reports various configuration settings that may be needed
  21. # when using the MySQL client library.
  22. #
  23. # This script try to match the shell script version as close as possible,
  24. # but in addition being compatible with ActiveState Perl on Windows.
  25. #
  26. # All unrecognized arguments to this script are passed to mysqld.
  27. #
  28. # NOTE: This script will only be used on Windows until solved how to
  29. # handle and other strings inserted that might contain
  30. # several arguments, possibly with spaces in them.
  31. #
  32. # NOTE: This script was deliberately written to be as close to the shell
  33. # script as possible, to make the maintenance of both in parallel
  34. # easier.
  35. #
  36. ##############################################################################
  37. use File::Basename;
  38. use Getopt::Long;
  39. use Cwd;
  40. use strict;
  41. my $cwd = cwd();
  42. my $basedir;
  43. my $socket = '/tmp/mysql.sock';
  44. my $version = '5.7.26';
  45. sub which
  46. {
  47. my $file = shift;
  48. my $IFS = $^O eq "MSWin32" ? ";" : ":";
  49. foreach my $dir ( split($IFS, $ENV{PATH}) )
  50. {
  51. if ( -f "$dir/$file" or -f "$dir/$file.exe" )
  52. {
  53. return "$dir/$file";
  54. }
  55. }
  56. print STDERR "which: no $file in ($ENV{PATH})\n";
  57. exit 1;
  58. }
  59. # ----------------------------------------------------------------------
  60. # If we can find the given directory relatively to where mysql_config is
  61. # we should use this instead of the incompiled one.
  62. # This is to ensure that this script also works with the binary MySQL
  63. # version
  64. # ----------------------------------------------------------------------
  65. sub fix_path
  66. {
  67. my $default = shift;
  68. my @dirs = @_;
  69. foreach my $dirname ( @dirs )
  70. {
  71. my $path = "$basedir/$dirname";
  72. if ( -d $path )
  73. {
  74. return $path;
  75. }
  76. }
  77. return $default;
  78. }
  79. sub get_full_path
  80. {
  81. my $file = shift;
  82. # if the file is a symlink, try to resolve it
  83. if ( $^O ne "MSWin32" and -l $file )
  84. {
  85. $file = readlink($file);
  86. }
  87. if ( $file =~ m,^/, )
  88. {
  89. # Do nothing, absolute path
  90. }
  91. elsif ( $file =~ m,/, )
  92. {
  93. # Make absolute, and remove "/./" in path
  94. $file = "$cwd/$file";
  95. $file =~ s,/\./,/,g;
  96. }
  97. else
  98. {
  99. # Find in PATH
  100. $file = which($file);
  101. }
  102. return $file;
  103. }
  104. ##############################################################################
  105. #
  106. # Form a command line that can handle spaces in paths and arguments
  107. #
  108. ##############################################################################
  109. sub quote_options {
  110. my @cmd;
  111. foreach my $opt ( @_ )
  112. {
  113. next unless $opt; # If undefined or empty, just skip
  114. push(@cmd, "\"$opt\""); # Quote argument
  115. }
  116. return join(" ", @cmd);
  117. }
  118. ##############################################################################
  119. #
  120. # Main program
  121. #
  122. ##############################################################################
  123. my $me = get_full_path($0);
  124. $basedir = dirname(dirname($me)); # Remove "/bin/mysql_config" part
  125. my $ldata = 'C:/Program Files/MySQL/MySQL Server 5.7/data';
  126. my $execdir = 'C:/Program Files/MySQL/bin';
  127. my $bindir = 'C:/Program Files/MySQL/bin';
  128. # ----------------------------------------------------------------------
  129. # If installed, search for the compiled in directory first (might be "lib64")
  130. # ----------------------------------------------------------------------
  131. my $pkglibdir = fix_path('C:/Program Files/MySQL/lib',"libmysql/relwithdebinfo",
  132. "libmysql/release","libmysql/debug","lib/mysql","lib");
  133. my $pkgincludedir = fix_path('C:/Program Files/MySQL/include', "include/mysql", "include");
  134. # Assume no argument with space in it
  135. my @ldflags = split(" ",'');
  136. my $port;
  137. if ( '0' == 0 ) {
  138. $port = 0;
  139. } else {
  140. $port = '3306';
  141. }
  142. # ----------------------------------------------------------------------
  143. # Create options
  144. # ----------------------------------------------------------------------
  145. my(@lib_opts,@lib_e_opts);
  146. if ( $^O eq "MSWin32" )
  147. {
  148. my $linkpath = "$pkglibdir";
  149. @lib_opts = ("$linkpath/LIBMYSQL_OS_OUTPUT_NAME-NOTFOUND");
  150. @lib_e_opts = ("$linkpath/mysqlserver");
  151. }
  152. else
  153. {
  154. my $linkpath = "-L$pkglibdir";
  155. @lib_opts = ($linkpath,"-lLIBMYSQL_OS_OUTPUT_NAME-NOTFOUND");
  156. @lib_e_opts = ($linkpath,"-lmysqlserver");
  157. }
  158. my $flags;
  159. $flags->{libs} = [@lib_opts, qw(ws2_32 Secur32)];
  160. $flags->{embedded_libs} = [@lib_e_opts, qw(ws2_32)];
  161. $flags->{include} = ["-I$pkgincludedir"];
  162. $flags->{cflags} = [@{$flags->{include}},split(" ",'')];
  163. $flags->{cxxflags}= [@{$flags->{include}},split(" ",'')];
  164. my $include = quote_options(@{$flags->{include}});
  165. my $cflags = quote_options(@{$flags->{cflags}});
  166. my $cxxflags= quote_options(@{$flags->{cxxflags}});
  167. my $libs = quote_options(@{$flags->{libs}});
  168. my $embedded_libs = quote_options(@{$flags->{embedded_libs}});
  169. ##############################################################################
  170. #
  171. # Usage information, output if no option is given
  172. #
  173. ##############################################################################
  174. sub usage
  175. {
  176. print <<EOF;
  177. Usage: $0 [OPTIONS]
  178. Options:
  179. --cflags [$cflags]
  180. --cxxflags [$cxxflags]
  181. --include [$include]
  182. --libs [$libs]
  183. --libs_r [$libs]
  184. --socket [$socket]
  185. --port [$port]
  186. --version [$version]
  187. --libmysqld-libs [$embedded_libs]
  188. EOF
  189. exit 1;
  190. }
  191. @ARGV or usage();
  192. ##############################################################################
  193. #
  194. # Get options and output the values
  195. #
  196. ##############################################################################
  197. GetOptions(
  198. "cflags" => sub { print "$cflags\n" },
  199. "cxxflags"=> sub { print "$cxxflags\n" },
  200. "include" => sub { print "$include\n" },
  201. "libs" => sub { print "$libs\n" },
  202. "libs_r" => sub { print "$libs\n" },
  203. "socket" => sub { print "$socket\n" },
  204. "port" => sub { print "$port\n" },
  205. "version" => sub { print "$version\n" },
  206. "embedded-libs|embedded|libmysqld-libs" =>
  207. sub { print "$embedded_libs\n" },
  208. ) or usage();
  209. exit 0