[2/3] Make init.c depend on source files

Message ID 20181224210927.16741-3-tom@tromey.com
State New
Headers show
Series
  • some minor Makefile improvements
Related show

Commit Message

Tom Tromey Dec. 24, 2018, 9:09 p.m.
I noticed that init.c depends on the object files that go into gdb.
Because init.c actually only requires the contents of the
corresponding source files, this unnecessarily serializes the step
that builds init.c.

This patch changes gdb's Makefile to make init.c depend on the source
files.  This also simplifies the rule to build init.c.

gdb/ChangeLog
2018-12-24  Tom Tromey  <tom@tromey.com>

	* Makefile.in (INIT_FILES): Redefine.
	(stamp-init): Remove sed, tr invocations.  Use for loop.  Don't
	set LANG or LC_ALL.
---
 gdb/ChangeLog   |  6 ++++++
 gdb/Makefile.in | 35 +++++++++++------------------------
 2 files changed, 17 insertions(+), 24 deletions(-)

-- 
2.17.2

Comments

Simon Marchi Dec. 27, 2018, 4:02 a.m. | #1
On 2018-12-24 16:09, Tom Tromey wrote:
> +INIT_FILES = \

> +	$(patsubst %.o,%.c, \

> +	  $(patsubst %-exp.o,%-exp.y, \

> +	    $(filter-out $(NATDEPFILES) init.o version.o %_S.o %_U.o,\

> +	      $(COMMON_OBS))))


What do %_S and %_U mean?

Simon
Tom Tromey Dec. 27, 2018, 4:21 a.m. | #2
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:


Simon> On 2018-12-24 16:09, Tom Tromey wrote:
>> +INIT_FILES = \

>> +	$(patsubst %.o,%.c, \

>> +	  $(patsubst %-exp.o,%-exp.y, \

>> +	    $(filter-out $(NATDEPFILES) init.o version.o %_S.o %_U.o,\

>> +	      $(COMMON_OBS))))


Simon> What do %_S and %_U mean?

"%" is just the way make patterns work, and the _S and _U deletions are
copied from the old code.  I believe they refer to the GNU Hurd
mig-generated files.  See gdb/config/i386/i386gnu.mn.

Tom
Simon Marchi Dec. 27, 2018, 4:23 a.m. | #3
On 2018-12-26 11:21 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

> 

> Simon> On 2018-12-24 16:09, Tom Tromey wrote:

>>> +INIT_FILES = \

>>> +	$(patsubst %.o,%.c, \

>>> +	  $(patsubst %-exp.o,%-exp.y, \

>>> +	    $(filter-out $(NATDEPFILES) init.o version.o %_S.o %_U.o,\

>>> +	      $(COMMON_OBS))))

> 

> Simon> What do %_S and %_U mean?

> 

> "%" is just the way make patterns work, and the _S and _U deletions are

> copied from the old code.  I believe they refer to the GNU Hurd

> mig-generated files.  See gdb/config/i386/i386gnu.mn.


Ahh! Stoopid me though they were Makefile special variables (like $@).

Simon
Simon Marchi Dec. 27, 2018, 4:23 a.m. | #4
On 2018-12-26 11:23 p.m., Simon Marchi wrote:
> Ahh! Stoopid me though they were Makefile special variables (like $@).


(I forgot for a moment that references to variables in Makefiles are in parentheses)

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 38d00b0632..e4d4a3449d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1831,37 +1831,24 @@  test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 #
 # Note that the set of files with init functions might change, or the names
 # of the functions might change, so this files needs to depend on all the
-# object files that will be linked into gdb.
+# source files that will be linked into gdb.  However, due to the way
+# this Makefile has generally been written, we do this indirectly, by
+# computing the list of source files from the list of object files.
 
-# FIXME: There is a problem with this approach - init.c may force
-# unnecessary files to be linked in.
+INIT_FILES = \
+	$(patsubst %.o,%.c, \
+	  $(patsubst %-exp.o,%-exp.y, \
+	    $(filter-out $(NATDEPFILES) init.o version.o %_S.o %_U.o,\
+	      $(COMMON_OBS))))
 
-# NOTE: cagney/2003-03-18: The sed pattern ``s|^\([^ /]...'' is
-# anchored on the first column and excludes the ``/'' character so
-# that it doesn't add the $(srcdir) prefix to any file that already
-# has an absolute path.  It turns out that $(DEC)'s True64 make
-# automatically adds the $(srcdir) prefixes when it encounters files
-# in sub-directories such as cli/ and mi/.
-
-INIT_FILES = $(COMMON_OBS)
 init.c: stamp-init; @true
 stamp-init: $(INIT_FILES)
 	@$(ECHO_INIT_C) echo "Making init.c"
 	@rm -f init.c-tmp init.l-tmp
 	@touch init.c-tmp
-	@-LANG=C ; export LANG ; \
-	LC_ALL=C ; export LC_ALL ; \
-	echo $(INIT_FILES) | \
-	tr ' ' '\012' | \
-	sed \
-	    -e '/^init.[co]$$/d' \
-	    -e '/version.[co]$$/d' \
-	    -e '/^[a-z0-9A-Z_]*_[SU].[co]$$/d' \
-	    -e 's/-exp\.o$$/-exp.y/' \
-	    -e 's/\.o$$/.c/' \
-	    -e 's|^\([^  /][^     ]*\)|$(srcdir)/\1|g' | \
-	while read f; do \
-	    sed -n -e 's/^_initialize_\([a-z_0-9A-Z]*\).*/\1/p' $$f 2>/dev/null; \
+	@-for f in $(INIT_FILES); do \
+	    sed -n -e 's/^_initialize_\([a-z_0-9A-Z]*\).*/\1/p' \
+	        $(srcdir)/$$f 2>/dev/null; \
 	done > init.l-tmp
 	@echo '/* Do not modify this file.  */' >>init.c-tmp
 	@echo '/* It is created automatically by the Makefile.  */'>>init.c-tmp