##
##  smlnj.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 information
Name:         smlnj
Summary:      Standard ML of New Jersey (SML/NJ)
URL:          http://www.smlnj.org/
Vendor:       University of Chicago
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Language
License:      BSD-like
Version:      110.75
Release:      20121006

#   list of sources
Source0:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/boot.sparc-unix.tgz
Source1:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/boot.x86-unix.tgz
Source2:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/MLRISC.tgz
Source3:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/ckit.tgz
Source4:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/cm.tgz
Source5:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/cml.tgz
Source6:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/config.tgz
Source7:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/eXene.tgz
Source8:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/ml-burg.tgz
Source9:      http://smlnj.cs.uchicago.edu/dist/working/%{version}/ml-lex.tgz
Source10:     http://smlnj.cs.uchicago.edu/dist/working/%{version}/ml-yacc.tgz
Source11:     http://smlnj.cs.uchicago.edu/dist/working/%{version}/nlffi.tgz
Source12:     http://smlnj.cs.uchicago.edu/dist/working/%{version}/runtime.tgz
Source13:     http://smlnj.cs.uchicago.edu/dist/working/%{version}/smlnj-c.tgz
Source14:     http://smlnj.cs.uchicago.edu/dist/working/%{version}/smlnj-lib.tgz
Source15:     http://smlnj.cs.uchicago.edu/dist/working/%{version}/system.tgz
Source16:     smlnj-config.sh

#   build information
BuildPreReq:  OpenPKG, openpkg, gcc, make
PreReq:       OpenPKG, openpkg

%description
    Standard ML of New Jersey (SML/NJ) is a compiler for the Standard
    ML '97 programming language with associated libraries, tools, and
    documentation. SML/NJ is the most popular implementation of the
    Standard Meta Language (SML). SML is a functional language from the
    ML family (like CAML).

%track
    prog smlnj = {
        version   = %{version}
        url       = http://smlnj.cs.uchicago.edu/dist/working/
        regex     = (11\d\.\d+)
    }

%prep
    #   make container directory
    %setup -c -T

    #   copy distribution tarballs to working directory
    for tarball in \
        %{SOURCE0}  %{SOURCE1}  %{SOURCE2}  %{SOURCE3}  %{SOURCE4} \
        %{SOURCE5}  %{SOURCE6}  %{SOURCE7}  %{SOURCE8}  %{SOURCE9} \
        %{SOURCE10} %{SOURCE11} %{SOURCE12} %{SOURCE13} %{SOURCE14} \
        %{SOURCE15}; do
        cp $tarball .
    done

    #   unpack bootstrapping part
    %{l_gzip} -d -c config.tgz | %{l_tar} xf -

    #   pre-unpack and patch some parts
    %{l_gzip} -d -c runtime.tgz | (mkdir src; cd src; %{l_tar} xf -) || exit $?

%build
    #   the actual build can't proceed this early, since the custom build
    #   scripts would require $RPM_BUILD_ROOT to exist already

%install

    #   make installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/smlnj \
        $RPM_BUILD_ROOT%{l_prefix}/bin

    #   determine heap directory
    HEAPDIR="%{l_prefix}/libexec/smlnj/bin/.heap"

    #   build distribution
    INSTALLDIR=$RPM_BUILD_ROOT%{l_prefix}/libexec/smlnj \
        %{l_bash} config/install.sh

    #   fix absolute symlink paths
    for symlink in `find $RPM_BUILD_ROOT%{l_prefix} -type l -print`; do
        target=`/bin/ls -al $symlink |\
            sed -e 's;^;X;' \
                -e "s;^X.* -> $RPM_BUILD_ROOT\\(.*\\)\$;\\1;g" \
                -e 's;^X.*;;'`
        if [ ".$target" != . ]; then
            rm -f $symlink
            ln -s $target $symlink
        fi
    done

    #   install wrapper scripts
    for binfile in $RPM_BUILD_ROOT%{l_prefix}/libexec/smlnj/bin/*; do
        simplename=`basename $binfile`
        ( echo "#!/bin/sh"
          echo "SMLNJ_HOME=\"%{l_prefix}/libexec/smlnj\""
          echo "export SMLNJ_HOME"
          echo "exec %{l_prefix}/libexec/smlnj/bin/$simplename \${1+\"\$@\"}"
        ) >wrapper
        %{l_shtool} install -c -m 755 \
            wrapper $RPM_BUILD_ROOT%{l_prefix}/bin/$simplename
    done

    #   install configuration script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        -e "s;@heapdir@;$HEAPDIR;g" \
        %{SOURCE smlnj-config.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/smlnj-config

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

