#
# spec file for package
#
# Copyright (c) 2011 SUSE LINUX Products 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/
#


%define qtdir /%{_lib}/qt4

Name:           vtk
Version:        5.6.1
Release:        1
# This is a variant BSD license, a cross between BSD and ZLIB.
# For all intents, it has the same rights and restrictions as BSD.
# http://fedoraproject.org/wiki/Licensing/BSD#VTKBSDVariant
License:        BSD
Summary:        The Visualization Toolkit - A high level 3D visualization library
Group:          Productivity/Scientific/Other
Source:         %{name}-%{version}.tar.bz2
# PATCH-FIX-UPSTREAM vtk-pythondestdir.patch --badshah400@gmail.com Correct installation destination for python libraries
Patch0:         vtk-pythondestdir.patch
# PATCH-FIX-UPSTREAM vtk-gcc43.patch --badshah400@gmail.com Compatibility with gcc 4.3 and above
Patch1:         vtk-gcc43.patch
# PATCH-FIX-UPSTREAM vtk-testcxxjavaremove.patch --badshah400@gmail.com
Patch2:         vtk-testcxxjavaremove.patch
# PATCH-FIX-UPSTREAM vtk-python27-compat.patch --badshah400@gmail.com Python 2.7 compatibility
Patch3:         vtk-python27-compat.patch
# PATCH-FIX-UPSTREAM vtk-gcc46.patch --badshah400@gmail.com Add needed includes for gcc 4.6
# http://public.kitware.com/Bug/view.php?id=11824
Patch4:         vtk-gcc46.patch
# PATCH-FIX-UPSTREAM vtk-system.patch --badshah400@gmail.com Use system libraries
# http://public.kitware.com/Bug/view.php?id=11823
Patch5:         vtk-system.patch
# PATCH-FIX-UPSTREAM vtk-soversion.patch --badshah400@gmail.com Upstream patch to add soversions to libCosmo and libVPIC
Patch6:         vtk-soversion.patch
# PATCH-FIX-UPSTREAM vtk-sqldatabaseschema.patch --badshah400@gmail.com Resolve problems with vtkSQLdatabaseschema.cxx, patch came from upstream
Patch7:         vtk-sqldatabaseschema.patch
%if 0%{?suse_version} > 1120
# PATCH-FIX-UPSTREAM vtk-libpng14.patch --badshah400@gmail.com Restore compatibility with libpng14
Patch8:         vtk-libpng14.patch
%endif
# PATCH-FIX-UPSTREAM vtk-string-length.patch badshah400@gmail.com Prevent buffer overflows during string copy
Patch9:         vtk-string-length.patch
# PATCH-FIX-UPSTREAM vtk-Balloon-Representation.patch badshah400@gmail.com Correct assignment operations in source files
Patch10:         vtk-Balloon-Representation.patch
# patch to fix the soname for libVTKnetcdf_cxx
Patch11:        vtk-soversion2.patch
Url:            http://vtk.org/
BuildRequires:  Mesa-devel
BuildRequires:  MesaGLw-devel
BuildRequires:  boost-devel
BuildRequires:  chrpath
BuildRequires:  cmake
BuildRequires:  doxygen
BuildRequires:  fdupes
BuildRequires:  freeglut-devel
BuildRequires:  freetype2-devel
BuildRequires:  gcc-c++
BuildRequires:  gcc-java
BuildRequires:  gnuplot
BuildRequires:  graphviz
BuildRequires:  java-devel
BuildRequires:  libexpat-devel
BuildRequires:  libgcj-devel
BuildRequires:  libjpeg-devel
BuildRequires:  libmysqlclient-devel
BuildRequires:  libpng-devel
BuildRequires:  libqt4-devel
BuildRequires:  libtheora-devel
BuildRequires:  libtiff-devel
BuildRequires:  libxml2-devel
BuildRequires:  make
BuildRequires:  openmotif-devel
BuildRequires:  postgresql-devel
BuildRequires:  python-devel
BuildRequires:  sqlite3-devel
BuildRequires:  tcl-devel
BuildRequires:  tk-devel
BuildRequires:  wget
BuildRequires:  xorg-x11-devel
BuildRequires:  zlib-devel
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

%package devel
Summary:        VTK header files for building C++ code
Group:          Development/Libraries/Other
Requires:       Mesa-devel
Requires:       libexpat-devel
Requires:       libjpeg-devel
Requires:       libmysqlclient-devel
Requires:       libogg-devel
Requires:       libpng-devel
Requires:       libqt4-devel
Requires:       libtheora-devel
Requires:       libtiff-devel
Requires:       postgresql-devel
Requires:       vtk = %{version}

%description devel
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

This provides the VTK header files required to compile C++ programs that
use VTK to do 3D visualisation.

%package tcl
Summary:        Tcl bindings for VTK
Group:          System/Libraries
Requires:       vtk = %{version}

%description tcl
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

This package provides tcl bindings for VTK.

%package -n python-vtk
Summary:        Python bindings for VTK
Group:          System/Libraries
Requires:       vtk = %{version}

%description -n python-vtk
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

This package provides python bindings for VTK.

%package java
Summary:        Java bindings for VTK
Group:          Development/Libraries/Java
Requires:       vtk = %{version}

%description java
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

This package provides java bindings for VTK.

%package testing
Summary:        Testing programs for VTK
Group:          Productivity/Scientific/Other
Requires:       vtk = %{version}
Requires:       vtkdata = %{version}

%description testing
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

This package provides a few testing programs for VTK

%package qt
Summary:        QT VTK widget
Requires:       vtk = %{version}
# do not neeeded to call it, rpm take care of it
#Requires:      libqt4
Group:          Development/Libraries/C and C++

%description qt
Qt VTK widget

%package examples
Summary:        Examples for VTK
Group:          Productivity/Scientific/Other
Requires:       vtk = %{version}
Requires:       vtkdata = %{version}

%description examples
VTK is an open-source software system for image processing, 3D
graphics, volume rendering and visualization. VTK includes many
advanced algorithms (e.g., surface reconstruction, implicit modelling,
decimation) and rendering techniques (e.g., hardware-accelerated
volume rendering, LOD control).

This package contains many well-commented examples showing how to use
VTK. Examples are available in the C++, Tcl, Python and Java
programming languages.

%prep
%setup -q -n VTK
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%if 0%{?suse_version} > 1120
%patch8 -p1
%endif
%patch9 -p1
%patch10 -p1
%patch11 -p1

# Replace relative path ../../../VTKData with %{_datadir}/vtkdata-%{version}
# otherwise it will break on symlinks.
grep -rl '\.\./\.\./\.\./\.\./VTKData' . | xargs \
  perl -pi -e's,\.\./\.\./\.\./\.\./VTKData,%{_datadir}/%{name},g'

# Save an unbuilt copy of the Example's sources for %doc
#mkdir vtk-examples-5.6
#cp -a Examples vtk-examples-5.6
# Don't ship Win32 examples
rm -rf vtk-examples-5.6/Examples/GUI/Win32
#find vtk-examples-5.6 -type f | xargs chmod -R a-x

%build
export CC='gcc'
export CXX='g++'
export MAKE='make'
export CFLAGS="%{optflags}"
export CXXFLAGS="%{optflags}"

cmake . \
    -DVTK_USE_QT:BOOL=ON \
    -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \
    -DVTK_INSTALL_LIB_DIR:PATH=/%{_lib}/%{name} \
    -DVTK_WRAP_PYTHON:BOOL=ON \
    -DVTK_WRAP_TCL:BOOL=ON \
    -DVTK_WRAP_JAVA:BOOL=ON \
    -DVTK_USE_PARALLEL:BOOL=ON \
    -DVTK_USE_RENDERING:BOOL=ON \
    -DBUILD_DOCUMENTATION:BOOL=OFF \
    -DBUILD_EXAMPLES:BOOL=ON \
    -DBUILD_SHARED_LIBS:BOOL=ON \
    -DBUILD_TESTING:BOOL=ON \
    -DVTK_USE_GUISUPPORT:BOOL=ON \
    -DVTK_INSTALL_QT_DIR:STRING=%{qtdir}/plugins/designer \
    -DVTK_USE_GL2PS:BOOL=ON \
    -DVTK_USE_SYSTEM_EXPAT:BOOL=ON \
    -DVTK_USE_SYSTEM_JPEG:BOOL=ON \
    -DVTK_USE_SYSTEM_PNG:BOOL=ON \
    -DVTK_USE_SYSTEM_TIFF:BOOL=ON \
    -DVTK_USE_SYSTEM_ZLIB:BOOL=ON \
    -DVTK_USE_SYSTEM_EXPAT:BOOL=ON \
    -DVTK_USE_SYSTEM_FREETYPE:BOOL=ON


%__make

# Remove executable bits from sources (some of which are generated)
find . -name \*.c -or -name \*.cxx -or -name \*.h -or -name \*.hxx -or \
       -name \*.gif | xargs chmod -x

%install
#mkdir -p %{buildroot}
#%makeinstall
make DESTDIR=%{buildroot} install

mv %{buildroot}%{_libdir}/%{name}/lib*.so* %{buildroot}%{_libdir}/

# Gather list of non-python/tcl libraries
ls %{buildroot}%{_libdir}/*.so.* \
  | grep -Ev '(Java|QVTK|Qt|PythonD|TCL)' | sed -e's,^%{buildroot},,' > libs.list

# List of executable utilities
cat > utils.list << EOF
vtkEncodeString
lproj
EOF

# List of executable examples
cat > examples.list << EOF
HierarchicalBoxPipeline
MultiBlock
Arrays
Cube
RGrid
SGrid
Medical1
Medical2
Medical3
finance
AmbientSpheres
Cylinder
DiffuseSpheres
SpecularSpheres
Cone
Cone2
Cone3
Cone4
Cone5
Cone6
EOF

# List of executable test binaries
cat > testing.list << EOF
CommonCxxTests
TestCxxFeatures
TestInstantiator
FilteringCxxTests
GraphicsCxxTests
GenericFilteringCxxTests
ImagingCxxTests
IOCxxTests
RenderingCxxTests
VTKBenchMark
VolumeRenderingCxxTests
WidgetsCxxTests
SocketClient
SocketServer
EOF

# Install utils/examples/testing, too
for filelist in utils.list examples.list testing.list; do
  for file in `cat $filelist`; do
    install -p bin/$file %{buildroot}%{_bindir}
  done
perl -pi -e's,^,%{_bindir}/,' $filelist
done

# Remove any remnants of rpaths
chrpath -d %{buildroot}%{_bindir}/*

# Main package contains utils and core libs
cat libs.list utils.list > main.list

# Make shared libs and scripts executable
chmod a+x %{buildroot}%{_libdir}/%{name}/doxygen/*.pl
chmod a+x %{buildroot}%{_libdir}/%{name}/testing/*.{py,tcl}

# Remove exec bit from non-scripts and %%doc
for file in `find %{buildroot} -type f -perm 0755 \
  | xargs -r file | grep ASCII | awk -F: '{print $1}'`; do
  head -1 $file | grep '^#!' > /dev/null && continue
  chmod 0644 $file
done
find Utilities/Upgrading -type f | xargs chmod -x

# Add exec bits to shared libs ...
#chmod 0755 %{buildroot}%{_libdir}/vtk-5.6/CMake/*.so
#chmod 0755 %{buildroot}%{_libdir}/python*/site-packages/vtk/*.so

# Verdict places the docs in the false folder
rm -rf %{buildroot}%{_libdir}/vtk/doc

#Move tcl script to %{_datadir}/tcl/vtk/
mkdir -p %{buildroot}%{_datadir}/tcl/vtk/
mv %{buildroot}%{_libdir}/%{name}/tcl/ %{buildroot}%{_datadir}/tcl/vtk/
mv %{buildroot}%{_libdir}/%{name}/*.tcl %{buildroot}%{_datadir}/tcl/%{name}/

%fdupes -s %{buildroot}

%clean
rm -rf %{buildroot}

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%post tcl -p /sbin/ldconfig

%postun tcl -p /sbin/ldconfig

%post -n python-vtk -p /sbin/ldconfig

%postun -n python-vtk -p /sbin/ldconfig

%post java -p /sbin/ldconfig

%postun java -p /sbin/ldconfig

%post qt -p /sbin/ldconfig

%postun qt -p /sbin/ldconfig

%files -f main.list
%defattr(-,root,root,-)
%doc --parents Copyright.txt README.html vtkLogo.jpg vtkBanner.gif Wrapping/*/README*
%doc README.html
%doc vtkLogo.jpg
%doc Copyright.txt

%files devel
%defattr(-,root,root,-)
%doc Utilities/Upgrading
%{_libdir}/%{name}/doxygen
%{_includedir}/%{name}-5.6
%{_libdir}/%{name}/CMake/
%{_libdir}/%{name}/*.cmake
%{_libdir}/%{name}/hints
%{_libdir}/*.so

%files tcl
%defattr(-,root,root,-)
%{_bindir}/vtkWrapTcl
%{_bindir}/vtkWrapTclInit
%{_bindir}/vtk
%{_libdir}/libvtk*TCL.so.*
%{_datadir}/tcl/vtk/
%doc README.html
%doc vtkLogo.jpg

%files -n python-vtk
%defattr(-,root,root,-)
%{_libdir}/*PythonD.so.*
%{python_sitelib}/%{name}/
%{_prefix}/lib/python%{py_ver}/site-packages/VTK-%{version}-py%{py_ver}.egg-info
%{_bindir}/vtkWrapPython
%{_bindir}/vtkWrapPythonInit
%{_bindir}/vtkpython
%doc README.html
%doc vtkLogo.jpg

%files java
%defattr(-,root,root,-)
%doc README.html
%doc vtkLogo.jpg
%dir %{_libdir}/%{name}
%{_bindir}/vtkParseJava
%{_bindir}/vtkWrapJava
%{_libdir}/%{name}/java/
%{_libdir}/*Java.so.*

%files testing -f testing.list
%defattr(-,root,root,-)
%dir %{_libdir}/%{name}
%{_libdir}/%{name}/testing/
%doc README.html
%doc vtkLogo.jpg

%files qt
%defattr(-,root,root,-)
%{_libdir}/libQVTK.so.*
%{_libdir}/libvtkQtChart.so*
#%{_bindir}/qtevents
#%{_bindir}/qtimageviewer
#%{_bindir}/qtsimpleview
%dir %{_prefix}/%{qtdir}/plugins/designer
%{_prefix}/%{qtdir}/plugins/designer/libQVTKWidgetPlugin.so

%files examples -f examples.list
%defattr(-,root,root,-)
%dir %{_libdir}/%{name}
%doc README.html
%doc vtkLogo.jpg

%changelog