Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/mkdep add -i and -v



details:   https://anonhg.NetBSD.org/src/rev/62c4a652b9d0
branches:  trunk
changeset: 785224:62c4a652b9d0
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Mar 05 01:59:56 2013 +0000

description:
add -i and -v

diffstat:

 usr.bin/mkdep/mkdep.1 |  15 +++++++-
 usr.bin/mkdep/mkdep.c |  86 +++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 75 insertions(+), 26 deletions(-)

diffs (273 lines):

diff -r ba02680ec893 -r 62c4a652b9d0 usr.bin/mkdep/mkdep.1
--- a/usr.bin/mkdep/mkdep.1     Mon Mar 04 23:12:52 2013 +0000
+++ b/usr.bin/mkdep/mkdep.1     Tue Mar 05 01:59:56 2013 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mkdep.1,v 1.17 2012/08/26 22:37:19 jmmv Exp $
+.\"    $NetBSD: mkdep.1,v 1.18 2013/03/05 01:59:56 christos Exp $
 .\"
 .\" Copyright (c) 1987, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)mkdep.1    8.1 (Berkeley) 6/6/93
 .\"
-.Dd August 26, 2012
+.Dd March 4, 2013
 .Dt MKDEP 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd construct Makefile dependency list
 .Sh SYNOPSIS
 .Nm
-.Op Fl aDdopq
+.Op Fl aDdiopqv
 .Op Fl f Ar file
 .Op Fl P Ar prefix
 .Op Fl s Ar suffixes
@@ -80,6 +80,13 @@
 Write the include file dependencies to
 .Ar file ,
 instead of the default ``.depend''.
+.It Fl i
+When
+.Fl d
+or
+.Fl D
+is used, instead of inlining the contents of the files to the resulting
+depend file, use include statements to include the source dependency files.
 .It Fl o
 Add an additional .OPTIONAL line for each dependent file.
 .It Fl P
@@ -118,6 +125,8 @@
 suffix with each element of
 .Ar suffixes .
 The list of suffixes may be space or comma separated.
+.It Fl v
+print debugging output.
 .El
 .Sh FILES
 .Bl -tag -width .depend -compact
diff -r ba02680ec893 -r 62c4a652b9d0 usr.bin/mkdep/mkdep.c
--- a/usr.bin/mkdep/mkdep.c     Mon Mar 04 23:12:52 2013 +0000
+++ b/usr.bin/mkdep/mkdep.c     Tue Mar 05 01:59:56 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdep.c,v 1.41 2012/08/26 22:37:19 jmmv Exp $ */
+/* $NetBSD: mkdep.c,v 1.42 2013/03/05 01:59:56 christos Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 #if !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\
  All rights reserved.");
-__RCSID("$NetBSD: mkdep.c,v 1.41 2012/08/26 22:37:19 jmmv Exp $");
+__RCSID("$NetBSD: mkdep.c,v 1.42 2013/03/05 01:59:56 christos Exp $");
 #endif /* not lint */
 
 #include <sys/mman.h>
@@ -74,12 +74,13 @@
 /* tree of includes for -o processing */
 static opt_t *opt;
 static int width;
+static int verbose;
 
 #define DEFAULT_PATH           _PATH_DEFPATH
 #define DEFAULT_FILENAME       ".depend"
 
 static void save_for_optional(const char *, const char *);
-static int write_optional(int, opt_t *, int);
+static size_t write_optional(int, opt_t *, size_t);
 
 static inline void *
 deconst(const void *p)
@@ -91,7 +92,7 @@
 usage(void)
 {
        (void)fprintf(stderr,
-           "usage: %s [-aDdopq] [-f file] [-P prefix] [-s suffixes] "
+           "usage: %s [-aDdiopqv] [-f file] [-P prefix] [-s suffixes] "
            "-- [flags] file ...\n",
            getprogname());
        exit(EXIT_FAILURE);
@@ -132,6 +133,13 @@
        (void)unlink(tmpfilename);
        *fname = tmpfilename;
 
+       if (verbose) {
+               char **a;
+               for (a = args; *a; a++)
+                       printf("%s ", *a);
+               printf("\n");
+       }
+
        switch (cpid = vfork()) {
        case 0:
                (void)dup2(tmpfd, STDOUT_FILENO);
@@ -208,7 +216,7 @@
 int
 main(int argc, char **argv)
 {
-       int     aflag, dflag, oflag, qflag;
+       int     aflag, dflag, iflag, oflag, qflag;
        const char *filename;
        int     dependfile;
        char    *buf, *lim, *ptr, *line, *suf, *colon, *eol;
@@ -229,6 +237,7 @@
 
        aflag = O_WRONLY | O_APPEND | O_CREAT | O_TRUNC;
        dflag = 0;
+       iflag = 0;
        oflag = 0;
        qflag = 0;
        filename = DEFAULT_FILENAME;
@@ -237,7 +246,7 @@
        opterr = 0;     /* stop getopt() bleating about errors. */
        for (;;) {
                ok_ind = optind;
-               ch = getopt_long(argc, argv, "aDdf:oP:pqRs:", longopt, NULL);
+               ch = getopt_long(argc, argv, "aDdf:ioP:pqRs:v", longopt, NULL);
                switch (ch) {
                case -1:
                        ok_ind = optind;
@@ -256,6 +265,9 @@
                case 'f':       /* Name of output file */
                        filename = optarg;
                        continue;
+               case 'i':
+                       iflag = 1;
+                       continue;
                case 'o':       /* Mark dependent files .OPTIONAL */
                        oflag = 1;
                        continue;
@@ -274,6 +286,9 @@
                case 's':       /* Suffix list */
                        suffixes = optarg;
                        continue;
+               case 'v':
+                       verbose = 1;
+                       continue;
                default:
                        if (dflag)
                                usage();
@@ -302,8 +317,7 @@
 
        dependfile = open(filename, aflag, 0666);
        if (dependfile == -1)
-               err(EXIT_FAILURE, "unable to %s to file %s\n",
-                   aflag & O_TRUNC ? "write" : "append", filename);
+               goto wrerror;
 
        while (dflag == 2 || *argv != NULL) {
                if (dflag) {
@@ -313,6 +327,12 @@
                                        break;
                        } else
                                fname = *argv++;
+                       if (iflag) {
+                               if (dprintf(dependfile, ".include \"%s\"\n",
+                                   fname) < 0)
+                                       goto wrerror;
+                               continue;
+                       }
                        fd = open(fname, O_RDONLY, 0);
                        if (fd == -1) {
                                if (!qflag)
@@ -366,7 +386,8 @@
                        }
                        if (isspace((unsigned char)*line) || colon == NULL) {
                                /* No dependency - just transcribe line */
-                               write(dependfile, line, eol - line);
+                               if (write(dependfile, line, eol - line) < 0)
+                                       goto wrerror;
                                line = eol;
                                continue;
                        }
@@ -405,18 +426,29 @@
                                for (sl = suff_list; sl != NULL; sl = sl->next)
                                {
                                        if (sl != suff_list)
-                                               write(dependfile, " ", 1);
+                                               if (write(dependfile, " ", 1)
+                                                   < 0)
+                                                       goto wrerror;
                                        if (prefix != NULL)
-                                               write(dependfile, prefix,
-                                                   strlen(prefix));
-                                       write(dependfile, line, suf - line);
-                                       write(dependfile, sl->suff, sl->len);
+                                               if (write(dependfile, prefix,
+                                                   strlen(prefix)) < 0)
+                                                       goto wrerror;
+                                       if (write(dependfile, line,
+                                           suf - line) < 0)
+                                               goto wrerror;
+                                       if (write(dependfile, sl->suff,
+                                           sl->len) < 0)
+                                               goto wrerror;
                                }
-                               write(dependfile, colon, eol - colon);
+                               if (write(dependfile, colon, eol - colon) < 0)
+                                       goto wrerror;
                        } else {
                                if (prefix != NULL)
-                                       write(dependfile, prefix, strlen(prefix));
-                               write(dependfile, line, eol - line);
+                                       if (write(dependfile, prefix,
+                                           strlen(prefix)) < 0)
+                                               goto wrerror;
+                               if (write(dependfile, line, eol - line) < 0)
+                                       goto wrerror;
                        }
 
                        if (oflag)
@@ -427,15 +459,21 @@
        }
 
        if (oflag && opt != NULL) {
-               write(dependfile, ".OPTIONAL:", 10);
+               if (write(dependfile, ".OPTIONAL:", 10) < 0)
+                       goto wrerror;
                width = 9;
                sz = write_optional(dependfile, opt, 0);
+               if (sz == (size_t)-1)
+                       goto wrerror;
                /* 'depth' is about 39 for an i386 kernel */
                /* fprintf(stderr, "Recursion depth %d\n", sz); */
        }
        close(dependfile);
 
        exit(EXIT_SUCCESS);
+wrerror:
+       err(EXIT_FAILURE, "unable to %s to file %s\n",
+           aflag & O_TRUNC ? "write" : "append", filename);
 }
 
 
@@ -492,19 +530,21 @@
        }
 }
 
-static int
-write_optional(int fd, opt_t *node, int depth)
+static size_t
+write_optional(int fd, opt_t *node, size_t depth)
 {
-       int d1 = ++depth;
+       size_t d1 = ++depth;
 
        if (node->left)
                d1 = write_optional(fd, node->left, d1);
        if (width > 76 - node->len) {
-               write(fd, " \\\n ", 4);
+               if (write(fd, " \\\n ", 4) < 0)
+                       return (size_t)-1;
                width = 1;
        }
        width += 1 + node->len;
-       write(fd, node->name, 1 + node->len);
+       if (write(fd, node->name, 1 + node->len) < 0)
+               return (size_t)-1;
        if (node->right)
                depth = write_optional(fd, node->right, depth);
        return d1 > depth ? d1 : depth;



Home | Main Index | Thread Index | Old Index