Module Name:    src
Committed By:   christos
Date:           Tue Mar  5 01:59:56 UTC 2013

Modified Files:
        src/usr.bin/mkdep: mkdep.1 mkdep.c

Log Message:
add -i and -v


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/mkdep/mkdep.1
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/mkdep/mkdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/mkdep/mkdep.1
diff -u src/usr.bin/mkdep/mkdep.1:1.17 src/usr.bin/mkdep/mkdep.1:1.18
--- src/usr.bin/mkdep/mkdep.1:1.17	Sun Aug 26 18:37:19 2012
+++ src/usr.bin/mkdep/mkdep.1	Mon Mar  4 20:59:56 2013
@@ -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 @@ depend files into a single file.
 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 @@ Expand each target filename to a list, r
 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

Index: src/usr.bin/mkdep/mkdep.c
diff -u src/usr.bin/mkdep/mkdep.c:1.41 src/usr.bin/mkdep/mkdep.c:1.42
--- src/usr.bin/mkdep/mkdep.c:1.41	Sun Aug 26 18:37:19 2012
+++ src/usr.bin/mkdep/mkdep.c	Mon Mar  4 20:59:56 2013
@@ -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 @@ typedef struct suff_list {
 /* 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 @@ __dead static void
 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 @@ run_cc(int argc, char **argv, const char
 	(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 @@ addsuff(suff_list_t **l, const char *s, 
 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 @@ main(int argc, char **argv)
 
 	aflag = O_WRONLY | O_APPEND | O_CREAT | O_TRUNC;
 	dflag = 0;
+	iflag = 0;
 	oflag = 0;
 	qflag = 0;
 	filename = DEFAULT_FILENAME;
@@ -237,7 +246,7 @@ main(int argc, char **argv)
 	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 @@ main(int argc, char **argv)
 		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 @@ main(int argc, char **argv)
 		case 's':	/* Suffix list */
 			suffixes = optarg;
 			continue;
+		case 'v':
+			verbose = 1;
+			continue;
 		default:
 			if (dflag)
 				usage();
@@ -302,8 +317,7 @@ main(int argc, char **argv)
 
 	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 @@ main(int argc, char **argv)
 					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 @@ main(int argc, char **argv)
 			}
 			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 @@ main(int argc, char **argv)
 				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 @@ main(int argc, char **argv)
 	}
 
 	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 @@ save_for_optional(const char *start, con
 	}
 }
 
-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;

Reply via email to