##
##  js.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_js                      1.6.20070208
%define       V_javascript              1.16
%define       V_javascript_spidermonkey 0.21
%define       V_javascript_squish       0.07
%define       V_javascript_code         0.08
%define       V_javascript_jslint       0.07
%define       V_javascript_engine       0.54
%define       V_jsmin                   20080803
%define       V_jsapigen                0.5.1

#   package information
Name:         js
Summary:      Mozilla JavaScript (JS)
URL:          http://www.mozilla.org/js/
Vendor:       Brendan Eich et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Language
License:      MPL/GPL/LGPL
Version:      %{V_js}
Release:      20181229

#   package options
%option       with_file        yes
%option       with_dso         yes
%option       with_jsapigen    no
%option       with_perl        no
%option       with_editline    no
%option       with_utf8        no

#   list of sources
Source0:      http://www.ossp.org/pkg/lib/js/js-%{V_js}.tar.gz
Source1:      http://www.cpan.org/modules/by-authors/id/C/CL/CLAESJAC/JavaScript-%{V_javascript}.tar.gz
Source2:      http://www.cpan.org/modules/by-module/JavaScript/JavaScript-SpiderMonkey-%{V_javascript_spidermonkey}.tar.gz
Source3:      http://www.cpan.org/modules/by-module/JavaScript/JavaScript-Squish-%{V_javascript_squish}.tar.gz
Source4:      http://www.cpan.org/modules/by-module/JavaScript/JavaScript-Code-%{V_javascript_code}.tar.gz
Source5:      http://www.cpan.org/modules/by-module/JavaScript/JavaScript-JSLint-%{V_javascript_jslint}.tar.gz
Source6:      http://www.cpan.org/modules/by-module/JavaScript/JE-%{V_javascript_engine}.tar.gz
Source7:      http://download.sourceforge.net/jsapigen/jsapigen-%{V_jsapigen}.tar.gz
Source8:      http://download.openpkg.org/components/versioned/jsmin/jsmin-%{V_jsmin}.c
Patch0:       js.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_perl}" == "yes"
BuildPreReq:  perl, perl-openpkg
PreReq:       perl
%endif
%if "%{with_editline}" == "yes"
BuildPreReq:  editline
PreReq:       editline
%endif
%if "%{with_jsapigen}" == "yes"
BuildPreReq:  flex, bison
%endif

%description
    This is the JavaScript (JS) reference implementation in C
    from Mozilla, aka JSRef or SpiderMonkey. JavaScript is the
    Netscape-developed object scripting language used in millions of web
    pages and server applications worldwide. Netscape's JavaScript is a
    superset of the ECMA-262 Edition 3 (ECMAScript) standard scripting
    language. This package is based on the OSSP js distribution of
    Mozilla JavaScript and also optionally provides Perl bindings.

%track
    prog js = {
        version   = %{V_js}
        url       = http://www.ossp.org/pkg/lib/js/
        regex     = js-(__VER__)\.tar\.gz
    }
    prog js:JavaScript = {
        version   = %{V_javascript}
        url       = http://www.cpan.org/modules/by-authors/id/C/CL/CLAESJAC/
        regex     = JavaScript-(__VER__)\.tar\.gz
    }
    prog js:JavaScript-SpiderMonkey = {
        version   = %{V_javascript_spidermonkey}
        url       = http://www.cpan.org/modules/by-module/JavaScript/
        regex     = JavaScript-SpiderMonkey-(__VER__)\.tar\.gz
    }
    prog js:JavaScript-Squish = {
        version   = %{V_javascript_squish}
        url       = http://www.cpan.org/modules/by-module/JavaScript/
        regex     = JavaScript-Squish-(__VER__)\.tar\.gz
    }
    prog js:JavaScript-Code = {
        version   = %{V_javascript_code}
        url       = http://www.cpan.org/modules/by-module/JavaScript/
        regex     = JavaScript-Code-(__VER__)\.tar\.gz
    }
    prog js:JavaScript-JSLint = {
        version   = %{V_javascript_jslint}
        url       = http://www.cpan.org/modules/by-module/JavaScript/
        regex     = JavaScript-JSLint-(__VER__)\.tar\.gz
    }
    prog js:JavaScript-Engine = {
        version   = %{V_javascript_engine}
        url       = http://www.cpan.org/modules/by-module/JavaScript/
        regex     = JE-(__VER__)\.tar\.gz
    }
    prog js:jsapigen = {
        version   = %{V_jsapigen}
        url       = http://sourceforge.net/projects/jsapigen/files/
        regex     = jsapigen-(__VER__)\.tar\.gz
    }
    prog js:jsmin = {
        version   = %{V_jsmin}
        url       = http://download.openpkg.org/components/versioned/jsmin/
        regex     = jsmin-(__VER__)\.c
    }

%prep
    %setup -q -c
    %setup -q -D -T -a 1
    %setup -q -D -T -a 2
    %setup -q -D -T -a 3
    %setup -q -D -T -a 4
    %setup -q -D -T -a 5
    %setup -q -D -T -a 6
    %setup -q -D -T -a 7
    %patch -p0

%build
    #   build components
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
%endif
    ( cd js-%{V_js}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      GREP="grep" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
%if "%{with_perl}" == "yes"
          --with-perl=%{l_prefix}/bin/perl \
%endif
%if "%{with_editline}" == "yes"
          --with-editline=%{l_prefix} \
%endif
%if "%{with_file}" != "yes"
          --without-file \
%endif
%if "%{with_dso}" == "yes"
          --with-dso \
%endif
%if "%{with_utf8}" == "yes"
          --with-utf8 \
%endif
          --disable-shared
      %{l_make} %{l_mflags}
    ) || exit $?

    #   build add-on tool "jsmin"
    %{l_cc} -o jsmin %{SOURCE jsmin-%{V_jsmin}.c}

    #   build add-on tool "jsapigen"
%if "%{with_jsapigen}" == "yes"
    ( cd jsapigen-%{V_jsapigen}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      GREP="grep" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man
      %{l_make} %{l_mflags}
    ) || exit $?
%endif

%if "%{with_perl}" == "yes"
    #   build add-on Perl bindings
    ( cd JavaScript-%{V_javascript}
      export JS_LIB="../js-%{V_js}/.libs"
      export JS_INC="../js-%{V_js}/src"
%if "%{with_utf8}" == "yes"
      export JS_UTF8="1"
%endif
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
    ( cd JavaScript-SpiderMonkey-%{V_javascript_spidermonkey}
      %{l_shtool} subst \
          -e 's;\.\./js/src;../js-%{V_js}/src;' \
          -e 's;\.\./js/.libs;../js-%{V_js}/.libs;' \
          Makefile.PL
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
    ( cd JavaScript-Squish-%{V_javascript_squish}
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
    ( cd JavaScript-Code-%{V_javascript_code}
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
    ( cd JavaScript-JSLint-%{V_javascript_jslint}
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
    ( cd JE-%{V_javascript_engine}
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
%endif

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/include/js \
        $RPM_BUILD_ROOT%{l_prefix}/lib \
        $RPM_BUILD_ROOT%{l_prefix}/lib/pkgconfig

    #   install vendor components
    ( cd js-%{V_js}
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
      strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
      rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/jslint
    ) || exit $?

    #   install add-on tool "jsmin"
    %{l_shtool} install -c -s -m 755 \
        jsmin $RPM_BUILD_ROOT%{l_prefix}/bin/

    #   install add-on tool "jsapigen"
%if "%{with_jsapigen}" == "yes"
    %{l_shtool} install -c -s -m 755 \
        jsapigen-%{V_jsapigen}/src/jsapigen \
        $RPM_BUILD_ROOT%{l_prefix}/bin/
%endif

%if "%{with_perl}" == "yes"
    #   install add-on Perl bindings
    ( cd JavaScript-%{V_javascript}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
    ( cd JavaScript-SpiderMonkey-%{V_javascript_spidermonkey}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
    ( cd JavaScript-Squish-%{V_javascript_squish}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
    ( cd JavaScript-Code-%{V_javascript_code}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
    ( cd JavaScript-JSLint-%{V_javascript_jslint}
      %{l_prefix}/bin/perl-openpkg install
      mv  $RPM_BUILD_ROOT%{l_prefix}/bin/jslint \
          $RPM_BUILD_ROOT%{l_prefix}/bin/jslint-perl
    ) || exit $?
    ( cd JE-%{V_javascript_engine}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
%endif

%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif

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

%files -f files

%clean

