This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


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

[patch] --MD option for gasp


This patch adds a --MD option to gasp, and adds the ability to pass '-' to
--MD meaning "print dependencies to stdout".

2000-03-16  Geoff Berry  <geoffb@bops.com>

	* Makefile.am (gasp_new_SOURCES): Add depend.c.
	* Makefile.in: Rebuild.
	* depend.c (print_dependencies): If `dep_file' is `-', print
	dependencies to stdout.
	* doc/as.texinfo: Document `-' special case of `--MD' flag.
	* doc/gasp.texinfo: Document `--MD' option.
	* gasp.c (out_file_name): New variable.
	(out_name): Replaced by `out_file_name'.
	(quit): Call `print_dependencies'.
	(new_file): Call `register_dependency'.
	(long_options, show_usage, main): Add `--MD'.
	(as_warn): New function.



diff -cbr ./gas/Makefile.am
/usr/bops-devel/binutils-2.9-bops/gas/Makefile.am
*** ./gas/Makefile.am	Tue Apr 07 15:47:30 1998
--- /usr/bops-devel/binutils-2.9-bops/gas/Makefile.am	Mon Feb 28 18:13:52
2000
***************
*** 397,403 ****
  	expr.h struc-symbol.h write.h frags.h hash.h read.h symbols.h tc.h \
  	obj.h listing.h bignum.h bit_fix.h $(INCDIR)/libiberty.h
  
! gasp_new_SOURCES = gasp.c macro.c sb.c hash.c
  gasp_new_LDADD = ../libiberty/libiberty.a
  
  EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
--- 397,403 ----
  	expr.h struc-symbol.h write.h frags.h hash.h read.h symbols.h tc.h \
  	obj.h listing.h bignum.h bit_fix.h $(INCDIR)/libiberty.h
  
! gasp_new_SOURCES = gasp.c macro.c sb.c hash.c depend.c
  gasp_new_LDADD = ../libiberty/libiberty.a
  
  EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
diff -cbr ./gas/Makefile.in
/usr/bops-devel/binutils-2.9-bops/gas/Makefile.in
*** ./gas/Makefile.in	Tue Apr 07 15:47:30 1998
--- /usr/bops-devel/binutils-2.9-bops/gas/Makefile.in	Mon Feb 28 18:14:22
2000
***************
*** 463,469 ****
  as_new_DEPENDENCIES = $(TARG_CPU_O) $(OBJ_FORMAT_O) $(ATOF_TARG_O) \
  	$(extra_objects) $(GASLIBS)
  
! gasp_new_SOURCES = gasp.c macro.c sb.c hash.c
  gasp_new_LDADD = ../libiberty/libiberty.a
  
  EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
--- 463,469 ----
  as_new_DEPENDENCIES = $(TARG_CPU_O) $(OBJ_FORMAT_O) $(ATOF_TARG_O) \
  	$(extra_objects) $(GASLIBS)
  
! gasp_new_SOURCES = gasp.c macro.c sb.c hash.c depend.c
  gasp_new_LDADD = ../libiberty/libiberty.a
  
  EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
***************
*** 1211,1217 ****
  literal.o macro.o messages.o output-file.o read.o sb.o stabs.o \
  subsegs.o symbols.o write.o
  as_new_LDFLAGS = 
! gasp_new_OBJECTS =  gasp.o macro.o sb.o hash.o
  gasp_new_DEPENDENCIES =  ../libiberty/libiberty.a
  gasp_new_LDFLAGS = 
  SCRIPTS =  $(noinst_SCRIPTS)
--- 1218,1224 ----
  literal.o macro.o messages.o output-file.o read.o sb.o stabs.o \
  subsegs.o symbols.o write.o
  as_new_LDFLAGS = 
! gasp_new_OBJECTS =  gasp.o macro.o sb.o hash.o depend.o
  gasp_new_DEPENDENCIES =  ../libiberty/libiberty.a
  gasp_new_LDFLAGS = 
  SCRIPTS =  $(noinst_SCRIPTS)
diff -cbr ./gas/depend.c /usr/bops-devel/binutils-2.9-bops/gas/depend.c
*** ./gas/depend.c	Tue Apr 07 15:47:31 1998
--- /usr/bops-devel/binutils-2.9-bops/gas/depend.c	Mon Feb 28 18:11:54
2000
***************
*** 189,208 ****
    if (dep_file == NULL)
      return;
  
    f = fopen (dep_file, "w");
    if (f == NULL)
      {
        as_warn ("Can't open `%s' for writing", dep_file);
        return;
      }
  
    column = 0;
!   wrap_output (f, out_file_name, ':');
    for (dep = dep_chain; dep != NULL; dep = dep->next)
      wrap_output (f, dep->file, ' ');
  
    putc ('\n', f);
  
!   if (fclose (f))
      as_warn ("Can't close %s", dep_file);
  }
--- 189,217 ----
    if (dep_file == NULL)
      return;
  
+   if (strcmp (dep_file, "-") == 0)
+     {
+       dep_file = "<stdout>";
+       f = stdout;
+     }
+   else
+     {
        f = fopen (dep_file, "w");
+       
        if (f == NULL)
  	{
  	  as_warn ("Can't open `%s' for writing", dep_file);
  	  return;
  	}
+     }
  
    column = 0;
!   wrap_output (f, out_file_name ? out_file_name : "<stdout>", ':');
    for (dep = dep_chain; dep != NULL; dep = dep->next)
      wrap_output (f, dep->file, ' ');
  
    putc ('\n', f);
  
!   if (f != stdout && fclose (f))
      as_warn ("Can't close %s", dep_file);
  }
diff -cbr ./gas/doc/as.texinfo
/usr/bops-devel/binutils-2.9-bops/gas/doc/as.texinfo
*** ./gas/doc/as.texinfo	Tue Apr 07 15:47:28 1998
--- /usr/bops-devel/binutils-2.9-bops/gas/doc/as.texinfo	Mon Feb 28
18:17:29 2000
***************
*** 1209,1215 ****
  file consists of a single rule suitable for @code{make} describing the
  dependencies of the main source file.
  
! The rule is written to the file named in its argument.
  
  This feature is used in the automatic updating of makefiles.
  
--- 1209,1216 ----
  file consists of a single rule suitable for @code{make} describing the
  dependencies of the main source file.
  
! The rule is written to the file named in its argument.  The special
argument
! @samp{-} means write to standard output.
  
  This feature is used in the automatic updating of makefiles.
  
diff -cbr ./gas/doc/gasp.texi
/usr/bops-devel/binutils-2.9-bops/gas/doc/gasp.texi
*** ./gas/doc/gasp.texi	Tue Apr 07 15:47:29 1998
--- /usr/bops-devel/binutils-2.9-bops/gas/doc/gasp.texi	Mon Feb 28 18:17:58
2000
***************
*** 168,173 ****
--- 168,174 ----
  gasp  [ -a | --alternate ]
        [ -c @var{char} | --commentchar @var{char} ]
        [ -d | --debug ]  [ -h | --help ] [ -M | --mri ]
+       --MD @var{depfile}
        [ -o @var{outfile} | --output @var{outfile} ]
        [ -p | --print ]  [ -s | --copysource ]
        [ -u | --unreasonable ]  [ -v | --version ]
***************
*** 233,238 ****
--- 234,252 ----
  Use MRI compatibility mode.  Using this option causes @sc{gasp} to
  accept the syntax and pseudo-ops used by the Microtec Research
  @code{ASM68K} assembler.
+ 
+ @item --MD @var{depfile}
+ @kindex --MD
+ @cindex dependency tracking
+ @cindex make rules
+ Generate a dependency file.  This file consists of a single rule
+ suitable for @code{make} describing the dependencies of the main source
+ file.
+ 
+ The rule is written to the file named in its argument.  The special
+ argument @samp{-} means write to standard output.
+ 
+ This feature is used in the automatic updating of makefiles.
  
  @item -o @var{outfile}
  @itemx --output @var{outfile}
diff -cbr ./gas/gasp.c /usr/bops-devel/binutils-2.9-bops/gas/gasp.c
*** ./gas/gasp.c	Tue Apr 07 15:47:32 1998
--- /usr/bops-devel/binutils-2.9-bops/gas/gasp.c	Mon Feb 28 18:12:30
2000
***************
*** 53,64 ****
--- 53,89 ----
  #include <stdio.h>
  #include <string.h>
  #include <getopt.h>
+ /* The first getopt value for long options.
+    150 isn't special; it's just an arbitrary non-ASCII char value.  */
+ #define OPTION_STD_BASE 150
+ 
  #include <ctype.h>
  
  #ifdef HAVE_STDLIB_H
  #include <stdlib.h>
  #endif
  
+ #ifdef HAVE_ERRNO_H
+ #include <errno.h>
+ #endif
+ 
+ #ifdef USE_STDARG
+ #include <stdarg.h>
+ #endif
+ 
+ #ifdef USE_VARARGS
+ #include <varargs.h>
+ #endif
+ 
+ #if !defined (USE_STDARG) && !defined (USE_VARARGS)
+ /* Roll our own.  */
+ #define va_alist REST
+ #define va_dcl
+ typedef int * va_list;
+ #define va_start(ARGS)	ARGS = &REST
+ #define va_end(ARGS)
+ #endif
+ 
  #ifdef NEED_MALLOC_DECLARATION
  extern char *malloc ();
  #endif
***************
*** 92,97 ****
--- 117,125 ----
  
  int had_end; /* Seen .END */
  
+ /* The name of the output file (NULL if stdout) */
+ char *out_file_name = 0;
+ 
  /* The output stream */
  FILE *outfile;
  
***************
*** 384,389 ****
--- 412,419 ----
  	  fprintf (stderr, "strings size %8d : %d\n", 1<<i,
string_count[i]);
  	}
      }
+   print_dependencies ();
    exit (exitcode);
  }
  
***************
*** 2890,2895 ****
--- 2920,2927 ----
    if (isp == MAX_INCLUDES)
      FATAL ((stderr, "Unreasonable include depth (%ld).\n", (long) isp));
  
+   register_dependency (name);
+   
    sp++;
    sp->handle = newone;
  
***************
*** 3547,3552 ****
--- 3581,3588 ----
    { "copysource", no_argument, 0, 's' },
    { "debug", no_argument, 0, 'd' },
    { "help", no_argument, 0, 'h' },
+ #define OPTION_DEPFILE (OPTION_STD_BASE)
+   { "MD", required_argument, NULL, OPTION_DEPFILE },
    { "mri", no_argument, 0, 'M' },
    { "output", required_argument, 0, 'o' },
    { "print", no_argument, 0, 'p' },
***************
*** 3569,3574 ****
--- 3605,3611 ----
    [-d]      [--debug]             print some debugging info\n\
    [-h]      [--help]              print this message\n\
    [-M]      [--mri]               enter MRI compatibility mode\n\
+             [--MD depfile]        write dependencies to depfile
    [-o out]  [--output out]        set the output file\n\
    [-p]      [--print]             print line numbers\n", program_name);
    fprintf (file, "\
***************
*** 3598,3604 ****
       char **argv;
  {
    int opt;
-   char *out_name = 0;
    sp = include_stack;
  
    ifstack[0].on = 1;
--- 3635,3640 ----
***************
*** 3622,3628 ****
        switch (opt)
  	{
  	case 'o':
! 	  out_name = optarg;
  	  break;
  	case 'u':
  	  unreasonable = 1;
--- 3658,3664 ----
        switch (opt)
  	{
  	case 'o':
! 	  out_file_name = optarg;
  	  break;
  	case 'u':
  	  unreasonable = 1;
***************
*** 3662,3667 ****
--- 3698,3706 ----
  	  mri = 1;
  	  comment_char = ';';
  	  break;
+ 	case OPTION_DEPFILE:
+ 	  start_dependencies (optarg);
+ 	  break;
  	case 'h':
  	  show_help ();
  	  /*NOTREACHED*/
***************
*** 3686,3697 ****
  
    macro_init (alternate, mri, 0, exp_get_abs);
  
!   if (out_name) {
!     outfile = fopen (out_name, "w");
      if (!outfile)
        {
  	fprintf (stderr, "%s: Can't open output file `%s'.\n",
! 		 program_name, out_name);
  	exit (1);
        }
    }
--- 3725,3736 ----
  
    macro_init (alternate, mri, 0, exp_get_abs);
  
!   if (out_file_name) {
!     outfile = fopen (out_file_name, "w");
      if (!outfile)
        {
  	fprintf (stderr, "%s: Can't open output file `%s'.\n",
! 		 program_name, out_file_name);
  	exit (1);
        }
    }
***************
*** 3738,3740 ****
--- 3777,3811 ----
    fprintf (stderr, "\nPlease report this bug.\n");
    exit (1);
  }
+ 
+ /* This function is used so that we can use depend.c without having to
+    use messages.c */
+ 
+ #ifdef USE_STDARG
+ void 
+ as_warn (const char *format,...)
+ {
+   va_list args;
+   char buffer[2000];
+ 
+   va_start (args, format);
+   vsprintf (buffer, format, args);
+   va_end (args);
+   WARNING ((stderr, buffer));
+ }				/* as_warn() */
+ #else
+ /*VARARGS1 */
+ void 
+ as_warn (format, va_alist)
+      const char *format;
+      va_dcl
+ {
+   va_list args;
+   char buffer[2000];
+ 
+   va_start (args);
+   vsprintf (buffer, format, args);
+   va_end (args);
+   WARNING ((stderr, buffer));
+ }				/* as_warn() */
+ #endif /* not NO_STDARG */
 

-- 
Geoff Berry


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