##
##  myodbc.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_major 5.1
%define       V_minor 6

#   package information
Name:         myodbc
Summary:      MySQL ODBC Driver
URL:          http://www.mysql.com/products/connector/odbc/
Vendor:       MySQL AB
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      GPL
Version:      %{V_major}.%{V_minor}
Release:      20091110

#   list of sources
Source0:      http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-ODBC/%{V_major}/mysql-connector-odbc-%{version}.tar.gz
Patch0:       myodbc.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  mysql, ODBC
PreReq:       mysql, ODBC

%description
    MyODBC is the MySQL ODBC driver.

%track
    prog myodbc = {
        version   = %{version}
        url       = http://dev.mysql.com/downloads/connector/odbc/
        regex     = mysql-connector-odbc-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n mysql-connector-odbc-%{V_major}.%{V_minor}
    %patch -p0

%build
    options=""
    case "`(odbc_config --odbcini) 2>&1`" in
        */unixodbc/* )
            options="$options --with-unixODBC=%{l_prefix}"
            options="$options --with-unixODBC-libs=%{l_prefix}/lib"
            options="$options --with-unixODBC-includes=%{l_prefix}/include"
            ;;
        * )
            options="$options --with-iODBC=%{l_prefix}"
            options="$options --with-iODBC-libs=%{l_prefix}/lib"
            options="$options --with-iODBC-includes=%{l_prefix}/include"
            ;;
    esac
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    LDFLAGS="-lm" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/myodbc \
        --libdir=%{l_prefix}/lib/myodbc \
        --with-mysql-path=%{l_prefix} \
        --disable-thread-safe \
        --disable-gui \
        --without-x \
        --enable-shared \
        --disable-static \
        $options
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install \
        prefix=$RPM_BUILD_ROOT%{l_prefix} \
        exec_prefix=$RPM_BUILD_ROOT%{l_prefix} \
        sysconfdir=$RPM_BUILD_ROOT%{l_prefix}/etc/myodbc \
        libdir=$RPM_BUILD_ROOT%{l_prefix}/lib/myodbc
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        #   optionally link into ODBC
        ( echo "[MySQL]"
          echo "Description     = MySQL ODBC Driver"
          echo "Driver          = $RPM_INSTALL_PREFIX/lib/libmyodbc3.so"
        ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -n "MySQL" -r >/dev/null 2>&1 || true
    fi
    exit 0

%preun
    if [ $1 -eq 0 ]; then
        #   optionally unlink from ODBC
        $RPM_INSTALL_PREFIX/bin/odbcinst -u -d -n "MySQL" >/dev/null 2>&1 || true
    fi
    exit 0

