##
##  json.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_api_c   0.13.1-20180305
%define       V_api_c2  1.1.0
%define       V_api_c3  0.8
%define       V_api_pl1 2.90
%define       V_api_pl2 0.03
%define       V_api_pl3 0.47
%define       V_api_pl4 3.01
%define       V_api_pl5 0.011
%define       V_api_js1 20091209
%define       V_api_js2 20091209

#   package information
Name:         json
Summary:      JavaScript Object Notation (JSON)
URL:          http://www.json.org/
Vendor:       D. Crockford et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Language
License:      Open Source
Version:      20191020
Release:      20191020

#   list of sources
Source0:      http://github.com/json-c/json-c/archive/json-c-%{V_api_c}.tar.gz
Source1:      http://download.sourceforge.net/zzjson/zzjson-%{V_api_c2}.tar.gz
Source2:      http://projects.snarc.org/libjson/download/libjson-%{V_api_c3}.tar.bz2
Source3:      http://www.cpan.org/authors/id/M/MA/MAKAMAKA/JSON-%{V_api_pl1}.tar.gz
Source4:      http://www.cpan.org/authors/id/M/MA/MAKAMAKA/JSON-PC-%{V_api_pl2}.tar.gz
Source5:      http://www.cpan.org/authors/id/D/DO/DOWENS/JSON-DWIW-%{V_api_pl3}.tar.gz
Source6:      http://www.cpan.org/authors/id/M/ML/MLEHMANN/JSON-XS-%{V_api_pl4}.tar.gz
Source7:      http://www.cpan.org/authors/id/P/PE/PERLER/JavaScript-Dumper-%{V_api_pl5}.tar.gz
Source8:      http://download.openpkg.org/components/versioned/json/json-%{V_api_js1}.js
Source9:      http://download.openpkg.org/components/versioned/json/json2-%{V_api_js2}.js
Source10:     http://www.ietf.org/rfc/rfc4627.txt
Patch0:       json.patch

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

%description
    JSON (JavaScript Object Notation) is a lightweight data-interchange
    format. It is easy for humans to read and write. It is easy for
    machines to parse and generate. It is based on a subset of the
    JavaScript Programming Language, Standard ECMA-262 3rd Edition.
    JSON is a text format that is completely language independent but
    uses conventions that are familiar to programmers of the C-family
    of languages. These properties make JSON an ideal data-interchange
    language.

%track
    prog json:json-c = {
        version   = %{V_api_c}
        url       = https://github.com/json-c/json-c/downloads
        regex     = json-c-(__VER__)\.tar\.gz
    }
    prog json:json-c2 = {
        version   = %{V_api_c2}
        url       = http://sourceforge.net/projects/zzjson/files/
        regex     = zzjson-(__VER__)\.tar\.gz
    }
    prog json:json-c3 = {
        version   = %{V_api_c3}
        url       = http://projects.snarc.org/libjson/download/
        regex     = libjson-(__VER__)\.tar\.bz2
    }
    prog json:json-pl1 = {
        version   = %{V_api_pl1}
        url       = http://www.cpan.org/authors/id/M/MA/MAKAMAKA/
        regex     = JSON-(__VER__)\.tar\.gz
    }
    prog json:json-pl2 = {
        version   = %{V_api_pl2}
        url       = http://www.cpan.org/authors/id/M/MA/MAKAMAKA/
        regex     = JSON-PC-(__VER__)\.tar\.gz
    }
    prog json:json-pl3 = {
        version   = %{V_api_pl3}
        url       = http://www.cpan.org/authors/id/D/DO/DOWENS/
        regex     = JSON-DWIW-(__VER__)\.tar\.gz
    }
    prog json:json-pl4 = {
        version   = %{V_api_pl4}
        url       = http://www.cpan.org/authors/id/M/ML/MLEHMANN/
        regex     = JSON-XS-(__VER__)\.tar\.gz
    }
    prog json:json-pl5 = {
        version   = %{V_api_pl5}
        url       = http://www.cpan.org/authors/id/P/PE/PERLER/
        regex     = JavaScript-Dumper-(__VER__)\.tar\.gz
    }
    prog json:json-js1 = {
        version   = %{V_api_js1}
        url       = http://download.openpkg.org/components/versioned/json/
        regex     = json-(__VER__)\.js
    }
    prog json:json-js2 = {
        version   = %{V_api_js2}
        url       = http://download.openpkg.org/components/versioned/json/
        regex     = json2-(__VER__)\.js
    }

%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
    cp %{SOURCE json-%{V_api_js1}.js} json.js
    cp %{SOURCE json2-%{V_api_js2}.js} json2.js
    %patch -p0

%build
    ( cd json-c-json-c-%{V_api_c}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?
    ( cd zzjson-%{V_api_c2}
      CC="%{l_cc}" \
      %{l_bash} ./buildstatic.sh
    ) || exit $?
    ( cd libjson-%{V_api_c3}
      %{l_make} %{l_mflags} \
          CC="%{l_cc}" \
          CFLAGS="%{l_cflags -O}" \
          libjson.a
    ) || exit $?
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_prefix}/bin/perl-openpkg -d JSON-%{V_api_pl1} configure build
    %{l_prefix}/bin/perl-openpkg -d JSON-PC-%{V_api_pl2} configure build
    %{l_prefix}/bin/perl-openpkg -d JSON-DWIW-%{V_api_pl3} configure build
    %{l_prefix}/bin/perl-openpkg -d JSON-XS-%{V_api_pl4} configure build
    %{l_prefix}/bin/perl-openpkg -d JavaScript-Dumper-%{V_api_pl5} configure build

%install
    ( cd json-c-json-c-%{V_api_c}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?
    ( cd zzjson-%{V_api_c2}
      %{l_shtool} install -c -m 644 \
          include/zzjson.h $RPM_BUILD_ROOT%{l_prefix}/include/
      %{l_shtool} install -c -m 644 \
          lib/libzzjson.a $RPM_BUILD_ROOT%{l_prefix}/lib/
    ) || exit $?
    ( cd libjson-%{V_api_c3}
      %{l_shtool} install -c -m 644 \
          json.h $RPM_BUILD_ROOT%{l_prefix}/include/
      %{l_shtool} install -c -m 644 \
          libjson.a $RPM_BUILD_ROOT%{l_prefix}/lib/
    ) || exit $?
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/json
    %{l_shtool} install -c -m 644 \
        json.js json2.js $RPM_BUILD_ROOT%{l_prefix}/share/json/
    %{l_shtool} install -c -m 644 \
        %{SOURCE rfc4627.txt} $RPM_BUILD_ROOT%{l_prefix}/share/json/
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apache/apache.d
    ( echo "Alias /openpkg-json/ %{l_prefix}/share/json/"
      echo "<Directory %{l_prefix}/share/json/>"
      echo "    Options       Indexes"
      echo "    AllowOverride none"
      echo "    Order         allow,deny"
      echo "    Allow         from all"
      echo "</Directory>"
    ) >json.conf
    %{l_shtool} install -c -m 644 \
        json.conf $RPM_BUILD_ROOT%{l_prefix}/etc/apache/apache.d/
    %{l_prefix}/bin/perl-openpkg -d JSON-%{V_api_pl1} install
    %{l_prefix}/bin/perl-openpkg -d JSON-PC-%{V_api_pl2} install
    %{l_prefix}/bin/perl-openpkg -d JSON-DWIW-%{V_api_pl3} install
    %{l_prefix}/bin/perl-openpkg -d JSON-XS-%{V_api_pl4} install
    %{l_prefix}/bin/perl-openpkg -d JavaScript-Dumper-%{V_api_pl5} install
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files` \
        '%config %{l_prefix}/etc/apache/apache.d/*'

%files -f files

%clean

