# when running make.
LDFLAGS = @LDFLAGS@
INTERNAL_LDFLAGS = $(LDFLAGS) @RDYNAMIC@
+IPA_INTERNAL_LDFLAGS = $(IPA_LDFLAGS) @RDYNAMIC@
# All source files that go into linking GDB remote server.
$(IPA_LIB): $(sort $(IPA_OBJS)) ${CDEPS}
$(SILENCE) rm -f $(IPA_LIB)
$(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \
- -Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
+ -Wl,--no-undefined $(INTERNAL_CFLAGS) $(IPA_INTERNAL_LDFLAGS) \
$(CXXFLAGS) \
-o $(IPA_LIB) ${IPA_OBJS} $(LIBIBERTY_FOR_SHLIB) -ldl -pthread
# CXXFLAGS is at the very end on purpose, so that user-supplied flags can
# override internal flags.
-IPAGENT_COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(IPAGENT_CFLAGS) $(CXXFLAGS) $(COMPILE.post)
+IPAGENT_COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(IPAGENT_CFLAGS) $(LIB_CXXFLAGS) $(COMPILE.post)
# Rules for special cases.
--- /dev/null
+%if 0%{?run_tests}
+%define gdb_run_tests 1
+%endif
+
+# Enable this when testing on device to:
+# 1. Enable macro to turn on testsuite building ('gdb_run_tests 1')
+# 2. Skip configure and make commands and go directly to 'make check'
+%if 0%{?run_tests_on_device}
+%define gdb_run_tests 1
+%define gdb_skip_configure 1
+%define gdb_skip_make 1
+%endif
+
+# Exit right after 'make ..' step to keep all object files produced by gdb build
+%if 0%{?exit_on_make_finish}
+%define gdb_exit_on_make_finish 1
+%endif
+
+Name: gdb
+Version: 13.2
+Release: 0
+License: GPL-3.0+
+Summary: A GNU source-level debugger for C, C++, Java and other languages
+Url: http://gnu.org/software/gdb/
+Group: Development/Toolchain
+Source: ftp://ftp.gnu.org/gnu/gdb/gdb-%{version}.tar.gz
+Source1001: gdb.manifest
+%define gdb_src gdb-%{version}
+%define gdb_build build-%{_target_platform}
+Requires: python3
+Requires: libgmp
+BuildRequires: bison
+BuildRequires: expat-devel
+BuildRequires: flex
+BuildRequires: gettext-tools
+BuildRequires: python3-devel
+BuildRequires: gcc-c++
+BuildRequires: ncurses-devel
+BuildRequires: makeinfo
+BuildRequires: gmp-devel
+%if 0%{?gdb_run_tests}
+BuildRequires: dejagnu
+BuildRequires: glibc-devel-static
+%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.
+
+%package devel
+Summary: Development files for gdb
+
+%description devel
+Development files for gdb.
+
+%ifnarch riscv64
+%package server
+Summary: A standalone server for GDB (the GNU source-level debugger)
+
+%description server
+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
+
+%{?gdb_run_tests:
+%package testresults
+Summary: Testsuite results
+License: Public Domain
+Group: Development/Building
+%description testresults
+Results from running the gdb tests.
+}
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+# 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
+export CFLAGS+=" -fPIE"
+#If you want to add a new LDFLAGS to IPA, add it to `IPA_LDFLAGS` rather than` LDFLAGS`.
+export LIB_CXXFLAGS=$CXXFLAGS
+export IPA_LDFLAGS=$LDFLAGS
+export CXXFLAGS+=" -fPIE"
+export LDFLAGS+=" -pie"
+
+%{!?gdb_skip_configure:
+%configure \
+ --with-gdb-datadir=%{_datadir}/gdb \
+ --enable-gdb-build-warnings=,-Wno-unused \
+ --disable-werror \
+ --with-separate-debug-dir=/usr/lib/debug \
+ %{!?gdb_run_tests:--disable-sim} \
+ --disable-rpath \
+ --with-expat \
+ --enable-64-bit-bfd \
+ --enable-debug \
+ %{!?gdb_run_tests: --enable-static --disable-shared}
+}
+
+%{!?gdb_skip_make:
+make %{?_smp_mflags}
+}
+
+%{?gdb_exit_on_make_finish:
+exit 1
+}
+
+%{?gdb_run_tests:
+echo "Run testsuite"
+# asan needs a whole shadow address space
+ulimit -v unlimited || true
+make -k check %{?_smp_mflags} || true
+mkdir ./testresults
+for tool in $(find -name '*.sum' -exec basename {} \; | sort -u | sed -e 's/.sum//'); do
+./contrib/dg-extract-results.sh -t $tool $(find -name '*.sum') | tee -a ./testresults/test_summary.txt
+done
+}
+
+
+%install
+%make_install
+
+%{?gdb_run_tests:
+ find . \( -name "*.sum" -o -name "*.log" -a \! -name "config.log" \) -exec tar -rf testresults.tar {} \;
+ mkdir -p ./testresults && tar -xf testresults.tar -C ./testresults
+ find ./testresults/ -type f -exec chmod 644 {} \;
+}
+
+%find_lang opcodes
+%find_lang bfd
+mv opcodes.lang %{name}.lang
+cat bfd.lang >> %{name}.lang
+
+%docs_package
+
+%lang_package
+
+%files
+%defattr(-,root,root)
+%manifest %{name}.manifest
+%license COPYING COPYING.LIB
+%{_bindir}/*
+%{_datadir}/gdb
+
+%ifnarch riscv64
+%files server
+%manifest %{name}.manifest
+%defattr(-,root,root)
+%{_bindir}/gdbserver
+%{_mandir}/*/gdbserver.1*
+%ifarch %{ix86} x86_64 aarch64
+%{_libdir}/libinproctrace.so
+%endif
+%endif
+
+%files devel
+%manifest %{name}.manifest
+%{_includedir}/*.h
+%{_includedir}/gdb/*.h
+
+%{?gdb_run_tests:
+%files testresults
+%defattr(-,root,root)
+%doc testresults/test_summary.txt
+%doc testresults/*
+}