##
##  bison.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_new       3.8.2
%define       V_old1      2.7.1
%define       V_old2      1.35

#   package information
Name:         bison
Summary:      Yacc-compatible LALR(1) Parser Generator
URL:          http://www.gnu.org/software/bison/
Vendor:       Free Software Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        CORE
Group:        CompilerCompiler
License:      GPL
Version:      %{V_new}
Release:      20210925

#   package options
%option       with_old   no

#   list of sources
Source0:      http://ftp.gnu.org/gnu/bison/bison-%{V_new}.tar.gz
Source1:      http://ftp.gnu.org/gnu/bison/bison-%{V_old1}.tar.gz
Source2:      http://ftp.gnu.org/gnu/bison/bison-%{V_old2}.tar.gz
Patch0:       bison.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, m4, make
PreReq:       OpenPKG, openpkg >= 20160101, m4
Conflicts:    yacc

%description
    Bison is a general-purpose parser generator that converts a grammar
    description for an LALR(1) context-free grammar into a C program
    to parse that grammar. Once you are proficient with bison, you may
    use it to develop a wide range of language parsers, from those used
    in simple desk calculators to complex programming languages. Bison
    is upward compatible with yacc: all properly-written yacc grammars
    ought to work with bison with no change. Anyone familiar with yacc
    should be able to use bison with little trouble.

%track
    prog bison:new = {
        version   = %{V_new}
        url       = http://ftp.gnu.org/gnu/bison/
        regex     = bison-(3.\d+(.\d+)*[a-z]?)\.tar\.gz
    }
    prog bison:old1 = {
        version   = %{V_old1}
        url       = http://ftp.gnu.org/gnu/bison/
        regex     = bison-(2.\d+(.\d+)*[a-z]?)\.tar\.gz
    }
    prog bison:old2 = {
        version   = %{V_old2}
        url       = http://ftp.gnu.org/gnu/bison/
        regex     = bison-(1\.3\d+)\.tar\.gz
    }

%prep
    %setup -q -c
    %patch -p0 -d bison-%{V_new}
%if "%{with_old}" == "yes"
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %{l_shtool} subst \
        -e 's;ac_config_files.*etc/bench\.pl";;' \
        bison-%{V_old1}/configure
    %{l_shtool} subst \
        -e 's;^\( *SUBDIRS = .*\) examples\(.*\)$;\1\2;' \
        -e 's;^\( *SUBDIRS = .*\) tests\(.*\)$;\1\2;' \
        -e 's;^\( *SUBDIRS = .*\) etc\(.*\)$;\1\2;' \
        bison-%{V_old1}/Makefile.in
    touch bison-%{V_old1}/doc/bison.1
%endif

%build
    ( cd bison-%{V_new}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      GREP="grep" \
      PERL="true" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
          --infodir=%{l_prefix}/info \
          --datadir=%{l_prefix}/share/bison \
          --disable-nls
      %{l_make} -f Makefile %{l_mflags}
    ) || exit $?
%if "%{with_old}" == "yes"
    ( cd bison-%{V_old1}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CONFIG_SHELL="%{l_bash}" \
      GREP="grep" \
      "%{l_bash}" configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
          --infodir=%{l_prefix}/info \
          --datadir=%{l_prefix}/share/bison/old \
          --disable-nls
      %{l_make} -f Makefile %{l_mflags}
    ) || exit $?
    ( cd bison-%{V_old2}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      GREP="grep" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
          --infodir=%{l_prefix}/info \
          --datadir=%{l_prefix}/share/bison/old2 \
          --disable-nls
      %{l_make} -f Makefile %{l_mflags}
    ) || exit $?
%endif

%install
%if "%{with_old}" == "yes"
    ( cd bison-%{V_old1}
      %{l_make} -f Makefile %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
      mv $RPM_BUILD_ROOT%{l_prefix}/bin/bison \
         $RPM_BUILD_ROOT%{l_prefix}/bin/bison-old
      mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/bison.1 \
         $RPM_BUILD_ROOT%{l_prefix}/man/man1/bison-old.1
      rm -f $RPM_BUILD_ROOT%{l_prefix}/info/*
    ) || exit $?
    ( cd bison-%{V_old2}
      %{l_make} -f Makefile %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
      mv $RPM_BUILD_ROOT%{l_prefix}/bin/bison \
         $RPM_BUILD_ROOT%{l_prefix}/bin/bison-old2
      mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/bison.1 \
         $RPM_BUILD_ROOT%{l_prefix}/man/man1/bison-old2.1
      rm -f $RPM_BUILD_ROOT%{l_prefix}/info/*
    ) || exit $?
%endif
    ( cd bison-%{V_new}
      %{l_make} -f Makefile %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/charset.alias
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

