##
##  io.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_opkg 20080330
%define       V_dist 2008-03-30
%define       V_git  6a5f734

#   package information
Name:         io
Summary:      IO Programming Language
URL:          http://www.iolanguage.com/
Vendor:       Steve Dekorte
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Language
License:      BSD
Version:      %{V_opkg}
Release:      20100110

#   package options
%option       with_threads no
%option       with_zlib    no
%option       with_libxml  no
%option       with_sqlite  no

#   list of sources
Source0:      http://download.github.com/stevedekorte-io-%{V_git}.tar.gz
Patch0:       io.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, infozip
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_zlib}" == "yes"
BuildPreReq:  zlib
PreReq:       zlib
%endif
%if "%{with_libxml}" == "yes"
BuildPreReq:  libxml
PreReq:       libxml
%endif
%if "%{with_sqlite}" == "yes"
BuildPreReq:  sqlite
PreReq:       sqlite
%endif

%description
    Io is a small, prototype-based programming language. The ideas
    in Io are mostly inspired by Smalltalk (all values are objects),
    Self (prototype-based), NewtonScript (differential inheritance),
    Act1 (actors and futures for concurrency), LISP (code is a runtime
    inspectable/modifiable tree) and Lua (small, embeddable).

%track
    prog io = {
        version   = %{V_dist}
        url       = http://github.com/stevedekorte/io/downloads
        regex     = (2\d\d\d\.\d\d\.\d\d)
    }

%prep
    %setup -q -n stevedekorte-io-%{V_git}
    %patch -p0

%build
    #   prepare addon directory
    ( cd addons
      addons=""
      addons="$addons BigNum Blowfish CGI ContinuedFraction Contracts MD5 Random"
      addons="$addons Rational Regex SHA1 SystemCall Socket User Vector"
%if "%{with_threads}" == "yes"
      addons="$addons Thread"
%endif
%if "%{with_zlib}" == "yes"
      addons="$addons Zlib"
%endif
%if "%{with_libxml}" == "yes"
      addons="$addons Libxml2"
%endif
%if "%{with_sqlite}" == "yes"
      addons="$addons SQLite3"
%endif
      for addon in *;       do mv $addon _$addon; done
      for addon in $addons; do mv _$addon $addon; done
      rm -rf _*
    ) || exit $?

    #   build program and addons
    %{l_make} %{l_mflags -O} \
        INSTALL_PREFIX=%{l_prefix} \
        CC="%{l_cc} %{l_cflags -O} %{l_cppflags} -L_build/lib %{l_ldflags}"

%install
    #   install program and addons
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/lib
    %{l_make} %{l_mflags} install \
        INSTALL_PREFIX=$RPM_BUILD_ROOT%{l_prefix}

    #   prune addon directory tree
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type d -depth -print | grep "/_build/headers" | xargs rm -rf
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type d -depth -print | grep "/_build/objs"    | xargs rm -rf
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type d -depth -print | grep "/_build/lib"     | xargs rm -rf
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type d -depth -print | grep "/tests"          | xargs rm -rf
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type d -depth -print | grep "/source"         | xargs rm -rf
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type f -depth -print | grep "build.io"        | xargs rm -f
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type f -depth -print | grep "depends"         | xargs rm -f
    find $RPM_BUILD_ROOT%{l_prefix}/lib/io -type d -depth -print | xargs rmdir >/dev/null 2>&1 || true

    #   prune executable
    mv  $RPM_BUILD_ROOT%{l_prefix}/bin/io_static \
        $RPM_BUILD_ROOT%{l_prefix}/bin/io
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   remove useless files
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/libiovmall.*

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

%files -f files

%clean

