mknative-gdb revision 1.18
11.1Snathanw#!/bin/sh
21.18Schristos#	$NetBSD: mknative-gdb,v 1.18 2024/08/27 14:58:45 christos Exp $
31.1Snathanw#
41.1Snathanw# Shell script for generating all the constants needed for a native
51.3Schristos# platform build of src/external/gpl3/gdb
61.1Snathanw#
71.1Snathanw
81.1Snathanw# initialise
91.1Snathanw
101.1Snathanw_TMPDIR=$2
111.1Snathanw_TOP=$3
121.1Snathanw_PLATFORM=$4
131.7Smrg_MACHINE_SUBDIR=$5
141.1Snathanw_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ 	]*,,'`
151.3Schristos_GDB=external/gpl3/gdb
161.1Snathanw
171.1Snathanw. $_TOP/tools/gcc/mknative.common
181.1Snathanw
191.3Schristos##### gdb/lib/libbfd #####
201.1Snathanw
211.1Snathanwget_gdb_libbfd () {
221.3Schristos	local _BFD=$_GDB/lib/libbfd
231.7Smrg	mkdir -p $_TOP/$_BFD/arch/$_MACHINE_SUBDIR
241.1Snathanw
251.1Snathanw	{
261.1Snathanw		getvars bfd/Makefile \
271.1Snathanw			libbfd_la_DEPENDENCIES libbfd_la_OBJECTS DEFS \
281.1Snathanw			INCLUDES TDEFAULTS
291.7Smrg	} | write_mk $_BFD/arch/$_MACHINE_SUBDIR/defs.mk
301.1Snathanw
311.16Schristos	for i in bfd-in3.h config.h bfd.h bfdver.h targmatch.h 
321.3Schristos	do
331.7Smrg	    write_c $_BFD/arch/$_MACHINE_SUBDIR/$i <$_TMPDIR/bfd/$i
341.3Schristos	done
351.1Snathanw}
361.1Snathanw
371.3Schristos##### gdb/lib/libopcodes #####
381.1Snathanw
391.1Snathanwget_gdb_libopcodes () {
401.3Schristos	local _OPCODES=$_GDB/lib/libopcodes
411.7Smrg	mkdir -p $_TOP/$_OPCODES/arch/$_MACHINE_SUBDIR
421.1Snathanw
431.1Snathanw	{
441.1Snathanw		getvars opcodes/Makefile \
451.1Snathanw			archdefs BFD_MACHINES libopcodes_la_SOURCES
461.7Smrg	} | write_mk $_GDB/lib/libopcodes//arch/$_MACHINE_SUBDIR/defs.mk
471.1Snathanw
481.1Snathanw	{
491.1Snathanw		cat $_TMPDIR/opcodes/config.h
501.7Smrg	} | write_c $_OPCODES/arch/$_MACHINE_SUBDIR/config.h
511.1Snathanw}
521.1Snathanw
531.3Schristos##### gdb/lib/libiberty #####
541.1Snathanw
551.1Snathanwget_gdb_libiberty () {
561.3Schristos	local _IBERTY=$_GDB/lib/libiberty
571.7Smrg	mkdir -p $_TOP/$_IBERTY/arch/$_MACHINE_SUBDIR
581.1Snathanw
591.1Snathanw	getvars libiberty/Makefile \
601.1Snathanw		ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
611.7Smrg		| write_mk $_IBERTY/arch/$_MACHINE_SUBDIR/defs.mk
621.1Snathanw
631.7Smrg	write_c $_IBERTY/arch/$_MACHINE_SUBDIR/config.h \
641.1Snathanw		<$_TMPDIR/libiberty/config.h
651.1Snathanw}
661.1Snathanw
671.3Schristos##### gdb/lib/libreadline #####
681.1Snathanw
691.1Snathanwget_gdb_libreadline () {
701.3Schristos	local _READLINE=$_GDB/lib/libreadline
711.7Smrg	mkdir -p $_TOP/$_READLINE/arch/$_MACHINE_SUBDIR
721.1Snathanw
731.1Snathanw	{
741.9Schristos		getvars readline/readline/Makefile \
751.1Snathanw			CCFLAGS OBJECTS
761.7Smrg	} | write_mk $_READLINE/arch/$_MACHINE_SUBDIR/defs.mk
771.3Schristos
781.7Smrg	write_c $_READLINE/arch/$_MACHINE_SUBDIR/config.h \
791.9Schristos		<$_TMPDIR/readline/readline/config.h
801.3Schristos}
811.3Schristos
821.3Schristos##### gdb/lib/libdecnumber #####
831.3Schristos
841.3Schristosget_gdb_libdecnumber () {
851.3Schristos	local _DECNUMBER=$_GDB/lib/libdecnumber
861.7Smrg	mkdir -p $_TOP/$_DECNUMBER/arch/$_MACHINE_SUBDIR
871.3Schristos
881.10Schristos	getvars libdecnumber/Makefile libdecnumber_a_OBJS |
891.16Schristos	sed -e s/libdecnumber_a_//g |
901.7Smrg	write_mk $_DECNUMBER/arch/$_MACHINE_SUBDIR/defs.mk
911.1Snathanw
921.7Smrg	write_c $_DECNUMBER/arch/$_MACHINE_SUBDIR/config.h \
931.9Schristos		<$_TMPDIR/readline/readline/config.h
941.3Schristos
951.7Smrg	write_c $_DECNUMBER/arch/$_MACHINE_SUBDIR/gstdint.h \
961.3Schristos		< $_TMPDIR/libdecnumber/gstdint.h
971.1Snathanw}
981.1Snathanw
991.10Schristos##### gdb/lib/libgdbsupport #####
1001.10Schristos
1011.10Schristosget_gdb_libgdbsupport () {
1021.10Schristos	local _GDBSUPPORT=$_GDB/lib/libgdbsupport
1031.10Schristos	mkdir -p $_TOP/$_GDBSUPPORT/arch/$_MACHINE_SUBDIR/gdbsupport
1041.10Schristos
1051.10Schristos	getvars gdbsupport/Makefile libgdbsupport_a_OBJECTS |
1061.16Schristos	sed -e s/libgdbsupport_a_//g |
1071.10Schristos	write_mk $_GDBSUPPORT/arch/$_MACHINE_SUBDIR/defs.mk
1081.10Schristos
1091.10Schristos	write_c $_GDBSUPPORT/arch/$_MACHINE_SUBDIR/gdbsupport/config.h \
1101.10Schristos		<$_TMPDIR/gdbsupport/config.h
1111.10Schristos}
1121.10Schristos
1131.16Schristos##### gdb/lib/libctf #####
1141.16Schristos
1151.10Schristosget_gdb_libctf () {
1161.10Schristos	local _CTF=$_GDB/lib/libctf
1171.10Schristos	mkdir -p $_TOP/$_CTF/arch/$_MACHINE_SUBDIR
1181.10Schristos
1191.10Schristos	getvars libctf/Makefile libctf_la_OBJECTS |
1201.16Schristos	sed -e s/libctf_la_//g -e 's/\.lo/.o/g' -e s/libctf_la-//g |
1211.10Schristos	write_mk $_CTF/arch/$_MACHINE_SUBDIR/defs.mk
1221.10Schristos
1231.10Schristos	write_c $_CTF/arch/$_MACHINE_SUBDIR/config.h \
1241.10Schristos		<$_TMPDIR/libctf/config.h
1251.10Schristos}
1261.10Schristos
1271.16Schristos##### gdb/lib/libbacktrace #####
1281.16Schristos
1291.16Schristosget_gdb_libbacktrace () {
1301.16Schristos	local _BACKTRACE=$_GDB/lib/libbacktrace
1311.16Schristos	mkdir -p $_TOP/$_BACKTRACE/arch/$_MACHINE_SUBDIR
1321.16Schristos
1331.16Schristos	getvars libbacktrace/Makefile libbacktrace_la_OBJECTS \
1341.16Schristos	    libbacktrace_la_LIBADD |
1351.16Schristos	sed -e s/libbacktrace_la_//g -e 's/\.lo/.o/g' -e s/libbacktrace_la-//g |
1361.16Schristos	write_mk $_BACKTRACE/arch/$_MACHINE_SUBDIR/defs.mk
1371.16Schristos
1381.16Schristos	write_c $_BACKTRACE/arch/$_MACHINE_SUBDIR/config.h \
1391.16Schristos		<$_TMPDIR/libbacktrace/config.h
1401.16Schristos	write_c $_BACKTRACE/arch/$_MACHINE_SUBDIR/backtrace-supported.h \
1411.16Schristos		<$_TMPDIR/libbacktrace/backtrace-supported.h
1421.16Schristos}
1431.16Schristos
1441.16Schristos##### gdb/lib/libsframe #####
1451.16Schristos
1461.16Schristosget_gdb_libsframe () {
1471.16Schristos	local _SFRAME=$_GDB/lib/libsframe
1481.16Schristos	mkdir -p $_TOP/$_SFRAME/arch/$_MACHINE_SUBDIR
1491.16Schristos
1501.16Schristos	getvars libsframe/Makefile libsframe_la_OBJECTS |
1511.16Schristos	sed -e s/libsframe_la_//g -e 's/\.lo/.o/g' -e s/libsframe_la-//g |
1521.16Schristos	write_mk $_SFRAME/arch/$_MACHINE_SUBDIR/defs.mk
1531.16Schristos}
1541.16Schristos
1551.10Schristos##### gdb/lib/libgnulib #####
1561.10Schristos
1571.10Schristosget_gdb_libgnulib () {
1581.10Schristos	local _GNULIB=$_GDB/lib/libgnulib
1591.16Schristos	mkdir -p $_TOP/$_GNULIB/arch/$_MACHINE_SUBDIR/gnulib/import/malloc
1601.10Schristos
1611.10Schristos	(getvars gnulib/Makefile gl_LIBOBJS |
1621.16Schristos	sed -e s/gl_LIB//g &&
1631.10Schristos	getvars gnulib/import/Makefile libgnu_a_OBJECTS |
1641.16Schristos	sed -e s/libgnu_a-//g -e s@glthread/@@g -e s@malloc/@@g) |
1651.10Schristos	write_mk $_GNULIB/arch/$_MACHINE_SUBDIR/defs.mk
1661.10Schristos
1671.10Schristos	for i in config.h \
1681.10Schristos	    import/alloca.h import/ctype.h \
1691.10Schristos	    import/dirent.h import/fcntl.h \
1701.10Schristos	    import/fnmatch.h import/glob.h \
1711.16Schristos	    import/glob-libc.gl.h \
1721.10Schristos	    import/inttypes.h import/limits.h \
1731.10Schristos	    import/locale.h import/math.h \
1741.16Schristos	    import/malloc/scratch_buffer.gl.h \
1751.10Schristos	    import/signal.h import/stdint.h \
1761.10Schristos	    import/stdio.h import/stdlib.h \
1771.10Schristos	    import/string.h import/time.h \
1781.10Schristos	    import/unistd.h import/wchar.h \
1791.10Schristos	    import/wctype.h
1801.10Schristos	do
1811.12Schristos	    write_c $_GNULIB/arch/$_MACHINE_SUBDIR/gnulib/$i \
1821.10Schristos		< $_TMPDIR/gnulib/$i
1831.10Schristos	done
1841.10Schristos}
1851.1Snathanw
1861.13Schristos##### gdb/lib/libgdb #####
1871.13Schristos
1881.3Schristosget_gdb_libgdb () {
1891.3Schristos	local _GDBP=$_GDB/lib/libgdb
1901.1Snathanw
1911.1Snathanw	{
1921.1Snathanw		getvars gdb/Makefile \
1931.1Snathanw			INTERNAL_CFLAGS LIBGDB_OBS SIM_OBS
1941.8Schristos	} | sed -e s@arch/@@g -e s@cli/@@g -e s@common/agent@common-agent@ \
1951.8Schristos		-e s@common/@@g -e s@compile/@@g -e s@guile/@@g -e s@mi/@@g \
1961.8Schristos		-e s@nat/@@g -e s@python/@@g -e s@target/@@g \
1971.9Schristos		-e s@dwarf2/@@g -e s@unittests/@@g \
1981.8Schristos		-e s@tui/@@g | write_mk $_GDBP/arch/$_MACHINE_SUBDIR/defs.mk
1991.1Snathanw
2001.1Snathanw#	getvars gdb/gdbserver/Makefile \
2011.1Snathanw#		INTERNAL_CFLAGS OBS \
2021.7Smrg#		| write_mk $_GDB/bin/gdb/arch/$_MACHINE_SUBDIR/gdbserver.mk
2031.1Snathanw
2041.8Schristos	for i in config.h version.c init.c \
2051.9Schristos	    xml-builtin.c jit-reader.h
2061.3Schristos	do
2071.7Smrg	    write_c $_GDBP/arch/$_MACHINE_SUBDIR/$i \
2081.3Schristos		< $_TMPDIR/gdb/$i
2091.1Snathanw	done
2101.9Schristos	
2111.1Snathanw
2121.1Snathanw	for f in nm tm xm; do
2131.9Schristos		if [ ! -f $_TMPDIR/gdb/$f.h ]; then 
2141.9Schristos			continue
2151.1Snathanw		fi
2161.9Schristos		ls -l $_TMPDIR/gdb/$f.h | \
2171.9Schristos			sed 's,^.*->.*/gdb/,,;s,^,#include <,;s,$,>,' | \
2181.9Schristos			write_c $_GDBP/arch/$_MACHINE_SUBDIR/$f.h
2191.1Snathanw	done
2201.1Snathanw
2211.3Schristos	local _LIBSIM=$_GDB/lib/libsim
2221.7Smrg	case $_MACHINE_SUBDIR in
2231.1Snathanw	powerpc*)
2241.7Smrg		mkdir -p $_TOP/$_LIBSIM/arch/$_MACHINE_SUBDIR
2251.18Schristos		#write_c $_LIBSIM/arch/$_MACHINE_SUBDIR/config.h \
2261.18Schristos		#	<$_TMPDIR/sim/ppc/config.h
2271.18Schristos		#write_c $_LIBSIM/arch/$_MACHINE_SUBDIR/build-config.h \
2281.18Schristos		#	<$_TMPDIR/sim/ppc/build-config.h
2291.7Smrg		#write_c $_LIBSIM/arch/$_MACHINE_SUBDIR/cconfig.h \
2301.7Smrg		#	<$_TMPDIR/sim/common/cconfig.h
2311.1Snathanw		;;
2321.5Schristos	xxmips*)	# Disabled for now
2331.7Smrg		mkdir -p $_TOP/$_LIBSIM/arch/$_MACHINE_SUBDIR
2341.7Smrg		write_c $_LIBSIM/arch/$_MACHINE_SUBDIR/config.h \
2351.1Snathanw			<$_TMPDIR/sim/mips/config.h
2361.7Smrg		#write_c $_LIBSIM/arch/$_MACHINE_SUBDIR/cconfig.h \
2371.7Smrg		#	<$_TMPDIR/sim/common/cconfig.h
2381.1Snathanw		{
2391.1Snathanw			getvars sim/mips/Makefile \
2401.1Snathanw				LIB_OBJS CONFIG_CFLAGS \
2411.1Snathanw			    	BUILT_SRC_FROM_IGEN IGEN_OBJS
2421.7Smrg		} | write_mk $_LIBSIM/arch/$_MACHINE_SUBDIR/defs.mk
2431.1Snathanw		;;
2441.1Snathanw	*)
2451.1Snathanw		;;
2461.1Snathanw	esac
2471.1Snathanw}
2481.1Snathanw
2491.13Schristos# gdb/bin/gdbserver`
2501.13Schristos
2511.13Schristosget_gdb_bingdbserver () {
2521.13Schristos	local _CTF=$_GDB/bin/gdbserver
2531.15Schristos
2541.15Schristos	if [ ! -f $_CTF/arch/$_MACHINE_SUBDIR/config.h ]; then
2551.15Schristos		return
2561.15Schristos	fi
2571.13Schristos	mkdir -p $_TOP/$_CTF/arch/$_MACHINE_SUBDIR
2581.13Schristos
2591.13Schristos	write_c $_CTF/arch/$_MACHINE_SUBDIR/config.h \
2601.13Schristos		<$_TMPDIR/gdbserver/config.h
2611.14Schristos	write_c $_CTF/arch/$_MACHINE_SUBDIR/version.cc \
2621.14Schristos		<$_TMPDIR/gdbserver/version-generated.cc
2631.13Schristos}
2641.13Schristos
2651.17Srin# info
2661.17Srin
2671.17Sringet_gdb_info () {
2681.17Srin	local _INFO=$_GDB/info
2691.17Srin	local _SRC=$_TMPDIR/gdb/doc
2701.17Srin
2711.17Srin	mkdir -p $_TOP/$_INFO
2721.17Srin
2731.17Srin	for i in $_SRC/*.info; do
2741.17Srin		j=`basename $i`
2751.17Srin		writefile $_INFO/$j < $i
2761.17Srin	done
2771.17Srin}
2781.17Srin
2791.1Snathanw##### main #####
2801.1Snathanw
2811.1Snathanwcase $1 in
2821.1Snathanwall|gdb)	# everything (uses "canadian cross" temp environment)
2831.3Schristos	get_gdb_libgdb
2841.10Schristos	get_gdb_libgdbsupport
2851.10Schristos	get_gdb_libctf
2861.16Schristos	get_gdb_libbacktrace
2871.16Schristos	get_gdb_libsframe
2881.10Schristos	get_gdb_libgnulib
2891.1Snathanw	get_gdb_libbfd
2901.1Snathanw	get_gdb_libopcodes
2911.1Snathanw	get_gdb_libiberty
2921.1Snathanw	get_gdb_libreadline
2931.3Schristos	get_gdb_libdecnumber
2941.13Schristos	get_gdb_bingdbserver
2951.17Srin	get_gdb_info
2961.1Snathanw	exit 0
2971.1Snathanw	;;
2981.1Snathanw
2991.1Snathanw*)	echo invalid arguments; exit 1;;
3001.1Snathanwesac
301