File gdb.spec of Package gdb.783

#
# spec file for package gdb
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2012 RedHat
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define _with_testsuite 1

Summary:        A GNU source-level debugger for C, C++, Fortran and other languages
License:        GPL-3.0+ and GPL-3.0-with-GCC-exception and LGPL-2.1+ and LGPL-3.0+
Group:          Development/Tools/Debuggers
Name:           gdb

%global snap       20130731
# See timestamp of source gnulib installed into gdb/gnulib/ .
%global snapgnulib 20121213
Version:        7.9.1
Release:        0

# The release always contains a leading reserved number, start it at 1.
# `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing.

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# Do not provide URL for snapshots as the file lasts there only for 2 days.
# ftp://sourceware.org/pub/gdb/releases/gdb-%{version}.tar.gz
Source:         gdb-%{version}.tar.bz2
Url:            http://gnu.org/software/gdb/

%if "%{scl}" == "devtoolset-1.1"
Obsoletes:      devtoolset-1.0-%{pkg_name}
%endif

# For our convenience
%global gdb_src %{name}-%{version}
%global gdb_build build-%{_target_platform}
%global gdb_docdir %{_docdir}/%{name}-doc

%global have_inproctrace 0
%ifarch %{ix86} x86_64
%global have_inproctrace 1
%endif # %{ix86} x86_64

# GDB patches have the format `gdb-<version>-bz<red-hat-bz-#>-<desc>.patch'.
# They should be created using patch level 1: diff -up ./gdb (or gdb-6.3/gdb).

#=
#push=Should be pushed upstream.
#maybepush=Should be pushed upstream unless it got obsoleted there.
#fedora=Should stay as a Fedora patch.
#ia64=Drop after RHEL-5 rebases and rebuilds are no longer meaningful.
#fedoratest=Keep it in Fedora only as a regression test safety.
#+ppc=Specific for ppc32/ppc64/ppc*
#+work=Requires some nontrivial work.

# Cleanup any leftover testsuite processes as it may stuck mock(1) builds.
#=push
Source2:        gdb-orphanripper.c

# Man page for gstack(1).
#=push
Source3:        gdb-gstack.man

# /etc/gdbinit (from Debian but with Fedora compliant location).
#=fedora
Source4:        gdbinit

# libstdc++ pretty printers from GCC SVN HEAD (4.5 experimental).
%global libstdcxxpython gdb-libstdc++-v3-python-r155978
Source5:        %{libstdcxxpython}.tar.bz2

# Provide gdbtui for RHEL-5 and RHEL-6 as it is removed upstream (BZ 797664).
Source6:        gdbtui

# Infrastructure to sync patches from the Fedora rpm
Source10:       patchlist.pl
Source11:       patchname_get.sh
Source12:       baselibs.conf
Source13:       gdb-rpmlintrc

#Fedora Packages begin
Patch1:         gdb-6.3-rh-testversion-20041202.patch
Patch2:         gdb-upstream.patch
Patch3:         gdb-archer.patch
Patch4:         gdb-vla-intel.patch
Patch5:         gdb-vla-intel-logical-not.patch
Patch6:         gdb-vla-intel-stringbt-fix.patch
Patch7:         gdb-vla-intel-04of23-fix.patch
Patch8:         gdb-6.3-rh-dummykfail-20041202.patch
Patch9:         gdb-6.3-ppc64syscall-20040622.patch
Patch10:        gdb-6.3-ppc64displaysymbol-20041124.patch
Patch11:        gdb-6.6-scheduler_locking-step-sw-watchpoints2.patch
Patch12:        gdb-6.3-gstack-20050411.patch
Patch13:        gdb-6.3-test-pie-20050107.patch
Patch14:        gdb-6.3-test-self-20050110.patch
Patch15:        gdb-6.3-test-dtorfix-20050121.patch
Patch16:        gdb-6.3-test-movedir-20050125.patch
Patch17:        gdb-6.3-threaded-watchpoints2-20050225.patch
Patch18:        gdb-6.3-inferior-notification-20050721.patch
Patch19:        gdb-6.3-inheritancetest-20050726.patch
Patch20:        gdb-6.3-readnever-20050907.patch
Patch21:        gdb-6.5-bz203661-emit-relocs.patch
Patch22:        gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
Patch23:        gdb-6.5-sharedlibrary-path.patch
Patch24:        gdb-6.5-bz190810-gdbserver-arch-advice.patch
Patch25:        gdb-6.5-BEA-testsuite.patch
Patch26:        gdb-6.5-last-address-space-byte-test.patch
Patch27:        gdb-6.5-readline-long-line-crash-test.patch
Patch28:        gdb-6.5-bz216711-clone-is-outermost.patch
Patch29:        gdb-6.5-bz218379-ppc-solib-trampoline-test.patch
Patch30:        gdb-6.5-bz218379-solib-trampoline-lookup-lock-fix.patch
Patch31:        gdb-6.5-bz109921-DW_AT_decl_file-test.patch
Patch32:        gdb-6.3-bz140532-ppc-unwinding-test.patch
Patch33:        gdb-6.3-bz202689-exec-from-pthread-test.patch
Patch34:        gdb-6.6-bz230000-power6-disassembly-test.patch
Patch35:        gdb-6.3-bz231832-obstack-2gb.patch
Patch36:        gdb-6.6-bz229517-gcore-without-terminal.patch
Patch37:        gdb-6.6-bz235197-fork-detach-info.patch
Patch38:        gdb-6.6-testsuite-timeouts.patch
Patch39:        gdb-6.6-bz237572-ppc-atomic-sequence-test.patch
Patch40:        gdb-6.6-scheduler_locking-step-is-default.patch
Patch41:        gdb-6.3-attach-see-vdso-test.patch
Patch42:        gdb-6.5-bz243845-stale-testing-zombie-test.patch
Patch43:        gdb-6.6-buildid-locate.patch
Patch44:        gdb-6.6-buildid-locate-solib-missing-ids.patch
Patch45:        gdb-6.6-buildid-locate-rpm.patch
Patch46:        gdb-6.7-charsign-test.patch
Patch47:        gdb-6.7-ppc-clobbered-registers-O2-test.patch
Patch48:        gdb-6.5-ia64-libunwind-leak-test.patch
Patch49:        gdb-6.5-missed-trap-on-step-test.patch
Patch50:        gdb-6.7-bz426600-DW_TAG_interface_type-test.patch
Patch51:        gdb-6.5-gcore-buffer-limit-test.patch
Patch52:        gdb-6.6-threads-static-test.patch
Patch53:        gdb-6.3-mapping-zero-inode-test.patch
Patch54:        gdb-6.3-focus-cmd-prev-test.patch
Patch55:        gdb-6.8-bz442765-threaded-exec-test.patch
Patch56:        gdb-6.8-sparc64-silence-memcpy-check.patch
Patch57:        gdb-6.5-section-num-fixup-test.patch
Patch58:        gdb-6.8-bz436037-reg-no-longer-active.patch
Patch59:        gdb-6.8-watchpoint-conditionals-test.patch
Patch60:        gdb-6.8-bz466901-backtrace-full-prelinked.patch
Patch61:        gdb-6.8-bz457187-largefile-test.patch
Patch62:        gdb-simultaneous-step-resume-breakpoint-test.patch
Patch63:        gdb-core-open-vdso-warning.patch
Patch64:        gdb-x86_64-i386-syscall-restart.patch
Patch65:        gdb-bz533176-fortran-omp-step.patch
Patch66:        gdb-follow-child-stale-parent.patch
Patch67:        gdb-ccache-workaround.patch
Patch68:        gdb-archer-pie-addons.patch
Patch69:        gdb-archer-pie-addons-keep-disabled.patch
Patch70:        gdb-lineno-makeup-test.patch
Patch71:        gdb-ppc-power7-test.patch
Patch72:        gdb-bz541866-rwatch-before-run.patch
Patch73:        gdb-moribund-utrace-workaround.patch
Patch74:        gdb-archer-next-over-throw-cxx-exec.patch
Patch75:        gdb-bz601887-dwarf4-rh-test.patch
Patch76:        gdb-6.6-buildid-locate-core-as-arg.patch
Patch77:        gdb-6.6-buildid-locate-rpm-librpm-workaround.patch
Patch78:        gdb-test-bt-cfi-without-die.patch
Patch79:        gdb-gdb-add-index-script.patch
Patch80:        gdb-bz568248-oom-is-error.patch
Patch81:        gdb-bz634108-solib_address.patch
Patch82:        gdb-test-pid0-core.patch
Patch83:        gdb-test-dw2-aranges.patch
Patch84:        gdb-test-expr-cumulative-archer.patch
Patch85:        gdb-7.2.50-sparc-add-workaround-to-broken-debug-files.patch
Patch86:        gdb-glibc-vdso-workaround.patch
Patch87:        gdb-runtest-pie-override.patch
Patch88:        gdb-attach-fail-reasons-5of5.patch
Patch89:        gdb-stale-frame_info.patch
Patch90:        gdb-glibc-strstr-workaround.patch
Patch91:        gdb-rhel5.9-testcase-xlf-var-inside-mod.patch
Patch92:        gdb-rhbz-818343-set-solib-absolute-prefix-testcase.patch
Patch93:        gdb-rhbz795424-bitpos-20of25.patch
Patch94:        gdb-rhbz795424-bitpos-21of25.patch
Patch95:        gdb-rhbz795424-bitpos-22of25.patch
Patch96:        gdb-rhbz795424-bitpos-23of25.patch
Patch97:        gdb-rhbz795424-bitpos-25of25.patch
Patch98:        gdb-rhbz795424-bitpos-25of25-test.patch
Patch99:        gdb-rhbz795424-bitpos-lazyvalue.patch
Patch100:       gdb-rhbz947564-findvar-assertion-frame-failed-testcase.patch
Patch101:       gdb-enable-count-crash.patch
Patch102:       gdb-gnat-dwarf-crash-3of3.patch
Patch103:       gdb-6.6-buildid-locate-misleading-warning-missing-debuginfo-rhbz981154.patch
Patch104:       gdb-archer-vla-tests.patch
Patch105:       gdb-btrobust.patch
Patch106:       gdb-fortran-frame-string.patch
Patch107:       gdb-python-gil.patch
Patch108:       gdb-jit-reader-multilib.patch
Patch109:       gdb-no-dg-extract-results-py.patch
Patch110:       gdb-python3-py_hash_t-32bit.patch
Patch111:       gdb-python3-testsuite.patch
Patch112:       gdb-dts-rhel6-python-compat.patch
Patch113:       gdb-6.6-buildid-locate-rpm-scl.patch
Patch114:       gdb-readline62-ask-more-rh.patch
Patch115:       gdb-6.8-attach-signalled-detach-stopped.patch
Patch116:       gdb-6.8-quit-never-aborts.patch
Patch117:       gdb-rhel5-compat.patch
#Fedora Packages end

# Upstream patch to fix gcc -Werror
Patch1002:      gdb-6.6-buildid-locate-rpm-suse.patch
# Upstream patch for reordering "s390:31-bit" (bnc#936050)
Patch1003:      gdb-s390-reorder-arch.diff
# fate#318039
Patch1004:      0001-S390-Fix-compiler-invocation-with-compile-command.patch
Patch1005:      0001-S390-Support-new-vector-register-sections.patch
Patch1006:      0001-S390-Add-target-descriptions-for-vector-register-set.patch
Patch1007:      0002-S390-Add-vector-register-support-to-gdb.patch
Patch1008:      0003-S390-Add-vector-register-support-to-gdbserver.patch
Patch1009:      0004-S390-Vector-register-test-case.patch
Patch1010:      0005-S390-Name-invisible-registers-with-the-empty-string-.patch

BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  gettext
BuildRequires:  glibc-devel
BuildRequires:  guile-devel
BuildRequires:  ncurses-devel
BuildRequires:  texinfo
%if %{suse_version} < 1020
BuildRequires:  expat
%else
BuildRequires:  libexpat-devel
%endif
BuildRequires:  pkg-config
BuildRequires:  readline-devel
BuildRequires:  rpm-devel
BuildRequires:  zlib-devel
%if 0%{!?_without_python:1}
%if 0%{suse_version} > 1000
Requires:       python-base
%endif
BuildRequires:  python-devel
%endif	# 0%{!?_without_python:1}

# BuildArch would break RHEL-5 by overriding arch and not building noarch.
%if 0%{?el5:1}
ExclusiveArch:  noarch i386 x86_64 ppc ppc64 ia64 s390 s390x
%endif # 0%{?el5:1}

%if 0%{?_with_testsuite:1}

# Ensure the devel libraries are installed for both multilib arches.
%global bits_local %{?_isa}
%global bits_other %{?_isa}
%if 0%{!?el5:1}
%ifarch s390x
%global bits_other (%{__isa_name}-32)
%else #!s390x
%ifarch ppc
%global bits_other (%{__isa_name}-64)
%else #!ppc
%ifarch sparc64 ppc64 s390x x86_64
%global bits_other (%{__isa_name}-32)
%endif #sparc64 ppc64 s390x x86_64
%endif #!ppc
%endif #!s390x
%endif #!el5

BuildRequires:  dejagnu
BuildRequires:  sharutils
# gcc-objc++ is not covered by the GDB testsuite.
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  gcc-fortran
BuildRequires:  gcc-java
BuildRequires:  gcc-objc
# Copied from gcc-4.1.2-32.
%ifarch %{ix86} x86_64 ia64 ppc ppc64 s390 alpha
BuildRequires:  gcc-ada
%endif
%if 0%{suse_version} > 1110
%ifarch x86_64 ppc64 s390x
BuildRequires:  gcc-c++-32bit
%endif
%endif

%endif # 0%{?_with_testsuite:1}

%ifarch ia64
BuildRequires:  libunwind-devel
Requires:       libunwind
%endif

%description
GDB, the GNU debugger, allows you to debug programs written in C, C++,
Java, and other languages, by executing them in a controlled fashion
and printing their data.

%if %{suse_version} > 1010
%package -n gdbserver
Summary:        A standalone server for GDB (the GNU source-level debugger)
License:        GPL-3.0+ and GPL-3.0-with-GCC-exception and LGPL-2.1+ and LGPL-3.0+
Group:          Development/Tools/Debuggers

%description -n gdbserver
GDB, the GNU debugger, allows you to debug programs written in C, C++,
Java, and other languages, by executing them in a controlled fashion
and printing their data.

This package provides a program that allows you to run GDB on a different
machine than the one which is running the program being debugged.
%endif

%package doc
Summary:        Documentation for GDB (the GNU source-level debugger)
License:        GFDL-1.3
Group:          Documentation/Other
PreReq:         %{install_info_prereq}

%if "%{scl}" == "devtoolset-1.1"
Obsoletes:      devtoolset-1.0-%{pkg_name}-doc
%endif

%description doc
GDB, the GNU debugger, allows you to debug programs written in C, C++,
Java, and other languages, by executing them in a controlled fashion
and printing their data.

This package provides INFO, HTML and PDF user manual for GDB.

%package testresults
Summary:        GDB testsuite results
License:        SUSE-Public-Domain
Group:          Development/Languages/C and C++

%description testresults
Results from running the GDB testsuite. 

%prep
%setup -q -n %{gdb_src}

%if 0%{?rhel:1} && 0%{?rhel} <= 6
# libstdc++ pretty printers.
tar xjf %{SOURCE5}
%endif # 0%{?rhel:1} && 0%{?rhel} <= 6

# Files have `# <number> <file>' statements breaking VPATH / find-debuginfo.sh .
rm -f gdb/ada-exp.c gdb/ada-lex.c gdb/c-exp.c gdb/cp-name-parser.c gdb/f-exp.c
rm -f gdb/jv-exp.c gdb/m2-exp.c gdb/objc-exp.c gdb/p-exp.c gdb/go-exp.c

# *.info* is needlessly split in the distro tar; also it would not get used as
# we build in %{gdb_build}, just to be sure.
find -name "*.info*"|xargs rm -f

#Fedora patching start
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
%patch34 -p1
%patch35 -p1
%patch36 -p1
%patch37 -p1
%patch38 -p1
%patch39 -p1
%patch40 -p1
%patch41 -p1
%patch42 -p1
%patch43 -p1
%patch44 -p1
%patch45 -p1
%patch46 -p1
%patch47 -p1
%patch48 -p1
%patch49 -p1
%patch50 -p1
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54 -p1
%patch55 -p1
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p1
%patch60 -p1
%patch61 -p1
%patch62 -p1
%patch63 -p1
%patch64 -p1
%patch65 -p1
%patch66 -p1
%patch67 -p1
%patch68 -p1
%patch69 -p1
%patch70 -p1
%patch71 -p1
%patch72 -p1
%patch73 -p1
%patch74 -p1
%patch75 -p1
%patch76 -p1
%patch77 -p1
%patch78 -p1
%patch79 -p1
%patch80 -p1
%patch81 -p1
%patch82 -p1
%patch83 -p1
%patch84 -p1
%patch85 -p1
%patch86 -p1
%patch87 -p1
%patch88 -p1
%patch89 -p1
%patch90 -p1
%patch91 -p1
%patch92 -p1
%patch93 -p1
%patch94 -p1
%patch95 -p1
%patch96 -p1
%patch97 -p1
%patch98 -p1
%patch99 -p1
%patch100 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch104 -p1
%patch105 -p1
%patch106 -p1
%patch107 -p1
%patch108 -p1
%patch109 -p1
%patch110 -p1
%patch111 -p1
%patch112 -p1
%patch112 -p1 -R
%patch113 -p1
%patch113 -p1 -R
%patch114 -p1
%patch114 -p1 -R
%patch115 -p1
%patch116 -p1
%patch117 -p1
%patch117 -p1 -R
%patch116 -p1 -R
%patch115 -p1 -R
#Fedora patching end

%patch1002 -p1
%patch1003 -p1
%patch1004 -p1
%patch1005 -p1
%patch1006 -p1
%patch1007 -p1
%patch1008 -p1
%patch1009 -p1
%patch1010 -p1

find -name "*.orig" | xargs rm -f
! find -name "*.rej" # Should not happen.

# Remove the info and other generated files added by the FSF release
# process.
rm -f libdecnumber/gstdint.h
rm -f bfd/doc/*.info
rm -f bfd/doc/*.info-*
rm -f gdb/doc/*.info
rm -f gdb/doc/*.info-*

%build
rm -rf %{buildroot}

# Identify the build directory with the version of gdb as well as the
# architecture, to allow for mutliple versions to be installed and
# built.
# Initially we're in the %{gdb_src} directory.

for fprofile in %{?_with_profile:-fprofile} ""
do

mkdir %{gdb_build}$fprofile
cd %{gdb_build}$fprofile

export CFLAGS="$RPM_OPT_FLAGS"
export LIBRPM=no
if test -f /usr/%{_lib}/librpm.so.1; then
  export LIBRPM=librpm.so.1
fi
if test -f /usr/%{_lib}/librpm.so.2; then
  export LIBRPM=librpm.so.2
fi
if test -f /usr/%{_lib}/librpm.so.3; then
  export LIBRPM=librpm.so.3
fi
%ifarch %ix86 ia64 ppc ppc64 ppc64le s390 s390x x86_64 aarch64
%define build_multitarget 1
%else
%define build_multitarget 0
%endif
# For now disable ia64 until ia64-tdep.c is fixed 
%define target_list i686 powerpc powerpc64 powerpc64le s390 s390x x86_64 arm aarch64 m68k
%define DIST %(echo '%distribution' | sed 's, /.*,,')
%if %build_multitarget
EXTRA_TARGETS="%(printf ,%%s-suse-linux %target_list)"
EXTRA_TARGETS="$EXTRA_TARGETS,spu-elf"
%else
EXTRA_TARGETS=
%endif

../configure							\
	--prefix=%{_prefix}					\
	--libdir=%{_libdir}					\
	--sysconfdir=%{_sysconfdir}				\
	--mandir=%{_mandir}					\
	--infodir=%{_infodir}					\
	--htmldir=%{gdb_docdir}					\
	--pdfdir=%{gdb_docdir}					\
	--with-system-gdbinit=%{_sysconfdir}/gdbinit		\
	--with-gdb-datadir=%{_datadir}/gdb			\
	--enable-gdb-build-warnings=,-Wno-unused		\
%ifnarch %{ix86} alpha ia64 ppc s390 s390x x86_64 ppc64 ppc64le sparc sparcv9 sparc64
	--disable-werror					\
%else
%if %{suse_version} < 1110
	--disable-werror					\
%else
	--enable-werror						\
%endif
%endif
	--with-separate-debug-dir=/usr/lib/debug		\
	--disable-sim						\
	--disable-rpath						\
%if %{suse_version} > 1110
	--with-system-readline					\
%else
	--without-system-readline				\
%endif
	--with-expat						\
$(: ppc64 host build crashes on ppc variant of libexpat.so )	\
	--without-libexpat-prefix				\
	--enable-tui						\
%if 0%{!?_without_python:1}
	--with-python						\
%else
	--without-python					\
%endif
%if %{suse_version} >= 1130
	--with-rpm=$LIBRPM					\
%else
	--without-rpm						\
%endif
%ifarch ia64
	--with-libunwind					\
%else
	--without-libunwind					\
%endif
%ifarch sparc sparcv9 sparc64
	--without-mmap						\
%endif
	--enable-64-bit-bfd					\
%if %{have_inproctrace}
	--enable-inprocess-agent				\
%else
	--disable-inprocess-agent				\
%endif
	--with-bugurl=http://bugs.opensuse.org/ \
	--with-pkgversion="GDB; %{DIST}" \
	${EXTRA_TARGETS:+--enable-targets="${EXTRA_TARGETS#,}"} \
%ifarch sparc sparcv9
	--build=sparc-%{_vendor}-%{_target_os}%{?_gnu}
%else
$(: It breaks RHEL-5 by %{_target_platform} being noarch-redhat-linux-gnu ) \
%ifarch noarch
	$(:)
%else
	--build=%{_target_platform}
%endif
%endif

if [ -z "%{!?_with_profile:no}" ]
then
  # Run all the configure tests being incompatible with $FPROFILE_CFLAGS.
  make %{?_smp_mflags} configure-host configure-target
  make %{?_smp_mflags} clean

  # Workaround -fprofile-use:
  # linux-x86-low.c:2225: Error: symbol `start_i386_goto' is already defined
  make %{?_smp_mflags} -C gdb/gdbserver linux-x86-low.o
fi

# Global CFLAGS would fail on:
# conftest.c:1:1: error: coverage mismatch for function 'main' while reading counter 'arcs'
if [ "$fprofile" = "-fprofile" ]
then
  FPROFILE_CFLAGS='-fprofile-generate'
elif [ -z "%{!?_with_profile:no}" ]
then
  FPROFILE_CFLAGS='-fprofile-use'
  # We cannot use -fprofile-dir as the bare filenames clash.
  (cd ../%{gdb_build}-fprofile;
   # It was 333 on x86_64.
   test $(find -name "*.gcda"|wc -l) -gt 300
   find -name "*.gcda" | while read -r i
   do
     ln $i ../%{gdb_build}/$i
   done
  )
else
  FPROFILE_CFLAGS=""
fi

# Prepare gdb/config.h first.
make %{?_smp_mflags} CFLAGS="$CFLAGS $FPROFILE_CFLAGS" LDFLAGS="$LDFLAGS $FPROFILE_CFLAGS" maybe-configure-gdb
perl -i.relocatable -pe 's/^(D\[".*_RELOCATABLE"\]=" )1(")$/${1}0$2/' gdb/config.status

make %{?_smp_mflags} CFLAGS="$CFLAGS $FPROFILE_CFLAGS" LDFLAGS="$LDFLAGS $FPROFILE_CFLAGS"

! grep '_RELOCATABLE.*1' gdb/config.h

if [ "$fprofile" = "-fprofile" ]
then
  cd gdb
  cp -p gdb gdb-withindex
  PATH="$PWD:$PATH" sh ../../gdb/gdb-add-index $PWD/gdb-withindex
  ./gdb -nx -ex q ./gdb-withindex
  ./gdb -nx -readnow -ex q ./gdb-withindex
  cd ..
fi

cd ..

done	# fprofile

cd %{gdb_build}

#make %{?_smp_mflags} -C gdb/doc {gdb,annotate}{.info,/index.html,.pdf} MAKEHTMLFLAGS=--no-split

grep '#define HAVE_ZLIB_H 1' gdb/config.h

# Copy the <sourcetree>/gdb/NEWS file to the directory above it.
cp $RPM_BUILD_DIR/%{gdb_src}/gdb/NEWS $RPM_BUILD_DIR/%{gdb_src}

%check
# Initially we're in the %{gdb_src} directory.
cd %{gdb_build}

%if 0%{!?_with_testsuite:1}
echo ====================TESTSUITE DISABLED=========================
%else
echo ====================TESTING=========================
cd gdb
gcc -o ./orphanripper %{SOURCE2} -Wall -lutil -ggdb2
# Need to use a single --ignore option, second use overrides first.
# No `%{?_smp_mflags}' here as it may race.
# WARNING: can't generate a core file - core tests suppressed - check ulimit
# "readline-overflow.exp" - Testcase is broken, functionality is OK.
(
  # ULIMIT required for `gdb.base/auxv.exp'.
  ulimit -H -c
  ulimit -c unlimited || :

  # Setup $CHECK as `check//unix/' or `check//unix/-m64' for explicit bitsize.
  # Never use two different bitsizes as it fails on ppc64.
  echo 'int main (void) { return 0; }' >biarch.c
  CHECK=""
  for BI in -m64 -m32 -m31 ""
  do
    # Do not use size-less options if any of the sizes works.
    # On ia64 there is no -m64 flag while we must not leave a bare `check' here
    # as it would switch over some testing scripts to the backward compatibility
    # mode: when `make check' was executed from inside the testsuite/ directory.
    if [ -z "$BI" -a -n "$CHECK" ];then
      continue
    fi
    # Do not use $RPM_OPT_FLAGS as the other non-size options will not be used
    # in the real run of the testsuite.
    if ! gcc $BI -o biarch biarch.c
    then
      continue
    fi
    CHECK="$CHECK check//unix/$BI"
  done
  # Do not try -m64 inferiors for -m32 GDB as it cannot handle inferiors larger
  # than itself.
  # s390 -m31 still uses the standard ELF32 binary format.
  gcc $RPM_OPT_FLAGS -o biarch biarch.c
  RPM_SIZE="$(file ./biarch|sed -n 's/^.*: ELF \(32\|64\)-bit .*$/\1/p')"
  if [ "$RPM_SIZE" != "64" ]
  then
    CHECK="$(echo " $CHECK "|sed 's# check//unix/-m64 # #')"
  fi

  # Disable some problematic testcases.
  # RUNTESTFLAGS='--ignore ...' is not used below as it gets separated by the
  # `check//...' target spawn and too much escaping there would be dense.
  for test in				\
    gdb.base/readline-overflow.exp	\
    gdb.base/bigcore.exp		\
  ; do
    mv -f ../../gdb/testsuite/$test ../gdb/testsuite/$test-DISABLED || :
  done

  # Run all the scheduled testsuite runs also in the PIE mode.
  # See also: gdb-runtest-pie-override.exp
  CHECK="$(echo $CHECK|sed 's#check//unix/[^ ]*#& &/-fPIC/-pie#g')"

  ./orphanripper make %{?_smp_mflags} -k $CHECK || :
)
for t in sum log
do
  for file in testsuite*/gdb.$t
  do
    suffix="${file#testsuite.unix.}"
    suffix="${suffix%/gdb.$t}"
    ln $file gdb-%{_target_platform}$suffix.$t || :
  done
done
# `tar | bzip2 | uuencode' may have some piping problems in Brew.
#tar cjf gdb-%{_target_platform}.tar.bz2 gdb-%{_target_platform}*.{sum,log}
#uuencode gdb-%{_target_platform}.tar.bz2 gdb-%{_target_platform}.tar.bz2
# Strip dates and completion times from the log to make build-compare happy
sed -i -e '/Test Run By abuild on/d' -e 's/completed in [0-9]* seconds//' *.{sum,log}
cd ../..
echo ====================TESTING END=====================
%endif

%install
# Initially we're in the %{gdb_src} directory.
cd %{gdb_build}

# It would break RHEL-5 by leaving excessive files for the doc subpackage.
%ifnarch noarch

make %{?_smp_mflags} install DESTDIR=$RPM_BUILD_ROOT

# Provide gdbtui for RHEL-5 and RHEL-6 as it is removed upstream (BZ 797664).
%if 0%{?rhel:1} && 0%{?rhel} <= 6
test ! -e $RPM_BUILD_ROOT%{_prefix}/bin/gdbtui
install -m 755 %{SOURCE6} $RPM_BUILD_ROOT%{_prefix}/bin/gdbtui
ln -sf gdb.1 $RPM_BUILD_ROOT%{_mandir}/man1/gdbtui.1
%endif # 0%{?rhel:1} && 0%{?rhel} <= 6

mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/gdbinit.d
touch -r %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/gdbinit.d
sed 's#%%{_sysconfdir}#%{_sysconfdir}#g' <%{SOURCE4} >$RPM_BUILD_ROOT%{_sysconfdir}/gdbinit
touch -r %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/gdbinit

for i in `find $RPM_BUILD_ROOT%{_datadir}/gdb/python/gdb -name "*.py"`
do
  # Files could be also patched getting the current time.
  touch -r $RPM_BUILD_DIR/%{gdb_src}/gdb/ChangeLog $i
done

%if 0%{?_enable_debug_packages:1} && 0%{!?_without_python:1}
mkdir -p $RPM_BUILD_ROOT/usr/lib/debug%{_bindir}
cp -p $RPM_BUILD_DIR/%{gdb_src}/gdb/gdb-gdb.py $RPM_BUILD_ROOT/usr/lib/debug%{_bindir}/
for pyo in "" "-O";do
  # RHEL-5: AttributeError: 'module' object has no attribute 'compile_file'
  python $pyo -c 'import compileall, re, sys; sys.exit (not compileall.compile_dir("'"$RPM_BUILD_ROOT/usr/lib/debug%{_bindir}"'", 1, "'"/usr/lib/debug%{_bindir}"'"))'
done
%endif # 0%{?_enable_debug_packages:1} && 0%{!?_without_python:1}

mkdir $RPM_BUILD_ROOT%{_datadir}/gdb/auto-load
%if 0%{?rhel:1} && 0%{?rhel} <= 6
%if 0%{!?_without_python:1}
# Temporarily now:
for LIB in lib lib64;do
  LIBPATH="$RPM_BUILD_ROOT%{_datadir}/gdb/auto-load%{_root_prefix}/$LIB"
  mkdir -p $LIBPATH
  # basename is being run only for the native (non-biarch) file.
  sed -e 's,@pythondir@,%{_datadir}/gdb/python,'		\
      -e 's,@toolexeclibdir@,%{_root_prefix}/'"$LIB,"		\
      < $RPM_BUILD_DIR/%{gdb_src}/%{libstdcxxpython}/hook.in	\
      > $LIBPATH/$(basename %{_root_prefix}/%{_lib}/libstdc++.so.6.*)-gdb.py
  # Test the filename 'libstdc++.so.6.*' has matched.
  test -f $LIBPATH/libstdc++.so.6.[0-9]*-gdb.py
done
test ! -e $RPM_BUILD_ROOT%{_datadir}/gdb/python/libstdcxx
cp -a $RPM_BUILD_DIR/%{gdb_src}/%{libstdcxxpython}/libstdcxx	\
      $RPM_BUILD_ROOT%{_datadir}/gdb/python/libstdcxx
for i in `find $RPM_BUILD_ROOT%{_datadir}/gdb/python -name "*.py"` \
         `find $RPM_BUILD_ROOT%{_datadir}/gdb/auto-load%{_prefix} -name "*.py"` \
; do
  # Files come from gdb-archer.patch and can be also further patched.
  touch -r $RPM_BUILD_DIR/%{gdb_src}/gdb/ChangeLog $i
done
%endif # 0%{!?_without_python:1}
%endif # 0%{?rhel:1} && 0%{?rhel} <= 6

# Remove the files that are part of a gdb build but that are owned and
# provided by other packages.
# These are part of binutils

rm -rf $RPM_BUILD_ROOT%{_datadir}/locale/
rm -f $RPM_BUILD_ROOT%{_infodir}/bfd*
rm -f $RPM_BUILD_ROOT%{_infodir}/standard*
rm -f $RPM_BUILD_ROOT%{_infodir}/configure*
rm -rf $RPM_BUILD_ROOT%{_includedir}
rm -rf $RPM_BUILD_ROOT/%{_libdir}/lib{bfd*,opcodes*,iberty*}

# pstack obsoletion

cp -p %{SOURCE3} $RPM_BUILD_ROOT%{_mandir}/man1/gstack.1
%endif	# 0%{!?_with_upstream:1}

# Packaged GDB is not a cross-target one.
(cd $RPM_BUILD_ROOT%{_datadir}/gdb/syscalls
 rm -f mips*.xml
%ifnarch sparc sparcv9 sparc64
 rm -f sparc*.xml
%endif
%ifnarch x86_64
 rm -f amd64-linux.xml
%endif
%ifnarch %{ix86} x86_64
 rm -f i386-linux.xml
%endif
%ifnarch ppc ppc64
 rm -f ppc{,64}-linux.xml
%endif
%ifnarch ppc64le
 rm -f ppc64le-linux.xml
%endif
)

# It would break RHEL-5 by leaving excessive files for the doc subpackage.
%if 0%{?el5:1}
rm -f $RPM_BUILD_ROOT%{_infodir}/annotate.info*
rm -f $RPM_BUILD_ROOT%{_infodir}/gdb.info*
%endif # 0%{?el5:1} 
# -j1: There is some race resulting in:
# /usr/bin/texi2dvi: texinfo.tex appears to be broken, quitting.
make -j1 -C gdb/doc install DESTDIR=$RPM_BUILD_ROOT

# Documentation only for development; keep 'rm's here after "noarch" above.
rm -f $RPM_BUILD_ROOT%{_infodir}/gdbint*
rm -f $RPM_BUILD_ROOT%{_infodir}/stabs*

# Delete this too because the dir file will be updated at rpm install time.
# We don't want a gdb specific one overwriting the system wide one.

rm -f $RPM_BUILD_ROOT%{_infodir}/dir

%clean
rm -rf $RPM_BUILD_ROOT

%post
# This step is part of the installation of the RPM. Not to be confused
# with the 'make install ' of the build (rpmbuild) process.

# For --excludedocs:
if [ -e %{_infodir}/gdb.info.gz ]
then
  %install_info --info-dir=%{_infodir} %{_infodir}/annotate.info.gz
  %install_info --info-dir=%{_infodir} %{_infodir}/gdb.info.gz
fi

%preun
if [ $1 = 0 ]
then
  # For --excludedocs:
  if [ -e %{_infodir}/gdb.info.gz ]
  then
    %install_info_delete --delete --info-dir=%{_infodir} %{_infodir}/annotate.info.gz
    %install_info_delete --delete --info-dir=%{_infodir} %{_infodir}/gdb.info.gz
  fi
fi

%files
%defattr(-,root,root)
%doc COPYING3 COPYING COPYING.LIB README NEWS
%{_bindir}/gcore
%{_mandir}/*/gcore.1*
%{_bindir}/gdb
%config(noreplace) %{_sysconfdir}/gdbinit
%{_sysconfdir}/gdbinit.d
%{_mandir}/*/gdb.1*
%{_bindir}/gstack
%{_mandir}/*/gstack.1*
# Provide gdbtui for RHEL-5 and RHEL-6 as it is removed upstream (BZ 797664).
%if 0%{?rhel:1} && 0%{?rhel} <= 6
%{_bindir}/gdbtui
%{_mandir}/*/gdbtui.1*
%endif # 0%{?rhel:1} && 0%{?rhel} <= 6
%{_bindir}/gdb-add-index
%{_mandir}/*/gdb-add-index.1*
%{_mandir}/*/gdbinit.5*
%{_datadir}/gdb
%{_infodir}/annotate.info*
%{_infodir}/gdb.info*
# In SLE10 gdbserver is not in a separate package
%if %{suse_version} <= 1010
%{_bindir}/gdbserver
%{_mandir}/*/gdbserver.1*
%ifnarch s390 s390x ia64 ppc %{sparc}
%{_libdir}/libinproctrace.so
%endif
%endif

%if 0%{?_with_testsuite:1}
%files testresults
%defattr(-,root,root)
%doc %{gdb_build}/gdb/gdb-*.sum
%doc %{gdb_build}/gdb/gdb-*.log
%endif

# don't include the files in include, they are part of binutils

%if %{suse_version} > 1010
%ifnarch sparcv9 hppa
%files -n gdbserver
%defattr(-,root,root)
%{_bindir}/gdbserver
%{_mandir}/*/gdbserver.1*
%if %{have_inproctrace}
%{_libdir}/libinproctrace.so
%endif # %{have_inproctrace}
%endif
%endif

%post doc
# This step is part of the installation of the RPM. Not to be confused
# with the 'make install ' of the build (rpmbuild) process.

# For --excludedocs:
if [ -e %{_infodir}/gdb.info.gz ]
then
  /sbin/install-info --info-dir=%{_infodir} %{_infodir}/annotate.info.gz || :
  /sbin/install-info --info-dir=%{_infodir} %{_infodir}/gdb.info.gz || :
fi

%preun doc
if [ $1 = 0 ]
then
  # For --excludedocs:
  if [ -e %{_infodir}/gdb.info.gz ]
  then
    /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/annotate.info.gz || :
    /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/gdb.info.gz || :
  fi
fi

%changelog