#
# spec file for package mariadb-connector-c
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# setting for eisfair
%define _mariadb_base_dir /usr/lib/mysql/102

%define sover 3
%define libname libmariadb
# equivalent mariadb version
%define mariadb_version 10.2.21
%if ! %{defined _rundir}
%define _rundir %{_localstatedir}/run
%endif
%bcond_with sqlite3
Name:           mariadb-connector-c
Version:        3.0.9
Release:        2.1
Summary:        MariaDB connector in C
License:        LGPL-2.1-or-later
Group:          Development/Libraries/C and C++
URL:            https://github.com/MariaDB/mariadb-connector-c
Source:         https://downloads.mariadb.com/Connectors/c/connector-c-%{version}/%{name}-%{version}-src.tar.gz
Source1:        https://downloads.mariadb.com/Connectors/c/connector-c-%{version}/%{name}-%{version}-src.tar.gz.asc
# Imported from keyserver based on keyid @ https://mariadb.com/kb/en/mariadb-enterprise/mariadb-enterprise-installation-guide/
Source2:        mariadb.keyring
Source3:        baselibs.conf
Patch1:         mariadb-connector-c-2.3.1_unresolved_symbols.patch
Patch3:         absolute_path_fix.patch
Patch4:         private_library.patch
BuildRequires:  cmake
BuildRequires:  curl-devel
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(krb5)
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(zlib)
%if %{with sqlite3}
BuildRequires:  pkgconfig(sqlite3)
%endif

%description
MariaDB Connector is used to connect applications developed in
C or C++ to MariaDB and MySQL databases.

%package -n %{libname}%{sover}
Summary:        MariaDB connector in C
Group:          System/Libraries

%description -n %{libname}%{sover}
MariaDB Connector is used to connect applications developed in
C or C++ to MariaDB and MySQL databases.

This package holds the runtime components.

%package -n %{libname}_plugins
Summary:        Plugins for the MariaDB C Connector
# We need "Conflicts" because we moved some plugins here:
# dialog.so was in mariadb-client package
# mysql_clear_password.so was in mariadb package
Group:          System/Libraries
Conflicts:      mariadb <= 10.1.25
Conflicts:      mariadb-client <= 10.1.25

%description -n %{libname}_plugins
MariaDB Connector is used to connect applications developed in
C or C++ to MariaDB and MySQL databases.

This package holds MariaDB library plugins.

%package -n %{libname}private
Summary:        Additional internal libraries for the MariaDB C Connector
Group:          System/Libraries

%description -n %{libname}private
MariaDB Connector is used to connect applications developed in
C or C++ to MariaDB and MySQL databases.

This package holds the runtime components with private API.

%package -n %{libname}-devel
Summary:        Development files for the MariaDB Connector C API
Group:          Development/Libraries/C and C++
Requires:       %{libname}%{sover} = %{version}
Requires:       pkgconfig(openssl)
# mysql-devel needs to be provided as some pkgs still depend on it
Provides:       mysql-devel = %{mariadb_version}
Obsoletes:      mysql-devel < %{mariadb_version}
Provides:       libmysqlclient-devel = %{mariadb_version}
Obsoletes:      libmysqlclient-devel < %{mariadb_version}

%description -n %{libname}-devel
MariaDB Connector is used to connect applications developed in
C or C++ to MariaDB and MySQL databases.

This package holds the development files.

%prep
%setup -q -n %{name}-%{version}-src
%patch1 -p1
%patch3 -p1
%patch4 -p1

%build
%cmake \
  %if %{with sqlite3}
  -DWITH_SQLITE:BOOL=ON \
  %endif
  -DWITH_EXTERNAL_ZLIB:BOOL=ON \
  -DMARIADB_UNIX_ADDR:STRING=%{_rundir}/mysql/mysql.sock \
  -DINSTALL_LIBDIR:STRING=%{_libdir} \
  -DINSTALL_INCLUDEDIR:STRING=%{_includedir}/mysql \
  -DINSTALL_PLUGINDIR:STRING=%{_mariadb_base_dir}/plugin/ \
  -DWITH_MYSQLCOMPAT=ON \
  -DWITH_SSL=OPENSSL \
  -DINSTALL_PCDIR="%{_libdir}/pkgconfig" \
%make_jobs

%install
%cmake_install

# remove static linked libraries
rm %{buildroot}%{_libdir}/libmariadbclient.a
rm %{buildroot}%{_libdir}/libmysqlclient.a
rm %{buildroot}%{_libdir}/libmysqlclient_r.a

# add a compatibility symlink
ln -s mariadb_config %{buildroot}%{_bindir}/mysql_config
ln -s mariadb_version.h %{buildroot}%{_includedir}/mysql/mysql_version.h

# install some extra required header file
install -Dpm 0644 build/include/ma_config.h \
  %{buildroot}%{_includedir}/mysql/my_config.h

%post   -n %{libname}%{sover} -p /sbin/ldconfig
%post   -n %{libname}private -p /sbin/ldconfig
%postun -n %{libname}%{sover} -p /sbin/ldconfig
%postun -n %{libname}private -p /sbin/ldconfig

%files -n %{libname}%{sover}
%license COPYING.LIB
%doc README
%{_libdir}/libmariadb.so.%{sover}

%files -n %{libname}_plugins
%dir %{_mariadb_base_dir}
%dir %{_mariadb_base_dir}/plugin/
%{_mariadb_base_dir}/plugin/dialog.so
%{_mariadb_base_dir}/plugin/mysql_clear_password.so
%{_mariadb_base_dir}/plugin/auth_gssapi_client.so
%{_mariadb_base_dir}/plugin/remote_io.so
%{_mariadb_base_dir}/plugin/sha256_password.so
%{_mariadb_base_dir}/plugin/caching_sha2_password.so

%files -n %{libname}private
%{_libdir}/libmariadbprivate.so

%files -n %{libname}-devel
%{_bindir}/mariadb_config
%{_bindir}/mysql_config
%dir %{_includedir}/mysql
%{_includedir}/mysql/*
%{_libdir}/pkgconfig/libmariadb.pc
%{_libdir}/libmariadb.so
%{_libdir}/libmysqlclient.so
%{_libdir}/libmysqlclient_r.so

%changelog
* Fri Mar  1 2019 kstreitova@suse.com
- move libmariadb.pc from /usr/lib/pkgconfig to
  /usr/lib64/pkgconfig [bsc#1126088]
* Wed Feb 13 2019 kstreitova@suse.com
- New upstream version 3.0.9
  * CONC-384: Incorrect packet when a connection attribute name or
    value is equal to or greater than 251
  * CONC-388: field->def_length is always set to 0 (only used by
    deprecated function mysql_list_fields)
  * Getter should get and the setter should set
    CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS
  * CONC-385: Removed some cmake system checks
  * CONC-387: Fix case sensitive include file names for cross
    compiling
  * Fixed cnake policy CMP007
  * Support static linking auth plugins
  * Fix build with deprecated OpenSSL API: replaced ERR_remove_state
    by ERR_remove_thread_state
  * Disable LOAD DATA LOCAL INFILE suport by default and auto-enable
    it for the duration of one query, if the query string starts with
    the word "load". In all other cases the application should enable
    LOAD DATA LOCAL INFILE support explicitly
  * Changed return code for mysql_optionv/mysql_get_optionv to 1
    (was -1) and added CR_NOT_IMPLEMENTED error message if a option
    is unknown or not supported. This will fix possible error when
    setting connection attribute failed
* Thu Jan  3 2019 kstreitova@suse.com
- New upstream version 3.0.8
  * mingw fix: use lowercase names for include files
  * CONC-375: Fixed handshake errors when mixing TLSv1.3 cipher
    suites with cipher suites from other TLS protocols
  * CONC-312: Added new caching_sha2_password authentication plugin
    for authentication with MySQL 8.0
- refresh mariadb-connector-c-2.3.1_unresolved_symbols.patch
- pack caching_sha2_password.so plugin
* Thu Nov 15 2018 kstreitova@suse.com
- New upstream version 3.0.7 [bsc#1116686]
  * Build fixes when building with ASAN/TSAN
  * CONC-370: Fixed memory leak in configuration file parsing.
  * CONC-371: Incorrect fractional part conversion when converting
    datetime string to MYSQL_TIME
  * CONC-283: Fixed pkg-config configuration
  * CONC-364: Not all sockets created in pvio_socket_connect
    function are closed
  * multiple fixes in named pipe implementation
  * CONC-349: Added new parameter STMT_ATTR_STATE to retrieve
    statement status via api function mysql_stmt_attr_get
- refresh private_library.patch and absolute_path_fix.patch
- pack libmariadb.pc
* Thu Aug  2 2018 kstreitova@suse.com
- New upstream version 3.0.6
  * MDEV-15263: FIx IS_NUM() macro
  * CONC-297: local infile parameter must be unsigned int instead
    of my_bool
  * CONC-329: change return value of internal socket functions
    from my_bool to int
  * CONC-332: my_auth doesn't read/update server ok packet
  * CONC-344: reset internal row counter
  * CONC-345: invalid heap use after free
  * CONC-346: Remove old cmake policies
  * fixed crash in mysql_select_db if NULL parameter was provided
- refresh private_library.patch
* Fri Jun 29 2018 kstreitova@suse.com
- New upstream version 3.0.5
- 3.0.5 important changes:
  * CONC-336: Allow multiple initialization of client library
  * Fixed string to MYSQL_TIME conversion (prepared statements)
  * CONC-334: Copy all members of MYSQL_FIELD to internal
    statement structure
  * Fixed double free in dynamic column library
  * Added checks for corrupted packets in protocol
  * MDEV-15450: Added default connection attribute _server_host
  * CONC-326: fixed wrong openssl thread id callback
- 3.0.4 important changes:
  * Added option MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS for
    mysql_options()/mysql_optionsv():
  * New plugin configuration interface: The default configuration
    for a specific plugin can be specified via cmake parameter
  - DCLIENT_PLUGIN_${PLUGIN}=[DYNAMIC|STATIC|OFF].
  * Added support for linux abstract socket (MDEV-15655).
  * CONC-320: Added asynchronous/non-blocking support for
    OpenSSL and GnuTLS
  * CONC-294: Access violation in mysql_close when using
    a connection plugin.
  * MDEV-14977: If built dynamically the old_password plugin
    could not be located due to wrong filename (must be
    mysql_old_password.so instead of old_password.so).
  * CONC-315: If no default client character set was specified,
    the utf8 character set will be used by default (instead of
    setting the client character set to server character set)
  * CONC-317: Parsing of configuration file fails if key/value
    pairs contain white spaces.
  * CONC-322: Correct handling of EAGAIN and EINPROGRESS in
    internal_connect (socket) for non windows platforms.
  * CONC-323: mariadb_stmt_execute_direct hangs forever if
    compression used.
  * CONC-324: Wrong codepage numbers for some collations.
  * CONC-326: ssl_thread_init() uses wrong openssl threadid
    callback
- refresh the following patches:
  * mariadb-connector-c-2.3.1_unresolved_symbols.patch
  * absolute_path_fix.patch
  * private_library.patch
* Fri Jun 29 2018 adam.majer@suse.de
- Drop libmysqlclient_r Provides from the -devel package.
  (bsc#1097938)
* Thu Apr 19 2018 kstreitova@suse.com
- New upstream version 3.0.3
  * Added support for new utf8mb4 character sets
  * MDEV-9059: Bundle first command with authentication packet
  * Build: support static OpenSSL on Windows
  * MDEV-14101: Add support for tls-version, via
    mysql_options(mysql, MARIADB_OPT_TLS_VERSION, value),
    where value must be "TLSv1.1", "TLSv1.2" or "TLSv1.3".
  * CONC-275: New indicator type STMT_INDICATOR_IGNORE_ROW for
    skipping particular parameter set in bulk operation
    (prepared statements).
  * MDEV-10361: Don't try to reconnect twice if mysql_ping failed.
  * Build fix for TSAN build with Clang
  * CONC-302: Fix output of mariadb_config
  * CONC-301: In case of a truncation the statement status was not
    updated correctly and further calls to mysql_stmt_fetch_column
    failed
  * MDEV-14647: Fixed crash when client receives extended ok packet
    with SESSION_TRACK_STATE_CHANGE information flag
  * CONC-297: setting MYSQL_OPT_LOCAL_INFILE failed on big endian
    systems.
  * MDEV-14514: mariadb_config returned wrong exit code when
    specifying an invalid option
  * MDEV-11546: Fixed timeout problem in Schannel
  * CONC-277: Allow reinitialization of the library if
    mysql_server_end() was called.
  * CONC-292: Fixed malloc result check in dynamic columns
  * MDEV-14165: The metadata length value for a column with a
    zerofill flag was calculated with a fixed length instead of using
    the reported length.
  * CONC-286: Force TLS/SSL usage if fingerprint parameters were
    specified.
  * CONC-282: Connector/C now provides additional information for
    package version
  * mariadb_config --cc_version lists the package version
  * Beside MARIADB_PACKAGE_VERSION numeric representation
    MARIADB_PACKAGE_VERSION_ID can be used now within preprocessor
    directives.
  * MDEV-13959: Fixed duplicate if condition in dynamic columns
  * Added MARIADB_BASE_VERSION definition in mariadb_version.h to
    distnguish MARIADB from MySQL
  * CONC-271: installation layout fix for RPM
- refresh the following patches:
  * absolute_path_fix.patch
  * private_library.patch
- drop 0334aa48.patch that is no longer needed
- use %%license instead of %%doc [bsc#1082318]
* Sun Nov 19 2017 mpluskal@suse.com
- Use more cmake macros
- Run spec-cleaner
* Fri Nov 17 2017 adam.majer@suse.de
- 0334aa48.patch: Backported implementation and testcase for
  skipping particular paramset in bulk operation/. This is needed
  to get current stable MariaDB connector/ODBC actually compilable.
* Mon Nov 13 2017 mpluskal@suse.com
- Install missing header (bsc#1067904)
* Thu Nov  2 2017 kstreitova@suse.com
- mariadb-connector-c is now a provider of the libmariadb library
  for mariadb and others
- add compatibility symlinks
- change LIBDIR, INCLUDEDIR and PLUGINDIR paths to be the same as
  it was in the mariadb package (compatibility reasons)
- add baselibs.conf
- add %%{mariadb_version} macro that should correspond with the
  current version of the mariadb package
- refresh absolute_path_fix.patch and private_library.patch
* Fri Sep 29 2017 kstreitova@suse.com
- move libraries to %%{_libdir}/mariadb/ to avoid a conflict
* Thu Sep 14 2017 kstreitova@suse.com
- add README and COPYING.LIB to %%doc
* Tue Aug 22 2017 kstreitova@suse.com
- New upstream version 3.0.2
  * Array support for prepared statements (bulk operations)
  * TLS/SSL support for GnuTLS, Windows SChannel and LibreSSL
  * Support for passphrase protected keys
  * SHA256 authentication plugin
- refreshed
  * mariadb-connector-c-2.3.1_unresolved_symbols.patch
  * absolute_path_fix.patch
  * private_library.patch
- change sover from 2 to 3
- tweak build options
  * DMYSQL_UNIX_ADDR is now DMARIADB_UNIX_ADDR
  * DPLUGIN_INSTALL_DIR is now DINSTALL_PLUGINDIR
  * add DINSTALL_LIBDIR, WITH_MYSQLCOMPAT and DWITH_SSL
- now we build also the following plugins:
  * auth_gssapi_client.so
  * remote_io.so
  * sha256_password.so
- move libmysqlclient* libraries to %%{_libdir}
* Tue Aug  8 2017 jengelh@inai.de
- Fix RPM groups once more.
* Thu Jul 13 2017 adam.majer@suse.de
- New upstream version 2.3.3:
  * Fixed build for big-endian platforms. Obsoletes
    bigendian_type_fixes.patch
  * Changed parameter type for parameter reconnect in
    mysql_optionsv from uint to my_bool
- absolute_path_fix.patch: refreshed
* Thu Jul 13 2017 olaf@aepfle.de
- Remove unused gnutls from buildrequires
* Mon Apr  3 2017 jengelh@inai.de
- Update descriptions and RPM groups
* Wed Mar 29 2017 adam.majer@suse.de
- Set proper MySQL socket path for localhost connections
* Thu Mar 23 2017 adam.majer@suse.de
- Update to version 2.3.2
  * Plugin API interface change: Changed the interface of
    authentication plugins, allowing plugins from C/C 3.0
    (like GSSAPI/Kerberos plugin)
  * CONC-205: Any field going after a TEXT field in the selecion
    list is fetched incorrectly (prepared statements)
  * CONC-198: Can't use more than one statement per connection
  * CONC-223: Add client support for missing collations
  * MDEV-10894: big endian conversion
  * fixed packet_length in dialog plugin
  * fixed include of my_stmt.h
  * fixed wrong behavior of read_timeout
  * fixed timeout for non-blocking operations
  * fixed output for plugindir in mariadb_config
  * removed extra check for non binary result types in fetch_bin
    (prepared statements)
- mariadb.keyring: add MariaDB Enterprise signing key
- bigendian_type_fixes.patch: fix build failure on Big endien
- absolute_path_fix.patch:
  * remove ugly paths in mariadb_config
  * list correct include paths
- private_library.patch: shared library with exported private
  symbols in place of a static library
- mariadb-connector-c-2.3.1_unresolved_symbols.patch: add missing
  library to link requirements.
* Mon Aug 22 2016 mrueckert@suse.de
- initial package