##
##  ocaml.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_major 5.4
%define       V_minor 0

#   package information
Name:         ocaml
Summary:      Objective Caml
URL:          http://caml.inria.fr/
Vendor:       INRIA
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Language
License:      LGPL+QPL
Version:      %{V_major}.%{V_minor}
Release:      20251010

#   list of sources
Source0:      http://caml.inria.fr/pub/distrib/ocaml-%{V_major}/ocaml-%{version}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make
PreReq:       OpenPKG, openpkg >= 20160101, gcc

%description
    Caml is a strongly-typed functional programming language from the ML
    family. OCaml (Objective Caml) and Caml Light are two open source
    implementations of Caml.

%track
    prog ocaml = {
        version   = %{V_major}
        url       = http://caml.inria.fr/pub/distrib/
        regex     = ocaml-(\d+\.\d+(\.\d+)*)
    }

%prep
    %setup -q

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        -prefix %{l_prefix}
    %{l_make} %{l_mflags} world
    %{l_make} %{l_mflags} bootstrap
    %{l_make} %{l_mflags} opt
    %{l_make} %{l_mflags} opt.opt

%install
    %{l_shtool} subst \
        -e "s;^prefix=%{l_prefix};prefix=$RPM_BUILD_ROOT%{l_prefix};" \
        Makefile.config
    %{l_make} %{l_mflags} install
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/*.opt \
          $RPM_BUILD_ROOT%{l_prefix}/bin/ocamlyacc \
          $RPM_BUILD_ROOT%{l_prefix}/bin/ocamlrun
    ( cd $RPM_BUILD_ROOT%{l_prefix}/bin
      for opt in *.opt; do
          mv $opt `echo $opt | sed -e 's;\.opt$;;'` || exit $?
      done
    ) || exit $?
    ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man3
      for man in *.3o; do
          mv $man `echo $man | sed -e 's;\.3o$;.3;'` || exit $?
      done
    ) || exit $?
    ( echo "%{l_prefix}/lib/ocaml/stublibs"
      echo "%{l_prefix}/lib/ocaml"
    ) >$RPM_BUILD_ROOT%{l_prefix}/lib/ocaml/ld.conf
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

