#
# spec file for package openjpeg2
#
# Copyright (c) 2017 SUSE LINUX 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 library_name  libopenjp2-7
%define base_version 2.3

Name:           openjpeg2
Version:        2.3.0
Release:        1.2
Summary:        Opensource JPEG 2000 Codec Implementation
License:        BSD-2-Clause
Group:          Productivity/Graphics/Other
Url:            http://www.openjpeg.org/
Source0:        https://github.com/uclouvain/openjpeg/archive/v%{version}.tar.gz#/openjpeg-%{version}.tar.gz
Source1:        baselibs.conf
Patch1:         install-fix.patch
BuildRequires:  cmake > 2.8.2
BuildRequires:  doxygen
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  pkg-config
BuildRequires:  pkgconfig(lcms2)
BuildRequires:  pkgconfig(libpng)
BuildRequires:  pkgconfig(libtiff-4)
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
The OpenJPEG library is an open-source JPEG 2000 codec written in C language.
It has been developed in order to promote the use of JPEG 2000, the new
still-image compression standard from the Joint Photographic Experts Group
(JPEG).

This package provides the codec executables.

%package -n %{library_name}
Summary:        Opensource JPEG 2000 Codec Implementation
Group:          System/Libraries

%description -n %{library_name}
The OpenJPEG library is an open-source JPEG 2000 codec written in C language.
It has been developed in order to promote the use of JPEG 2000, the new
still-image compression standard from the Joint Photographic Experts Group
(JPEG).

%package        devel
Summary:        Development files for %{name}
Group:          Development/Libraries/Other
Requires:       %{library_name} = %{version}
Recommends:     %{name} = %{version}

%description    devel
The OpenJPEG library is an open-source JPEG 2000 codec written in C language.
It has been developed in order to promote the use of JPEG 2000, the new
still-image compression standard from the Joint Photographic Experts Group
(JPEG).

This package provides the development files for %{name}.

%prep
%setup -q -n openjpeg-%{version}
# do not embed timestamps into html documentation
sed -i 's|^HTML_TIMESTAMP[ =].*$|HTML_TIMESTAMP = NO|' doc/Doxyfile.dox.cmake.in
%patch1 -p1

# ensure no bundled libraries are used
for d in thirdparty/*; do
    [ -d "$d" ] && rm -rf "$d"
done

%build
%cmake \
  -DBUILD_SHARED_LIBS=ON \
  -DBUILD_CODEC=ON \
  -DBUILD_JPIP=OFF \
  -DBUILD_JPWL=OFF \
  -DBUILD_MJ2=OFF \
  -DBUILD_TESTING=OFF \
  -DBUILD_DOC=ON \
  -DBUILD_THIRDPARTY=OFF \
  -DOPENJPEG_INSTALL_LIB_DIR=%{_lib}

make %{?_smp_mflags} VERBOSE=1 all doc

cat << END > libopenjp2.pc

Name:           openjpeg
Version:        %{version}
Url:            %{url}
Description: Opensource JPEG 2000 Codec Implementation
Libs: -L%{_libdir} -lopenjp2
Libs.private: -lm
Cflags: -I%{_includedir}/openjpeg-%{base_version}
END
%fdupes -s doc/html/

%install
%cmake_install

mkdir -p %{buildroot}%{_libdir}/pkgconfig/
install -m 644 build/libopenjp2.pc %{buildroot}%{_libdir}/pkgconfig/
rm -rf %{buildroot}%{_datadir}/doc

%post -n %{library_name} -p /sbin/ldconfig

%postun -n %{library_name} -p /sbin/ldconfig

%files
%defattr(-,root,root,-)
%doc AUTHORS.md CHANGELOG.md NEWS.md LICENSE README.md THANKS.md
%{_bindir}/opj_*
%{_mandir}/man1/opj_*.1%{ext_man}

%files -n %{library_name}
%defattr(-,root,root,-)
%{_libdir}/libopenjp2.so.*

%files devel
%defattr(-,root,root,-)
%doc build/doc/html/
%{_includedir}/openjpeg-%{base_version}/
%{_libdir}/libopenjp2.so
%{_libdir}/pkgconfig/libopenjp2.pc
%{_libdir}/openjpeg-%{base_version}/
%{_mandir}/man3/libopenjp2.3%{ext_man}

%changelog
* Mon Oct 23 2017 idonmez@suse.com
- Update to version 2.3.0
- Drop upstream patches:
  * 0018-tcd_get_decoded_tile_size.patch
  * openjpeg2-CVE-2016-10504.patch
  * openjpeg2-CVE-2016-10505.patch
  * openjpeg2-CVE-2016-10506.patch
  * openjpeg2-CVE-2017-12982.patch
  * openjpeg2-CVE-2017-14039.patch
  * openjpeg2-CVE-2017-14040.patch
  * openjpeg2-CVE-2017-14041.patch
  * openjpeg2-CVE-2017-14151.patch
  * openjpeg2-CVE-2017-14152.patch
- Add install-fix.patch from upstream to fix library installation.
* Tue Sep 12 2017 hpj@suse.com
- Add security fixes:
  openjpeg2-CVE-2016-10504.patch (CVE-2016-10504, bsc#1056351),
  openjpeg2-CVE-2016-10505.patch (CVE-2016-10505, bsc#1056363),
  openjpeg2-CVE-2016-10506.patch (CVE-2016-10506, bsc#1056396),
  openjpeg2-CVE-2017-12982.patch (CVE-2017-12982, bsc#1054696),
  openjpeg2-CVE-2017-14039.patch (CVE-2017-14039, CVE-2017-14164,
  bsc#1056622, bsc#1057511),
  openjpeg2-CVE-2017-14040.patch (CVE-2017-14040, bsc#1056621),
  openjpeg2-CVE-2017-14041.patch (CVE-2017-14041, bsc#1056562),
  openjpeg2-CVE-2017-14151.patch (CVE-2017-14151, bsc#1057336),
  openjpeg2-CVE-2017-14152.patch (CVE-2017-14152, bsc#1057335),
  most of which are critical, including heap and stack overwrites,
  over-reads and division by zero errors.
* Mon Dec 19 2016 normand@linux.vnet.ibm.com
- update to version 2.1.2
  Bug fixes including security fixes among which:
  CVE-2016-8332 CVE-2016-7163
  CVE-2016-5139 CVE-2016-5159
  CVE-2016-5158 (not listed but solved different way)
  Huge amount of critical bugfixes
  Speed improvements
  No API/ABI break compared to v2.1.1/v2.1
- some doc files now have '.md' suffix (like README.md)
- CVE-2016-5152 with new 0018-tcd_get_decoded_tile_size.patch
* Tue Dec  8 2015 p.drouand@gmail.com
- Add a pkg-config dependency; expand pkgconfig
* Mon Oct 19 2015 schwab@suse.de
- Re-add baselibs.conf, needed by poppler and leptonica
* Fri Sep  4 2015 mpluskal@suse.com
- Use cmake macro
- Remove baselibs.conf (it was broken anyways for months)
- Cleanup spec file with spec-cleaner
* Sat May 31 2014 coolo@suse.com
- pimp up the previous changelog
* Tue May 27 2014 opensuse@dstoecker.de
- update to version 2.1.0
  New Features:
  * Digital Cinema profiles have been fixed and updated
  * New option to disable MCT if needed
  * extended RAW support: it is now possible to input raw images
    with subsampled color components (422, 420, etc)
  * New way to deal with profiles
  API/ABI modifications: (see abi_compat_report in dev-utils/scripts)
  * Removed deprecated functions
  - opj_stream_create_default_file_stream(FILE*,...)
  - opj_stream_create_file_stream(FILE*,...)
  - opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data)
  * Added
  - opj_stream_create_default_file_stream(char*,...)
  - opj_stream_create_file_stream(char*,...)
  - opj_stream_destroy(opj_stream_t*)
  - opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data,
    ... opj_stream_free_user_data_fn p_function)
  - JPEG 2000 profiles and Part-2 extensions defined through '#define'
  * Changed
  - 'alpha' field added to 'opj_image_comp' structure
  - 'OPJ_CLRSPC_EYCC' added to enum COLOR_SPACE
  - 'OPJ_CLRSPC_CMYK' added to enum COLOR_SPACE
  - 'OPJ_CODEC_JPP' and 'OPJ_CODEC_JPX' added to CODEC_FORMAT
    (not yet used in use)
  - 'max_cs_size' and 'rsiz' fields added to opj_cparameters_t
  Misc:
  * OpenJPEG is now officialy conformant with JPEG 2000 Part-1
    and will soon become official reference software at the
    JPEG committee.
  * Huge amount of bug fixes. See CHANGES for details.
* Thu May  8 2014 hpj@urpla.net
- version 2.0.1
  - New Features:
  * Digital Cinema profiles have been fixed and updated
  * New option to disable MCT if needed
  * extended RAW support: it is now possible to input raw images
    with subsampled color components (422, 420, etc)
  - API/ABI modifications: (see abi_compat_report_2.0.1.html in dev-utils/scripts)
  * No changes, API/ABI fully compatible with 2.0.0
  - Misc:
  * OpenJPEG is now officialy conformant with JPEG 2000 Part-1
    and will soon become official reference software at the
    JPEG committee.
  * Huge amount of bug fixes. See CHANGES for details.
- adjust library name
* Tue Feb 18 2014 pgajdos@suse.com
- add libopenjp2.pc (demand introduced by ImageMagick 6.8.8-5)
* Tue Nov 26 2013 gber@opensuse.org
- remove bogus dependency on libjpeg-devel
* Tue Nov 26 2013 mrdocs@opensuse.org
- add explicit libjpeg-devel to fix build on SLE 11
* Sun Nov 24 2013 gber@opensuse.org
- use pkgconfig macros
- let openjpeg2-devel only recommend openjpeg2
* Wed Nov 13 2013 gber@opensuse.org
- remove bogus dependency on libgeotiff-devel and depend on
  libtiff-devel
- ensure no bundled libraries are used
* Tue Nov 12 2013 gber@opensuse.org
- cleanup
  - improve group, summary, description
  - fix license
  - fix build dependencies
  - use optflags, don't mess with debug symbols
  - fix library install path
  - create main package containing codec tools
  - build doxygen documentaion
  - fix %%post/un scriptlets for the libopenjp2-6 subpackage
  - add baselibs
* Wed May  8 2013 behrisch@users.sourceforge.net
- fixed make install for non suse targets
* Sun Nov 25 2012 Angelos Tzotsos <tzotsos@opensuse.org>
  Update to version 2.0 Final, fixed some major issues :
  * support of Large JPEG2000 Files greater than 2 GBytes
  * support of tile coding and decoding which allows to encode or decode only specific part of image if the file is tiled
  * implements subset of the MCT part 2
  * streaming system
  * improvement of the cmake build system
  * adding a CDash platform to support continuous integration of the different version
  * opaque pointers (opj_stream, opj_codec) have been used to simplify the API
  * the library does not perform the t1 decoding of non-needed resolutions any more (increases performance)
  * a lot of code has been simplified/factored in order to lower the memory consumption.
  * j2k.c and jp2.c have been modified to support a simpler extension mechanism
  * prefix all public and the great majority of the private symbols with opj_ to avoid conflict with external libraries
* Sun Jan 24 2010 Angelos Tzotsos <tzotsos@opensuse.org>
  * Initial build from SVN