1#!/bin/sh
2# Copyright (c) 2000, 2014, 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-1335  USA
16
17# This script reports various configuration settings that may be needed
18# when using the MariaDB client library.
19
20#
21# If we can find the given directory relatively to where mysql_config is
22# we should use this instead of the incompiled one.
23# This is to ensure that this script also works with the binary MariaDB
24# version
25
26fix_path ()
27{
28  var=$1
29  shift
30  for filename
31  do
32    path=$basedir/$filename
33    if [ -d "$path" ] ;
34    then
35      eval "$var"=$path
36      return
37    fi
38  done
39}
40
41get_full_path ()
42{
43  file=$1
44
45  # if the file is a symlink, try to resolve it
46  if [ -h $file ];
47  then
48    file=`ls -l $file | awk '{ print $NF }'`
49  fi
50
51  case $file in
52    /*) echo "$file";;
53    */*) tmp=`pwd`/$file; echo $tmp | sed -e 's;/\./;/;' ;;
54    *) command -v $file ;;
55  esac
56}
57
58me=`get_full_path $0`
59
60# Script might have been renamed but assume mysql_<something>config<something>
61basedir=`echo $me | sed -e 's;/bin/mysql_.*config.*;;'`
62
63ldata='@localstatedir@'
64execdir='@libexecdir@'
65bindir='@bindir@'
66
67# If installed, search for the compiled in directory first (might be "lib64")
68pkglibdir='@pkglibdir@'
69pkglibdir_rel=`echo $pkglibdir | sed -e "s;^$basedir/;;"`
70fix_path pkglibdir $pkglibdir_rel @libsubdir@/mysql @libsubdir@
71
72plugindir='@pkgplugindir@'
73plugindir_rel=`echo $plugindir | sed -e "s;^$basedir/;;"`
74fix_path plugindir $plugindir_rel @libsubdir@/mysql/plugin @libsubdir@/plugin
75
76pkgincludedir='@pkgincludedir@'
77fix_path pkgincludedir include/mysql
78
79version='@VERSION@'
80socket='@MYSQL_UNIX_ADDR@'
81
82if [ @MYSQL_TCP_PORT_DEFAULT@ -eq 0 ]; then
83  port=0
84else
85  port=@MYSQL_TCP_PORT@
86fi
87
88# Create options
89libs="-L$pkglibdir @RPATH_OPTION@ @LIBS_FOR_CLIENTS@"
90embedded_libs="-L$pkglibdir @RPATH_OPTION@ @EMB_LIBS_FOR_CLIENTS@"
91embedded_libs="$embedded_libs -L%%LOCALBASE%%/lib "
92
93include="-I$pkgincludedir"
94if [ "$basedir" != "/usr" ]; then
95  include="$include -I$pkgincludedir/.."
96fi
97cflags="$include @CFLAGS_FOR_CLIENTS@"
98
99mariadb_config="$basedir/bin/mariadb_config"
100if test -x "$basedir/bin/mariadb_config"; then
101  cflags=`"$mariadb_config" --cflags`
102  include=`"$mariadb_config" --include`
103  libs=`"$mariadb_config" --libs`
104  plugindir=`"$mariadb_config" --plugindir`
105  socket=`"$mariadb_config" --socket`
106  port=`"$mariadb_config" --port`
107  version=`"$mariadb_config" --version`
108fi
109
110usage () {
111        cat <<EOF
112Usage: $0 [OPTIONS]
113Options:
114        --cflags         [$cflags]
115        --include        [$include]
116        --libs           [$libs]
117        --libs_r         [$libs]
118        --plugindir      [$plugindir]
119        --socket         [$socket]
120        --port           [$port]
121        --version        [$version]
122        --libmysqld-libs [$embedded_libs]
123        --variable=VAR   VAR is one of:
124                pkgincludedir [$pkgincludedir]
125                pkglibdir     [$pkglibdir]
126                plugindir     [$plugindir]
127EOF
128  exit $1
129}
130
131if test $# -le 0; then usage 0 ; fi
132
133while test $# -gt 0; do
134        case $1 in
135        --cflags)  echo "$cflags" ;;
136        --include) echo "$include" ;;
137        --libs)    echo "$libs" ;;
138        --libs_r)  echo "$libs" ;;
139        --plugindir) echo "$plugindir" ;;
140        --socket)  echo "$socket" ;;
141        --port)    echo "$port" ;;
142        --version) echo "$version" ;;
143        --embedded-libs | --embedded | --libmysqld-libs) echo "$embedded_libs" ;;
144        --variable=*)
145          var=`echo "$1" | sed 's,^[^=]*=,,'`
146          case "$var" in
147            pkgincludedir) echo "$pkgincludedir" ;;
148            pkglibdir) echo "$pkglibdir" ;;
149            plugindir) echo "$plugindir" ;;
150            *) usage 1 >&2 ;;
151          esac
152          ;;
153        *) usage 1 >&2 ;;
154        esac
155
156        shift
157done
158
159#echo "ldata: '"$ldata"'"
160#echo "execdir: '"$execdir"'"
161#echo "bindir: '"$bindir"'"
162#echo "pkglibdir: '"$pkglibdir"'"
163#echo "pkgincludedir: '"$pkgincludedir"'"
164#echo "version: '"$version"'"
165#echo "socket: '"$socket"'"
166#echo "port: '"$port"'"
167#echo "ldflags: '"$ldflags"'"
168#echo "client_libs: '"$client_libs"'"
169
170exit 0
171