File octave.spec of Package octave

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

# Use native graphics or gnuplot
%define with_native_graphics 1
# Build GUI
%define with_gui 1
# Use Qt5 GUI
%define with_qt5gui 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
# BLAS library
%define with_openblas 1

%if 0%{?suse_version} <= 1320
%define with_qt5gui 0

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

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

# architecture-specific
%ifarch %ix86
# tests failure with openblas
%define with_openblas 0

Name:           octave
Version:        4.2.2
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-or-later
Group:          Productivity/Scientific/Math
%define apiver  v51
Source3:        octave.macros
# PATCH-FIX-UPSTREAM octave-java-use-source-target-1_6.patch -- Switch source/target to 1.6 from 1.3, to get octave building with java 9 (for openSUSE >= 1320); patch taken from upstream mercurial repository.
Patch1:         octave-java-use-source-target-1_6.patch
BuildRequires:  arpack-ng-devel
BuildRequires:  bison
%if 0%{?with_openblas}
BuildRequires:  openblas-devel
BuildRequires:  blas-devel
BuildRequires:  dejagnu
BuildRequires:  fftw3-threads-devel
BuildRequires:  flex
BuildRequires:  gcc-c++
BuildRequires:  gcc-fortran
BuildRequires:  glpk-devel
BuildRequires:  gmp-devel
BuildRequires:  gperf
BuildRequires:  hdf5-devel
BuildRequires:  lapack-devel
%if 0%{?with_imagemagick}
BuildRequires:  pkgconfig(ImageMagick++)
BuildRequires:  pkgconfig(GraphicsMagick++)
BuildRequires:  lzip
BuildRequires:  pcre-devel
BuildRequires:  pkg-config
BuildRequires:  qhull-devel
BuildRequires:  qrupdate-devel
BuildRequires:  readline-devel
BuildRequires:  suitesparse-devel
BuildRequires:  termcap
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(zlib)
# Documentation build requires
BuildRequires:  gnuplot
BuildRequires:  texinfo
BuildRequires:  texlive-dvips
BuildRequires:  texlive-latex
# GUI build requires
%if 0%{?with_gui}
BuildRequires:  desktop-file-utils
BuildRequires:  hicolor-icon-theme
BuildRequires:  update-desktop-files
%if 0%{?with_qt5gui}
# Required for Patch0
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  libtool
BuildRequires:  libqscintilla_qt5-devel
BuildRequires:  libqt5-linguist
BuildRequires:  pkgconfig(Qt5Core)
BuildRequires:  pkgconfig(Qt5Gui)
BuildRequires:  pkgconfig(Qt5Network)
BuildRequires:  pkgconfig(Qt5OpenGL)
BuildRequires:  pkgconfig(Qt5PrintSupport)
BuildRequires:  libqt4-devel
BuildRequires:  qscintilla-devel
Obsoletes:      octave-gui < 4.0
# Sound IO build requires
%if 0%{?with_sound}
BuildRequires:  pkgconfig(alsa)
BuildRequires:  pkgconfig(portaudio-2.0)
BuildRequires:  pkgconfig(sndfile)
# JAVA functions build requires
%if 0%{?with_java}
BuildRequires:  java-devel
# JIT build requires
%if 0%{?with_jit}
BuildRequires:  llvm-devel
# Native graphics build requires
%if 0%{?with_native_graphics}
BuildRequires:  Mesa-devel
BuildRequires:  fltk-devel
BuildRequires:  gl2ps-devel
BuildRequires:  pkgconfig(fontconfig)
BuildRequires:  pkgconfig(freetype2)
BuildRequires:  pkgconfig(glu)
BuildRequires:  pkgconfig(xft)
Requires:       gnuplot
# Tests build requires
BuildRequires:  unzip
BuildRequires:  zip
Requires:       octave-cli = %{version}
Requires(post): update-alternatives
Requires(preun): update-alternatives
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

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

%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
# transfig requires texlive installation now
# Recommends:     transfig
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}
%if 0%{?with_openblas}
Requires:       openblas-devel
Requires:       blas-devel
Requires:       fftw3-devel
Requires:       fftw3-threads-devel
Requires:       gcc-c++
Requires:       gcc-fortran
Requires:       hdf5-devel
Requires:       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

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

This package contains documentation for Octave.

%setup -q -n %{name}-%{src_ver}

# define octave_blas macros
%if 0%{?with_openblas}
sed -i 's/OCTAVE_BLAS_LIBRARY_NAME/openblas/g' %{SOURCE3}

%if 0%{?suse_version} > 1320
%patch1 -p1

# Patch0 and Patch1 edit m4 files, so regenerate configure
%if 0%{?with_qt5gui} || 0%{?suse_version} > 1320
autoreconf -fvi

export CPPFLAGS="-DH5_USE_16_API"
%configure \
  --libexecdir=%{_libdir} \
  %if 0%{?with_openblas}
  --with-blas=openblas \
  --with-blas=blas \
  %if %{?with_gui} == 0
  --disable-gui \
  %if %{?with_jit} == 1
  --enable-jit \
  %if %{?with_java} == 0
  --disable-java \

make %{?_smp_mflags}

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

# see bnc#557340
mkdir -p %{buildroot}/%{_sysconfdir}/
echo %{_libdir}/%{name}/%{src_ver} > %{buildroot}/%{_sysconfdir}/{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/
# 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/' %{buildroot}%{_datadir}/appdata/octave.appdata.xml
sed -i 's/screenshot.png/screenshot-2016.png/' %{buildroot}%{_datadir}/appdata/octave.appdata.xml
rm -rf %{buildroot}/%{_datadir}/icons/hicolor/
rm -rf %{buildroot}/%{_datadir}/appdata/
# 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}

make check

%{_sbindir}/update-alternatives --install %{_bindir}/%{name}-%{src_ver} %{name} %{_bindir}/%{name}-gui-%{src_ver} 50
%if 0%{?with_gui}

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

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

%if 0%{?with_gui}

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

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

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

%postun cli
%install_info_delete --info-dir=%{_infodir} %{_infodir}/

%doc README ChangeLog
%ghost %{_sysconfdir}/alternatives/%{name}
%ghost %{_sysconfdir}/alternatives/%{name}-%{src_ver}
%ghost %{_bindir}/%{name}-%{src_ver}
%if 0%{?with_gui}
%if 0%{?suse_version} <= 1315
%dir %{_datadir}/appdata

%files cli
%ghost %{_bindir}/%{name}-%{src_ver}
%ghost %{_sysconfdir}/alternatives/%{name}
%ghost %{_sysconfdir}/alternatives/%{name}-%{src_ver}
%config %{_sysconfdir}/{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}
%if 0%{?with_gui}
%dir %{_libdir}/%{name}/%{src_ver}/exec/
%dir %{_libdir}/%{name}/%{src_ver}/exec/*-*-linux-gnu*/
%exclude %{_datadir}/%{name}/%{src_ver}/locale/

%files devel
%config %{_sysconfdir}/rpm/macros.octave

%files doc
%doc doc/interpreter/octave.pdf
%doc doc/liboctave/liboctave.pdf
%doc doc/refcard/refcard-a4.pdf
%doc doc/refcard/refcard-legal.pdf

openSUSE Build Service is sponsored by