Summary: The GNU gdb debugger
Name: gdb
Version: 7.5
Release: 4
Copyright: GPL
Group: Development/Tools
URL: http://www.gnu.org/software/gdb/
Source0: http://ftp.gnu.org/gnu/gdb/%{name}-%{version}.tar.gz
Patch0: gdb-%{version}-configure-ppc64.patch
Patch1: gdb-%{version}-ptrace64.patch
Patch2: gdb-%{version}-core.patch
Patch3: gdb-%{version}-xcoffread.patch
Patch4: gdb-%{version}-aix64-thread.patch
Patch5: gdb-%{version}-inf-ptrace64.patch
Patch6: gdb-%{version}-mmap.patch
Patch7: gdb-%{version}-core_addr_reloc.patch
Prefix: %{_prefix}
#BuildRequires: bzip2
BuildRoot: %{_tmppath}/%{name}-root
Prereq: /sbin/install-info
Requires: AIX-rpm >= 5.1.0.0
Requires: expat
%define DEFCC cc

%description
GNU gdb is the standard GNU program debugger.

%prep
%setup -q
%patch0 -p0 -b .config-ppc64
%patch1 -p1 -b .enable-ptrace64
%patch2 -p1 -b .enable-core
%patch3 -p1 -b .xcoff
%patch4 -p1 -b .aixthread
%patch5 -p1 -b .infptrace
%patch6 -p1 -b .mmap
%patch7 -p1 -b .reloc

%build

# Use the default compiler for this platform - gcc otherwise
#if [[ -z "$CC" ]]
#then
#    if test "X`type %{DEFCC} 2>/dev/null`" != 'X'; then
#       export CC=%{DEFCC}
#    else 
#       export CC=gcc
#    fi
#fi

if [[ "$CC" != "gcc" ]]
then
       export RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed 's:-fsigned-char::'`
fi

export CC=gcc
export CXX=g++
export OBJECT_MODE=64
export CFLAGS="-maix64 -D_LARGE_FILES"

#export LDFLAGS="-L/opt/freeware/lib -blibpath:/opt/freeware/lib:/usr/lib:/lib"

#export AR_FOR_TARGET="/usr/bin/ar -X64"

./configure --prefix=%{_prefix} \
	    --infodir=%{_infodir} \
	    --mandir=%{_mandir} \
            --disable-werror \
            --enable-sim \
            --target=powerpc64-ibm-aix6.1.2.0 \
            --build=powerpc64-ibm-aix6.1.2.0

gmake %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
gmake DESTDIR=${RPM_BUILD_ROOT} install

# Strip all of the executables
/usr/bin/strip ${RPM_BUILD_ROOT}%{prefix}/bin/* 2>/dev/null || :

# compress the info files
gzip -9fn ${RPM_BUILD_ROOT}%{_infodir}/* 

# install the gcore script in /usr/bin
cp ./gdb/gdb_gcore.sh ${RPM_BUILD_ROOT}%{prefix}/bin/gcore
chmod 755 ${RPM_BUILD_ROOT}%{prefix}/bin/gcore

# Create links into /usr/bin and /usr/linux/bin.
(
    cd $RPM_BUILD_ROOT
    mkdir -p usr/bin
    cd usr/bin
    ln -sf ../..%{prefix}/bin/* .
)

%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/install-info %{_infodir}/annotate.info.gz %{_infodir}/dir
/sbin/install-info %{_infodir}/gdb.info.gz %{_prefix}/info/dir
/sbin/install-info %{_infodir}/gdbint.info.gz %{_prefix}/info/dir
/sbin/install-info %{_infodir}/stabs.info.gz %{_prefix}/info/dir

%postun
if [ $1 = 0 ] ; then
/sbin/install-info --delete %{_infodir}/annotate.info.gz %{_infodir}/dir
/sbin/install-info --delete %{_infodir}/gdb.info.gz %{_prefix}/info/dir
/sbin/install-info --delete %{_infodir}/gdbint.info.gz %{_prefix}/info/dir
/sbin/install-info --delete %{_infodir}/stabs.info.gz %{_prefix}/info/dir
fi

%files
%defattr(-,bin,bin)
%doc COPYING COPYING.LIB README 
%{_mandir}/man1/*
%{prefix}/bin/*
%{_infodir}/annotate.info.gz
%{_infodir}/gdb*
%{_infodir}/stabs.info.gz
/usr/bin/*

%changelog
* Wed Jul 3 2013 Raunaq Bathija <raunaq12@in.ibm.com> 7.5-4
- Modify aix-thread and inf-ptrace patch to remove multiple #ifdef
- Add mmap command to gdb

* Wed Apr 3 2013 Raunaq Bathija <raunaq12@in.ibm.com> 7.5-3
- Remove changes from generic files and make equivalent changes in AIX specific files.

* Mon Feb 18 2013 Raunaq Bathija <raunaq12@in.ibm.com> 7.5-2
- Modify the fix for setting breakpoints (mentioned initially in 7.5-1)
- Add fix for proper listing of functions in an xlc compiled object.

* Wed Jan 16 2013 Raunaq Bathija <raunaq12@in.ibm.com> 7.5-1
- Update gdb version to 7.5
- Modify the fix for stopping at first executable statement of functions.
- Add a fix for setting breakpoints properly instead of multiple entries.

* Tue Jun 26 2012 Sangamesh Mallayya <smallayy@in.ibm.com> 7.3-5
- Skip reading @FIX entries

* Wed Mar 14 2012 Sangamesh Mallayya <smallayy@in.ibm.com> 7.3-4
- Add a fix for filename issue. If -qfuncsect compiler option is
- used then gdb is displays filename as _start_.

- Add a fix for proper address relocation for core dump.

* Mon Feb 06 2012 Sangamesh Mallayya <smallayy@in.ibm.com> 7.3-3
- Add fix for stopping at first executable statement of a functions.

* Thu Dec 01 2011 Sangamesh Mallayya <smallayy@in.ibm.com> 7.3-2
- Add fix for Internal Error issue in case of -qfuncsect xlc option.

* Fri Nov 11 2011 Sangamesh Mallayya <smallayy@in.ibm.com> 7.3-1
- Build 64-bit version (alpha)

* Thu Sep 23 2004 David Clissold <cliss@austin.ibm.com> 6.0-1
- Initial version, adopted from old GNUPro.spec (which included an older gdb).
