# From src/version.h:#define OCTAVE_API_VERSION
%global octave_api api-v53

%global macrosdir %(d=%{_rpmconfigdir}/macros.d; [ -d $d ] || d=%{_sysconfdir}/rpm; echo $d)

%define pkg_name    octave
%define pkg_version 5.1.0
%define pkg_release 3%{?_dist_release}

Summary:     GNU Octave -- a high-level language for numerical computations
Summary(ja): 数値計算のための高級言語
Name:        %{pkg_name}
Version:     %{pkg_version}
Release:     %{pkg_release}

License: GPLv3
Group:   Applications/Edutainment
URL:     http://www.gnu.org/software/octave/

Source0: ftp://ftp.octave.org/gnu/octave/%{name}-%{version}.tar.lz

# RPM macros for helping to build Octave packages
Source1: macros.octave

Buildroot: %{_tmppath}/%{name}-%{version}-root

BuildRequires: gcc-gfortran
BuildRequires: bison flex gperf texinfo less
BuildRequires: gnuplot
BuildRequires: ghostscript-devel
BuildRequires: mesa-libOSMesa-devel
%if %{?_dist_release} == "vl6"
BuildRequires: arpack
BuildRequires: blas-devel lapack-devel
%endif
%if %{?_dist_release} >= "vl7"
BuildRequires: arpack-devel
BuildRequires: openblas-devel
%endif
BuildRequires: pcre-devel
BuildRequires: readline-devel
BuildRequires: curl-devel
BuildRequires: fftw3-devel
BuildRequires: fontconfig-devel
BuildRequires: freetype-devel
BuildRequires: glpk-devel
BuildRequires: GraphicsMagick-c++-devel
BuildRequires: hdf5-devel
BuildRequires: java-devel
BuildRequires: qhull-devel
BuildRequires: qrupdate
BuildRequires: suitesparse-devel
BuildRequires: zlib-devel
BuildRequires: xz-devel
BuildRequires: libtool-ltdl-devel
BuildRequires: libXext-devel
BuildRequires: openssl-devel
BuildRequires: desktop-file-utils
BuildRequires: freeglut-devel
BuildRequires: fltk-devel
BuildRequires: gl2ps-devel
%if %{?_dist_release} == "vl6"
BuildRequires: qt4-devel
BuildRequires: qscintilla-devel
%endif
%if %{?_dist_release} >= "vl7"
BuildRequires: qt5-qtbase-devel
BuildRequires: qt5-qttools-devel
%endif
BuildRequires: portaudio-devel
BuildRequires: libsndfile-devel
BuildRequires: lzip

Requires: ghostscript
%if %{?_dist_release} == "vl6"
Requires: blas lapack
%endif
%if %{?_dist_release} >= "vl7"
Requires: openblas
%endif
Requires: pcre
Requires: readline
Requires: mesa-libOSMesa
Requires: gnuplot
Requires: arpack
Requires: curl
Requires: fftw3
Requires: fontconfig
Requires: freetype
Requires: glpk
Requires: GraphicsMagick-c++
Requires: hdf5
Requires: libqhull
Requires: qrupdate
Requires: suitesparse
Requires: zlib
Requires: openssl
Requires: pstoedit epstool transfig
Requires: freeglut
Requires: fltk
Requires: gl2ps
%if %{?_dist_release} == "vl6"
Requires: qt4
Requires: qscintilla
%endif
%if %{?_dist_release} >= "vl7"
Requires: qt5-qtbase
Requires: qt5-qttools-libs-help
%endif
Requires: portaudio
Requires: libsndfile

Requires(post):   /sbin/install-info
Requires(postun): /sbin/ldconfig
Requires(post):   /sbin/ldconfig
Requires(preun):  /sbin/install-info

Provides:       octave(api) = %{octave_api}

Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
GNU Octave is a high-level language, primarily intended for numerical
computations. It provides a convenient command line interface for
solving linear and nonlinear problems numerically, and for performing
other numerical experiments using a language that is mostly compatible
with Matlab. It may also be used as a batch-oriented language.

Octave has extensive tools for solving common numerical linear algebra
problems, finding the roots of nonlinear equations, integrating
ordinary functions, manipulating polynomials, and integrating ordinary
differential and differential-algebraic equations. It is easily
extensible and customizable via user-defined functions written in
Octave's own language, or using dynamically loaded modules written in
C++, C, Fortran, or other languages.
# '

%description -l ja
GNU Octave は数値計算用に開発の始められた高級言語です。線形問題や非線形
問題を数値的に解いたり、その他のMatlab と互換性の高い言語を用いた数値計算
を行うための使いやすいコマンドライン・インタフェースを備えています。
バッチ指向言語としても使うこともできます。Octave は多機能なツールで、
一般的な線形幾何の問題の数値解や、通常の関数の積分・微分、多項式の操作等を
行うことができます。
Octave の言語でユーザが関数を定義したり、C++, C, Fortran その他の言語で
書いた動的ライブラリを用いて容易に拡張やカスタマイズを行うことができます。

(注意)
デフォルトではグラフの描画にOpenGL/fltkを使用してます。
もし不安定な場合には、
gnuplotをデフォルトとするために ~/.octaverc に
graphics_toolkit("gnuplot");
を追加してから起動して下さい。


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q

%build
%{configure} \
 CPPFLAGS="-I%{_includedir}/pcre" \
 --with-x \
 --with-magick=GraphicsMagick \
 --with-curl-includedir=%{_includedir}/curl \
 --with-glpk-includedir=%{_includedir}/glpk \
 --with-qhull-includedir=%{_includedir}/libqhull \
 --with-amd-includedir=%{_includedir}/suitesparse \
 --with-camd-includedir=%{_includedir}/suitesparse \
 --with-colamd-includedir=%{_includedir}/suitesparse \
 --with-ccolamd-includedir=%{_includedir}/suitesparse \
 --with-cholmod-includedir=%{_includedir}/suitesparse \
 --with-cxsparse-includedir=%{_includedir}/suitesparse \
 --with-umfpack-includedir=%{_includedir}/suitesparse \
 --enable-java \
 --with-qt=5

# Check that octave_api is set correctly (autogenerated file)
make liboctave/version.h
if ! grep -q '^#define OCTAVE_API_VERSION "%{octave_api}"' liboctave/version.h
then
  echo "octave_api variable in spec does not match liboctave/version.h"
  exit 1
fi

%{__make} %{?_smp_mflags}


%install
%{make_install}

find %{buildroot} -name "*.oct" | xargs strip

# Make library links
%{__mkdir_p} ${RPM_BUILD_ROOT}/etc/ld.so.conf.d
echo "%{_libdir}/octave-%{version}" > \
     ${RPM_BUILD_ROOT}/etc/ld.so.conf.d/octave-%{_arch}.conf

# Remove RPM_BUILD_ROOT from ls-R files
%{__perl} -pi -e "s,%{buildroot},," ${RPM_BUILD_ROOT}%{_libdir}/%{name}/ls-R
%{__perl} -pi -e "s,%{buildroot},," ${RPM_BUILD_ROOT}%{_datadir}/%{name}/ls-R
# Make sure ls-R exists
touch ${RPM_BUILD_ROOT}%{_datadir}/%{name}/ls-R

# Create directories for add-on packages
HOST_TYPE=`%{buildroot}%{_bindir}/octave-config -p CANONICAL_HOST_TYPE`
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_libdir}/%{name}/site/oct/%{octave_api}/$HOST_TYPE
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_libdir}/%{name}/site/oct/$HOST_TYPE
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_datadir}/%{name}/packages
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_libdir}/%{name}/packages
touch ${RPM_BUILD_ROOT}%{_datadir}/%{name}/octave_packages

# desktop file
%{__perl} -pi -e s/"Education;Science;Math;"/"Education;Science;"/g \
 ${RPM_BUILD_ROOT}%{_datadir}/applications/org.octave.Octave.desktop

# rpm macros
%{__mkdir_p} ${RPM_BUILD_ROOT}%{macrosdir}
cp -p %{SOURCE1} ${RPM_BUILD_ROOT}%{macrosdir}


%check
%{__make} %{?_smp_mflags} check

%clean
%{__rm} -rf ${RPM_BUILD_ROOT}


%post -p %{_syssbindir}/ldconfig

%postun -p %{_syssbindir}/ldconfig


%files
%defattr(-,root,root)
%license COPYING
%doc AUTHORS BUGS CITATION ChangeLog NEWS README
%doc examples doc/interpreter/octave.pdf doc/refcard
# FIXME: Create an -emacs package that has the emacs addon
%config(noreplace) %{_sysconfdir}/ld.so.conf.d/octave-*.conf
%{_bindir}/
%{_libdir}/octave
%{_libdir}/pkgconfig/*.pc
%{_includedir}/octave-%{version}
%{_datadir}/applications/
%{_datadir}/icons/
%{_datadir}/metainfo/
%{_datadir}/octave
%{_libexecdir}/octave
%{macrosdir}/macros.octave


%changelog
* Sun Nov 03 2019 Toshiaki Ara <ara_t@384.jp> 5.1.0-3
- Rebuild for suitesparse 5.4.0
- change using openblas for VineSeed
- add macros.octave from Fedora

* Sat Aug 31 2019 Toshiaki Ara <ara_t@384.jp> 5.1.0-2
- rebuild with readline-8.0 and ncurses-6.1

* Sun Apr 21 2019 Toshiaki Ara <ara_t@384.jp> 5.1.0-1
- update to 5.1.0
- drop gui/sound option

* Fri Jan 25 2019 Toshiaki Ara <ara_t@384.jp> 4.4.1-3
- rebuild with gfortran-8.2.0

* Tue Sep 04 2018 Toshiaki Ara <ara_t@384.jp> 4.4.1-2
- rebuild with qhull-2015.2

* Thu Aug 30 2018 Toshiaki Ara <ara_t@384.jp> 4.4.1-1
- update to 4.4.1

* Sun Jul 01 2018 Toshiaki Ara <ara_t@384.jp> 4.4.0-4
- using qt5 for VineSeed
  - add configure option: --with-qt=5
  - add BuildRequires: qt5-qtbase-devel and qt5-qttools-devel
  - add Requires: qt5-qtbase and qt5-qttools-libs-help

* Sun Jul 01 2018 Toshiaki Ara <ara_t@384.jp> 4.4.0-3
- rebuild with hdf5-1.8.20 for VineSeed

* Wed Jun 06 2018 Toshiaki Ara <ara_t@384.jp> 4.4.0-2
- add BuildRequires: arpack-devel for VineSeed

* Sun May 20 2018 Toshiaki Ara <ara_t@384.jp> 4.4.0-1
- update to 4.4.0
- correct License

* Sun Apr 01 2018 Toshiaki Ara <ara_t@384.jp> 4.2.2-1
- update to 4.2.2

* Sun Oct 29 2017 Toshiaki Ara <ara_t@384.jp> 4.2.1-2
- rebuild under glpk-4.63

* Mon Feb 27 2017 Toshiaki Ara <ara_t@384.jp> 4.2.1-1
- update to 4.2.1

* Sat Nov 19 2016 Toshiaki Ara <ara_t@384.jp> 4.2.0-1
- update to 4.2.0
- add make check
- add BuildRequires: lzip
- change BuildRequires: java-devel

* Mon Jul 18 2016 Toshiaki Ara <ara_t@384.jp> 4.0.3-1
- update to 4.0.3
- change BuildRequires: java-1.8.0-openjdk-devel for VineSeed

* Wed May 11 2016 Toshiaki Ara <ara_t@384.jp> 4.0.2-1
- update to 4.0.2
- add BuildRequires: openssl-devel
- add Requires: openssl

* Wed Apr 13 2016 Toshiaki Ara <ara_t@384.jp> 4.0.1-1
- update to 4.0.1
- change dependencies

* Sun Oct 05 2014 Toshiaki Ara <ara_t@384.jp> 3.6.4-2
- [BTS:0002801] add configure option --with-magick=Magick
- delete BuildRequires: texlive-collection-texinfo
- add BuildRequires: texlive-collection-plainextra
- add BuildRequires: texlive-collection-latexextra
- add BuildRequires: texlive-collection-fontsrecommended
-   for VineSeed

* Wed Mar 06 2013 Toshiaki Ara <ara_t@384.jp> 3.6.4-1
- update to 3.6.4
- add BuildRequires: freeglut-devel and Requires: freeglut for VineSeed

* Tue Sep 11 2012 Toshiaki Ara <ara_t@384.jp> 3.6.2-2
- delete octave from menu (programming)

* Tue Aug 28 2012 Toshiaki Ara <ara_t@384.jp> 3.6.2-1
- update to 3.6.2
- correct spec file for version 3.6.2
- add BuildRequires: pcre-devel fltk-devel
- add BuildRequires: ImageMagick-devel ImageMagick-c++-devel
- add BuildRequires: gcc-gfortran
- add BuildRequires: texlive texlive-common texlive-collection-basic
- add BuildRequires: texlive-collection-texinfo texlive-collection-genericrecommended
- chanfe Group to Applications/Edutainment

* Sat Aug 23 2008 Shu KONNO <owa@bg.wakwak.com> 3.0.2-1vl5
- update to 3.0.2
- applied new versioning policy, spec in utf-8

* Sun Feb 03 2008 NAKAMURA Kenta <kenta@vinelinux.org> 3.0.0-0vl1
- update to 3.0.0

* Sat Aug 18 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.9.13-0vl2
- rebuilt for VineSeed

* Fri Aug 17 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.9.13-0vl1
- update to 2.9.13
- rebuilt with new toolchain and environment

* Sun Apr 20 2003 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.17-0vl1
- update to 2.0.17
- rebuild with new toolchains
- add BuildRequires: gcc295, gcc295-c++

* Sun Mar  3 2002 Jun Nishii <jun@vinelinux.org> 2.1.35-0vl1
- ver.up

* Tue Sep 26 2000 Jun Nishii <jun@vinelinux.org> 2.0.16-0vl1
- build for Vine Linux 2.1

* Mon Aug 07 2000 Frederic Lepied <flepied@mandrakesoft.com> 2.0.16-5mdk
- automatically added BuildRequires

* Wed Jul 26 2000 Vincent Saugey <vince@mandrakesoft.com> 2.0.16-4mdk
- Macros, BM, add multiple icons sizes

* Wed Apr 12 2000 Vincent Saugey <vince@mandrakesoft.com> 2.0.16-3mdk
- strip oct file
- add menu entry
 
* Tue Mar 21 2000 Vincent Saugey <vince@mandrakesoft.com> 2.0.16-2mdk
- corrected for new groups

* Thu Mar 09 2000 Lenny Cartier <lenny@mandrakesoft.com>
- mandrake build
- v2.0.16

* Fri Oct 23 1998 Jeff Johnson <jbj@redhat.com>
- update to 2.0.13.90

* Thu Jul  9 1998 Jeff Johnson <jbj@redhat.com>
- repackage in powertools.

* Thu Jun 11 1998 Andrew Veliath <andrewtv@usa.net>
- Add %attr, build as user.

* Mon Jun 1 1998 Andrew Veliath <andrewtv@usa.net>
- Add BuildRoot, installinfo, require gnuplot, description from
  Octave's web page, update to Octave 2.0.13.
- Adapt from existing spec file.

* Tue Dec  2 1997 Otto Hammersmith <otto@redhat.com>
- removed libreadline stuff from the file list

* Mon Nov 24 1997 Otto Hammersmith <otto@redhat.com>
- changed configure command to put things in $RPM_ARCH-rehat-linux, 
  rather than genereated one... was causing problems between building 
  on i686 build machine.

* Mon Nov 17 1997 Otto Hammersmith <otto@redhat.com>
- moved buildroot from /tmp to /var/tmp

* Mon Sep 22 1997 Mike Wangsmo <wanger@redhat.com>
- Upgraded to version 2.0.9 and built for glibc system

* Thu May 01 1997 Michael Fulbright <msf@redhat.com>
- Updated to version 2.0.5 and changed to build using a BuildRoot