## START: Set by rpmautospec
## (rpmautospec version 0.5.1)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# ZIMPL is only available in the scipoptsuite tarball, which is a collection of
# packages.  Most of them can be downloaded separately, so we do not build the
# entire suite here.  See https://github.com/scipopt/scip/issues/37.
%global scipoptsuitever 8.1.0

Name:           zimpl
Version:        3.5.3
Release:        %autorelease
Summary:        Zuse Institut Mathematical Programming Language

%global upver   %(sed 's/\\.//g' <<< %{version})

# LGPL-3.0-or-later: the project as a whole
# Other licenses are due to fonts embedded in the PDF manual:
# OFL-1.1-RFN: AMS
# Knuth-CTAN: CM
# GPL-1.0-or-later: CM-Super
License:        LGPL-3.0-or-later AND OFL-1.1-RFN AND Knuth-CTAN AND GPL-1.0-or-later
URL:            https://zimpl.zib.de/
Source0:        https://scipopt.org/download/release/scipoptsuite-%{scipoptsuitever}.tgz
# Build a shared library instead of a static library.  ZIMPL leaves some symbols
# undefined, namely those listed in src/zimpl/xlpglue.h.  They take advantage of
# the fact that linking with a static library only pulls in the referenced
# symbols to avoid referring to the xlp symbols in certain cases, for example,
# in the scip test suite.  Since Fedora wants shared libraries, we have to give
# those symbols weak dummy definitions to avoid unresolved symbols at link time.
Patch0:         %{name}-shared.patch
# This package and cddlib both have C functions named set_copy and set_free.
# This is a problem for polymake, which links both libraries.  Rename the
# zimpl functions to set_copy_zimpl and set_free_zimpl.
Patch1:         %{name}-cddlib-set-clash.patch

# See https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
ExcludeArch:    %{ix86}

BuildRequires:  bison
BuildRequires:  cmake
BuildRequires:  flex
BuildRequires:  gcc
BuildRequires:  pkgconfig(gmp)
BuildRequires:  pkgconfig(zlib)

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

%global _desc %{expand:
Zimpl is a little language to translate the mathematical model of a
problem into a linear or nonlinear (mixed-) integer mathematical program
expressed in .lp or .mps file format which can be read and (hopefully)
solved by a LP or MIP solver.}

%description %_desc

This package contains a command-line tool to access ZIMPL
functionality.

%package -n     libzimpl
# LGPL-3.0-or-later: the project as a whole
# LGPL-2.0-or-later: src/zimpl/{mmlparse2.y,mmlscan.l}
# GPL-3.0-or-later WITH Bison-exception-2.2: mmlparse2.{c,h}
License:        LGPL-3.0-or-later AND LGPL-2.0-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2
Summary:        Zuse Institut Mathematical Programming Language

%description -n libzimpl %_desc

This package contains a library interface to ZIMPL functionality.

%package -n     libzimpl-devel
# LGPL-3.0-or-later: the project as a whole
# GPL-3.0-or-later WITH Bison-exception-2.2: mmlparse2.h
License:        LGPL-3.0-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2
Summary:        Headers and library links for libzimpl
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       libzimpl%{?_isa} = %{version}-%{release}

%description -n libzimpl-devel
This package contains headers and library links for developing
applications that use libzimpl.

%prep
%autosetup -n scipoptsuite-%{scipoptsuitever}/%{name} -p1

# Fix installation directories
if [ "%{_lib}" != "lib" ]; then
  sed -i 's,\(DESTINATION \)lib,\1%{_lib},' src/CMakeLists.txt
fi

# Avoid warnings about obsolete invocations of grep
sed -i 's/fgrep/grep -F/' check/check.sh

%build
export CFLAGS='%{build_cflags} -DFREEMEM -DNO_MSHELL'
export CXXFLAGS='%{build_cxxflags} -DFREEMEM -DNO_MSHELL'
%cmake
%cmake_build

%install
%cmake_install
mkdir -p %{buildroot}%{_mandir}/man1
cp -p doc/zimpl.man %{buildroot}%{_mandir}/man1/zimpl.1

%check
# The following tests are supposed to fail due to unimplemented QUBO support,
# but pass because the support has been implemented:
# - errors/e401.zpl
# - errors/e402.zpl
# - errors/e405.zpl
rm check/errors/e40{1,2,5}.*

export LD_LIBRARY_PATH=%{buildroot}%{_libdir}
cd check
sh check.sh ../%{_vpath_builddir}/bin/zimpl
cd -

%files
%doc doc/zimpl.pdf
%{_bindir}/zimpl
%{_mandir}/man1/zimpl.1*

%files -n libzimpl
%doc CHANGELOG README
%license LICENSE
%{_libdir}/libzimpl.so.0*

%files -n libzimpl-devel
%{_includedir}/zimpl/
%{_libdir}/libzimpl.so
%{_libdir}/cmake/zimpl/

%changelog
## START: Generated by rpmautospec
* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.5.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 01 2024 Jerry James <loganjerry@gmail.com> - 3.5.3-1
- Initial RPM
## END: Generated by rpmautospec