This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [build/rfc] automatic md file dependencies


On Wed, Dec 15, 2004 at 05:15:26PM -0800, Zack Weinberg wrote:
> Richard's MD dependency generator could be modified to create these.
> Off the top of my head I can't think of any problems this would cause,
> but I might be missing something.

That works.  Updated patch follows, same changelog.


r~



Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1432
diff -u -p -r1.1432 Makefile.in
--- Makefile.in	13 Dec 2004 10:27:41 -0000	1.1432
+++ Makefile.in	16 Dec 2004 01:39:00 -0000
@@ -2216,6 +2216,17 @@ libbackend.o : $(OBJS-common:.o=.c) $(ou
   insn-emit.c insn-recog.c insn-extract.c insn-output.c insn-peep.c \
   insn-attr.h insn-attrtab.c insn-preds.c
 
+# Dependencies for the md file.  The first time through, we just assume
+# the md file itself and the generated dependency file (in order to get
+# it built).  The second time through we have the dependency file.
+-include mddeps.mk
+MD_DEPS = s-mddeps $(md_file) $(MD_INCLUDES)
+
+s-mddeps: $(md_file) $(MD_INCLUDES) build/genmddeps$(build_exeext)
+	$(RUN_GEN) build/genmddeps$(build_exeext) $(md_file) > tmp-mddeps
+	$(SHELL) $(srcdir)/../move-if-change tmp-mddeps mddeps.mk
+	$(STAMP) s-mddeps
+
 # The following pair of rules has this effect:
 # genconfig is run only if the md has changed since genconfig was last run;
 # but the file insn-config.h is touched only when its contents actually change.
@@ -2236,13 +2247,13 @@ libbackend.o : $(OBJS-common:.o=.c) $(ou
 # trailing `;'), we call true for each.
 
 insn-config.h: s-config ; @true
-s-config : $(md_file) build/genconfig$(build_exeext)
+s-config : $(MD_DEPS) build/genconfig$(build_exeext)
 	$(RUN_GEN) build/genconfig$(build_exeext) $(md_file) > tmp-config.h
 	$(SHELL) $(srcdir)/../move-if-change tmp-config.h insn-config.h
 	$(STAMP) s-config
 
 insn-conditions.c: s-conditions ; @true
-s-conditions : $(md_file) build/genconditions$(build_exeext)
+s-conditions : $(MD_DEPS) build/genconditions$(build_exeext)
 	$(RUN_GEN) build/genconditions$(build_exeext) $(md_file) > tmp-conditions.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-conditions.c insn-conditions.c
 	$(STAMP) s-conditions
@@ -2255,19 +2266,19 @@ build/insn-conditions.o : insn-condition
 build/dummy-conditions.o : dummy-conditions.c
 
 insn-flags.h: s-flags ; @true
-s-flags : $(md_file) build/genflags$(build_exeext)
+s-flags : $(MD_DEPS) build/genflags$(build_exeext)
 	$(RUN_GEN) build/genflags$(build_exeext) $(md_file) > tmp-flags.h
 	$(SHELL) $(srcdir)/../move-if-change tmp-flags.h insn-flags.h
 	$(STAMP) s-flags
 
 insn-codes.h: s-codes ; @true
-s-codes : $(md_file) build/gencodes$(build_exeext)
+s-codes : $(MD_DEPS) build/gencodes$(build_exeext)
 	$(RUN_GEN) build/gencodes$(build_exeext) $(md_file) > tmp-codes.h
 	$(SHELL) $(srcdir)/../move-if-change tmp-codes.h insn-codes.h
 	$(STAMP) s-codes
 
 insn-constants.h: s-constants ; @true
-s-constants : $(md_file) build/genconstants$(build_exeext)
+s-constants : $(MD_DEPS) build/genconstants$(build_exeext)
 	$(RUN_GEN) build/genconstants$(build_exeext) $(md_file) > tmp-constants.h
 	$(SHELL) $(srcdir)/../move-if-change tmp-constants.h insn-constants.h
 	$(STAMP) s-constants
@@ -2279,7 +2290,7 @@ insn-emit.o : insn-emit.c $(CONFIG_H) $(
 	  $(OUTPUT_OPTION)
 
 insn-emit.c: s-emit ; @true
-s-emit : $(md_file) build/genemit$(build_exeext)
+s-emit : $(MD_DEPS) build/genemit$(build_exeext)
 	$(RUN_GEN) build/genemit$(build_exeext) $(md_file) > tmp-emit.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-emit.c insn-emit.c
 	$(STAMP) s-emit
@@ -2291,7 +2302,7 @@ insn-recog.o : insn-recog.c $(CONFIG_H) 
 	  $(OUTPUT_OPTION)
 
 insn-recog.c: s-recog ; @true
-s-recog : $(md_file) build/genrecog$(build_exeext)
+s-recog : $(MD_DEPS) build/genrecog$(build_exeext)
 	$(RUN_GEN) build/genrecog$(build_exeext) $(md_file) > tmp-recog.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-recog.c insn-recog.c
 	$(STAMP) s-recog
@@ -2302,7 +2313,7 @@ insn-opinit.o : insn-opinit.c $(CONFIG_H
 	  $(OUTPUT_OPTION)
 
 insn-opinit.c: s-opinit ; @true
-s-opinit : $(md_file) build/genopinit$(build_exeext)
+s-opinit : $(MD_DEPS) build/genopinit$(build_exeext)
 	$(RUN_GEN) build/genopinit$(build_exeext) $(md_file) > tmp-opinit.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-opinit.c insn-opinit.c
 	$(STAMP) s-opinit
@@ -2313,7 +2324,7 @@ insn-extract.o : insn-extract.c $(CONFIG
 	  $(OUTPUT_OPTION)
 
 insn-extract.c: s-extract ; @true
-s-extract : $(md_file) build/genextract$(build_exeext)
+s-extract : $(MD_DEPS) build/genextract$(build_exeext)
 	$(RUN_GEN) build/genextract$(build_exeext) $(md_file) > tmp-extract.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-extract.c insn-extract.c
 	$(STAMP) s-extract
@@ -2325,7 +2336,7 @@ insn-peep.o : insn-peep.c $(CONFIG_H) $(
 	  $(OUTPUT_OPTION)
 
 insn-peep.c: s-peep ; @true
-s-peep : $(md_file) build/genpeep$(build_exeext)
+s-peep : $(MD_DEPS) build/genpeep$(build_exeext)
 	$(RUN_GEN) build/genpeep$(build_exeext) $(md_file) > tmp-peep.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-peep.c insn-peep.c
 	$(STAMP) s-peep
@@ -2337,13 +2348,13 @@ insn-attrtab.o : insn-attrtab.c $(CONFIG
 	  $(OUTPUT_OPTION)
 
 insn-attr.h: s-attr ; @true
-s-attr : $(md_file) build/genattr$(build_exeext)
+s-attr : $(MD_DEPS) build/genattr$(build_exeext)
 	$(RUN_GEN) build/genattr$(build_exeext) $(md_file) > tmp-attr.h
 	$(SHELL) $(srcdir)/../move-if-change tmp-attr.h insn-attr.h
 	$(STAMP) s-attr
 
 insn-attrtab.c: s-attrtab ; @true
-s-attrtab : $(md_file) build/genattrtab$(build_exeext)
+s-attrtab : $(MD_DEPS) build/genattrtab$(build_exeext)
 	$(RUN_GEN) build/genattrtab$(build_exeext) $(md_file) > tmp-attrtab.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-attrtab.c insn-attrtab.c
 	$(STAMP) s-attrtab
@@ -2356,7 +2367,7 @@ insn-output.o : insn-output.c $(CONFIG_H
 	  $(OUTPUT_OPTION)
 
 insn-output.c: s-output ; @true
-s-output : $(md_file) build/genoutput$(build_exeext)
+s-output : $(MD_DEPS) build/genoutput$(build_exeext)
 	$(RUN_GEN) build/genoutput$(build_exeext) $(md_file) > tmp-output.c
 	$(SHELL) $(srcdir)/../move-if-change tmp-output.c insn-output.c
 	$(STAMP) s-output
@@ -2388,7 +2399,7 @@ s-modes: build/genmodes$(build_exeext)
 
 insn-preds.c tm-preds.h: s-preds; @true
 
-s-preds: $(md_file) build/genpreds$(build_exeext)
+s-preds: $(MD_DEPS) build/genpreds$(build_exeext)
 	$(RUN_GEN) build/genpreds$(build_exeext) -h $(md_file) > tmp-preds.h
 	$(SHELL) $(srcdir)/../move-if-change tmp-preds.h tm-preds.h
 	$(RUN_GEN) build/genpreds$(build_exeext) $(md_file) > tmp-preds.c
@@ -2506,7 +2517,7 @@ genobjnames=$(genprognames:%=%.o) read-r
 	genconstants.o gen-protos.o scan.o fix-header.o scan-decls.o \
 	gencheck.o dummy-conditions.o genconditions.o errors.o ggc-none.o \
 	min-insn-modes.o rtl.o print-rtl.o varray.o gcov-iov.o \
-	insn-conditions.o gengtype-lex.o gengtype-yacc.o
+	insn-conditions.o gengtype-lex.o gengtype-yacc.o genmddeps.o
 
 genobjs=$(genobjnames:%=build/%)
 
@@ -2536,6 +2547,15 @@ build/genflags.o : genflags.c $(RTL_BASE
 build/gencodes.o : gencodes.c $(RTL_BASE_H) $(BCONFIG_H) \
   $(SYSTEM_H) coretypes.h $(GTM_H) errors.h gensupport.h
 
+build/genmddeps$(build_exeext) : build/genmddeps.o $(BUILD_RTL) \
+  $(BUILD_EARLY_SUPPORT) $(BUILD_ERRORS) $(BUILD_LIBDEPS)
+	$(CC_FOR_BUILD) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) -o $@ \
+	 build/genmddeps.o $(BUILD_EARLY_SUPPORT) $(BUILD_RTL) \
+	 $(BUILD_ERRORS) $(BUILD_LIBS)
+
+build/genmddeps.o: genmddeps.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h \
+  $(GTM_H) $(RTL_BASE_H) errors.h gensupport.h
+
 build/genconstants$(build_exeext) : build/genconstants.o $(BUILD_RTL) \
   $(BUILD_EARLY_SUPPORT) $(BUILD_ERRORS) $(BUILD_LIBDEPS)
 	$(CC_FOR_BUILD) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) -o $@ \
@@ -3068,6 +3088,7 @@ mostlyclean: lang.mostlyclean
 	-rm -rf libgcc
 # Delete build programs
 	-rm -f build/*
+	-rm -f mddeps.mk
 # Delete the temp files made in the course of building libgcc.a.
 	-rm -f xlimits.h
 # Delete other built files.
Index: genmddeps.c
===================================================================
RCS file: genmddeps.c
diff -N genmddeps.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ genmddeps.c	16 Dec 2004 01:39:00 -0000
@@ -0,0 +1,70 @@
+/* genmddeps.c - creates a makefile dependency fragment for the md file.
+   Copyright (C) 2004 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 2, 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, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#include "bconfig.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "rtl.h"
+#include "gensupport.h"
+#include "errors.h"
+
+
+struct filedep
+{
+  struct filedep *next;
+  const char *pathname;
+};
+
+static struct filedep *deps, **last = &deps;
+
+static void
+add_filedep (const char *pathname)
+{
+  struct filedep *n = XNEW (struct filedep);
+  n->pathname = pathname;
+  *last = n;
+  last = &n->next;
+}
+
+int
+main (int argc, char **argv)
+{
+  struct filedep *d;
+
+  progname = "genmddeps";
+  include_callback = add_filedep;
+  
+  if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
+    return (FATAL_EXIT_CODE);
+
+  *last = NULL;
+
+  /* Output a variable containing all of the include files.  */
+  fputs ("MD_INCLUDES =", stdout);
+  for (d = deps; d ; d = d->next)
+    printf (" \\\n\t%s", d->pathname);
+  putchar ('\n');
+
+  /* Output make targets for these includes with empty actions.  This
+     will guard against make errors when includes are removed.  */
+  for (d = deps; d ; d = d->next)
+    printf ("\n%s:\n", d->pathname);
+
+  fflush (stdout);
+  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+}
Index: gensupport.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gensupport.c,v
retrieving revision 1.57
diff -u -p -r1.57 gensupport.c
--- gensupport.c	9 Sep 2004 13:22:38 -0000	1.57
+++ gensupport.c	16 Dec 2004 01:39:00 -0000
@@ -37,6 +37,10 @@ int insn_elision = 1;
 
 const char *in_fname;
 
+/* This callback will be invoked whenever an rtl include directive is
+   processed.  To be used for creation of the dependency file.  */
+void (*include_callback) (const char *);
+
 static struct obstack obstack;
 struct obstack *rtl_obstack = &obstack;
 
@@ -245,6 +249,9 @@ process_include (rtx desc, int lineno)
   read_rtx_filename = pathname;
   read_rtx_lineno = 1;
 
+  if (include_callback)
+    include_callback (pathname);
+
   /* Read the entire file.  */
   while (read_rtx (input_file, &desc, &lineno))
     process_rtx (desc, lineno);
Index: gensupport.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gensupport.h,v
retrieving revision 1.10
diff -u -p -r1.10 gensupport.h
--- gensupport.h	15 Oct 2004 14:47:07 -0000	1.10
+++ gensupport.h	16 Dec 2004 01:39:00 -0000
@@ -92,4 +92,8 @@ extern void add_predicate (struct pred_d
 
 #define FOR_ALL_PREDICATES(p) for (p = first_predicate; p; p = p->next)
 
+/* This callback will be invoked whenever an rtl include directive is
+   processed.  To be used for creation of the dependency file.  */
+extern void (*include_callback) (const char *);
+
 #endif /* GCC_GENSUPPORT_H */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]