Orion Poplawski b62f11
# Octave packaging macros
Orion Poplawski b62f11
Orion Poplawski b62f11
# Octave binary API provided
834892
%octave_api %(octave-config -p API_VERSION || echo 0)
Orion Poplawski b62f11
Orion Poplawski b62f11
# Octave Package Directories
Orion Poplawski b62f11
%octshareprefix %{_datadir}/octave
Orion Poplawski b62f11
%octprefix %{octshareprefix}/packages
Orion Poplawski 265a73
%octarchprefix %{_libdir}/octave/packages
Orion Poplawski 6948e3
%octpkgdir %{octprefix}/%{octpkg}-%{version}
Orion Poplawski b62f11
%octpkglibdir %{octarchprefix}/%{octpkg}-%{version}
Orion Poplawski b62f11
Orion Poplawski b62f11
# Run an octave command - quietly with no startup files
Orion Poplawski 8e9833
%octave_cmd() octave -H -q --no-window-system --no-site-file --eval '%*';
Orion Poplawski b62f11
Orion Poplawski af0420
# For compiled tarfile name
Orion Poplawski af0420
%octave_host %(octave-config -p CANONICAL_HOST_TYPE || echo 0)
Orion Poplawski af0420
Orion Poplawski c146c5
# Build unpacked source directory into a package tar file in a temporary location
Orion Poplawski 171daa
# Pass -T to use source tarball
Orion Poplawski 171daa
%octave_pkg_build(T) %{lua: 
Orion Poplawski 7a5c2d
  if (rpm.expand("%{-T}") == "-T") then
Orion Poplawski 7a5c2d
    octpkg_tarfile = rpm.expand("%{SOURCE0}")
Orion Poplawski 7a5c2d
  else
Orion Poplawski 171daa
    octpkg_tarfile = rpm .expand("%{_tmppath}/%{octpkg}-%{version}.tar.gz")
Orion Poplawski 171daa
    print("tar czf "..octpkg_tarfile.." -C "..rpm.expand("%{_builddir} %{buildsubdir}").."\\n")
Orion Poplawski 171daa
  end
Orion Poplawski 7a5c2d
  -- Avoid a warning from pkg build about making the build directory
Orion Poplawski 7a5c2d
  -- and use a clean directory as octave pkg build will delete contents
Orion Poplawski 7a5c2d
  print(rpm.expand("mkdir -p %{_builddir}/%{buildsubdir}/build\\n"))
Orion Poplawski 7a5c2d
  -- This fails to keep the arguments to %octave_cmd for some reason
Orion Poplawski 171daa
  -- print(rpm.expand("%octave_cmd pkg build -verbose -nodeps %{_builddir}/%{buildsubdir} "..octpkg_tarfile).."\\n")
Orion Poplawski 29021a
  print(rpm.expand("octave -H -q --no-window-system --no-site-file --eval 'pkg build -verbose -nodeps %{_builddir}/%{buildsubdir}/build "..octpkg_tarfile).."'\\n")
Orion Poplawski 7a5c2d
  -- Extract the source tarball for debuginfo generation
Orion Poplawski 7a5c2d
  print(rpm.expand("tar xf "..octpkg_tarfile.." -C %{_builddir}/%{buildsubdir}/build\\n"))
Orion Poplawski 5c42e7
  -- Define %octave_tar_suffix for later use by install/check macros
Orion Poplawski 5c42e7
  if (rpm.expand("%{?buildarch}") ~= "noarch") then
Orion Poplawski 5c42e7
    rpm.define("octave_tar_suffix %{octave_host}-%{octave_api}")
Orion Poplawski 5c42e7
  else
Orion Poplawski 5c42e7
    rpm.define("octave_tar_suffix any-none")
Orion Poplawski 5c42e7
  end
Orion Poplawski 171daa
}
Orion Poplawski b62f11
Orion Poplawski b62f11
# Install a package.  We use the octave pkg install command to install the
Orion Poplawski b62f11
# built package into the buildroot.  We also put a note to prevent the root
Orion Poplawski b62f11
# user from removing the package with the octave pkg uninstall command
Orion Poplawski 5ebd21
# We call unlink to remove the 'octave_packages' file which contains the
Orion Poplawski 5ebd21
# buildroot string and needs to be generated at package install time.
Orion Poplawski cf6b5f
%octave_pkg_install \
Orion Poplawski 5ebd21
mkdir -p %{buildroot}%{octprefix} \
Orion Poplawski 5ebd21
mkdir -p %{buildroot}%{octarchprefix} \
Orion Poplawski 5c42e7
%octave_cmd pkg("prefix","%{buildroot}%{octprefix}","%{buildroot}%{octarchprefix}");pkg("global_list",fullfile("%{buildroot}%{octshareprefix}","octave_packages"));pkg("local_list",fullfile("%{buildroot}%{octshareprefix}","octave_packages"));pkg("install","-nodeps","-verbose","%{_builddir}/%{buildsubdir}/build/%{octpkg}-%{version}-%{octave_tar_suffix}.tar.gz");unlink(pkg("local_list"));unlink(pkg("global_list")); \
Orion Poplawski cf6b5f
if [ -e %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m ] \
Orion Poplawski cf6b5f
then \
Orion Poplawski ba0a20
  mv %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m.orig \
Orion Poplawski cf6b5f
fi \
Orion Poplawski cf6b5f
echo "function on_uninstall (desc)" > %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m \
Orion Poplawski cf6b5f
echo "  error ('Can not uninstall %s installed by the redhat package manager', desc.name);" >> %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m \
Orion Poplawski cf6b5f
echo "endfunction" >> %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m \
e487e9
if [ -e %{_builddir}/%{buildsubdir}/build/%{octpkg}-%{version}/*.metainfo.xml ] \
Orion Poplawski 86c9c9
then \
e487e9
  echo "Found .metainfo.xml appdata file" \
Orion Poplawski 86c9c9
  mkdir -p %{buildroot}/%{_datadir}/appdata \
e487e9
  cp -p %{_builddir}/%{buildsubdir}/build/%{octpkg}-%{version}/*.metainfo.xml %{buildroot}/%{_datadir}/appdata/ \
e487e9
  appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/appdata/*.metainfo.xml \
e487e9
else \
e487e9
  echo "Did not find a .metainfo.xml appdata file" \
Orion Poplawski 86c9c9
fi \
Orion Poplawski cf6b5f
%{nil}
Orion Poplawski b62f11
Orion Poplawski 5ebd21
# Run pkg tests - We need to reinstall to recreate 'octave_packages' so that
Orion Poplawski ed607f
# octave can find the package, then remove 'octave_packages' again, and re-strip
Orion Poplawski ed607f
# any shared objects.
Orion Poplawski 5ebd21
%octave_pkg_check \
eb697c
%octave_cmd pkg("prefix","%{buildroot}%{octprefix}","%{buildroot}%{octarchprefix}");pkg("local_list",fullfile("%{buildroot}%{octshareprefix}","octave_packages"));pkg("list");pkg("install","-verbose","%{_builddir}/%{buildsubdir}/build/%{octpkg}-%{version}-%{octave_tar_suffix}.tar.gz");pkg("load","%{octpkg}");pkg("list");runtests("%{buildroot}%{octpkgdir}");unlink(pkg("local_list")); \
Orion Poplawski ed607f
/usr/lib/rpm/brp-strip-shared %{__strip} \
Orion Poplawski 5ebd21
%{nil}
Orion Poplawski 5ebd21
Orion Poplawski b62f11
# preun script - we need to remove our uninstall protection and perhaps
Orion Poplawski b62f11
# run the package's own uninstall script.
Orion Poplawski 265a73
%octave_pkg_preun \
Orion Poplawski cf6b5f
if [ -e %{octpkgdir}/packinfo/on_uninstall.m.orig ]; then \
Orion Poplawski cf6b5f
  mv %{octpkgdir}/packinfo/on_uninstall.m.orig %{octpkgdir}/packinfo/on_uninstall.m \
Orion Poplawski cf6b5f
  cd %{octpkgdir}/packinfo \
Orion Poplawski 8e9833
  %octave_cmd l=pkg("list");on_uninstall(l{cellfun(@(x)strcmp(x.name,"%{octpkg}"),l)}); \
Orion Poplawski b60558
else \
Orion Poplawski b60558
  echo > %{octpkgdir}/packinfo/on_uninstall.m \
Orion Poplawski cf6b5f
fi \
Orion Poplawski cf6b5f
%{nil}