%define vtkver 5.4
%define version %{vtkver}.2
%define vtkdata_dir %{_datadir}/vtk-data-%{version}
%define qt_designer_plugins_dir %(qmake -query QT_INSTALL_PREFIX)/plugins/designer
%define tcl_ver %(echo "puts [info tclversion]" | %{_bindir}/tclsh)
Summary: The Visualization Toolkit - A high level 3D visualization library
Summary: The Visualization Toolkit - ハイレベル3D可視化ライブラリ
Group: System Environment/Libraries
Name: vtk
Version: %{version}
Release: 3%{?_dist_release}
Source0: vtk-%{version}.tar.gz
Source1: vtkdata-%{version}.tar.gz
Patch2: vtk-5.2.1-boost-1.42.patch
License: BSD style
URL: http://www.vtk.org/
BuildRequires: cmake >= 2.0.0
BuildRequires: xorg-x11-devel, mesa-libGL-devel
BuildRequires: expat-devel, zlib-devel
BuildRequires: netcdf
BuildRequires: libjpeg-devel, libpng-devel, libtiff-devel, freetype2-devel
BuildRequires: tcl, tk, python, python-devel
BuildRequires: qt4-devel
BuildRequires: libboost-devel
BuildRequires: libxml2-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Requires: cmake
Requires: xorg-x11-libs, mesa-libGL
Requires: expat, zlib
Requires: netcdf
Requires: libjpeg, libpng, libtiff, freetype2
Obsoletes: %{name}-ruby < %{version}
Distribution: Project Vine
Vendor: Vine Linux
Packager: owa

%description
VTK - the Visualization Toolkit is an object oriented, high
level library that allows one to easily write C++ programs, Tcl,
Python and Java scripts that do 3D visualization.  This package
provides the shared libraries needed to run C++ programs that use VTK.
To compile C++ code that uses VTK you have to install vtk-devel.

VTK enables users to concentrate on their work by providing a
large number of excellent and feature packed high level functions that
do visualization.  The library needs OpenGL to render the graphics and
for Linux machines Mesa is necessary. The terms/copyright can be read
in %{_docdir}/vtk-%{version}-%{release}/README.html. VTK-Linux-HOWTO has
information about using vtk, getting documentataion or help and
instructions on building VTK. This package is relocatable.

%package devel
Summary: VTK header files for building C++ code.
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description devel
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: Applications/Engineering
Requires: %{name} = %{version}-%{release}
Requires: tcl

%description tcl
VTK - the Visualization Toolkit is an object oriented, high level
library that allows one to easily write C++ programs, Tcl, Python and Java
scripts that do 3D visualization.  This package provides the shared
libraries that enable one to use VTK via Tcl scripts.  This version also
provides the vtkTkRenderWindow class. This package does not require the vtk
package to be installed.  The library needs OpenGL to render the graphics and
for Linux machines Mesa is necessary.

The terms/copyright can be read in
/usr/share/doc/vtk-tcl-%{version}-%{release}/README.html. VTK-Linux-HOWTO has
information about using vtk, getting documentation or help and instructions on
building VTK. This package is relocatable.


%package python
Summary: Python bindings for VTK.
Group: Applications/Engineering
Requires: %{name} = %{version}-%{release}
Requires: python

%description python 
This provides the shared libraries that enable one to use VTK from
python scripts.  You will need python and vtk installed to use this.
Remember to set your PYTHONPATH variable properly before running your
scripts.


%package qt
Summary: QT VTK widget
Group: System Environment/Libraries
Requires: %{name} = %{version}-%{release}
Requires: qt

%description qt
The vtkQt classes combine VTK and Qt(TM) for X11.


%package examples
Summary: C++, Tcl and Python example programs/scripts for VTK.
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description examples
This package contains all the examples from the VTK source.
To compile the C++ examples you will need to install the vtk-devel
package as well. The Python and Tcl examples can be run with the
corresponding packages (vtk-python, vtk-tcl).


%package testing-progs
Summary: Tests programs for VTK.
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description testing-progs
This package contains all testing programs from the VTK
source. The source code of these programs can be found in the
vtk-examples package.


%package data
Summary: Data for VTK.
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Prefix: /usr

%description data
This package contains all the data from the VTKData repository.
These data are required to run various examples from the examples package.


%prep
%setup -q -n VTK
%patch2 -p1 -b .boost-1.42

# fix data path
find . -type f | xargs sed -i -e 's|../../../../VTKData|%{vtkdata_dir}|g'


%build
## This section wad fixed reference to Mandriva package
# Remove old cmake files
rm -f CMake/FindBoost*

# Due to cmake prefix point already for _prefix, we need
# push only the necessary extra paths
%cmake \
	-DVTK_INSTALL_BIN_DIR:PATH=/bin \
	-DVTK_INSTALL_PACKAGE_DIR=/%{_lib}/vtk-%{vtkver} \
	-DVTK_INSTALL_INCLUDE_DIR:PATH=/include/vtk-%{vtkver} \
	-DVTK_PYTHON_MODULE_PLATFORM_INSTALL_DIR=/%{_lib}/pyhton%{pyver}/site-packages \
	-DVTK_DATA_ROOT:PATH=/share/vtk-%{vtkver} \
	\
	-DVTK_USE_SYSTEM_LIBPROJ4:BOOL=OFF \
	-DVTK_WRAP_PYTHON:BOOL=ON \
	-DVTK_WRAP_JAVA:BOOL=OFF \
	-DVTK_WRAP_TCL:BOOL=ON \
	-DVTK_USE_RENDERING:BOOL=ON \
	-DDESIRED_QT_VERSION=4 \
	-DBUILD_DOCUMENTATION:BOOL=OFF \
	-DBUILD_EXAMPLES:BOOL=ON \
	-DBUILD_SHARED_LIBS:BOOL=ON \
	-DBUILD_TESTING:BOOL=ON \
	-DVTK_USE_SYSTEM_EXPAT=ON \
	-DVTK_USE_SYSTEM_JPEG=ON \
	-DVTK_USE_SYSTEM_PNG=ON \
	-DVTK_USE_SYSTEM_TIFF=ON \
	-DVTK_USE_SYSTEM_ZLIB=ON \
	-DVTK_USE_SYSTEM_FREETYPE=ON \
	-DVTK_USE_ANSI_STDLIB:BOOL=ON \
	-DVTK_USE_PARALLEL:BOOL=ON \
	-DVTK_USE_GUISUPPORT:BOOL=ON \
	-DVTK_USE_QVTK=ON \
	-DVTK_PYTHON_SETUP_ARGS:STRING="--prefix=%{_prefix} --root=%{buildroot}" \
	-DVTK_INSTALL_QT_PLUGIN_DIR=%{qt_designer_plugins_dir} \
	-DVTK_USE_GL2PS:BOOL=ON \
	-DVTK_USE_SYSTEM_LIBXML2:BOOL=ON \
	-DVTK_USE_QVTK_QTOPENGL:BOOL=ON \
	-DVTK_USE_BOOST:BOOL=ON \
	-DTCL_LIBRARY:FILEPATH=%{_libdir}/libtcl%{tcl_ver}.so\
	-DTK_LIBRARY:FILEPATH=%{_libdir}/libtk%{tcl_ver}.so\
	;

## don't use _smp_mflags
##%__make %{?_smp_mflags}
%__make


%install
rm -rf $RPM_BUILD_ROOT
%makeinstall DESTDIR=$RPM_BUILD_ROOT

%if %{_lib} == lib64
	mkdir -p $RPM_BUILD_ROOT%{_libdir}
	mv $RPM_BUILD_ROOT%{_prefix}/lib/python%{pyver} $RPM_BUILD_ROOT%{_libdir}/
	mv $RPM_BUILD_ROOT%{_prefix}/lib/vtk-%{vtkver}/* $RPM_BUILD_ROOT%{_libdir}/vtk-%{vtkver}/
%endif
mv $RPM_BUILD_ROOT%{_libdir}/vtk-%{vtkver}/lib*.so* $RPM_BUILD_ROOT%{_libdir}/

rm -f bin/*.so*
install -m 755 bin/* $RPM_BUILD_ROOT%{_bindir}
rm -rf doc
for d in Common Filtering GenericFiltering Graphics Hybrid IO Imaging Parallel Rendering VolumeRendering Widgets
do
        install -d -m 755 doc/Testing/$d
        cp -a $d/Testing/* doc/Testing/$d
done

cp -a Examples doc
find doc -name "*.o" -exec rm {} \;
find doc -name CMakeCache.txt -exec rm {} \;
find doc -name Makefile -exec rm {} \;
find doc -name DartTestfile.txt -exec rm {} \;
find doc -name .NoDartCoverage -exec rm {} \;
find doc -name "cmake.*" -exec rm {} \;

echo "%defattr (-, root, root)" > testing-progs-list
find ${RPM_BUILD_ROOT}%{_bindir} -type f | \
        sed -e "s#^${RPM_BUILD_ROOT}##g" | \
        egrep -v '^%{_bindir}/(vtk|pvtk|vtkWrap.*|vtkParseJava|VTKJavaExecutable|vtkpython|pvtkpython)$' \
        >> testing-progs-list

tar zxvf %{SOURCE1}
install -d $RPM_BUILD_ROOT%{_datadir}
cp -r VTKData $RPM_BUILD_ROOT/%{vtkdata_dir}

# Remove any possible verdict docs
rm -rf %buildroot/%{_libdir}/vtk-%{vtkver}/doc


%post -p /sbin/ldconfig
%post tcl -p /sbin/ldconfig
%post python -p /sbin/ldconfig
%post qt -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%postun tcl -p /sbin/ldconfig
%postun python -p /sbin/ldconfig
%clean 
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc Copyright.txt README.html TestingLogo.gif vtkLogo.jpg
%{_libdir}/*.so.*

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


%files tcl
%defattr(-,root,root)
%dir %{_libdir}/vtk-%{vtkver}/testing
%{_bindir}/vtk
%{_bindir}/vtkWrapTcl
%{_bindir}/vtkWrapTclInit
%{_libdir}/libvtk*TCL.so.*
%{_libdir}/vtk-%{vtkver}/tcl/
%{_libdir}/vtk-%{vtkver}/testing/*tcl
%{_libdir}/vtk-%{vtkver}/pkgIndex.tcl


%files python
%defattr(-,root,root)
%{_bindir}/vtkpython
%{_bindir}/vtkWrapPython
%{_bindir}/vtkWrapPythonInit
%{_libdir}/libvtk*Python*.so.*
%{_libdir}/python%{pyver}/site-packages/*
%{_libdir}/vtk-%{vtkver}/testing/*py


%files qt
%defattr(-,root,root)
%{_libdir}/libQVTK.so.*


%files examples
%defattr(-,root,root)
%doc doc/Examples/
%doc doc/Testing/


%files testing-progs -f testing-progs-list


%files data
%defattr(-,root,root)
%{vtkdata_dir}


%changelog
* Mon May 09 2011 Shu KONNO <owa@bg.wakwak.com> 5.4.2-3
- s/qt-devel/qt4-devel/ at BR:
- add BR: libxml2-devel

* Sun May 08 2011 Shu KONNO <owa@bg.wakwak.com> 5.4.2-2
- remove _smp_mflags
- added tcl_ver macro
- added TCL_LIBRARY, TK_LIBRARY to cmake

* Tue May 04 2010 Shu KONNO <owa@bg.wakwak.com> 5.4.2-1
- updated vtk to 5.4.2
- updated vtkdata to 5.4.2
- added Obsoletes: %%{name}-ruby < 5.4.2
- added Patch2: vtk-5.2.1-boost-1.42.patch (from Mandriva)
- dropt Patch0: vtk-5.0-getsockname.patch
- dropt Patch1: vtk-ruby-060915.patch

* Thu Jul 31 2008 Shu KONNO <owa@bg.wakwak.com> 5.0.4-1vl5
- updated vtk to 5.0.4
- updated vtkdata to 5.0.4
- built with xorg-x11-devel, python-2.5
- applied new versioning policy
- spec in utf-8

* Mon Feb 25 2008 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 5.0.2-0vl6
- rebuild with expat-2.0.1
- add BuildPrereq: freetype2-devel and drop freetype-devel
- add BuildPrereq: qt-devel
- add Requires: freetype2 and drop freetype

* Sun Feb 17 2008 Shu KONNO <owa@bg.wakwak.com> 5.0.2-0vl5
- rebuild with tcl/tk-8.4.18

* Tue Oct 09 2007 Shu KONNO <owa@bg.wakwak.com> 5.0.2-0vl4
- rebuild with tcl/tk-8.4.16

* Mon Aug 27 2007 Shu KONNO <owa@bg.wakwak.com> 5.0.2-0vl3
- added %%define py_ver, py_dir
- added %%{?_smp_mflags} to make
- change for x86_64
	- changed lib to %%{_lib}
	- added VTK_INSTALL_LIB_DIR=PATH=/%{_lib} in cmake
	- added --install-lib at VTK_PYTHON_SETUP_ARGS in cmake

* Tue May 15 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 5.0.2-0vl2
- rebuild with new environment/toolchain

* Fri Sep 15 2006 Seiya Nishizawa <seiya@kugi.kyoto-u.ac.jp> 5.0.2-0vl1
- new upstream
- add ruby patch

* Sat Jul 29 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 5.0.1-0vl1
- new upstream
- fixed spec file encoding
- changed Group to System Environment/Libraries

* Mon Feb 06 2006 Seiya Nishizawa <seiya@kugi.kyoto-u.ac.jp> 5.0.0-0vl1
- source verion up

* Tue Mar 29 2005 Seiya Nishizawa <seiya@kugi.kyoto-u.ac.jp> 4.4.2-0vl1
- source verion up

* Sun Mar 20 2005 Seiya Nishizawa <seiya@kugi.kyoto-u.ac.jp> 4.2.6-0vl1
- initial build for Vine Linux
