File octave.spec of Package octave

#
# spec file for package octave
#
# Copyright (c) 2016 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/
#


# Use native graphics or gnuplot
%define with_native_graphics 1
# Build GUI
%define with_gui 1
# JIT compilation
%define with_jit 0
# JAVA support
%define with_java 1
# Image processing library
# Default variant - GraphicsMagick
%define with_imagemagick 0
# Sound IO
%define with_sound 1

# SLE11
%if 0%{?suse_version} == 1110
%define with_gui 0
%define with_jit 0
%define with_imagemagick 1
%endif

# SLE12
%if 0%{?suse_version} == 1315 && 0%{?is_opensuse} == 0
%define with_gui 0
%define with_jit 0
%define with_imagemagick 1
%endif

Name:           octave
Version:        4.0.3
Release:        0
# Required for RC builds, in this case version contains ~rc, src_ver -rc
%define src_ver %{version}
Summary:        A High Level Programming Language
License:        GPL-3.0+
Group:          Productivity/Scientific/Math
%define apiver  v50+
Url:            http://www.octave.org/
Source:         ftp://ftp.gnu.org/gnu/octave/%{name}-%{src_ver}.tar.xz
Source2:        octave.pc.in
Source3:        octave.macros
Patch1:         octave-gcc6.patch
BuildRequires:  arpack-ng-devel
BuildRequires:  bison
BuildRequires:  blas-devel
BuildRequires:  dejagnu
BuildRequires:  fftw3-threads-devel
BuildRequires:  flex
BuildRequires:  freetype2-devel
BuildRequires:  gcc-c++
BuildRequires:  gcc-fortran
BuildRequires:  gl2ps-devel
BuildRequires:  glpk-devel
BuildRequires:  gmp-devel
BuildRequires:  gnuplot
BuildRequires:  gperf
BuildRequires:  hdf5-devel
BuildRequires:  lapack-devel
%if 0%{?with_imagemagick}
BuildRequires:  libMagick++-devel
%else
BuildRequires:  libGraphicsMagick++-devel
%endif
BuildRequires:  libcurl-devel
BuildRequires:  liblcms-devel
BuildRequires:  pcre-devel
BuildRequires:  pkg-config
BuildRequires:  qhull-devel
BuildRequires:  qrupdate-devel
BuildRequires:  readline-devel
BuildRequires:  suitesparse-devel
BuildRequires:  termcap
BuildRequires:  texinfo
%if 0%{?suse_version} > 1220
BuildRequires:  texlive-dvips
%endif
BuildRequires:  texlive-latex
BuildRequires:  xz
BuildRequires:  zlib-devel
# GUI build requires
%if 0%{?with_gui}
BuildRequires:  desktop-file-utils
BuildRequires:  hicolor-icon-theme
BuildRequires:  libqt4-devel
BuildRequires:  qscintilla-devel
BuildRequires:  update-desktop-files
Obsoletes:      octave-gui < 4.0
%endif
# Sound IO build requires
%if 0%{?with_sound}
BuildRequires:  alsa-devel
BuildRequires:  libsndfile-devel
BuildRequires:  portaudio-devel
%endif
# JAVA functions build requires
%if 0%{?with_java}
BuildRequires:  java-devel
%endif
# JIT build requires
%if 0%{?with_jit}
BuildRequires:  llvm-devel
%endif
# Native graphics build requires
%if 0%{?with_native_graphics}
%if 0%{?suse_version} > 1220
BuildRequires:  glu-devel
%endif
BuildRequires:  Mesa-devel
BuildRequires:  fltk-devel
BuildRequires:  fontconfig-devel
BuildRequires:  xorg-x11-devel
BuildRequires:  xorg-x11-libSM-devel
BuildRequires:  xorg-x11-libX11-devel
BuildRequires:  xorg-x11-libXext-devel
%else
Requires:       gnuplot
%endif
# Tests build requires
BuildRequires:  unzip
BuildRequires:  zip
Requires:       octave-cli = %{version}
Requires(post): update-alternatives
Requires(preun): update-alternatives
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Octave is a high level programming language. It is designed for the
solution of numeric problems. There is a command line interface
supplied.
%if 0%{?with_gui}
This package contains graphical user interface.
%endif

%package        cli
Summary:        Command-line user interface for Octave
Group:          Productivity/Scientific/Math
Requires:       makeinfo
Requires(post): update-alternatives
Requires(preun): update-alternatives
%if 0%{?with_native_graphics}
Recommends:     epstool
Recommends:     pstoedit
Recommends:     transfig
%endif
Recommends:     octave-devel = %{version}
Recommends:     octave-doc = %{version}

%description    cli
Octave is a high level programming language. It is designed for the
solution of numeric problems.

This package contains command-line user interface.

%package        devel
Summary:        Development files for Octave
Group:          Productivity/Scientific/Math
Requires:       %{name}-cli = %{version}
Recommends:     blas-devel
Recommends:     fftw3-devel
Recommends:     fftw3-threads-devel
Recommends:     gcc
Recommends:     gcc-fortran
Recommends:     hdf5-devel
Recommends:     make

%description    devel
Octave is a high level programming language. It is designed for the
solution of numeric problems.

This package contains all necessary include files and libraries needed
to develop applications using Octave.

%package        doc
Summary:        Documentation for Octave
Group:          Documentation/Other
%if 0%{?suse_version} > 1110
BuildArch:      noarch
%endif

%description    doc
Octave is a high level programming language. It is designed for the
solution of numeric problems.

This package contains documentation for Octave.

%if 0%{?suse_version} > 1320
%if %( echo `rpm -q --queryformat %%{version} gcc` ) > 5
%define with_gcc6 1
%endif
%endif

%prep
%setup -q -n %{name}-%{src_ver}
%if 0%{?with_gcc6}
%patch1 -p1
find -name \*.cc -o -name \*.h -o -name \*.yy | xargs sed -i -e 's/#include <c\(math\|stdlib\)>/#include <\1.h>/'
find -name \*.h -o -name \*.cc | xargs sed -i -e 's/<config.h>/"config.h"/' -e 's/<base-list.h>/"base-list.h"/'
%endif

%build
export CPPFLAGS="-DH5_USE_16_API"
%configure \
  --libexecdir=%{_libdir} \
  %if %{?with_gui} == 0
  --disable-gui \
  %endif
  %if %{?with_jit} == 1
  --enable-jit \
  %endif
  %if %{?with_java} == 0
  --disable-java \
  %endif
  %if 0%{?suse_version} <= 1310
  --with-umfpack="-lumfpack -lcholmod -lcolamd -lsuitesparseconfig -lrt -llapack" \
  --with-cholmod="-lcholmod -lsuitesparseconfig -lrt" \
  %endif
  --enable-openmp

make %{?_smp_mflags}

# .pc file
cp %{SOURCE2} octave.pc
sed -i 's:@VERSION@:%{src_ver}:' octave.pc
sed -i 's:@LIB@:%{_lib}:' octave.pc

%install
%make_install
# see bnc#557340
mkdir -p %{buildroot}/%{_sysconfdir}/ld.so.conf.d
echo %{_libdir}/%{name}/%{src_ver} > %{buildroot}/%{_sysconfdir}/ld.so.conf.d/%{name}.conf
rm %{buildroot}/%{_libdir}/%{name}/%{src_ver}/*.la
# local rc file into /etc
mkdir %{buildroot}/%{_sysconfdir}/%{name}
mv %{buildroot}/%{_datadir}/%{name}/site/m/startup/octaverc %{buildroot}/%{_sysconfdir}/%{name}
ln -s %{_sysconfdir}/%{name}/octaverc %{buildroot}/%{_datadir}/%{name}/site/m/startup/octaverc
#
mkdir -p %{buildroot}/%{_libdir}/%{name}/packages
mkdir -p %{buildroot}/%{_datadir}/%{name}/packages
# .pc file
mkdir -p %{buildroot}/%{_libdir}/pkgconfig
cp octave.pc %{buildroot}/%{_libdir}/pkgconfig
# big icons size
%if 0%{?suse_version} <= 1320
rm -rf %{buildroot}/%{_datadir}/icons/hicolor/512x512/
%endif
# gui related fixes
%if %{?with_gui}
mv %{buildroot}/%{_datadir}/applications/*octave.desktop %{buildroot}/%{_datadir}/applications/octave.desktop
%suse_update_desktop_file -r octave "Science;Math"
# appdata
mv %{buildroot}%{_datadir}/appdata/*octave.appdata.xml %{buildroot}%{_datadir}/appdata/octave.appdata.xml
sed -i 's/www.octave.org-octave.desktop/octave.desktop/' %{buildroot}%{_datadir}/appdata/octave.appdata.xml
sed -i 's/screenshot.png/screenshot-2016.png/' %{buildroot}%{_datadir}/appdata/octave.appdata.xml
%else
rm -rf %{buildroot}/%{_datadir}/icons/hicolor/
rm -rf %{buildroot}/%{_datadir}/appdata/
%endif
# rpm macros
install -Dm 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/rpm/macros.octave
# dummy target for update-alternatives
install -d %{buildroot}/%{_sysconfdir}/alternatives
ln -s %{name} %{buildroot}/%{_sysconfdir}/alternatives/%{name}
# move gui binaries
mv %{buildroot}/%{_bindir}/%{name} %{buildroot}/%{_bindir}/%{name}-gui
mv %{buildroot}/%{_bindir}/%{name}-%{src_ver} %{buildroot}/%{_bindir}/%{name}-gui-%{src_ver}

ln -s %{name}-%{src_ver} %{buildroot}/%{_bindir}/%{name}
ln -s %{name}-cli-%{src_ver} %{buildroot}/%{_bindir}/%{name}-%{src_ver}

%check
make check

%post
%{_sbindir}/update-alternatives --install %{_bindir}/%{name}-%{src_ver} %{name} %{_bindir}/%{name}-gui-%{src_ver} 50
/sbin/ldconfig

%posttrans
if [ "$1" = 0 ] ; then
  if ! [ -f %{_bindir}/%{name}-%{src_ver} ] ; then
      %{_sbindir}/update-alternatives --auto %{name}
  fi
fi

%preun
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove %{name} %{_bindir}/%{name}-gui-%{src_ver}
fi

%postun
/sbin/ldconfig

%post cli
%{_sbindir}/update-alternatives --install %{_bindir}/%{name}-%{src_ver} %{name} %{_bindir}/%{name}-cli-%{src_ver} 20
/sbin/ldconfig
%install_info --info-dir=%{_infodir} %{_infodir}/octave.info.gz

%posttrans cli
if [ "$1" = 0 ] ; then
  if ! [ -f %{_bindir}/%{name}-%{src_ver} ] ; then
      %{_sbindir}/update-alternatives --auto %{name}
  fi
fi

%preun cli
if [ "$1" = 0 ] ; then
   %{_sbindir}/update-alternatives --remove %{name} %{_bindir}/%{name}-cli-%{src_ver}
fi

%postun cli
/sbin/ldconfig
%install_info_delete --info-dir=%{_infodir} %{_infodir}/octave.info.gz

%files
%defattr(-,root,root,-)
%doc AUTHORS BUGS COPYING NEWS
%doc README ChangeLog
%ghost %{_sysconfdir}/alternatives/%{name}
%ghost %{_bindir}/%{name}-%{src_ver}
%{_bindir}/%{name}-gui
%{_bindir}/%{name}-gui-%{src_ver}
%if 0%{?with_gui}
%{_libdir}/%{name}/%{src_ver}/exec/*-*-linux-gnu*/octave-gui
%{_libdir}/%{name}/%{src_ver}/liboctgui.so.*
%{_datadir}/%{name}/%{src_ver}/locale/
%{_datadir}/appdata/*.xml
%{_datadir}/applications/*.desktop
%if 0%{?suse_version} <= 1315
%dir %{_datadir}/appdata
%endif
%{_datadir}/icons/hicolor/*/apps/octave.*
%endif

%files cli
%defattr(-,root,root)
%{_bindir}/%{name}
%ghost %{_bindir}/%{name}-%{src_ver}
%ghost %{_sysconfdir}/alternatives/%{name}
%{_bindir}/octave-cli
%{_bindir}/octave-cli-%{src_ver}
%{_mandir}/man1/octave.1.gz
%{_mandir}/man1/octave-cli.1.gz
%{_bindir}/mkoctfile
%{_bindir}/mkoctfile-%{src_ver}
%{_mandir}/man1/mkoctfile.1.gz
%{_bindir}/octave-config
%{_bindir}/octave-config-%{src_ver}
%{_mandir}/man1/octave-config.1.gz
%{_infodir}/*.gz
%config %{_sysconfdir}/ld.so.conf.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/%{name}/octaverc
%dir %{_libdir}/%{name}
%dir %{_libdir}/%{name}/%{src_ver}
%dir %{_libdir}/%{name}/packages
%dir %{_datadir}/%{name}/packages
%dir %{_sysconfdir}/%{name}
%{_libdir}/%{name}/%{src_ver}/oct
%{_libdir}/%{name}/%{src_ver}/liboctave.so.*
%{_libdir}/%{name}/%{src_ver}/liboctinterp.so.*
%if 0%{?with_gui}
%dir %{_libdir}/%{name}/%{src_ver}/exec/
%dir %{_libdir}/%{name}/%{src_ver}/exec/*-*-linux-gnu*/
%exclude %{_datadir}/%{name}/%{src_ver}/locale/
%endif
%{_datadir}/octave/
%{_libdir}/%{name}/site
%{_libdir}/pkgconfig/octave.pc

%files devel
%defattr(-,root,root)
%{_includedir}/*
%{_libdir}/%{name}/%{src_ver}/lib*.so
%{_libdir}/%{name}/api-%{apiver}
%config %{_sysconfdir}/rpm/macros.octave

%files doc
%defattr(-,root,root)
%doc doc/interpreter/octave.pdf
%doc doc/liboctave/liboctave.pdf
%doc doc/refcard/refcard-a4.pdf
%doc doc/refcard/refcard-legal.pdf

%changelog