File coq.spec of Package coq

# spec file for package coq
# Copyright (c) 2021 SUSE LLC
# Copyright (c) 2012-2018 Peter Trommler, peter.trommler at
# 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

%bcond_without ide

Name:           coq
Version:        8.13.2
Release:        0
Summary:        Proof Assistant based on the Calculus of Inductive Constructions
License:        LGPL-2.1-only
Group:          Productivity/Scientific/Math
Source1:        coq.desktop
Source2:        coq.xml
Source50:       coq-refman-%{version}.tar.xz
Source51:       coq-stdlib-%{version}.tar.xz
Source100:      %{name}-rpmlintrc
BuildRequires:  desktop-file-utils
BuildRequires:  make >= 3.81
BuildRequires:  ocaml >= 4.05.0
BuildRequires:  ocaml-camlp5-devel >= 5.08
BuildRequires:  ocamlfind(findlib)
BuildRequires:  ocamlfind(zarith)
%if %{with ide}
BuildRequires:  update-desktop-files
BuildRequires:  ocamlfind(lablgtk3)
BuildRequires:  pkgconfig(gdk-3.0)
BuildRequires:  pkgconfig(gtk+-3.0)
BuildRequires:  pkgconfig(gtksourceview-3.0)

Proof assistant which allows to handle calculus assertions, check mechanically
proofs of these assertions, helps to find formal proofs and extracts a certified
program from the constructive proof of its formal specification.

This package contains shared files and the command line interface.
For a graphical interface install %{name}-ide.

%package ide
Summary:        IDE for The Coq Proof Assistant
Group:          Productivity/Scientific/Math
Requires:       %{name} = %{version}-%{release}

%description ide
The Coq Integrated Development Interface is a graphical interface for the Coq proof assistant.

%package devel
Summary:        Development files for coq
Group:          Development/Libraries/Other
Requires:       %{name} = %{version}-%{release}
Requires:       ocaml >= 4.05.0
Requires:       ocamlfind(findlib)

%description devel
This package contains development files for Coq.

%package doc
Summary:        Documentation for coq
Group:          Documentation/HTML
Requires:       %{name} = %{version}

%description doc
HTML reference manual for Coq and full documentation of the standard library.

%setup -q -a 50 -a 51
# META for ocamlfind doesn't contain a version, so fails. We patch that.
sed -i 's/v, _ = tryrun camlexec.find \["query"; "-format"; "%v"; "lablgtk3"\]/v = "%{pkg_version ocamlfind(lablgtk3)}"/' \

export CFLAGS='%{optflags}'
# TODO: Add -with-doc yes
./configure                \
   -bindir %{_bindir}      \
   -libdir %{_libdir}/coq  \
   -mandir %{_mandir}      \
   -datadir %{_datadir}/%{name} \
   -docdir %{_docdir}/%{name} \
   -configdir %{_sysconfdir}/xdg/%{name} \
   -coqdocdir %{_datadir}/texmf/tex/latex/misc \
%if %{with ide}
   -coqide opt \
   -coqide no \
   -native-compiler yes \
   -natdynlink yes \
   -browser "xdg-open %s"

make %{?_smp_mflags} world

%if %{with ide}
# Fixup dependencies before we install. Some are apparently not detected.
sed -i 's#^ide/ide_MLLIB_DEPENDENCIES:=.*$#& ide/configwin_types ide/protocol/richpp#' \

make COQINSTALLPREFIX=%{buildroot} install

%if %{with ide}
%suse_update_desktop_file -i %{SOURCE1}
install -D -m 644 %{SOURCE1} %{buildroot}%{_datadir}/applications/coq.desktop
install -D -m 644 %{SOURCE2} %{buildroot}%{_datadir}/mime/packages/coq.xml
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/256x256/apps
ln -s %{_datadir}/coq/coq.png %{buildroot}%{_datadir}/icons/hicolor/256x256/apps/coq.png
rm %{buildroot}%{_bindir}/coqidetop{,.opt} %{buildroot}%{_mandir}/man1/coqide.1

# Sometimes we get identical x and x.opt files, replace by symlink x -> x.opt.
for bin in %{buildroot}%{_bindir}/*.opt
    if [ -f ${bin%.opt} ] && diff $bin ${bin%.opt}
        rm ${bin%.opt}
        ln -s ${bin#%{buildroot}} ${bin%.opt}

# Fix executable bit and shebangs, preferring python3.
# (
chmod -x %{buildroot}%{_libdir}/%{name}/tools/
sed -i '1s|^#!/usr/bin/env *|#!/usr/bin/|;1s|^#!/usr/bin/python$|#!/usr/bin/python3|' \

# Remove superfluous man page.
rm %{buildroot}%{_mandir}/man1/coqtop.byte.1

# Remove unneeded empty *.vos files.
find %{buildroot}%{_libdir}/coq -empty -name '*.vos' -delete

# Build lists of runtime and devel files by ending.
# Compiled theories and shared objects are needed at runtime.
find %{buildroot}%{_libdir}/coq/{plugins,theories} -type d | \
    sed "s|%{buildroot}|%%dir |g" >runtime.list
find %{buildroot}%{_libdir}/coq -name '*.cmxs' \
                -or -name '*.so' \
                -or -name '*.vo' | sed "s|%{buildroot}||g" >>runtime.list

# Object files, static libraries and import definitions are only needed for development.
# For now, we also put the standard library Coq sources here, since the runtime
# package contains the HTML documentation for the standard library.
find %{buildroot}%{_libdir}/coq -type d | sed "s|%{buildroot}|%%dir |g" >devel.list
find %{buildroot}%{_libdir}/coq -name '*.a' \
                -or -name '*.cma' \
                -or -name '*.cmi' \
                -or -name '*.cmx' \
                -or -name '*.cmxa' \
                -or -name '*.glob' \
                -or -name '*.o' \
                -or -name '*.v' | sed "s|%{buildroot}||g" >>devel.list

# Until we can build it, we fetch the documentation from the official website:
# svn export{version}/refman
# svn export{version}/stdlib
# tar --sort=name --owner=0 --group=0 --mtime="@$(stat -c %%Y refman/index.html)" \
#,delete=atime,delete=ctime \
#     -cJf coq-refman-%{version}.tar.xz refman
# tar --sort=name --owner=0 --group=0 --mtime="@$(stat -c %%Y stdlib/index.html)" \
#,delete=atime,delete=ctime \
#     -cJf coq-stdlib-%{version}.tar.xz stdlib

# Drop some CSS files and headers in stdlib documentation, add some margin directly.
find stdlib/ -name '*.html' -exec sed -i '
/<link type="text\/css" rel="stylesheet" media="all" href="\/\/\/.*.css" \/>/d
/<div id="container">/s/>/ style="margin:1em;">/
/^  <div id="headertop">$/,/^  <\/div>$/d
/^  <div id="header">$/,/^  <\/div>$/d
' {} +
cp -r refman stdlib %{buildroot}%{_docdir}/coq
rm -r %{buildroot}%{_docdir}/coq/refman/{.doctrees,_sources}

%files -f runtime.list


%dir %{_libdir}/coq
%dir %{_libdir}/coq/kernel
%dir %{_libdir}/coq/kernel/byterun
%exclude %{_libdir}/coq/tools/
%dir %{_libdir}/coq/user-contrib


%dir %{_datadir}/texmf
%dir %{_datadir}/texmf/tex
%dir %{_datadir}/texmf/tex/latex
%dir %{_datadir}/texmf/tex/latex/misc

%if %{with ide}
%files ide

%files devel -f devel.list

%files doc

openSUSE Build Service is sponsored by