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]

Re: Implement -MF <output-filename>


Zack Weinberg wrote:-

> If you have to respin the patch anyway, you might split it up and
> apply just the code rearrangement first.

And this is the meaty part.  In cpplib.h, since the library structure
is becoming clearer, I've started to breifly document the interface.

Bootstrapping i586 Linux.

Neil.

	* c-lang.c (c_post_options): Call cpp_post_options.
	* cppmain.c (main): Similarly.
	* fix-header.c (read_scan_file): Similarly.
	* cp/decl2.c (cxx_post_options): Similarly.
	* objc/objc-act.c (objc_post_options): Similarly.
	* cppinit.c (cpp_start_read): Move option consistency checks
	to cpp_post_options.  Don't call init_dependency_output.
	If needed, add default target and main file dependency.
	(OPT_MD, OPT_MMD): Remove.
	(OPT_MF): New.
	(cpp_handle_option): Update for OPT_* changes.
	(cpp_post_options): New.
	(init_dependency_output): Command line -MF overrides environment
	variables.  Don't set default target etc.  Suppress output
	if dependencies are going to stdout.
	(print_help): Update.
	* cpplib.h (cpp_post_options): New.
	* gcc.c (cpp_options): Update for -MD, -MMD, -MF.

Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.43
diff -u -p -r1.43 c-lang.c
--- c-lang.c	2001/01/07 03:34:27	1.43
+++ c-lang.c	2001/01/07 11:38:54
@@ -47,6 +47,7 @@ struct lang_hooks lang_hooks = {c_post_o
 static void
 c_post_options ()
 {
+  cpp_post_options (parse_in);
 }
 
 /* Each of the functions defined here
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.132
diff -u -p -r1.132 cppinit.c
--- cppinit.c	2001/01/07 11:15:13	1.132
+++ cppinit.c	2001/01/07 11:39:05
@@ -867,25 +867,6 @@ cpp_start_read (pfile, fname)
 {
   struct pending_option *p, *q;
 
-  /* -MG doesn't select the form of output and must be specified with one of
-     -M or -MM.  -MG doesn't make sense with -MD or -MMD since they don't
-     inhibit compilation.  */
-  if (CPP_OPTION (pfile, print_deps_missing_files)
-      && (CPP_OPTION (pfile, print_deps) == 0
-	  || !CPP_OPTION (pfile, no_output)))
-    {
-      cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
-      return 0;
-    }
-
-  /* -Wtraditional is not useful in C++ mode.  */
-  if (CPP_OPTION (pfile, cplusplus))
-    CPP_OPTION (pfile, warn_traditional) = 0;
-
-  /* Set this if it hasn't been set already. */
-  if (CPP_OPTION (pfile, user_label_prefix) == NULL)
-    CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
-
   /* Set up the include search path now.  */
   if (! CPP_OPTION (pfile, no_standard_includes))
     init_standard_includes (pfile);
@@ -906,8 +887,6 @@ cpp_start_read (pfile, fname)
       fprintf (stderr, _("End of search list.\n"));
     }
 
-  /* Open the main input file.  This must be done early, so we have a
-     buffer to stand on.  */
   if (CPP_OPTION (pfile, in_fname) == NULL
       || *CPP_OPTION (pfile, in_fname) == 0)
     {
@@ -918,11 +897,20 @@ cpp_start_read (pfile, fname)
   if (CPP_OPTION (pfile, out_fname) == NULL)
     CPP_OPTION (pfile, out_fname) = "";
 
+  if (CPP_OPTION (pfile, print_deps))
+    {
+      /* Set the default target (if there is none already).  */
+      deps_add_default_target (pfile->deps, CPP_OPTION (pfile, in_fname));
+
+      if (CPP_OPTION (pfile, in_fname))
+	deps_add_dep (pfile->deps, CPP_OPTION (pfile, in_fname));
+    }
+
+  /* Open the main input file.  This must be done early, so we have a
+     buffer to stand on.  */
   if (!_cpp_read_file (pfile, fname))
     return 0;
 
-  init_dependency_output (pfile);
-
   /* Install __LINE__, etc.  */
   init_builtins (pfile);
 
@@ -1050,10 +1038,9 @@ new_pending_directive (pend, text, handl
   DEF_OPT("H",                        0,      OPT_H)                          \
   DEF_OPT("I",                        no_dir, OPT_I)                          \
   DEF_OPT("M",                        0,      OPT_M)                          \
-  DEF_OPT("MD",                       no_fil, OPT_MD)                         \
+  DEF_OPT("MF",                       no_fil, OPT_MF)                         \
   DEF_OPT("MG",                       0,      OPT_MG)                         \
   DEF_OPT("MM",                       0,      OPT_MM)                         \
-  DEF_OPT("MMD",                      no_fil, OPT_MMD)                        \
   DEF_OPT("MP",                       0,      OPT_MP)                         \
   DEF_OPT("MQ",                       no_tgt, OPT_MQ)                         \
   DEF_OPT("MT",                       no_tgt, OPT_MT)                         \
@@ -1448,43 +1435,22 @@ cpp_handle_option (pfile, argc, argv)
 		}
 	  }
 	  break;
-	  /* The style of the choices here is a bit mixed.
-	     The chosen scheme is a hybrid of keeping all options in one string
-	     and specifying each option in a separate argument:
-	     -M|-MM|-MD file|-MMD file [-MG].  An alternative is:
-	     -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
-	     -M[M][G][D file].  This is awkward to handle in specs, and is not
-	     as extensible.  */
-	  /* ??? -MG must be specified in addition to one of -M or -MM.
-	     This can be relaxed in the future without breaking anything.
-	     The converse isn't true.  */
 
-	  /* -MG isn't valid with -MD or -MMD.  This is checked for later.  */
 	case OPT_MG:
 	  CPP_OPTION (pfile, print_deps_missing_files) = 1;
 	  break;
 	case OPT_M:
-	case OPT_MD:
+	  CPP_OPTION (pfile, print_deps) = 2;
+	  break;
 	case OPT_MM:
-	case OPT_MMD:
-	  if (opt_code == OPT_M || opt_code == OPT_MD)
-	    CPP_OPTION (pfile, print_deps) = 2;
- 	  else
-	    CPP_OPTION (pfile, print_deps) = 1;
-
-	  /* For -MD and -MMD, write deps on file named by next arg.  */
-	  /* For -M and -MM, write deps on standard output and
-	     suppress the usual output.  */
-	  if (opt_code == OPT_MD || opt_code == OPT_MMD)
-	      CPP_OPTION (pfile, deps_file) = arg;
- 	  else
-	      CPP_OPTION (pfile, no_output) = 1;
+	  CPP_OPTION (pfile, print_deps) = 1;
 	  break;
-
-	case OPT_MP:
+	case OPT_MF:
+	  CPP_OPTION (pfile, deps_file) = arg;
+	  break;
+ 	case OPT_MP:
 	  CPP_OPTION (pfile, deps_phony_targets) = 1;
 	  break;
-
 	case OPT_MQ:
 	case OPT_MT:
 	  /* Add a target.  -MQ quotes for Make.  */
@@ -1680,9 +1646,37 @@ cpp_handle_options (pfile, argc, argv)
       if (strings_processed == 0)
 	break;
     }
+
   return i;
 }
 
+/* Extra processing when all options are parsed, after all calls to
+   cpp_handle_option[s].  Consistency checks etc.  */
+void
+cpp_post_options (pfile)
+     cpp_reader *pfile;
+{
+  /* -Wtraditional is not useful in C++ mode.  */
+  if (CPP_OPTION (pfile, cplusplus))
+    CPP_OPTION (pfile, warn_traditional) = 0;
+
+  /* Set this if it hasn't been set already. */
+  if (CPP_OPTION (pfile, user_label_prefix) == NULL)
+    CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
+
+  /* We need to do this after option processing and before
+     cpp_start_read, as cppmain.c relies on the options->no_output to
+     set its callbacks correctly before calling cpp_start_read.  */
+  init_dependency_output (pfile);
+
+  /* -MG doesn't select the form of output and must be specified with
+     one of -M or -MM.  -MG doesn't make sense unless preprocessed
+     output (and compilation) is inhibited.  */
+  if (CPP_OPTION (pfile, print_deps_missing_files)
+      && CPP_OPTION (pfile, print_deps) == 0)
+    cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
+}
+
 /* Set up dependency-file output.  */
 static void
 init_dependency_output (pfile)
@@ -1722,15 +1716,17 @@ init_dependency_output (pfile)
       else
 	output_file = spec;
 
-      CPP_OPTION (pfile, deps_file) = output_file;
+      /* Command line overrides environment variables.  */
+      if (CPP_OPTION (pfile, deps_file) == 0)
+	CPP_OPTION (pfile, deps_file) = output_file;
       CPP_OPTION (pfile, print_deps_append) = 1;
     }
-
-  /* Set the default target (if there is none already).  */
-  deps_add_default_target (pfile->deps, CPP_OPTION (pfile, in_fname));
 
-  if (CPP_OPTION (pfile, in_fname))
-    deps_add_dep (pfile->deps, CPP_OPTION (pfile, in_fname));
+  /* If dependencies go to standard output, we need to suppress
+     output.  The user may be requesting other stuff to stdout, with
+     -dM, -v etc.  We let them shoot themselves in the foot.  */
+  if (CPP_OPTION (pfile, deps_file) == 0)
+    CPP_OPTION (pfile, no_output) = 1;
 }
 
 static void
@@ -1799,9 +1795,13 @@ Switches:\n\
   fputs (_("\
   -M                        Generate make dependencies\n\
   -MM                       As -M, but ignore system header files\n\
-  -MD                       As -M, but put output in a .d file\n\
-  -MMD                      As -MD, but ignore system header files\n\
+  -MF <file>                Write dependency output to the given file\n\
   -MG                       Treat missing header file as generated files\n\
+"), stdout);
+  fputs (_("\
+  -MP			    Generate phony targets for all headers\n\
+  -MQ <target>              Add a MAKE-quoted target\n\
+  -MT <target>              Add an unquoted target\n\
   -g3                       Include #define and #undef directives in the output\n\
 "), stdout);
   fputs (_("\
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.156
diff -u -p -r1.156 cpplib.h
--- cpplib.h	2001/01/05 23:41:00	1.156
+++ cpplib.h	2001/01/07 11:39:08
@@ -704,14 +704,25 @@ struct cpp_hashnode
   union tree_node *fe_value;		/* Front end value.  */
 };
 
+/* Call this first to get a handle to pass to other functions.  */
 extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
+
+/* Now call cpp_handle_option[s] to handle 1[or more] switches.  The
+   return value is the number of arguments used.  If
+   cpp_handle_options returns without using all arguments, it couldn't
+   understand the next switch.  When there are no switches left, you
+   must call cpp_post_options before calling cpp_start_read.  Only
+   after cpp_post_options are the contents of the cpp_options
+   structure reliable.  */
+extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
+extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
+extern void cpp_post_options PARAMS ((cpp_reader *));
+
 extern unsigned int cpp_token_len PARAMS ((const cpp_token *));
 extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *,
 						 const cpp_token *));
 extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *,
 					       unsigned char *));
-extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
-extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
 extern void cpp_register_pragma PARAMS ((cpp_reader *,
 					 const char *, const char *,
 					 void (*) PARAMS ((cpp_reader *))));
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.50
diff -u -p -r1.50 cppmain.c
--- cppmain.c	2001/01/05 23:41:00	1.50
+++ cppmain.c	2001/01/07 11:39:11
@@ -79,6 +79,7 @@ main (argc, argv)
   argi += cpp_handle_options (pfile, argc - argi , argv + argi);
   if (argi < argc && ! CPP_FATAL_ERRORS (pfile))
     cpp_fatal (pfile, "Invalid option %s", argv[argi]);
+  cpp_post_options (pfile);
   if (CPP_FATAL_ERRORS (pfile))
     return (FATAL_EXIT_CODE);
 
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.59
diff -u -p -r1.59 fix-header.c
--- fix-header.c	2000/12/18 19:00:14	1.59
+++ fix-header.c	2001/01/07 11:39:16
@@ -629,6 +629,7 @@ read_scan_file (in_fname, argc, argv)
   i = cpp_handle_options (scan_in, argc, argv);
   if (i < argc && ! CPP_FATAL_ERRORS (scan_in))
     cpp_fatal (scan_in, "Invalid option `%s'", argv[i]);
+  cpp_post_options (pfile);
   if (CPP_FATAL_ERRORS (scan_in))
     exit (FATAL_EXIT_CODE);
 
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.194
diff -u -p -r1.194 gcc.c
--- gcc.c	2001/01/07 09:42:49	1.194
+++ gcc.c	2001/01/07 11:40:21
@@ -586,7 +586,7 @@ static const char *cpp_options =
 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
  %{std*} %{nostdinc*}\
  %{C} %{v} %{I*} %{P} %{$} %I\
- %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{MP} %{MQ} %{MT}\
+ %{M} %{MM} %{MD:-M -MF %b.d} %{MMD:-MM -MF %b.d} %{MF} %{MG} %{MP} %{MQ} %{MT}\
  %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
  %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
  %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.420
diff -u -p -r1.420 decl2.c
--- decl2.c	2001/01/07 03:34:28	1.420
+++ decl2.c	2001/01/07 11:40:44
@@ -551,6 +551,7 @@ struct lang_hooks lang_hooks = {cxx_post
 static void
 cxx_post_options ()
 {
+  cpp_post_options (parse_in);
 }
 
 /* Compare two option strings, pointed two by P1 and P2, for use with
Index: objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.60
diff -u -p -r1.60 objc-act.c
--- objc-act.c	2001/01/07 03:34:28	1.60
+++ objc-act.c	2001/01/07 11:41:12
@@ -634,6 +634,7 @@ struct lang_hooks lang_hooks = {objc_pos
 static void
 objc_post_options ()
 {
+  cpp_post_options (parse_in);
 }
 
 /* Some platforms pass small structures through registers versus through

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