Patchwork [Trunk] patch for GNU-friendly gengtype

login
register
mail settings
Submitter jeremie.salvucci@free.fr
Date June 22, 2010, 2:40 p.m.
Message ID <1912594726.385401277217637011.JavaMail.root@zimbra30-e5.priv.proxad.net>
Download mbox | patch
Permalink /patch/56520/
State New
Headers show

Comments

jeremie.salvucci@free.fr - June 22, 2010, 2:40 p.m.
With Basile, we decided to not use version.o in build/. as Laurynas suggested we print usage and version on stdout.

gcc/Changelog entry :
2010-06-22  Jeremie Salvucci  <jeremie.salvucci@free.fr>
	    Basile Starynkevitch  <basile@starynkevitch.net>

	* Makefile.in (gengtype.o): Pass version information strings as
	-DGENGTYPE_* preprocessor flags.

	* gengtype.c: Include getopt.h.
	(do_dump): Added static variable moved from main.
	(inputlist): Ditto.
	(plugin_output_filename): Ditto.
	(gengtype_long_options): New variable.
	(print_usage): Added function.
	(bug_report_url, version_string, pkgversion_string): Added variable.
	(print_version): Added function.
	(parse_program_options): Added new function.
	(main): Changed program invocation convention. Call
	parse_program_options. Removed old argument parsing.

Attached the patch to trunk revision 161188.

Ok for trunk ?

Patch

Index: gcc/gengtype.c
===================================================================
--- gcc/gengtype.c	(revision 161188)
+++ gcc/gengtype.c	(working copy)
@@ -21,9 +21,11 @@ 
 #include "bconfig.h"
 #include "system.h"
 #include "gengtype.h"
+#include "getopt.h"
 #include "errors.h"	/* for fatal */
 #include "double-int.h"
 #include "hashtab.h"
+#include "version.h"    /* for version_string & pkgversion_string */
 
 /* Data types, macros, etc. used only in this file.  */
 
@@ -145,10 +147,12 @@ 
 /* The list of output files.  */
 static outf_p output_files;
 
-/* The plugin input files and their number; in that case only
-   a single file is produced.  */
+/* The plugin input files and their number; in that case only a single
+   file is produced.  Each element of plugin_files should have an all
+   zero lang_bitmap. */
 static char** plugin_files;
 static size_t nb_plugin_files;
+
 /* the generated plugin output name & file */
 static outf_p plugin_output;
 
@@ -162,6 +166,10 @@ 
 /* Length of srcdir name.  */
 static size_t srcdir_len = 0;
 
+static int do_dump = 0;
+static char* inputlist = NULL;
+static char* plugin_output_filename = NULL;
+
 static outf_p create_file (const char *, const char *);
 
 static const char * get_file_basename (const char *);
@@ -4158,54 +4166,129 @@ 
 }
 
 
+/* Option specification for getopt_long.  */
+static const struct option gengtype_long_options[] = 
+{
+  { "help",      no_argument, NULL, 'h' },
+  { "version",   no_argument, NULL, 'v' },
+  { "dump",      no_argument, NULL, 'd' },
+  { "plugin",    required_argument, NULL, 'P' },
+  { "srcdir",    required_argument, NULL, 'S' },
+  { "inputs",    required_argument, NULL, 'I' },
+  { NULL,        no_argument, NULL, 0   },
+};
+
+
+static void
+print_usage (void)
+{
+ printf ("Usage: %s\n", progname);
+ printf ("\t -h | --help  \t# Give this help.\n");
+ printf ("\t -v | --version  \t# Give version information.\n");
+ printf ("\t -d | --dump  \t# Dump state for debugging.\n");
+ printf ("\t -P | --plugin <output-file>  \t#  Generate for a plugin.\n");
+ printf ("\t -S | --srcdir <GCC-directory>  \t#  Specify the GCC source directory.\n");
+ printf ("\t -I | --inputs <input-list>  \t#  Specify the file with source files list.\n");
+}
+
+
+/* This is the location of the online document giving instructions for
+   reporting bugs.  If you distribute a modified version of GCC,
+   please configure with --with-bugurl pointing to a document giving
+   instructions for reporting bugs to you, not us.  (You are of course
+   welcome to forward us bugs reported to you, if you determine that
+   they are not bugs in your modifications.)  */
+const char bug_report_url[] = GENGTYPE_BUGURL;
+/* The complete version string, assembled from several pieces.
+   GENGTYPE_BASEVER, GENGTYPE_DATESTAMP, GENGTYPE_DEVPHASE, and
+   GENGTYPE_REVISION are defined by the Makefile.  */
+
+const char version_string[] = GENGTYPE_BASEVER GENGTYPE_DATESTAMP GENGTYPE_DEVPHASE GENGTYPE_REVISION;
+const char pkgversion_string[] = GENGTYPE_PKGVERSION;
+
+static void
+print_version (void)
+{
+  /* Since we cannot depend upon version.o, we have to duplicate
+     version information here. */
+ printf ("%s %s%s\n", progname, pkgversion_string, version_string);
+ printf ("Report bugs: %s\n", bug_report_url);
+}
+
+
+/* Parse the program options using getopt_long... */
+static void
+parse_program_options (int argc, char**argv)
+{
+  int opt = -1;
+  while ((opt = getopt_long (argc, argv, "hvdP:S:I:",
+			     gengtype_long_options, NULL)) >= 0)
+    {
+      switch (opt)
+	{
+	case 'h': /* --help */
+	  print_usage ();
+	  break;
+	case 'v': /* --version */
+	  print_version ();
+	  break;
+	case 'd': /* --dump */
+	  do_dump = 1;
+	  break;
+	case 'P': /* --plugin */
+	  if (optarg)
+	    plugin_output_filename = optarg;
+	  else
+	    fatal ("missing plugin output file name");
+	  break;
+	case 'S': /* --srcdir */
+	  if (optarg)
+	    srcdir = optarg;
+	  else
+	    fatal ("missing source directory");
+	  srcdir_len = strlen (srcdir);
+	  break;
+	case 'I': /* --inputs */
+	  if (optarg)
+	    inputlist = optarg;
+	  else
+	    fatal ("missing input list");
+	  break;
+	default:
+	  fprintf (stderr, "%s: unknown flag '%c'\n", progname, opt);
+	  print_usage ();
+	  fatal ("unexpected flag");
+	}
+    };
+  if (plugin_output_filename)
+    {
+      /* In plugin mode we require some input files. */
+      int i = 0;
+      if (optind >= argc)
+	fatal("no source files given in plugin mode");
+      nb_plugin_files = argc - optind;
+      for  (i = 0; i < (int) nb_plugin_files; i++)
+	{
+	  /* Place an all zero lang_bitmap before the plugin file
+	     name.  */
+	  char *name = argv[i + optind];
+	  int len = strlen(name) + 1 + sizeof (lang_bitmap);
+	  plugin_files[i] = XCNEWVEC (char, len) + sizeof (lang_bitmap);
+	  strcpy (plugin_files[i], name);
+	}
+    }
+}
+
 int
 main (int argc, char **argv)
 {
   size_t i;
   static struct fileloc pos = { this_file, 0 };
-  char* inputlist = 0;
-  int do_dump = 0;
   outf_p output_header;
-  char* plugin_output_filename = NULL;
   /* fatal uses this */
-  progname = "gengtype";
+  progname = (argc > 0) ? argv[0] : "gengtype";
+  parse_program_options (argc, argv);
 
-  if (argc >= 2 && !strcmp (argv[1], "-d"))
-    {
-      do_dump = 1;
-      argv = &argv[1];
-      argc--;
-    }
-
-  if (argc >= 6 && !strcmp (argv[1], "-P"))
-    {
-      plugin_output_filename = argv[2];
-      plugin_output = create_file ("GCC", plugin_output_filename);
-      srcdir = argv[3];
-      inputlist = argv[4];
-      nb_plugin_files = argc - 5;
-      plugin_files = XCNEWVEC (char *, nb_plugin_files);
-      for (i = 0; i < nb_plugin_files; i++)
-      {
-        /* Place an all zero lang_bitmap before the plugin file
-	   name.  */
-        char *name = argv[i + 5];
-        int len = strlen(name) + 1 + sizeof (lang_bitmap);
-        plugin_files[i] = XCNEWVEC (char, len) + sizeof (lang_bitmap);
-        strcpy (plugin_files[i], name);
-      }
-    }
-  else if (argc == 3)
-    {
-      srcdir = argv[1];
-      inputlist = argv[2];
-    }
-  else
-    fatal ("usage: gengtype [-d] [-P pluginout.h] srcdir input-list "
-           "[file1 file2 ... fileN]");
-
-  srcdir_len = strlen (srcdir);
-
   read_input_list (inputlist);
   if (hit_error)
     return 1;
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 161188)
+++ gcc/Makefile.in	(working copy)
@@ -3745,7 +3745,7 @@ 
 
 s-gtype: build/gengtype$(build_exeext) $(filter-out [%], $(GTFILES)) \
 	 gtyp-input.list
-	$(RUN_GEN) build/gengtype$(build_exeext) $(srcdir) gtyp-input.list
+	$(RUN_GEN) build/gengtype$(build_exeext) -S $(srcdir) -I gtyp-input.list
 	$(STAMP) s-gtype
 
 generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \
@@ -3831,8 +3831,17 @@ 
 build/gengtype-lex.o : gengtype-lex.c gengtype.h $(BCONFIG_H) $(SYSTEM_H)
 build/gengtype-parse.o : gengtype-parse.c gengtype.h $(BCONFIG_H)	\
   $(SYSTEM_H)
+
+# gengtype cannot depend of version.o, otherwise a circular make
+# dependency appears.
 build/gengtype.o : gengtype.c $(BCONFIG_H) $(SYSTEM_H) gengtype.h 	\
-  rtl.def insn-notes.def errors.h double-int.h $(HASHTAB_H)
+  rtl.def insn-notes.def errors.h double-int.h $(HASHTAB_H) \
+   $(REVISION) $(DATESTAMP) $(BASEVER) 
+	$(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \
+	-DGENGTYPE_BASEVER=$(BASEVER_s) -DGENGTYPE_DATESTAMP=$(DATESTAMP_s) \
+	-DGENGTYPE_REVISION=$(REVISION_s) \
+	-DGENGTYPE_DEVPHASE=$(DEVPHASE_s) -DGENGTYPE_PKGVERSION=$(PKGVERSION_s) \
+	-DGENGTYPE_BUGURL=$(BUGURL_s) -c $(srcdir)/gengtype.c $(OUTPUT_OPTION)
 build/genmddeps.o: genmddeps.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h	\
   errors.h $(READ_MD_H)
 build/genmodes.o : genmodes.c $(BCONFIG_H) $(SYSTEM_H) errors.h		\