--- freetds.spec.orig
+++ freetds.spec
@@ -1,14 +1,24 @@
+%ifarch alpha ia64 x86_64 ppc64 sparc64 s390x
+%define bits	64
+%else
+%define bits	32
+%endif
+
 Name: freetds
 Summary: Implementation of the TDS (Tabular DataStream) protocol
-Version: 0.64
-Release: 1
+Version: 0.82
+Release: 6%{?dist}
 Group: System Environment/Libraries
-License: LGPL 
-Source:	freetds-%{version}.tar.gz
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
-BuildRequires: unixODBC-devel
-BuildRequires: doxygen, docbook-style-dsssl
-Patch0: freetds-0.64-makefile-doc.patch
+License: LGPLv2+ and GPLv2+
+URL: http://www.freetds.org/
+Source0: ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-%{version}.tar.gz
+Source1: freetds-tds_sysdep_public.h
+Patch0: ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/cspublic.BLK_VERSION_150.patch
+Patch1: freetds-0.82-shared-libtds.patch
+Patch2: freetds-0.82-libtool.patch
+
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+BuildRequires: unixODBC-devel, readline-devel, gnutls-devel, libtool
  
 
 %description 
@@ -19,48 +29,56 @@ level interfaces for DB-Lib, CT-Lib, and
 
 
 %package devel
-Summary: Header files, libraries and development documentation for %{name}
+Summary: Header files and development libraries for %{name}
 Group: Development/Libraries
 Requires: %{name} = %{version}-%{release}
 
 %description devel
-This package contains the header files and development documentation
+This package contains the header files and development libraries
 for %{name}. If you like to develop programs using %{name}, you will need
 to install %{name}-devel.
 
 
+%package doc
+Summary: Development documentation for %{name}
+Group: Documentation
+
+%description doc
+This package contains the development documentation for %{name}.
+If you like to develop programs using %{name}, you will need to install
+%{name}-doc.
+
+
 %prep 
 %setup -q
-%patch0 -p1
+%patch0 -p0
+%patch1 -p1
+%patch2 -p1
 
-# cleanup the initial source
-sed -i 's/\r//' doc/tds_ssl.html
-sed -i '1 s,#!.*/perl,#!%{__perl},' samples/*.pl doc/api_status.txt
-
-find doc/ samples/ COPYING* -type f -print0 | xargs -0 chmod -x
-find . -name "*.[ch]" -print0 | xargs -0 chmod -x
-
-# cause to rebuild docs
-rm doc/doc/freetds-%{version}/reference/index.html
-rm doc/doc/freetds-%{version}/userguide/index.htm
+#  correct perl path
+sed -i '1 s,#!.*/perl,#!%{__perl},' samples/*.pl
 
+chmod -x samples/*.sh
+
+# Remove bogus libtool-related macros
+rm -f m4/lib-*.m4
+
+#  needed after patch0 ...
+autoreconf -f -i
  
+
 %build 
 %configure \
 	--disable-dependency-tracking \
+	--disable-rpath \
 	%{!?_with_static: --disable-static} \
 	--with-tdsver="4.2" \
 	--with-unixodbc="%{_prefix}" \
 	--enable-msdblib \
-	--enable-sybase-compat
+	--enable-sybase-compat \
+	--with-gnutls
 
-# avoid any rpath
-sed -i -e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' \
-	-e 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
-
-make %{?_smp_mflags} DOCBOOK_DSL="`rpm -ql docbook-style-dsssl | fgrep html/docbook.dsl`"
-
-chmod -x samples/*.template
+make %{?_smp_mflags}
 
  
 %install 
@@ -70,8 +88,15 @@ make install DESTDIR=$RPM_BUILD_ROOT
 
 rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
 
+mv -f $RPM_BUILD_ROOT%{_includedir}/tds_sysdep_public.h \
+	$RPM_BUILD_ROOT%{_includedir}/tds_sysdep_public_%{bits}.h
+install -p -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_includedir}/tds_sysdep_public.h
+
 rm -f samples/Makefile* samples/*.in samples/README
 
+mv -f samples/unixodbc.freetds.driver.template \
+	samples/unixodbc.freetds.driver.template-%{bits}
+
 
 %post -p /sbin/ldconfig
 
@@ -86,21 +111,73 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-, root, root, -) 
 %{_bindir}/*
 %{_libdir}/*.so.*
+%{_libdir}/libtds-%{version}.so
 %config(noreplace) %{_sysconfdir}/*.conf
-%doc AUTHORS BUGS COPYING* NEWS README TODO 
-%doc doc/*.html doc/doc/freetds-%{version}/userguide
+%doc AUTHORS BUGS COPYING* NEWS README TODO doc/*.html
+%doc doc/doc/freetds-%{version}/userguide doc/images
 %{_mandir}/*/*
 
  
 %files devel 
-%defattr (-, root, root) 
-%doc samples doc/doc/freetds-%{version}/reference
+%defattr (-, root, root, -) 
+%doc samples
 %{?_with_static: %{_libdir}/*.a}
 %{_libdir}/*.so
+%exclude %{_libdir}/libtds-%{version}.so
 %{_includedir}/*
+
+
+%files doc
+%defattr (-, root, root, -) 
+%doc doc/doc/freetds-%{version}/reference
  
 
-%changelog 
+%changelog
+* Fri Jul 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.82-6
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild
+
+* Thu Mar 26 2009 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.82-5
+- add upstream patch cspublic.BLK_VERSION_150.patch (#492393)
+
+* Tue Feb 24 2009 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.82-4
+- fix autoconf data for libtool2 (patch by Tom Lane <tgl@redhat.com>)
+
+* Fri Jan 30 2009 Karsten Hopp <karsten@redhat.com> 0.82-3
+- add s390x to 64 bit archs
+
+* Sun Jan 11 2009 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.82-3
+- Use gnutls for SSL (#479148)
+
+* Tue Jun 17 2008 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.82-2
+- Continue to provide an internal libtds library as public
+  (patch from Hans de Goede, #451021). This shared library is needed
+  for some existing applications (libgda etc.), which still use it directly.
+
+* Mon Jun  9 2008 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.82-1
+- Upgrade to 0.82
+
+* Tue Feb 26 2008 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.64-11
+- fix "64 or 32 bit" test (#434975)
+
+* Mon Feb 18 2008 Fedora Release Engineering <rel-eng@fedoraproject.org> - 0.64-10
+- Autorebuild for GCC 4.3
+
+* Mon Jan 28 2008 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.64-9
+- drop "Obsoletes:" from -doc subpackage to avoid extra complexity.
+
+* Fri Jan 25 2008 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.64-8
+- resolve multiarch conflicts (#341181):
+  - split references to separate freetds-doc subpackage
+  - add arch-specific suffixes for arch-specific filenames in -devel
+  - add wrapper for tds_sysdep_public.h
+- add readline support (#430196)
+
+* Tue Aug 28 2007 Fedora Release Engineering <rel-eng at fedoraproject dot org> - 0.64-7
+- Rebuild for selinux ppc32 issue.
+
+* Thu Aug 16 2007 Dmitry Butskoy <Dmitry@Butskoy.name>
+- Change License tag to "LGPLv2+ and GPLv2+"
+
 * Fri Jun 15 2007 Dmitry Butskoy <Dmitry@Butskoy.name> - 0.64-6 
 - bump release to provide update path over Livna
 
