%define __libtoolize true
%define vine26 0

%define kde 1
# disable -kde subpackage on Vine Linux 2.5,2.6/alpha
%if %{vine26}
%ifarch alpha
%define kde 0
%endif
%endif

Summary: A complete ODBC Driver Manager for Linux
Name: unixODBC
Version: 2.2.12
Release: 1%{?_dist_release}
License: LGPL
Group: System Environment/Libraries
Source: http://www.unixODBC.org/%{name}-%{version}.tar.gz
Source1: odbcinst.ini
Source2: ODBCConfig.desktop
Source3: DataManager.desktop

Patch1: unixODBC-2.2.11-symbols.patch
Patch2: nortldglobal.patch
Patch100: unixODBC-2.2.5-backslash-typo.patch
URL: http://www.unixODBC.org/
Conflicts: iodbc

BuildRoot: %{_tmppath}/%{name}-%{version}-root
%if %{vine26}
BuildRequires: autoconf253 automake15
%else
BuildRequires: autoconf >= 2.53
BuildRequires: automake >= 1.5
%endif
%if %{kde}
BuildRequires: kdelibs-devel
BuildRequires: qt-devel
BuildRequires: libmng-devel
%endif

%description
The unixODBC Project goals are to develop and promote unixODBC to
be the definitive standard for ODBC on the Linux platform. This is to
include GUI support for KDE.

Install unixODBC if you'd like to access databases through ODBC. This
package include drivers for PostgreSQL and local files.

If you want to develop programs that will access data through ODBC,
you'll also need to have the unixODBC package installed.

%package devel
Summary: Development files for programs which will use the unixODBC library.
Group: Development/Libraries
Requires: unixODBC = %{version}

%description devel
Install unixODBC if you'd like to access databases through ODBC drivers.

If you want to develop programs that will access data through ODBC, 
you'll also need to install the unixODBC-devel (this) package.

%package kde
Summary: KDE DriverManager components for ODBC
Group: System Environment/Libraries
Requires: unixODBC = %{version}
#Requires: XFree86-libs qt freetype2 libjpeg libmng libpng zlib

%description kde
Components for the ODBCConfig and DataManager (KDE) Components of unixODBC.

%prep
%setup -q

%patch1 -p1

# 2.2.8 includes a libtool that is too old for some of our architectures.
# Blow it away and replace with build system's libtool.  (We intend to use
# the installed libtool anyway, but this makes sure they match.)
rm -rf config.guess config.sub ltmain.sh libltdl
cp -r /usr/share/libtool/* .

# Use newer install-sh and mkinstalldirs, too
if [ -f libltdl/install-sh ]; then
  cp -f libltdl/install-sh .
fi
if [ -f libltdl/mkinstalldirs ]; then
  cp -f libltdl/mkinstalldirs .
fi

# libltdl patch has to be applied after the above
%patch2 -p1

%build
%if %{vine26}
[ -x /usr/bin/autoconf-2.5? ] && ln -s /usr/bin/autoconf-2.5? autoconf
[ -x /usr/bin/autoheader-2.5? ] && ln -s /usr/bin/autoheader-2.5? autoheader
[ -x /usr/bin/aclocal-1.5 ] && ln -s /usr/bin/aclocal-1.5 aclocal
[ -x /usr/bin/automake-1.5 ] && ln -s /usr/bin/automake-1.5 automake
export PATH=`pwd`:$PATH
%endif

%if %{kde}
# pick up qt path
export QTDIR=
. /etc/profile.d/qt.sh
%endif

aclocal
automake --add-missing
autoconf
pushd libltdl
aclocal
automake
autoconf
popd

%configure --with-gnu-ld=yes --enable-threads=yes --enable-gui=yes --enable-static=yes --enable-drivers
make all

%install
%if %{kde}
# pick up qt path
unset QTDIR || : ; . /etc/profile.d/qt.sh
%endif

rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/X11/applnk/System
mkdir -p $RPM_BUILD_ROOT%{_datadir}/icons

%makeinstall
cp %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}
#cp DataManager/LinuxODBC.xpm $RPM_BUILD_ROOT%{_datadir}/icons
#cp odbcinstQ/smallLinuxODBC.xpm $RPM_BUILD_ROOT%{_datadir}/icons

#install -m755 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/X11/applnk/System
#install -m755 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/X11/applnk/System

rm -f $RPM_BUILD_ROOT%{_libdir}/lib*.la

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%if %{kde}
%post kde -p /sbin/ldconfig

%postun kde -p /sbin/ldconfig
%endif

%files
%defattr(-,root,root)
%doc README COPYING AUTHORS ChangeLog NEWS INSTALL doc
%config(noreplace) %{_sysconfdir}/odbc*
%{_bindir}/dltest
%{_bindir}/isql
%{_bindir}/iusql
%{_bindir}/odbcinst
%{_libdir}/libboundparam.so.*
%{_libdir}/libesoobS.so.*
%{_libdir}/libgtrtst.so.*
%{_libdir}/libmimerS.so.*
%{_libdir}/libnn.so.*
%{_libdir}/libodbc.so.*
%{_libdir}/libodbccr.so.*
%{_libdir}/libodbcdrvcfg1S.so.*
%{_libdir}/libodbcdrvcfg2S.so.*
#%{_libdir}/libodbcextras.so.*
%{_libdir}/libodbcinst.so.*
%{_libdir}/libodbcminiS.so.*
%{_libdir}/libodbcmyS.so.*
%{_libdir}/libodbcnnS.so.*
%{_libdir}/libodbcpsql.so.*
%{_libdir}/libodbcpsqlS.so.*
%{_libdir}/libodbctxt.so.*
%{_libdir}/libodbctxtS.so.*
%{_libdir}/liboplodbcS.so.*
%{_libdir}/liboraodbcS.so.*
%{_libdir}/libsapdbS.so.*
%{_libdir}/libtdsS.so.*
%{_libdir}/libtemplate.so.*

%files devel
%defattr(-,root,root)
%{_bindir}/odbc_config
%{_includedir}/*
%{_libdir}/libboundparam.so
%{_libdir}/libesoobS.so
%{_libdir}/libgtrtst.so
%{_libdir}/libmimerS.so
%{_libdir}/libnn.so
%{_libdir}/libodbc.so
%{_libdir}/libodbccr.so
%{_libdir}/libodbcdrvcfg1S.so
%{_libdir}/libodbcdrvcfg2S.so
#%{_libdir}/libodbcextras.so
%{_libdir}/libodbcinst.so
%{_libdir}/libodbcminiS.so
%{_libdir}/libodbcmyS.so
%{_libdir}/libodbcnnS.so
%{_libdir}/libodbcpsql.so
%{_libdir}/libodbcpsqlS.so
%{_libdir}/libodbctxt.so
%{_libdir}/libodbctxtS.so
%{_libdir}/liboplodbcS.so
%{_libdir}/liboraodbcS.so
%{_libdir}/libsapdbS.so
%{_libdir}/libtdsS.so
%{_libdir}/libtemplate.so
%{_libdir}/*.a
#{_libdir}/*.la

%if %{kde}
%files kde
%defattr(-,root,root)
%{_bindir}/DataManager
%{_bindir}/DataManagerII
%{_bindir}/ODBCConfig
%{_bindir}/odbctest
%{_libdir}/libodbcinstQ.so*
#%{_sysconfdir}/X11/applnk/System/*
%endif

%changelog
* Sat Sep 20 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.2.12-1
- applied new versioning policy
- removed *.la files from devel package

* Sun Sep 02 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.2.12-0vl1
- updated to 2.2.12
- rebuilt with new toolchain

* Thu Sep 07 2006 NAKAMURA Kenta <kenta@vinelinux.org> 2.2.11-0vl3
- use installed libltdl
- added unixODBC-2.2.11-symbols.patch and nortldglobal.patch

* Sat Apr 29 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.2.11-0vl2
- rebuilt with readline 5.1

* Wed Aug 24 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.2.11-0vl1
- updated to 2.2.11
- not libtoolize

* Sat Sep 27 2003 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.2.5-0vl2
- added Patch100 to fix typo in doc/Makefile.am from failure on compiling

* Fri Jun  6 2003 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 2.2.5-0vl1
- source upgrade
- remove patch (no need)
- run libtoolize etc for VineSeed

* Wed Feb 12 2003 Tomoya TAKA <taka@vinelinux.org> 2.2.4-0vl2
- enable -kde subpackage on alpha, but still disable for Vine2.5/2.6

* Sun Feb  9 2003 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 2.2.4-0vl1
- source upgrade
- change spec to build both VineSeed and Vine2.5/2.6
- add patch from rawhide 2.2.3-6

* Sun Oct 13 2002 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 2.2.3-0vl2
- Requires: libjpeg (not libjpeg-6b)

* Sun Oct  6 2002 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 2.2.3-0vl1
- source upgrade
- add BuildPrereq: autoconf253 automake15
- add PreReq: ldconfig
- fix %files section and clean up spec
- for unixODBC-kde package
  - add Requires: unixODBC = %{version}
  - add Requires: XFree86-libs qt freetype2 libjpeg-6b libmng libpng zlib
  - delete .desktop files

* Thu Apr  4 2002 AKIYAMA Kazuhito <akiyama@karen.servepics.com> 2.2.0-0vl2
- rebuild with KDE3

* Sat Feb 23 2002 Satoshi MACHINO <machino@vinelinux.org> 2.2.0-0vl1
- updated unixODBC-2.2.0
- fixed LinuxODBC.xpm and smallLinuxODBC.xpm dir

* Wed Jan 30 2002 Tomoya TAKA <taka@vinelinux.org> 2.0.7-3vl2
- remove -kde package on alpha

* Fri Jan  4 2002 Akira TAGOH <tagoh@gnome.gr.jp> 2.0.7-3vl1
- Rebuild for Vine.

* Sun Jun 24 2001 Than Ngo <than@redhat.com>
- rebuild against qt-2.3.1, kde-2.1.x

* Fri Jun 15 2001 Trond Eivind Glomsrød <teg@redhat.com>
- Better default odbcinst.ini
- Minor cleanups

* Wed Jun  6 2001 Trond Eivind Glomsrød <teg@redhat.com>
- 2.0.7

* Wed Apr 25 2001 Trond Eivind Glomsrød <teg@redhat.com>
- Fix for isql segfault on EOF/ctrl-d exit

* Fri Apr 20 2001 Trond Eivind Glomsrød <teg@redhat.com>
- 2.0.6
- add patch for 64 bit archs (dword shouldn't be "long int")

* Wed Feb 28 2001 Trond Eivind Glomsrød <teg@redhat.com>
- rebuild

* Tue Nov 28 2000 Trond Eivind Glomsrød <teg@redhat.com>
- 1.8.13

* Tue Oct 10 2000 Trond Eivind Glomsrød <teg@redhat.com>
- enable GUI now that we have KDE compiled with the standard
  compiler
- move the applnk entries to the KDE package

* Thu Aug 24 2000 Nalin Dahyabhai <nalin@redhat.com>
- add the missing shared libs to the non-devel package

* Wed Aug 23 2000 Preston Brown <pbrown@redhat.com>
- 1.8.12 fixes problems with the postgresql driver

* Mon Jul 31 2000 Trond Eivind Glomsrød <teg@redhat.com>
- disable KDE subpackage to avoid the mess that is C++ binary
  compatibility 

* Wed Jul 12 2000 Prospector <bugzilla@redhat.com>
- automatic rebuild

* Fri Jun 30 2000 Florian La Roche <laroche@redhat.com>
- improved QTDIR detection

* Thu Jun 28 2000 Trond Eivind Glomsrød <teg@redhat.com>
- 1.8.10
- use %%{_tmppath}
- update URL
- including two missing libraries

* Tue Jun 13 2000 Preston Brown <pbrown@redhat.com>
- 1.8.9

* Fri Jun 09 2000 Preston Brown <pbrown@redhat.com>
- adopted for Winston, changed to Red Hat packaging standards

* Tue Apr 18 2000 Murray Todd Williams <murray@codingapes.com>
- added a unixODBC-devel RPM to the group, added KDE links and icons to system
- all of which came from recommendations from Fredrick Meunier
- <Fredrick.Meunier@computershare.com.au>

* Mon Apr 17 2000 Murray Todd Williams <murray@codingapes.com>
- unixODBC-1.8.7
- moved install to $RPM_BUILD_ROOT so it didn't overrun existing files.


