mysql_config.sh 4.58 KB
Newer Older
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/sh
# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
# 
# 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; either version 2 of the License, or
# (at your option) any later version.
# 
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# This script reports various configuration settings that may be needed
# when using the MySQL client library.

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
which ()
{
  IFS="${IFS=   }"; save_ifs="$IFS"; IFS=':'
  for file
  do
    for dir in $PATH
    do
      if test -f $dir/$file
      then
        echo "$dir/$file"
        continue 2
      fi
    done
    echo "which: no $file in ($PATH)"
    exit 1
  done
  IFS="$save_ifs"
}

40 41 42 43 44 45
#
# 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

46 47
fix_path ()
{
48 49 50 51 52 53 54 55 56 57 58
  var=$1
  shift
  for filename
  do
    path=$basedir/$filename
    if [ -d "$path" ] ;
    then
      eval "$var"=$path
      return
    fi
  done
59 60
}

61 62
get_full_path ()
{
63 64 65 66 67 68 69 70 71 72 73 74 75
  file=$1

  # if the file is a symlink, try to resolve it
  if [ -h $file ];
  then
    file=`ls -l $file | awk '{ print $NF }'`
  fi

  case $file in
    /*) echo "$file";;
    */*) tmp=`pwd`/$file; echo $tmp | sed -e 's;/\./;/;' ;;
    *) which $file ;;
  esac
76 77 78
}

me=`get_full_path $0`
79 80 81

basedir=`echo $me | sed -e 's;/bin/mysql_config;;'`

bk@work.mysql.com's avatar
bk@work.mysql.com committed
82 83 84 85
ldata='@localstatedir@'
execdir='@libexecdir@'
bindir='@bindir@'
pkglibdir='@pkglibdir@'
86
fix_path pkglibdir lib/mysql lib
bk@work.mysql.com's avatar
bk@work.mysql.com committed
87
pkgincludedir='@pkgincludedir@'
88
fix_path pkgincludedir include/mysql include
bk@work.mysql.com's avatar
bk@work.mysql.com committed
89 90 91 92 93
version='@VERSION@'
socket='@MYSQL_UNIX_ADDR@'
port='@MYSQL_TCP_PORT@'
ldflags='@LDFLAGS@'

serg@serg.mylan's avatar
serg@serg.mylan committed
94
# Create options
95

96 97
libs="$ldflags -L$pkglibdir -lmysqlclient @ZLIB_DEPS@ @NON_THREADED_LIBS@"
libs="$libs @openssl_libs@ @STATIC_NSS_FLAGS@"
98
libs=`echo "$libs" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
99 100

libs_r="$ldflags -L$pkglibdir -lmysqlclient_r @ZLIB_DEPS@ @LIBS@ @openssl_libs@"
101
libs_r=`echo "$libs_r" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
serg@serg.mylan's avatar
serg@serg.mylan committed
102
cflags="-I$pkgincludedir @CFLAGS@ " #note: end space!
103
include="-I$pkgincludedir"
104
embedded_libs="$ldflags -L$pkglibdir -lmysqld @LIBS@ @WRAPLIBS@ @innodb_system_libs@ $client_libs"
105 106 107
embedded_libs=`echo "$embedded_libs" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`

# Remove some options that a client doesn't have to care about
kent@mysql.com's avatar
kent@mysql.com committed
108 109
# FIXME until we have a --cxxflags, we need to remove -Xa
#       and -xstrconst to make --cflags usable for Sun Forte C++
serg@serg.mylan's avatar
serg@serg.mylan committed
110 111
for remove in DDBUG_OFF DSAFEMALLOC USAFEMALLOC DSAFE_MUTEX \
              DPEDANTIC_SAFEMALLOC DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS \
kent@mysql.com's avatar
kent@mysql.com committed
112 113
              DEXTRA_DEBUG DHAVE_purify 'O[0-9]' 'W[-A-Za-z]*' \
              Xa xstrconst
serg@serg.mylan's avatar
serg@serg.mylan committed
114
do
115 116
  # The first option we might strip will always have a space before it because
  # we set -I$pkgincludedir as the first option
117
  cflags=`echo "$cflags"|sed -e "s/ -$remove  */ /g"` 
serg@serg.mylan's avatar
serg@serg.mylan committed
118 119
done
cflags=`echo "$cflags"|sed -e 's/ *\$//'` 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
120 121 122 123 124

usage () {
        cat <<EOF
Usage: $0 [OPTIONS]
Options:
125
        --cflags         [$cflags]
kent@mysql.com's avatar
kent@mysql.com committed
126
        --include        [$include]
127
        --libs           [$libs]
128
        --libs_r         [$libs_r]
129 130 131
        --socket         [$socket]
        --port           [$port]
        --version        [$version]
kent@mysql.com's avatar
kent@mysql.com committed
132
        --libmysqld-libs [$embedded_libs]
bk@work.mysql.com's avatar
bk@work.mysql.com committed
133 134 135 136
EOF
        exit 1
}

137
if test $# -le 0; then usage; fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
138 139 140 141

while test $# -gt 0; do
        case $1 in
        --cflags)  echo "$cflags" ;;
kent@mysql.com's avatar
kent@mysql.com committed
142
        --include) echo "$include" ;;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
143
        --libs)    echo "$libs" ;;
144
        --libs_r)  echo "$libs_r" ;;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
145 146 147
        --socket)  echo "$socket" ;;
        --port)    echo "$port" ;;
        --version) echo "$version" ;;
kent@mysql.com's avatar
kent@mysql.com committed
148
        --embedded-libs | --embedded | --libmysqld-libs) echo "$embedded_libs" ;;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        *)         usage ;;
        esac

        shift
done

#echo "ldata: '"$ldata"'"
#echo "execdir: '"$execdir"'"
#echo "bindir: '"$bindir"'"
#echo "pkglibdir: '"$pkglibdir"'"
#echo "pkgincludedir: '"$pkgincludedir"'"
#echo "version: '"$version"'"
#echo "socket: '"$socket"'"
#echo "port: '"$port"'"
#echo "ldflags: '"$ldflags"'"
#echo "client_libs: '"$client_libs"'"

exit 0