Blob Blame History Raw
# Conditional for release and snapshot builds. Uncomment for release-builds.
%global rel_build 1

# Conditionals controlling the build.
%if 0%{?fedora} || 0%{?rhel} >= 6
%global with_guile	1
%endif # 0%{?fedora} || 0%{?rhel} >= 6
%if 0%{?fedora} || (0%{?rhel} && 0%{?rhel} <= 6)
%global with_octave	1
%endif # 0%{?fedora} || (0%{?rhel} && 0%{?rhel} <= 6)
%if 0%{?fedora} || 0%{?rhel} >= 7
%global with_py		1
%endif # 0%{?fedora} || 0%{?rhel} >= 7
%if 0%{?fedora} || 0%{?rhel} >= 8
%global with_py3	1
%endif # 0%{?fedora} || 0%{?rhel} >= 8

# Settings used for build from snapshots.
%{!?rel_build:%global commit		35e63778654f55baafbdf554de58ac3c20220c33}
%{!?rel_build:%global commit_date	20130903}
%{!?rel_build:%global shortcommit	%(c=%{commit};echo ${c:0:7})}
%{!?rel_build:%global gitver		git%{commit_date}-%{shortcommit}}
%{!?rel_build:%global gitrel		.git%{commit_date}.%{shortcommit}}
%{!?rel_build:%global gittar		%{name}-%{version}-%{gitver}.tar.gz}

# Get a lowercase name for virtual provides.
%define lc_name %(echo %{name} | tr '[:upper:]' '[:lower:]')

# We don't want provides for libs in private dirs.
%global __provides_exclude_from ^%{python2_sitearch}/.*\\.so

Name:			NLopt
Version:		2.4.2
Release:		3%{?gitrel}%{?dist}
Summary:		Open-Source library for nonlinear optimization
%{?el5:Group:		System Environment/Libraries}

# The detailed license-breakdown of the sources is:
#
# BSD (2 clause)
# --------------
# util/mt19937ar.c
#
#
# BSD (3 clause)
# --------------
# slsqp/*
#
#
# LGPL (v2 or later)
# ------------------
# luksan/*
#
# MIT/X11 (BSD like)
# ------------------
# api/*		auglag/*	bobyqa/*	cdirect/*	cobyla/*
# cquad/*	crs/*		direct/*	esch/*		isres/*
# mlsl/*	mma/*		neldermead/*	newuoa/*	octave/*
# stogo/*	tensor/*	test/*		util/* (ex. util/mt19937ar.c)
#
#
# Public Domain
# -------------
# praxis/*	subplex/*
#
License:		BSD and LGPLv2+ and MIT and Public Domain
URL:			http://ab-initio.mit.edu/%{lc_name}
%{?rel_build:Source0:	%{url}/%{lc_name}-%{version}.tar.gz#/%{name}-%{version}.tar.gz}
%{!?rel_build:Source0:	https://github.com/stevengj/%{lc_name}/archive/%{commit}/%{gittar}}

%{?el5:BuildRoot:	%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)}
BuildRequires:		libtool
BuildRequires:		ncurses-devel

# The "gnulib" is a copylib and has a wildcard-permission from FPC.
# See: https://fedorahosted.org/fpc/ticket/174
Provides:		bundled(gnulib)
Provides:		%{lc_name}			=  %{version}-%{release}
Provides:		%{lc_name}%{?_isa}		=  %{version}-%{release}

%description
NLopt is a library for nonlinear local and global optimization, for
functions with and without gradient information.  It is designed as
as simple, unified interface and packaging of several free/open-source
nonlinear optimization libraries.

It features bindings for GNU Guile, Octave and Python.  This build has
been made with C++-support enabled.


%package devel
Summary:		Development files for %{name}
%{?el5:Group:		Development/Libraries}

Requires:		%{name}%{?_isa}			=  %{version}-%{release}

Provides:		%{lc_name}-devel		=  %{version}-%{release}
Provides:		%{lc_name}-devel%{?_isa}	=  %{version}-%{release}

%description devel
This package contains development files for %{name}.


%package doc
Summary:		Documentation files for %{name}
%{?el5:Group:		Documentation}

%{!?el5:BuildArch:	noarch}
Provides:		%{lc_name}-doc			=  %{version}-%{release}

%description doc
This package contains documentation files for %{name}.


%if 0%{?with_guile}
%package -n guile-%{name}
# For compatibility with RHEL <= 6.
%{!?guile_pkgconf:%global guile_pkgconf %(pkg-config --list-all | grep guile | sed -e 's! .*$!!g')}
%{!?guile_sitedir:%global guile_sitedir %(pkg-config --variable=sitedir %{guile_pkgconf})}

Summary:		Guile bindings for %{name}

BuildRequires:		guile-devel
BuildRequires:		pkgconfig
BuildRequires:		swig

Requires:		guile%{?_isa}
Requires:		%{name}%{?_isa}			=  %{version}-%{release}

Provides:		guile-%{lc_name}		=  %{version}-%{release}
Provides:		guile-%{lc_name}%{?_isa}	=  %{version}-%{release}

%description -n guile-%{name}
This package contains Guile bindings for %{name}.


%package -n guile-%{name}-devel
Summary:		Development files of Guile bindings for %{name}

Requires:		guile-%{name}%{?_isa}		=  %{version}-%{release}
Requires:		%{name}-devel%{?_isa}		=  %{version}-%{release}

Provides:		guile-%{lc_name}-devel		=  %{version}-%{release}
Provides:		guile-%{lc_name}-devel%{?_isa}	=  %{version}-%{release}

%description -n guile-%{name}-devel
This package contains Development files
of Guile bindings for %{name}.
%endif # 0%{?with_guile}


%if 0%{?with_octave}
%package -n octave-%{name}
%global octpkg %{name}
# For compatibility with RHEL <= 6.
%{!?octave_api:		%global octave_api	%(octave-config -p API_VERSION || echo 0)}
%{!?octshareprefix:	%global octshareprefix	%{_datadir}/octave}
%{!?octprefix:		%global octprefix	%{octshareprefix}/packages}
%{!?octarchprefix:	%global octarchprefix	%{_libdir}/octave/packages}
%{!?octpkgdir:		%global octpkgdir	%{octshareprefix}/%{octpkg}-%{version}}
%{!?octpkglibdir:	%global octpkglibdir	%{octarchprefix}/%{octpkg}-%{version}}

Summary:		Octave bindings for %{name}
%{?el5:Group:		System Environment/Libraries}

BuildRequires:		octave-devel

Requires:		%{name}%{?_isa}			=  %{version}-%{release}
Requires:		octave(api)			=  %{octave_api}
Requires(post):		octave
Requires(postun):	octave

Provides:		octave-%{lc_name}		=  %{version}-%{release}
Provides:		octave-%{lc_name}%{?_isa}	=  %{version}-%{release}

%description -n octave-%{name}
This package contains the Octave bindings for %{name}.
%endif # 0%{?with_octave}


%if 0%{?with_py}
%package -n python-%{name}
Summary:		Python bindings for %{name}

BuildRequires:		numpy
BuildRequires:		python2-devel

Requires:		%{name}%{?_isa}			=  %{version}-%{release}

Provides:		python-%{lc_name}		=  %{version}-%{release}
Provides:		python-%{lc_name}%{?_isa}	=  %{version}-%{release}

%description -n python-%{name}
This package contains Python bindings for %{name}.
%endif # 0%{?with_py}


%if 0%{?with_py3}
%package -n python3-%{name}
Summary:		Python3 bindings for %{name}

BuildRequires:		python3-devel
BuildRequires:		python3-numpy

Requires:		%{name}%{?_isa}			=  %{version}-%{release}

Provides:		python3-%{lc_name}		=  %{version}-%{release}
Provides:		python3-%{lc_name}%{?_isa}	=  %{version}-%{release}

%description -n python3-%{name}
This package contains Python3 bindings for %{name}.
%endif # 0%{?with_py3}


%prep
%setup -q%{!?rel_build:n %{lc_name}-%{commit_src}}%{?rel_build:n %{lc_name}-%{version}}

# Move all %%doc to topdir and append their belonging.
[[ -f README.md ]] &&								\
mv -f README.md README
_topdir="`pwd`"
for _dir in `find . -type d |							\
	sed -e "/\.libs/d" -e "s/\.\///g" -e "/\./d" | sort -u`
do
  pushd ${_dir}
  for _file in 'AUTHOR*' 'COPY*' 'README*' '*[Pp][Dd][Ff]'
  do
    for _doc in `find . -name "${_file}"`
    do
      mv -f ${_doc} ${_topdir}/${_doc}.`echo ${_dir} | sed -e "s/\//_/g"`
    done
  done
  popd
done

# Get rid of obsoleted autotools-macros for el6+.
%{!?el5:sed -i -e 's!^AC_PROG_LIBTOOL!LT_INIT!g' configure.ac}

# On el5 we need to exclude anything SWIG-related.
#%%{?el5:sed -i -e 's!swig!!g' Makefile.am}
%{?el5:	_file="swig/Makefile.am" &&						\
	mv -f ${_file} ${_file}.orig &&						\
	touch -r ${_file}.orig ${_file} &&					\
	rm -f ${_file}.orig}

# Bootstrapping once before we create a copy in %%{py3dir}.
touch swig/nlopt.scm.in
%{!?el5:autoreconf -fiv}

# Fix library-name in pkg-config file.
_file="%{lc_name}.pc.in" &&							\
sed -i.orig -e 's!-l%{lc_name}!&_cxx!' ${_file} &&				\
touch -r ${_file}.orig ${_file} &&						\
rm -f ${_file}.orig

%if 0%{?with_py3}
# Creating a copy for building the Python3-plugin.
rm -rf %{py3dir}
cp -a . %{py3dir}
%endif # 0%{?with_py3}


%build
%if 0%{?fedora} >= 19 || 0%{?rhel} >= 7
export CFLAGS="%{optflags} -fpermissive"
export CXXFLAGS="%{optflags} -fpermissive"
%endif # 0%{?fedora} >= 19 || 0%{?rhel} >= 7

%configure									\
	--enable-shared								\
	--enable-maintainer-mode						\
	--with-cxx								\
%if 0%{?with_py}
	PYTHON=%{__python2}							\
%endif # 0%{?with_py}
	OCT_INSTALL_DIR=%{octpkglibdir}

# Parallel-build might fail because of some race-condition
#make %{?_smp_mflags}
make

%if 0%{?with_py3}
pushd %{py3dir}
%configure									\
	--enable-shared								\
	--enable-maintainer-mode						\
	--with-cxx								\
	PYTHON=%{__python3}							\
	OCT_INSTALL_DIR=%{octpkglibdir}

# Parallel-build might fail because of some race-condition
#make %{?_smp_mflags}
make
%endif # 0%{?with_py3}


%install
%{?el5:rm -rf %{buildroot}}
make install DESTDIR=%{buildroot}

%if 0%{?with_py3}
pushd %{py3dir}
make install DESTDIR=%{buildroot}
popd
%endif # 0%{?with_py3}

# We don't want these static-libs and libtool-dumplings
find %{buildroot} -depth -name '*.*a' -print0 | xargs -0 rm -f

# Python bits need to be arched, but some end-up in %%{python_sitelib}.
%if 0%{?with_py}
[[ "%{python2_sitearch}" != "%{python2_sitelib}" ]] &&				\
	mv -f %{buildroot}%{python2_sitelib}/* %{buildroot}%{python2_sitearch}
%endif # 0%{?with_py}
%if 0%{?with_py3}
[[ "%{python3_sitearch}" != "%{python3_sitelib}" ]] &&				\
	mv -f %{buildroot}%{python3_sitelib}/* %{buildroot}%{python3_sitearch}
%endif # 0%{?with_py3}

%if 0%{?with_octave}
# Setup octave stuff properly.
mkdir -p %{buildroot}%{octpkgdir}/packinfo
mv %{buildroot}%{octpkglibdir}/*.m %{buildroot}%{octpkgdir}
chmod 0755 %{buildroot}%{octpkglibdir}/*.oct
install -pm 0644 COPYING %{buildroot}%{octpkgdir}/packinfo

cat > %{buildroot}%{octpkgdir}/packinfo/DESCRIPTION << EOF
Name: %{name}
Version: %{version}
Date: %(date +%Y-%m-%d)
Author: Steven G. Johnson <stevenj@alum.mit.edu>
Maintainer: Björn Esser <besser82@fedoraproject.org>
Title: Open-Source library for nonlinear optimization
Description: NLopt is a library for nonlinear local and global
 optimization, for functions with and without gradient information.
 It is designed as as simple, unified interface and packaging of
 several free/open-source nonlinear optimization libraries.
Url: %{url}
EOF

cat > %{buildroot}%{octpkgdir}/packinfo/on_uninstall.m << EOF
function on_uninstall (desc)
  error ('Can not uninstall %s installed by the redhat package manager', desc.name);
endfunction
EOF
%endif # 0%{?with_octave}


%check
pushd test
make check
popd

%if 0%{?with_py3}
pushd %{py3dir}/test
make check
popd
%endif # 0%{?with_py3}


%{?el5:%clean}
%{?el5:rm -rf %{buildroot}}


%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%if 0%{?with_guile}
%post -n guile-%{name} -p /sbin/ldconfig
%postun -n guile-%{name} -p /sbin/ldconfig
%endif # 0%{?with_guile}

%if 0%{?with_octave}
%if 0%{?fedora} || 0%{?rhel} >= 7
%post -n octave-%{name}
%octave_cmd pkg rebuild

%preun -n octave-%{name}
%octave_pkg_preun

%postun -n octave-%{name}
%octave_cmd pkg rebuild
%else
%post -n octave-%{name}
octave -H -q --no-window-system --no-site-file --eval "pkg rebuild"

%preun -n octave-%{name}
rm -f %{octpkgdir}/packinfo/on_uninstall.m
if [ -e %{octpkgdir}/packinfo/on_uninstall.m.orig ]
then
  mv -f %{octpkgdir}/packinfo/on_uninstall.m.orig %{octpkgdir}/packinfo/on_uninstall.m
  cd %{octpkgdir}/packinfo
  octave -H -q --no-window-system --no-site-file --eval "l=pkg('list');on_uninstall(l{cellfun(@(x)strcmp(x.name,'%{octpkg}'),l)});"
fi

%postun -n octave-%{name}
octave -H -q --no-window-system --no-site-file --eval "pkg rebuild"
%endif # 0%{?fedora} || 0%{?rhel} >= 7
%endif # 0%{?with_octave}

%files
%doc ChangeLog COPY* NEWS
%{_libdir}/lib%{lc_name}_cxx.so.*

%files devel
%doc %{_mandir}/man3/*
%{_includedir}/*
%{_libdir}/lib%{lc_name}_cxx.so
%{_libdir}/pkgconfig/%{lc_name}.pc

%files doc
%doc AUTHOR* ChangeLog COPY* NEWS README* TODO *.[Pp][Dd][Ff].*

%if 0%{?with_guile}
%files -n guile-%{name}
%{_libdir}/lib%{lc_name}_cxx_guile.so.*
%{guile_sitedir}/*

%files -n guile-%{name}-devel
%{_libdir}/lib%{lc_name}_cxx_guile.so
%endif # 0%{?with_guile}

%if 0%{?with_octave}
%files -n octave-%{name}
%{octpkglibdir}
%{octpkgdir}
%endif # 0%{?with_octave}

%if 0%{?with_py}
%files -n python-%{name}
%{python2_sitearch}/*
%endif # 0%{?with_py}

%if 0%{?with_py3}
%files -n python3-%{name}
%{python3_sitearch}/*.so*
%{python3_sitearch}/*.py*
%{python3_sitearch}/__pycache__/*.py*
%endif # 0%{?with_py3}

%changelog
* Fri Aug 15 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.4.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Thu Jul 17 2014 Björn Esser <bjoern.esser@gmail.com> - 2.4.2-2
- disable octave-subpkg on el7

* Thu Jul 17 2014 Björn Esser <bjoern.esser@gmail.com> - 2.4.2-1
- new upstream release (#1116586)
- adapted spec to use named conditionals for packages

* Fri Jun 06 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.4.1-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Wed May 28 2014 Kalev Lember <kalevlember@gmail.com> - 2.4.1-6
- Rebuilt for https://fedoraproject.org/wiki/Changes/Python_3.4

* Tue Jan 14 2014 Björn Esser <bjoern.esser@gmail.com> - 2.4.1-5
- fixed description-file for octave-NLopt (#1048510)

* Tue Jan 14 2014 Björn Esser <bjoern.esser@gmail.com> - 2.4.1-4
- fixed nlopt.pc to reflect the correct lib to link against

* Sat Dec 28 2013 Kevin Fenzi <kevin@scrye.com> - 2.4.1-3
- Rebuild to fix broken deps

* Sat Dec 28 2013 Björn Esser <bjoern.esser@gmail.com> - 2.4.1-2
- rebuild for octave-3.8.0-rc2

* Fri Dec 20 2013 Björn Esser <bjoern.esser@gmail.com> - 2.4.1-1
- new upstream release: v2.4.1
- adapted %%{source0} to match %%{name}
- changed `%%global lc_name` to `%%define lc_name`, because of globbing problems
- use `tr` instead of shell-builtin for `%%define lc_name`
- move `README.md` only if existing
- create an empty Makefile on el5 instead of modifying top-level Makefile.am
- do not autoreconf on el5
- append `-fpermissive` to C[XX]FLAGS on Fedora 19+

* Fri Dec 20 2013 Björn Esser <bjoern.esser@gmail.com> - 2.4-3.git20130903.35e6377
- made %%clean-target conditional on el5
- restructured spec-file for quick switching between snapshot and release
- moved package-specific macros to the corresponding subpackage

* Wed Oct 02 2013 Björn Esser <bjoern.esser@gmail.com> - 2.4-2.git20130903.35e6377
- adaptions for new Python-guidelines

* Thu Sep 19 2013 Björn Esser <bjoern.esser@gmail.com> - 2.4-1.git20130903.35e6377
- Initial rpm release (#1004209)