[patch 1/2] Make gdbtui a shell script

Jan Kratochvil
2011-12-21T11:47:10Z

Hi,

it is discussed for years it is not great to have almost the same gdb and
gdbtui binaries, each ~5MB. Make gdbtui a shell script.

I am not so sure how well is the shell script portable across Unices.
I assume MinGW is out of question anyway but that may not be a concern.

Fedora has been using gdb<->gdbtui hardlink but according to Tom argv[0]
should not be used. GNU Coding Standards IMO do not say exactly this thing.

Thanks,
Jan

gdb/
2011-12-21 Jan Kratochvil <jan.kratochvil@redhat.com>

Replace gdbtui binary by a shell script.
* Makefile.in (INSTALL_SCRIPT): New variable.
(SUBDIR_TUI_OBS): Remove tui-main.o.
(SUBDIR_TUI_SRCS): Remove tui/tui-main.c.
(all-tui): Remove its $(TUI)$(EXEEXT) dependency.
(install-tui): Change INSTALL_PROGRAM to INSTALL_SCRIPT, add .sh to
source $(TUI) and remove $(EXEEXT) from the target.
(uninstall-tui): Remove $(EXEEXT) from the target.
($(TUI)$(EXEEXT)): Remove.
(clean-tui): Remove its only recipe.
(tui-main.o): Remove.
(all_object_files): Remove tui-main.o.
* gdbtui.sh: New file.
* tui/tui-main.c: Remove.

--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -59,6 +59,7 @@ LN_S = @LN_S@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@

DESTDIR =

@@ -237,7 +238,6 @@ SUBDIR_TUI_OBS = \
tui-io.o \
tui-layout.o \
tui-out.o \
- tui-main.o \
tui-regs.o \
tui-source.o \
tui-stack.o \
@@ -256,7 +256,6 @@ SUBDIR_TUI_SRCS = \
tui/tui-interp.c \
tui/tui-io.c \
tui/tui-layout.c \
- tui/tui-main.c \
tui/tui-out.c \
tui/tui-regs.c \
tui/tui-source.c \
@@ -961,7 +960,7 @@ generated_files = config.h observer.h observer.inc ada-lex.c jit-reader.h \
all: gdb$(EXEEXT) $(CONFIG_ALL)
@$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do
.PHONY: all-tui
-all-tui: $(TUI)$(EXEEXT)
+all-tui:

installcheck:

@@ -1050,8 +1049,8 @@ install-tui:
true ; \
fi ; \
$(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(bindir) ; \
- $(INSTALL_PROGRAM) $(TUI)$(EXEEXT) \
- $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) ; \
+ $(INSTALL_SCRIPT) $(TUI).sh \
+ $(DESTDIR)$(bindir)/$$transformed_name ; \
$(SHELL) $(srcdir)/../mkinstalldirs \
$(DESTDIR)$(man1dir) ; \
$(INSTALL_DATA) $(srcdir)/gdb.1 \
@@ -1080,7 +1079,7 @@ uninstall-tui:
else \
true ; \
fi ; \
- rm -f $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) \
+ rm -f $(DESTDIR)$(bindir)/$$transformed_name \
$(DESTDIR)$(man1dir)/$$transformed_name.1

# The C++ name parser can be built standalone for testing.
@@ -1185,12 +1184,6 @@ gdb$(EXEEXT): gdb.o libgdb.a $(ADD_DEPS) $(CDEPS) $(TDEPLIBS)
-o gdb$(EXEEXT) gdb.o libgdb.a \
$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)

-$(TUI)$(EXEEXT): tui-main.o libgdb.a $(ADD_DEPS) $(CDEPS) $(TDEPLIBS)
- rm -f $(TUI)$(EXEEXT)
- $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
- -o $(TUI)$(EXEEXT) tui-main.o libgdb.a \
- $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
-
# Convenience rule to handle recursion.
$(LIBGNU) $(GNULIB_H): all-lib
all-lib: gnulib/Makefile
@@ -1253,7 +1246,6 @@ clean mostlyclean: $(CONFIG_CLEAN)

.PHONY: clean-tui
clean-tui:
- rm -f $(TUI)$(EXEEXT)

# This used to depend on c-exp.c m2-exp.c TAGS
# I believe this is wrong; the makefile standards for distclean just
@@ -2020,10 +2012,6 @@ tui-layout.o: $(srcdir)/tui/tui-layout.c
$(COMPILE) $(srcdir)/tui/tui-layout.c
$(POSTCOMPILE)

-tui-main.o: $(srcdir)/tui/tui-main.c
- $(COMPILE) $(srcdir)/tui/tui-main.c
- $(POSTCOMPILE)
-
tui-out.o: $(srcdir)/tui/tui-out.c
$(COMPILE) $(srcdir)/tui/tui-out.c
$(POSTCOMPILE)
@@ -2205,7 +2193,7 @@ py-value.o: $(srcdir)/python/py-value.c

# A list of all the objects we might care about in this build, for
# dependency tracking.
-all_object_files = gdb.o tui-main.o $(LIBGDB_OBS) gdbtk-main.o \
+all_object_files = gdb.o $(LIBGDB_OBS) gdbtk-main.o \
test-cp-name-parser.o

# Ensure that generated files are created early. Use order-only
--- /dev/null
+++ b/gdb/gdbtui.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if [ "${0%/*}" != "$0" ]
+then
+ exec "${0%/*}/gdb" --tui "$@"
+else
+ exec gdb --tui "$@"
+fi
--- a/gdb/tui/tui-main.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Main function for TUI gdb.
-
- Copyright (C) 2002, 2004, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
-
- This file is part of GDB.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "defs.h"
-#include "main.h"
-#include "gdb_string.h"
-#include "interps.h"
-
-int
-main (int argc, char **argv)
-{
- struct captured_main_args args;
-
- memset (&args, 0, sizeof args);
- args.argc = argc;
- args.argv = argv;
- args.use_windows = 0;
- args.interpreter_p = INTERP_TUI;
- return gdb_main (&args);
-}