File openEMS.spec of Package openEMS

#
# spec file for package openEMS
#
# 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/
#


Name:           openEMS
%define octpkg  openems
Version:        0.0.34
Release:        0
Summary:        Electromagnetic field solver using the EC-FDTD method
License:        GPL-3.0
Group:          Productivity/Scientific/Physics
Url:            http://openems.de
Source0:        https://github.com/thliebig/%{name}/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
# PATCH-FIX-UPSTREAM openEMS-vtk.patch -- Fix linking for VTK >= 6.3
Patch1:         openEMS-vtk.patch
# PATCH-FIX-OPENSUSE openEMS-octave-openEMS-load.patch -- Fix openEMS.sh load
Patch2:         openEMS-octave-openEMS-load.patch
# PATCH-FIX-OPENSUSE openEMS-octave-nf2ff-load.patch -- Fix nf2ff load
Patch3:         openEMS-octave-nf2ff-load.patch
# PATCH-FIX-OPENSUSE openEMS-readme-octave-package.patch -- Add correct instruction about Octave and MATLAB packages
Patch4:         openEMS-readme-octave-package.patch
# PATCH-FIX-UPSTREAM openEMS-hdf5.patch -- Fix build with HDF5
Patch5:         openEMS-hdf5.patch
# PATCH-FIX-UPSTREAM openEMS-no-return.patch
Patch6:         openEMS-no-return.patch
BuildRequires:  CSXCAD-devel
BuildRequires:  boost-devel
BuildRequires:  cmake
BuildRequires:  gcc-c++
BuildRequires:  hdf5-devel
BuildRequires:  octave-devel
BuildRequires:  tinyxml-devel
BuildRequires:  vtk-devel
BuildRequires:  pkgconfig(fparser)
BuildRequires:  pkgconfig(python3)
BuildRequires:  pkgconfig(sm)
BuildRequires:  pkgconfig(xt)
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Electromagnetic field solver using the EC-FDTD method.

%package -n     libnf2ff0
Summary:        Near-field to far-field transformation library
Group:          System/Libraries

%description -n libnf2ff0
Near-field to far-field transformation library.

%package -n     libopenEMS0
Summary:        Electromagnetic field solver library
Group:          System/Libraries

%description -n libopenEMS0
Electromagnetic field solver using the EC-FDTD method library.

%package        devel
Summary:        openEMS development files
Group:          Development/Libraries/C and C++
Requires:       libnf2ff0 = %{version}
Requires:       libopenEMS0 = %{version}

%description    devel
This package contains libraries for developing applications
that use %{name}.

%package -n     octave-%{name}
Summary:        Octave interface for openEMS
Group:          Productivity/Scientific/Physics
Requires:       %{name} = %{version}
Requires:       AppCSXCAD
Requires:       octave-CSXCAD
Requires:       octave-cli

%description -n octave-%{name}
Electromagnetic field solver using the EC-FDTD method.

This package provides Octave interface for openEMS.

%package -n     %{name}-matlab
Summary:        MATLAB interface for openEMS
Group:          Productivity/Scientific/Physics
Requires:       %{name} = %{version}
Requires:       AppCSXCAD
Requires:       CSXCAD-matlab

%description -n %{name}-matlab
Electromagnetic field solver using the EC-FDTD method.

This package provides MATLAB interface for openEMS.

%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1

echo "Name: %{octpkg}" >> DESCRIPTION
echo "Version: %{version}" >> DESCRIPTION
echo "Date: 2015-10-10" >> DESCRIPTION
echo "Author: Thorsten Liebig" >> DESCRIPTION
echo "Maintainer: Thorsten Liebig" >> DESCRIPTION
echo "Title: Electromagnetic field solver using the EC-FDTD method" >> DESCRIPTION
echo "Description: Electromagnetic field solver using the EC-FDTD method." >> DESCRIPTION
echo "Categories: openEMS" >> DESCRIPTION
echo "Depends: csxcad" >> DESCRIPTION
echo "Autoload: yes" >> DESCRIPTION

cat > Makefile-octave << 'EOF'
MKOCTFILE := mkoctfile

all: h5readatt_octave.oct

%.oct: %.cc
	$(MKOCTFILE) -lhdf5 -DH5_USE_16_API -s $<

clean: ; rm *.o *.oct
EOF

rm matlab/setup.m

mkdir octave_build
cp -r matlab octave_build
pushd octave_build/matlab
    mkdir src
    mv *.cc src/
    mv ../../Makefile-octave src/Makefile
    mkdir inst
    mv *.m inst/
    mv {private,examples,Tutorials} inst/
    cp ../../COPYING .
    mv ../../DESCRIPTION .
    cd ..
    %octave_pkg_src
popd

%build
%ifarch %ix86
export CFLAGS="%{optflags} -mavx"
export CXXFLAGS="%{optflags} -mavx"
%endif
%cmake

make %{?_smp_mflags}

cd ..
pushd octave_build
    %octave_pkg_build
popd

%install
%cmake_install

pushd octave_build
    %octave_pkg_install
popd

%post -n libnf2ff0 -p /sbin/ldconfig

%postun -n libnf2ff0 -p /sbin/ldconfig

%post -n libopenEMS0 -p /sbin/ldconfig

%postun -n libopenEMS0 -p /sbin/ldconfig

%post -n octave-%{name}
%octave --eval "pkg rebuild -auto %{octpkg}"

%postun -n octave-%{name}
%octave --eval "pkg rebuild"

%files
%defattr(-,root,root,-)
%doc COPYING NEWS README
%{_bindir}/*

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

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

%files devel
%defattr(-,root,root,-)
%{_libdir}/libnf2ff.so
%{_libdir}/libopenEMS.so

%files -n octave-%{name}
%defattr(-,root,root,-)
%{octpackages_dir}/%{octpkg}-%{version}
%{octlib_dir}/%{octpkg}-%{version}

%files -n %{name}-matlab
%defattr(-,root,root,-)
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/matlab/

%changelog