##
##  gdb.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_tarball 16.3
%define       V_subdir  16.3

#   package information
Name:         gdb
Summary:      GNU Debugger
URL:          http://www.gnu.org/software/gdb/
Vendor:       Free Software Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Debugging
License:      GPL
Version:      %{V_tarball}
Release:      20250421

#   list of sources
Source0:      http://ftp.gnu.org/gnu/gdb/gdb-%{V_tarball}.tar.gz
Patch0:       gdb.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, flex, m4
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  ncurses, libiconv
PreReq:       ncurses, libiconv

%description
    The purpose of a debugger such as GDB is to allow you to see what
    is going on `inside' another program while it executes -- or what
    another program was doing at the moment it crashed.

%track
    prog gdb = {
        version   = %{V_tarball}
        url       = http://ftp.gnu.org/gnu/gdb/
        regex     = gdb-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n gdb-%{V_subdir}
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;-Werror;;' \
        `find . -type f -name configure -print`
    mkdir build
    cd build
    CC="%{l_cc} %{l_ldflags}" \
    CFLAGS="%{l_cflags -O} %{l_cppflags ncurses .}" \
    CPPFLAGS="%{l_cppflags ncurses .}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="%{l_ldflags} -liconv" \
    MAKEINFO="true" \
    ../configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --infodir=%{l_prefix}/info \
        --without-expat \
        --with-libiconv-prefix=%{l_prefix} \
        --disable-werror \
        --disable-nls
    %{l_make} %{l_mflags -O}

%install
    (   cd build
        %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/include
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/configure.info*
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/standards.info*
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/bfd.info*
    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

