mysql_config 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/bin/sh
  2. # Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; version 2 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. # This script reports various configuration settings that may be needed
  17. # when using the MySQL client library.
  18. which ()
  19. {
  20. IFS="${IFS= }"; save_ifs="$IFS"; IFS=':'
  21. for file
  22. do
  23. for dir in $PATH
  24. do
  25. if test -f $dir/$file
  26. then
  27. echo "$dir/$file"
  28. continue 2
  29. fi
  30. done
  31. echo "which: no $file in ($PATH)"
  32. exit 1
  33. done
  34. IFS="$save_ifs"
  35. }
  36. #
  37. # If we can find the given directory relatively to where mysql_config is
  38. # we should use this instead of the incompiled one.
  39. # This is to ensure that this script also works with the binary MySQL
  40. # version
  41. fix_path ()
  42. {
  43. var=$1
  44. shift
  45. for filename
  46. do
  47. path=$basedir/$filename
  48. if [ -d "$path" ] ;
  49. then
  50. eval "$var"=$path
  51. return
  52. fi
  53. done
  54. }
  55. get_full_path ()
  56. {
  57. file=$1
  58. # if the file is a symlink, try to resolve it
  59. if [ -h $file ];
  60. then
  61. file=`ls -l $file | awk '{ print $NF }'`
  62. fi
  63. case $file in
  64. /*) echo "$file";;
  65. */*) tmp=`pwd`/$file; echo $tmp | sed -e 's;/\./;/;' ;;
  66. *) which $file ;;
  67. esac
  68. }
  69. me=`get_full_path $0`
  70. # Script might have been renamed but assume mysql_<something>config<something>
  71. basedir=`echo $me | sed -e 's;/bin/mysql_.*config.*;;'`
  72. ldata='/var/lib/mysql'
  73. execdir='/usr/sbin'
  74. bindir='/usr/bin'
  75. # If installed, search for the compiled in directory first (might be "lib64")
  76. pkglibdir='/usr/lib/x86_64-linux-gnu'
  77. pkglibdir_rel=`echo $pkglibdir | sed -e "s;^$basedir/;;"`
  78. fix_path pkglibdir $pkglibdir_rel lib/x86_64-linux-gnu/mysql lib/x86_64-linux-gnu
  79. plugindir='/usr/lib/mysql/plugin'
  80. plugindir_rel=`echo $plugindir | sed -e "s;^$basedir/;;"`
  81. fix_path plugindir $plugindir_rel lib/x86_64-linux-gnu/mysql/plugin lib/x86_64-linux-gnu/plugin
  82. pkgincludedir='/usr/include/mysql'
  83. if [ -f "$basedir/include/mysql/mysql.h" ]; then
  84. pkgincludedir="$basedir/include/mysql"
  85. elif [ -f "$basedir/include/mysql.h" ]; then
  86. pkgincludedir="$basedir/include"
  87. fi
  88. version='5.6.30'
  89. socket='/var/run/mysqld/mysqld.sock'
  90. ldflags=''
  91. if [ 0 -eq 0 ]; then
  92. port=0
  93. else
  94. port=3306
  95. fi
  96. # Create options
  97. # We intentionally add a space to the beginning and end of lib strings, simplifies replace later
  98. libs=" $ldflags -L$pkglibdir -lmysqlclient -lpthread -lz -lm -ldl "
  99. libs="$libs "
  100. libs="$libs "
  101. libs_r=" $ldflags -L$pkglibdir -lmysqlclient -lpthread -lz -lm -ldl "
  102. libs_r="$libs_r "
  103. embedded_libs=" $ldflags -L$pkglibdir -lmysqld -lpthread -lz -lm -lwrap -lcrypt -ldl -laio "
  104. embedded_libs="$embedded_libs "
  105. cflags="-I$pkgincludedir -g -O2 -Wformat -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF " #note: end space!
  106. cxxflags="-I$pkgincludedir -g -O2 -Wformat -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF " #note: end space!
  107. include="-I$pkgincludedir"
  108. # Remove some options that a client doesn't have to care about
  109. for remove in DDBUG_OFF DSAFE_MUTEX DFORCE_INIT_OF_VARS \
  110. DEXTRA_DEBUG DHAVE_purify O 'O[0-9]' 'xO[0-9]' 'W[-A-Za-z]*' \
  111. 'mtune=[-A-Za-z0-9]*' 'mcpu=[-A-Za-z0-9]*' 'march=[-A-Za-z0-9]*' \
  112. unroll2 ip mp restrict
  113. do
  114. # The first option we might strip will always have a space before it because
  115. # we set -I$pkgincludedir as the first option
  116. cflags=`echo "$cflags"|sed -e "s/ -$remove */ /g"`
  117. cxxflags=`echo "$cxxflags"|sed -e "s/ -$remove */ /g"`
  118. done
  119. cflags=`echo "$cflags"|sed -e 's/ *\$//'`
  120. cxxflags=`echo "$cxxflags"|sed -e 's/ *\$//'`
  121. # Same for --libs(_r)
  122. for remove in lmtmalloc static-libcxa i-static static-intel
  123. do
  124. # We know the strings starts with a space
  125. libs=`echo "$libs"|sed -e "s/ -$remove */ /g"`
  126. libs_r=`echo "$libs_r"|sed -e "s/ -$remove */ /g"`
  127. embedded_libs=`echo "$embedded_libs"|sed -e "s/ -$remove */ /g"`
  128. done
  129. # Strip trailing and ending space if any, and '+' (FIXME why?)
  130. libs=`echo "$libs" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
  131. libs_r=`echo "$libs_r" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
  132. embedded_libs=`echo "$embedded_libs" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
  133. usage () {
  134. cat <<EOF
  135. Usage: $0 [OPTIONS]
  136. Options:
  137. --cflags [$cflags]
  138. --cxxflags [$cxxflags]
  139. --include [$include]
  140. --libs [$libs]
  141. --libs_r [$libs_r]
  142. --plugindir [$plugindir]
  143. --socket [$socket]
  144. --port [$port]
  145. --version [$version]
  146. --libmysqld-libs [$embedded_libs]
  147. --variable=VAR VAR is one of:
  148. pkgincludedir [$pkgincludedir]
  149. pkglibdir [$pkglibdir]
  150. plugindir [$plugindir]
  151. EOF
  152. exit 1
  153. }
  154. if test $# -le 0; then usage; fi
  155. while test $# -gt 0; do
  156. case $1 in
  157. --cflags) echo "$cflags" ;;
  158. --cxxflags)echo "$cxxflags";;
  159. --include) echo "$include" ;;
  160. --libs) echo "$libs" ;;
  161. --libs_r) echo "$libs_r" ;;
  162. --plugindir) echo "$plugindir" ;;
  163. --socket) echo "$socket" ;;
  164. --port) echo "$port" ;;
  165. --version) echo "$version" ;;
  166. --embedded-libs | --embedded | --libmysqld-libs) echo "$embedded_libs" ;;
  167. --variable=*)
  168. var=`echo "$1" | sed 's,^[^=]*=,,'`
  169. case "$var" in
  170. pkgincludedir) echo "$pkgincludedir" ;;
  171. pkglibdir) echo "$pkglibdir" ;;
  172. plugindir) echo "$plugindir" ;;
  173. *) usage ;;
  174. esac
  175. ;;
  176. *) usage ;;
  177. esac
  178. shift
  179. done
  180. #echo "ldata: '"$ldata"'"
  181. #echo "execdir: '"$execdir"'"
  182. #echo "bindir: '"$bindir"'"
  183. #echo "pkglibdir: '"$pkglibdir"'"
  184. #echo "pkgincludedir: '"$pkgincludedir"'"
  185. #echo "version: '"$version"'"
  186. #echo "socket: '"$socket"'"
  187. #echo "port: '"$port"'"
  188. #echo "ldflags: '"$ldflags"'"
  189. #echo "client_libs: '"$client_libs"'"
  190. exit 0