##
##  yaml.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_libsyck             0.70
%define       V_libyaml             0.2.5
%define       V_perl_yaml           1.31
%define       V_perl_yaml_syck      1.34
%define       V_perl_yaml_tiny      1.73
%define       V_perl_yaml_appconfig 0.19
%define       V_perl_yaml_libyaml   0.89
%define       V_perl_yaml_active    1.100810
%define       V_perl_yaml_object    0.04
%define       V_perl_io_yaml        0.10
%define       V_yaml_javascript     0.03
%define       V_yaml_spec           2004-12-28
%define       V_java_jvyaml         0.2.1
%define       V_java_jyaml          1.3
%define       V_php_yaml            2.2.4
%define       V_php_spyc            0.4.5

#   package information
Name:         yaml
Summary:      YAML Ain't Markup Language (YAML)
URL:          http://yaml.org/
Vendor:       B. Ingerson, C. Evans, O. Ben-Kiki et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Language
License:      BSD/Artistic
Version:      0
Release:      20241008

#   package options
%option       with_perl   no
%option       with_php    no
%option       with_ruby   no
%option       with_java   no

#   list of sources
Source0:      http://cloud.github.com/downloads/indeyets/syck/syck-%{V_libsyck}.tar.gz
Source1:      http://pyyaml.org/download/libyaml/yaml-%{V_libyaml}.tar.gz
Source2:      http://www.cpan.org/modules/by-module/YAML/YAML-%{V_perl_yaml}.tar.gz
Source3:      http://www.cpan.org/modules/by-module/YAML/YAML-Syck-%{V_perl_yaml_syck}.tar.gz
Source4:      http://www.cpan.org/modules/by-module/YAML/YAML-Tiny-%{V_perl_yaml_tiny}.tar.gz
Source5:      http://www.cpan.org/modules/by-module/YAML/YAML-AppConfig-%{V_perl_yaml_appconfig}.tar.gz
Source6:      http://www.cpan.org/modules/by-module/YAML/YAML-LibYAML-%{V_perl_yaml_libyaml}.tar.gz
Source7:      http://www.cpan.org/modules/by-module/YAML/YAML-Active-%{V_perl_yaml_active}.tar.gz
Source8:      http://www.cpan.org/authors/id/N/NK/NKUITSE/IO-YAML-%{V_perl_io_yaml}.tar.gz
Source9:      http://osdn.dl.sourceforge.net/yaml-javascript/yaml-javascript-%{V_yaml_javascript}.tar.gz
Source10:     https://jvyaml.dev.java.net/files/documents/5215/41455/jvyaml-src-%{V_java_jvyaml}.tar.gz
Source11:     http://download.sourceforge.net/jyaml/jyaml-src-%{V_java_jyaml}.tgz
Source12:     http://www.cpan.org/authors/id/E/EI/EIDOLON/YAML-Object-%{V_perl_yaml_object}.tar.gz
Source13:     http://pecl.php.net/get/yaml-%{V_php_yaml}.tgz
Source14:     http://spyc.googlecode.com/files/spyc-%{V_php_spyc}.zip
Source15:     http://yaml.org/spec/history/%{V_yaml_spec}/%{V_yaml_spec}.pdf
Source16:     yaml.yml
Patch0:       yaml.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, bison
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_perl}" == "yes"
BuildPreReq:  perl, perl-openpkg, perl-module
PreReq:       perl
%endif
%if "%{with_php}" == "yes"
BuildPreReq:  php, autoconf
PreReq:       php
%endif
%if "%{with_ruby}" == "yes"
BuildPreReq:  ruby
PreReq:       ruby
%endif
%if "%{with_java}" == "yes"
BuildPreReq:  java, JAVA-JDK, ant
PreReq:       java, JAVA-JDK
%endif

%description
    YAML Ain't Markup Language (YAML) is an international collaboration
    to make a sophisticated data serialization language which is both
    human readable and computationally powerful. This OpenPKG package
    provides C, and JavaScript plus optionally Perl, PHP, and Ruby APIs
    for the generation and parsing of YAML.

%track
    prog yaml:libsyck = {
        version   = %{V_libsyck}
        url       = http://github.com/indeyets/syck/downloads
        regex     = syck-(__VER__)\.tar\.gz
    }
    prog yaml:libyaml = {
        version   = %{V_libyaml}
        url       = http://pyyaml.org/download/libyaml/
        regex     = yaml-(__VER__)\.tar\.gz
    }
    prog yaml:YAML = {
        version   = %{V_perl_yaml}
        url       = http://www.cpan.org/modules/by-module/YAML/
        regex     = YAML-(__VER__)\.tar\.gz
    }
    prog yaml:YAML-Syck = {
        version   = %{V_perl_yaml_syck}
        url       = http://www.cpan.org/modules/by-module/YAML/
        regex     = YAML-Syck-(__VER__)\.tar\.gz
    }
    prog yaml:YAML-Tiny = {
        version   = %{V_perl_yaml_tiny}
        url       = http://www.cpan.org/modules/by-module/YAML/
        regex     = YAML-Tiny-(__VER__)\.tar\.gz
    }
    prog yaml:YAML-AppConfig = {
        version   = %{V_perl_yaml_appconfig}
        url       = http://www.cpan.org/modules/by-module/YAML/
        regex     = YAML-AppConfig-(__VER__)\.tar\.gz
    }
    prog yaml:YAML-LibYAML = {
        version   = %{V_perl_yaml_libyaml}
        url       = http://www.cpan.org/modules/by-module/YAML/
        regex     = YAML-LibYAML-(__VER__)\.tar\.gz
    }
    prog yaml:YAML-Active = {
        comment   = "rse: 1.08 requires Class::Accessor::Complex and this too many others"
        version   = %{V_perl_yaml_active}
        url       = http://www.cpan.org/modules/by-module/YAML/
        regex     = YAML-Active-(__VER__)\.tar\.gz
    }
    prog yaml:IO-YAML = {
        version   = %{V_perl_io_yaml}
        url       = http://www.cpan.org/authors/id/N/NK/NKUITSE/
        regex     = IO-YAML-(__VER__)\.tar\.gz
    }
    prog yaml:yaml-javascript = {
        version   = %{V_yaml_javascript}
        url       = http://sourceforge.net/projects/yaml-javascript/files/
        regex     = yaml-javascript-(__VER__)\.tar\.gz
    }
    prog yaml:yaml-spec = {
        disabled
        comment   = "rse: website references not existing 2004-12-30 and no updates since recently anyway"
        version   = %{V_yaml_spec}
        url       = http://yaml.org/spec/
        regex     = (\d{4}-\d{2}-\d{2})\.pdf
    }
    prog yaml:java-jvyaml = {
        version   = %{V_java_jvyaml}
        url       = http://jvyaml.dev.java.net/servlets/ProjectDocumentList
        regex     = jvyaml-src-(__VER__)\.tar\.gz
    }
    prog yaml:java-jyaml = {
        version   = %{V_java_jyaml}
        url       = http://sourceforge.net/projects/jyaml/files/
        regex     = jyaml-src-(__VER__)\.tgz
    }
    prog yaml:YAML-Object = {
        version   = %{V_perl_yaml_object}
        url       = http://www.cpan.org/authors/id/E/EI/EIDOLON/
        regex     = YAML-Object-(__VER__)\.tar\.gz
    }
    prog yaml:PHP-YAML = {
        version   = %{V_php_yaml}
        url       = http://pecl.php.net/package/yaml
        regex     = yaml-(__VER__)\.tgz
    }
    prog yaml:PHP-spyc = {
        version   = %{V_php_spyc}
        url       = http://spyc.googlecode.com/files/
        regex     = spyc-(__VER__)\.zip
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %setup -q -T -D -a 5
    %setup -q -T -D -a 6
    %setup -q -T -D -a 7
    %setup -q -T -D -a 8
    %setup -q -T -D -a 9
    %setup -q -T -D -a 10
    %setup -q -T -D -a 11
    %setup -q -T -D -a 12
    %setup -q -T -D -a 13
    %setup -q -T -D -a 14
    %patch -p0

%build
    #   build YAML C API
    ( cd yaml-%{V_libyaml}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?

    #   build Syck C API
    ( cd syck-%{V_libsyck}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix}
      %{l_make} %{l_mflags}
    ) || exit $?

    #   build PHP API
%if "%{with_php}" == "yes"
    ( cd yaml-%{V_php_yaml}
      %{l_prefix}/bin/phpize
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="-I`pwd`/../yaml-%{V_libyaml}/include" \
      LDFLAGS="-L`pwd`/../yaml-%{V_libyaml}/src/.libs" \
      ./configure \
          --with-yaml=`pwd`/../yaml-%{V_libyaml}
      %{l_make} %{l_mflags}
    ) || exit $?
%endif

    #   build Ruby API
%if "%{with_ruby}" == "yes"
    ( cd syck-%{V_libsyck}/ext/ruby
      %{l_prefix}/bin/ruby install.rb config --prefix=%{l_prefix}
      %{l_prefix}/bin/ruby install.rb setup
    ) || exit $?
%endif

    #   build Perl API
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_prefix}/bin/perl-openpkg -d YAML-%{V_perl_yaml}                     configure build
    %{l_prefix}/bin/perl-openpkg -d YAML-Syck-%{V_perl_yaml_syck}           configure build
    %{l_prefix}/bin/perl-openpkg -d YAML-Tiny-%{V_perl_yaml_tiny}           configure build
    %{l_prefix}/bin/perl-openpkg -d YAML-AppConfig-%{V_perl_yaml_appconfig} configure build
    %{l_prefix}/bin/perl-openpkg -d YAML-LibYAML-%{V_perl_yaml_libyaml}     configure build
    %{l_prefix}/bin/perl-openpkg -d YAML-Active-%{V_perl_yaml_active}       configure build
    %{l_prefix}/bin/perl-openpkg -d YAML-Object-%{V_perl_yaml_object}       configure build
    %{l_prefix}/bin/perl-openpkg -d IO-YAML-%{V_perl_io_yaml}               configure build
%endif

    #   build Java API
%if "%{with_java}" == "yes"
    ( cd jvyaml-%{V_java_jvyaml}
      %{l_prefix}/bin/ant
    ) || exit $?
    ( cd jyaml
      %{l_prefix}/bin/ant
    ) || exit $?
%endif

%install

    #   install YAML C API
    ( cd yaml-%{V_libyaml}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?

    #   install Syck C API
    ( cd syck-%{V_libsyck}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?

    #   install PHP API
%if "%{with_php}" == "yes"
    ( cd yaml-%{V_php_yaml}
      %{l_make} %{l_mflags} install INSTALL_ROOT=$RPM_BUILD_ROOT
    ) || exit $?
    ( cd spyc-%{V_php_spyc}
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/yaml
      %{l_shtool} install -c -m 644 \
          spyc.php $RPM_BUILD_ROOT%{l_prefix}/share/yaml/
    ) || exit $?
%endif

    #   install Ruby API
%if "%{with_ruby}" == "yes"
    ( cd syck-%{V_libsyck}/ext/ruby
      %{l_prefix}/bin/ruby install.rb install --prefix=$RPM_BUILD_ROOT
    ) || exit $?
%endif

    #   install Perl API
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg -d YAML-%{V_perl_yaml}                     install
    %{l_prefix}/bin/perl-openpkg -d YAML-Syck-%{V_perl_yaml_syck}           install
    %{l_prefix}/bin/perl-openpkg -d YAML-Tiny-%{V_perl_yaml_tiny}           install
    %{l_prefix}/bin/perl-openpkg -d YAML-AppConfig-%{V_perl_yaml_appconfig} install
    %{l_prefix}/bin/perl-openpkg -d YAML-LibYAML-%{V_perl_yaml_libyaml}     install
    %{l_prefix}/bin/perl-openpkg -d YAML-Active-%{V_perl_yaml_active}       install
    %{l_prefix}/bin/perl-openpkg -d YAML-Object-%{V_perl_yaml_object}       install
    %{l_prefix}/bin/perl-openpkg -d IO-YAML-%{V_perl_io_yaml}               install
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif

    #   install Java API
%if "%{with_java}" == "yes"
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/lib/yaml
    %{l_shtool} install -c -m 644 \
        jvyaml-%{V_java_jvyaml}/lib/jvyaml.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/yaml/
    %{l_shtool} install -c -m 644 \
        jyaml/dist/jyaml-*.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/yaml/jyaml.jar
%endif

    #   install JavaScript API
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/yaml
    %{l_shtool} install -c -m 644 \
        yaml-javascript-%{V_yaml_javascript}/yaml_dumper.js \
        $RPM_BUILD_ROOT%{l_prefix}/share/yaml/

    #   install YAML specification and quick reference
    %{l_shtool} install -c -m 644 \
        %{SOURCE %{V_yaml_spec}.pdf} \
        $RPM_BUILD_ROOT%{l_prefix}/share/yaml/yaml.pdf
    %{l_shtool} install -c -m 644 \
        %{SOURCE yaml.yml} \
        $RPM_BUILD_ROOT%{l_prefix}/share/yaml/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

