%bcond_with doc

# Filter provides from Python libraries
%{?filter_setup:
%filter_provides_in %{python3_sitearch}.*\.so$
%filter_setup
}

Name:           OpenColorIO
Version:        2.1.0
Release:        1%{?_dist_release}
Summary:        Enables color transforms and image display across graphics apps
Summary(ja):    アプリケーション間での色変換と画像表示を行うためのライブラリ
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        BSD
URL:            https://opencolorio.org/
# Github archive was generated on the fly using the following URL:
# https://github.com/imageworks/OpenColorIO/tarball/v1.0.8

Source0:        https://github.com/AcademySoftwareFoundation/OpenColorIO/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
# https://github.com/AcademySoftwareFoundation/OpenColorIO/issues/1296
Patch0:         ocio-install.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires:  cmake
BuildRequires:  git
BuildRequires:  help2man
BuildRequires:  python3-devel
BuildRequires:  python3-rpm-macros
%if %{with doc}
BuildRequires:  texlive-collection-fontsrecommended
BuildRequires:  texlive-collection-latexextra
BuildRequires:  texlive-collection-latexrecommended
%endif

# Libraries
BuildRequires:  OpenEXR-devel
BuildRequires:  libboost-devel
BuildRequires:  expat-devel
BuildRequires:  freeglut-devel
BuildRequires:  glew-devel
BuildRequires:  libX11-devel libXmu-devel libXi-devel
BuildRequires:  mesa-libGL-devel mesa-libGLU-devel
#BuildRequires:  opencv-devel
BuildRequires:  pybind11-devel
BuildRequires:  python3-devel
BuildRequires:  python3-pip
#BuildRequires:  pystring-devel
BuildRequires:  zlib-devel

# WARNING: OpenColorIO and OpenImageIO are cross dependent.
# If an ABI incompatible update is done in one, the other also needs to be
# rebuilt.
BuildRequires:  OpenImageIO-devel

#######################
# Unbundled libraries #
#######################
BuildRequires:  lcms2-devel
#BuildRequires:  yaml-cpp-devel

# The following bundled projects  are only used for document generation.
#BuildRequires:  python-docutils
#BuildRequires:  python-jinja2
#BuildRequires:  python-pygments
#BuildRequires:  python-setuptools
#BuildRequires:  python-sphinx

%if ! %{with doc}
Obsoletes: %{name}-doc < %{version}-%{release}
%endif

%description
OCIO enables color transforms and image display to be handled in a consistent
manner across multiple graphics applications. Unlike other color management
solutions, OCIO is geared towards motion-picture post production, with an
emphasis on visual effects and animation color pipelines.


%package devel
Summary:        Development libraries and headers for %{name}
Summary(ja):    %{name} の開発用ライブラリおよびヘッダファイル
Group:          programming
Requires:       %{name} = %{version}-%{release}

%description devel
Development libraries and headers for %{name}.


%package doc
Summary:        API Documentation for %{name}
Summary(ja):    %{name} API のドキュメント
Group:          documentation
BuildArch:      noarch
Requires:       %{name} = %{version}-%{release}

%description doc
API documentation for %{name}.


%debug_package


%prep
%autosetup -p1


%build
rm -rf %{_vpath_builddir}

export CXXFLAGS="%{optflags} -Wno-deprecated-declarations -Wno-cast-function-type -Wno-unused-function"

%cmake \
       -DPYTHON=%{__python3} \
       -DPYLIB_INSTALL_DIR:PATH=%{python3_sitearch} \
       -DOCIO_BUILD_STATIC=OFF \
%if %{with doc}
       -DOCIO_BUILD_DOCS=ON \
%else
       -DOCIO_BUILD_DOCS=OFF \
%endif
       -DOCIO_BUILD_TESTS=ON \
       -DOCIO_USE_HEADLESS=ON \
       -DOCIO_PYGLUE_SONAME=OFF \
       -DUSE_EXTERNAL_YAML=FALSE \
       -DUSE_EXTERNAL_LCMS=TRUE \
%ifnarch x86_64
       -DOCIO_USE_SSE=OFF \
%endif
       -DOpenGL_GL_PREFERENCE=GLVND

%cmake_build


%install
rm -rf %{buildroot}
%cmake_install

# Remove static libs
find %{buildroot} -type f -name "*.a" -exec rm -f {} \;

# Generate man pages
pushd %{_vpath_builddir}/src/apps
mkdir -p %{buildroot}%{_mandir}/man1
for app in ociobakelut ociocheck ociochecklut ocioconvert ociolutimage ociomakeclf ocioperf ociowrite; do \
help2man -N -s 1 %{?fedora:--version-string=%{version}} \
         -o %{buildroot}%{_mandir}/man1/$app.1 \
         $app/$app
done
popd

# Move installed documentation back so it doesn't conflict with the main package

%if %{with doc}
rm -rf _tmpdoc
mkdir -p _tmpdoc
mv %{buildroot}%{_docdir}/%{name}/* _tmpdoc/
%endif


%check
# Testing passes locally in mock but fails on the fedora build servers.
#pushd build && make test


%clean
rm -rf %{buildroot}


%files
%license LICENSE
%doc CHANGELOG* README*
%{_bindir}/*
%{_libdir}/*.so.*
%dir %{_datadir}/ocio
%{_datadir}/ocio/setup_ocio.sh
%{_mandir}/man1/*
%{python3_sitearch}/*.so

%files devel
%{_includedir}/OpenColorIO/
%{_libdir}/*.so
%dir %{_libdir}/pkgconfig
%{_libdir}/pkgconfig/%{name}.pc
%dir %{_libdir}/cmake
%{_libdir}/cmake/*

%if %{with doc}
%files doc
%doc _tmpdoc/*
%endif


%changelog
* Wed Sep 01 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.1.0-1
- new upstream release.
- dropped ldconfig scriptlets.
- dropped Patch1.
- imported Patch0 from rawhide.

* Sat Oct 26 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 1.1.1-1
- new upstream release.

* Tue Jun 28 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 1.0.8-8
- rebuild with gcc-5.4.0

* Tue Jan 13 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 1.0.8-7
- Initial build for Vine Linux
- used bundled yaml-cpp

* Mon Sep 23 2013 Richard Shaw <hobbes1069@gmail.com> - 1.0.8-6
- Rebuild against yaml-cpp03 compatibility package.

* Mon Aug 26 2013 Richard Shaw <hobbes1069@gmail.com> - 1.0.8-5
- Fix for new F20 feature, unversion doc dir. Fixes BZ#1001264

* Fri Aug 02 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Wed Feb 13 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.8-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Tue Dec 11 2012 Richard Shaw <hobbes1069@gmail.com> - 1.0.8-1
- Update to latest upstream release.

* Wed Jul 18 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.7-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Thu Apr 26 2012 Richard Shaw <hobbes1069@gmail.com> - 1.0.7-4
- Only use SSE instructions on x86_64.

* Wed Apr 25 2012 Richard Shaw <hobbes1069@gmail.com> - 1.0.7-3
- Misc spec cleanup for packaging guidelines.
- Disable testing for now since it fails on the build servers.

* Wed Apr 18 2012 Richard Shaw <hobbes1069@gmail.com> - 1.0.7-1
- Latest upstream release.

* Thu Apr 05 2012 Richard Shaw <hobbes1069@gmail.com> - 1.0.6-1
- Latest upstream release.

* Wed Nov 16 2011 Richard Shaw <hobbes1069@gmail.com> - 1.0.2-1
- Initial release.
