##
##  wdg-validator.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 versions
%define       V_validator     1.2.3
%define       V_lq_sp         1.3.4.14
%define       V_wdg_sgml_lib  1.1.5

#   package information
Name:         wdg-validator
Summary:      Web Design Group HTMLHelp.com Offline Validator
URL:          http://www.htmlhelp.com/tools/validator/offline/
Vendor:       Liam Quinn
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        HTML
License:      Artistic
Version:      %{V_validator}
Release:      20110303

#   list of sources
Source0:      http://www.htmlhelp.com/tools/validator/offline/validate-%{V_validator}
Source1:      http://www.htmlhelp.com/tools/validator/src/lq-sp-%{V_lq_sp}.tar.gz
Source2:      http://www.htmlhelp.com/tools/validator/src/wdg-sgml-lib-%{V_wdg_sgml_lib}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc, gcc::with_cxx = yes, m4, perl
PreReq:       OpenPKG, openpkg >= 20160101, perl, perl-www

%description
    The Web Design Group HTMLHelp.com Offline Validator checks the
    syntax of HTML and XHTML documents.

%track
    prog wdg-validator = {
        version   = %{V_validator}
        url       = http://www.htmlhelp.com/tools/validator/offline/
        regex     = ">validate</a></strong> \(Version (__VER__)\)</dt>"
    }
    prog wdg-validator:lq-sp = {
        version   = %{V_lq_sp}
        url       = http://www.htmlhelp.com/tools/validator/src/
        regex     = lq-sp-(__VER__)\.tar\.gz
    }
    prog wdg-validator:wdg-sgml-lib = {
        version   = %{V_wdg_sgml_lib}
        url       = http://www.htmlhelp.com/tools/validator/src/
        regex     = wdg-sgml-lib-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -T -D -c
    %setup -q -T -D -a 1
    ( cd lq-sp-%{V_lq_sp}
      xlibs=""
      case "%{l_platform -t}" in
          *-sunos* ) xlibs="-lnsl -lsocket" ;;
      esac
      %{l_shtool} subst \
          -e 's;^\(prefix=\).*$;\1%{l_prefix}/libexec/wdg-validator;' \
          -e 's;^\(CC=\).*$;\1%{l_cc};' \
          -e 's;^\(CFLAGS=\).*$;\1%{l_cflags -O};' \
          -e 's;^\(CXX=\).*$;\1%{l_cxx};' \
          -e 's;^\(CXXFLAGS=\).*$;\1%{l_cxxflags -O} -ansi;' \
          -e 's;^\(LDFLAGS=\).*$;\1%{l_ldflags};' \
          -e "s;^\(XLIBS=\).*$;\1$xlibs;" \
          -e 's;^\(M4=\).*$;\1%{l_prefix}/bin/m4;' \
          -e 's;^\(PERL=\).*$;\1%{l_prefix}/bin/perl;' \
          -e 's;^\(INSTALL=\).*$;\1%{l_shtool} install;' \
          Makefile
    ) || exit $?

%build
    ( cd lq-sp-%{V_lq_sp}
        %{l_make} clean
        sleep 1; touch Makefile; sleep 1
        %{l_make} %{l_mflags -O}
    ) || exit $?

%install

    #   install WDG validator
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin
    %{l_shtool} install -c -m 755 \
        -e 's;^\(#!\)/.*$;\1%{l_prefix}/bin/perl -T;' \
        -e 's;\(Usage: \)\(validate\);\1wdg-\2;g' \
        -e 's;^\(my $nsgmlsLocation =\).*$;\1 "%{l_prefix}/libexec/wdg-validator/bin/lq-nsgmls"\;;' \
        -e 's;^\(my $sgmlDir =\).*$;\1 "%{l_prefix}/share/wdg-validator/sgml-lib"\;;' \
        %{SOURCE validate-%{V_validator}} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/wdg-validate

    #   install variant of James Clark's SP modified by Liam Quinn
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/wdg-validator
    ( cd lq-sp-%{V_lq_sp}
        %{l_make} %{l_mflags} install \
            prefix="$RPM_BUILD_ROOT%{l_prefix}/libexec/wdg-validator"
    ) || exit $?

    #   install SGML lib
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/wdg-validator/sgml-lib
    ( umask 022
      %{l_tar} xzf %{SOURCE wdg-sgml-lib-%{V_wdg_sgml_lib}.tar.gz} \
          -C $RPM_BUILD_ROOT%{l_prefix}/share/wdg-validator/sgml-lib/ \
          --strip-components 2
    ) || exit $?

    strip $RPM_BUILD_ROOT%{l_prefix}/libexec/wdg-validator/bin/* \
        >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

