File ocaml.spec of Package ocaml.2515

#
# spec file for package ocaml
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2010 Andrew Psaltis <ampsaltis at gmail dot com>
# Copyright (c) 2011 Andrew Psaltis <ampsaltis at gmail dot com>
#
# 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/
#


%define doc_version 4.02
#
%define do_opt 0
# This ensures that the find_provides/find_requires calls ocamlobjinfo correctly.
%global __ocaml_requires_opts -c -f "%{buildroot}%{_bindir}/ocamlrun %{buildroot}%{_bindir}/ocamlobjinfo"
%global __ocaml_provides_opts -f "%{buildroot}%{_bindir}/ocamlrun %{buildroot}%{_bindir}/ocamlobjinfo"
# macros to be set in prjconf:
#Macros:
#_with_ocaml_force_enable_ocaml_opt 1
#_with_ocaml_force_disable_ocaml_opt 1
#_with_ocaml_make_testsuite 1
%bcond_with ocaml_force_enable_ocaml_opt
%bcond_with ocaml_force_disable_ocaml_opt
%bcond_with ocaml_make_testsuite
%if %{with ocaml_force_enable_ocaml_opt}
%define do_opt 1
%endif
%if %{without ocaml_force_enable_ocaml_opt}
%ifarch %arm aarch64 %ix86 ppc ppc64 ppc64le x86_64
%define do_opt 1
%endif
%endif
#
%if %{with ocaml_force_disable_ocaml_opt}
%define do_opt 0
%endif
Name:           ocaml
Version:        4.02.3
Release:        0
Summary:        The Objective Caml Compiler and Programming Environment
License:        QPL-1.0 and SUSE-LGPL-2.0-with-linking-exception
Group:          Development/Languages/Other
Url:            http://caml.inria.fr/
#
# http://caml.inria.fr/pub/distrib/
Source0:        http://caml.inria.fr/pub/distrib/ocaml-%{doc_version}/ocaml-%{version}.tar.xz
Source1:        ocaml-%{doc_version}-refman-html-0.tar.xz
Source2:        ocaml-%{doc_version}-refman-html-1.tar.xz
Source3:        ocaml-%{doc_version}-refman.info.tar.xz
Source4:        rpmlintrc
Patch0:         ocaml-3.00-camldebug_el.patch
Patch2:         ocaml-3.04-ocamltags--no-site-start.patch
# FIX-UPSTREAM pass RPM_OPT_FLAGS to build
Patch4:         ocaml-configure-Allow-user-defined-C-compiler-flags.patch
Patch5:         ocaml-3.08.3-gcc4.patch
Patch7:         ocaml-3.09-emacs_localcompile.patch
# FIX-UPSTREAM enable build on PowerPC 64bit platform.
Patch9:         ocaml-ppc64.patch
# FIX-UPSTREAM enable build on PowerPC 64bit LE platform.
Patch10:        ocaml-ppc64le.patch
# PATCH-FIX-UPSTREAM bnc#977990 CVE-2015-8869 kstreitova@suse.com -- prevent buffer overflow and information leak
Patch11:        ocaml-4.02.3-bufferoverflow_infoleak.patch
# This gets ocamlobjinfo to work with .cmxs files
BuildRequires:  binutils-devel
BuildRequires:  emacs-nox
BuildRequires:  fdupes
BuildRequires:  ncurses-devel
BuildRequires:  pkgconfig(x11)
Requires:       ocaml-runtime = %{version}
Requires(pre):  %{install_info_prereq}
Requires(post): %{install_info_prereq}
Provides:       ocaml(compiler) = %{version}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if %{do_opt}
Requires:       gcc
Provides:       ocaml(ocaml.opt) = %{version}
%endif

%description
Objective Caml is a high-level, strongly-typed, functional and
object-oriented programming language from the ML family of languages.

This package comprises two batch compilers (a fast bytecode compiler
and an optimizing native-code compiler), an interactive top level
system, Lex&Yacc tools, a replay debugger, and a comprehensive library.

%package       rpm-macros
Summary:        RPM macros for building OCaml source packages
License:        QPL-1.0 and SUSE-LGPL-2.0-with-linking-exception
Group:          Development/Languages/Other

%description       rpm-macros
A set of helper macros to unify common code used in ocaml spec files.

%package runtime
Summary:        The Objective Caml Compiler and Programming Environment
License:        QPL-1.0
Group:          Development/Languages/Other
Provides:       ocaml(runtime) = %{version}
%if 0%{?suse_version} < 1210
# Due to lack of generated requires in old rpm, force this
Requires:       ocaml-compiler-libs = %{version}
%endif

%description runtime
Objective Caml is a high-level, strongly-typed, functional and
object-oriented programming language from the ML family of languages.

This package contains the runtime environment needed to run Objective
Caml bytecode.

%package source
Summary:        Source code for Objective Caml libraries
License:        QPL-1.0 and SUSE-LGPL-2.0-with-linking-exception
Group:          Development/Languages/Other
Requires:       ocaml = %{version}

%description source
Source code for Objective Caml libraries.

%package x11
Summary:        X11 support for Objective Caml
License:        SUSE-LGPL-2.0-with-linking-exception
Group:          System/Libraries
Requires:       ocaml-runtime = %{version}

%description x11
X11 support for Objective Caml.

%package ocamldoc
Summary:        The Objective Caml Compiler and Programming Environment
License:        QPL-1.0
Group:          Development/Languages/Other
Requires:       ocaml = %{version}

%description ocamldoc
Objective Caml is a high-level, strongly-typed, functional and
object-oriented programming language from the ML family of languages.

This package contains a documentation generator for Objective Caml.

%package emacs
Summary:        The Objective Caml Compiler and Programming Environment
License:        GPL-2.0+
Group:          Development/Languages/Other
Requires:       emacs
Requires:       ocaml = %{version}
Provides:       caml-mode

%description emacs
Objective Caml is a high-level, strongly-typed, functional and
object-oriented programming language from the ML family of languages.

This package provides caml-mode for emacs

%package docs
Summary:        The Objective Caml Compiler and Programming Environment
License:        GPL-2.0+ and QPL-1.0
Group:          Development/Languages/Other
Requires:       ocaml = %{version}

%description docs
Objective Caml is a high-level, strongly-typed, functional and
object-oriented programming language from the ML family of languages.

This package comprises two batch compilers (a fast bytecode compiler
and an optimizing native-code compiler), an interactive top level
system, Lex&Yacc tools, a replay debugger, and a comprehensive library.

%package compiler-libs
Summary:        Libraries used internal to the OCaml Compiler
License:        QPL-1.0
Group:          Development/Libraries/Other
Requires:       ocaml = %{version}

%description compiler-libs
Objective Caml is a high-level, strongly-typed, functional and
object-oriented programming language from the ML family of languages.

This package contains several modules used internally by the OCaml
compilers. They are not needed for normal OCaml development, but may
be helpful in the development of certain applications.

%package compiler-libs-devel
Summary:        Libraries used internal to the OCaml Compiler
License:        QPL-1.0
Group:          Development/Libraries/Other
Requires:       ocaml-compiler-libs = %{version}

%description compiler-libs-devel
The %{name}-devel package contains libraries and signature files for
developing applications that use %{name}.

%prep
: do_opt %{do_opt}
%setup -q -a 1 -a 2 -a 3
%patch0 -p1
%patch2 -p1
%patch4 -p1
%patch5
%patch7
%patch9 -p1
%patch10 -p1
%patch11 -p1

%build
%ifarch %ix86
# Default OPT flags for these architectures use -fomit-frame-pointer,
# which gets in the way of some of the profiling done within.
export RPM_OPT_FLAGS="${RPM_OPT_FLAGS/-fomit-frame-pointer/}"
%endif

# For ppc64 we need a larger stack than default to compile some files
# because the stages in the OCaml compiler are not mutually tail
# recursive.
%ifarch ppc64 ppc64le
ulimit -a
ulimit -Hs 65536
ulimit -Ss 65536
%endif
CFLAGS="%{optflags} -DUSE_INTERP_RESULT" \
./configure -bindir %{_bindir} \
            -libdir %{_libdir}/ocaml \
	    -mandir %{_mandir} \
            -x11include %{_includedir} \
            -x11lib %{_libdir}
%if %{do_opt}
make world.opt \
%else
make world \
%endif
	BYTECCRPATH= \
	NATIVECCRPATH= \
	MKSHAREDLIBRPATH=

%install
make install \
     BINDIR="%{buildroot}%{_bindir}" \
     LIBDIR="%{buildroot}%{_libdir}/ocaml" \
     MANDIR="%{buildroot}%{_mandir}"
sed -i -e "s|^$RPM_BUILD_ROOT||" %{buildroot}%{_libdir}/ocaml/ld.conf

install -d %{buildroot}%{_infodir} \
           %{buildroot}%{_datadir}/emacs/site-lisp
(
  cd emacs
  make install BINDIR=%{buildroot}/%{_bindir} EMACSDIR=%{buildroot}%{_datadir}/emacs/site-lisp
  make install-ocamltags BINDIR=%{buildroot}/%{_bindir}
)

(
  cd infoman; cp -f ocaml* %{buildroot}%{_infodir}
)

# fix bnc#411232
echo '(load "ocaml.el" nil t t)' >%{buildroot}%{_datadir}/emacs/site-lisp/suse-start-ocaml.el
cat <<EOF >%{buildroot}%{_datadir}/emacs/site-lisp/%{name}.el
(autoload 'caml-mode "caml" "Caml editing mode" t)
(add-hook 'caml-mode-hook 'font-lock-mode)
(add-to-list 'auto-mode-alist '("\\\\.mli?$" . caml-mode))
EOF
sed -i '1s/^/#!\/usr\/bin\/ocaml\n/' %{buildroot}/%{_bindir}/ocamltags

export EXCLUDE_FROM_STRIP="ocamldebug ocamlbrowser"

# Install the compiler libs
install -d %{buildroot}%{_libdir}/ocaml/compiler-libs
cp -a typing/ utils/ parsing/ %{buildroot}%{_libdir}/ocaml/compiler-libs
%fdupes %{buildroot}

mkdir -vp %{buildroot}%{_sysconfdir}/rpm
cat > %{buildroot}%{_sysconfdir}/rpm/macros.%{name} <<_EOF_
# get rid of /usr/lib/rpm/find-debuginfo.sh
# strip kills the bytecode part of ELF binaries
%if %{do_opt}
%%ocaml_preserve_bytecode \
	%%{nil}
%%ocaml_native_compiler 1
%else
%%ocaml_preserve_bytecode \
	%%undefine _build_create_debug \
	%%define __arch_install_post export NO_BRP_STRIP_DEBUG=true \
	%%{nil}
%%ocaml_native_compiler 0
%endif
_EOF_
cat %{buildroot}%{_sysconfdir}/rpm/macros.%{name}

%post
%install_info --info-dir=%{_infodir} %{_infodir}/%{name}.info.gz

%postun
%install_info_delete --info-dir=%{_infodir} %{_infodir}/%{name}.info.gz

%files
%defattr(-,root,root)
%doc Changes LICENSE README
%{_bindir}/*
%{_mandir}/*/*
%{_libdir}/ocaml/*.a
%if %{do_opt}
%{_libdir}/ocaml/*.cmxs
%{_libdir}/ocaml/*.cmxa
%{_libdir}/ocaml/*.cmx
%{_libdir}/ocaml/*.o
%endif
%{_libdir}/ocaml/*.mli
%{_libdir}/ocaml/libcamlrun_shared.so
%if %{do_opt}
%{_libdir}/ocaml/libasmrun_shared.so
%endif
%{_libdir}/ocaml/vmthreads/*.mli
%{_libdir}/ocaml/vmthreads/*.a
%if %{do_opt}
%{_libdir}/ocaml/threads/*.a
%{_libdir}/ocaml/threads/*.cmxa
%{_libdir}/ocaml/threads/*.cmx
%endif
%{_libdir}/ocaml/caml
%{_libdir}/ocaml/ocamlbuild
%{_libdir}/ocaml/Makefile.config
%{_libdir}/ocaml/VERSION
%{_libdir}/ocaml/extract_crc
%{_libdir}/ocaml/camlheader
%{_libdir}/ocaml/camlheader_ur
%{_libdir}/ocaml/expunge
%{_libdir}/ocaml/ld.conf
%{_libdir}/ocaml/objinfo_helper
%exclude %{_libdir}/ocaml/graphicsX11.mli
%{_infodir}/*
%exclude %{_bindir}/ocamlrun
%exclude %{_bindir}/ocamltags
%exclude %{_bindir}/ocamldoc*
%exclude %{_libdir}/ocaml/ocamldoc

%files rpm-macros
%defattr(-,root,root,-)
%dir %{_sysconfdir}/rpm
%config %{_sysconfdir}/rpm/*

%files runtime
%defattr(-,root,root,-)
%{_bindir}/ocamlrun
%dir %{_libdir}/ocaml
%{_libdir}/ocaml/*.cmo
%{_libdir}/ocaml/*.cmi
%{_libdir}/ocaml/*.cmt
%{_libdir}/ocaml/*.cmti
%{_libdir}/ocaml/*.cma
%{_libdir}/ocaml/stublibs
%dir %{_libdir}/ocaml/vmthreads
%{_libdir}/ocaml/vmthreads/*.cmi
%{_libdir}/ocaml/vmthreads/*.cma
%dir %{_libdir}/ocaml/threads
%{_libdir}/ocaml/threads/*.cmi
%{_libdir}/ocaml/threads/*.cma
%exclude %{_libdir}/ocaml/graphicsX11.cmi
%doc README LICENSE Changes

%files x11
%defattr(-,root,root,-)
%{_libdir}/ocaml/graphicsX11.cmi
%{_libdir}/ocaml/graphicsX11.mli

%files source
%defattr(-,root,root,-)
%{_libdir}/ocaml/*.ml

%files ocamldoc
%defattr(-,root,root,-)
%{_bindir}/ocamldoc*
%{_libdir}/ocaml/ocamldoc
%doc ocamldoc/Changes.txt

%files docs
%defattr(-,root,root,-)
%doc htmlman

%files emacs
%defattr(-,root,root,-)
%doc emacs/README
%dir %{_datadir}/emacs
%dir %{_datadir}/emacs/site-lisp
%{_datadir}/emacs/site-lisp/*
%{_bindir}/ocamltags

%files compiler-libs
%defattr(-,root,root,-)
%doc LICENSE README
%{_libdir}/ocaml/compiler-libs
%if %{do_opt}
%exclude %{_libdir}/ocaml/compiler-libs/*/*.cmx
%exclude %{_libdir}/ocaml/compiler-libs/*/*.o
%endif
%exclude %{_libdir}/ocaml/compiler-libs/*/*.mli
%exclude %{_libdir}/ocaml/compiler-libs/*/*.ml

%files compiler-libs-devel
%defattr(-,root,root,-)
%doc LICENSE README
%if %{do_opt}
%{_libdir}/ocaml/compiler-libs/*/*.cmx
%{_libdir}/ocaml/compiler-libs/*/*.o
%endif
%{_libdir}/ocaml/compiler-libs/*/*.ml
%{_libdir}/ocaml/compiler-libs/*/*.mli

%if %{with ocaml_make_testsuite}
%check
make %{?_smp_mflags} -C testsuite clean
if make -C testsuite all
then
	: passed
else
	: failed
fi
%endif

%changelog
openSUSE Build Service is sponsored by