Module Name:    src
Committed By:   jmmv
Date:           Sun Aug 26 22:37:19 UTC 2012

Modified Files:
        src/doc: CHANGES
        src/tests/usr.bin/mkdep: t_mkdep.sh
        src/tools/host-mkdep: host-mkdep.in
        src/usr.bin/mkdep: mkdep.1 mkdep.c

Log Message:
Add a new "-P prefix" option to mkdep(1).

This option prepends the string given in prefix to every target
filename.  This is useful for programs that have source files in
multiple subdirectories and a single Makefile that references all of
them explicitly (without using the VPATH functionality because there
can be files with the same name in each subdirectory).


To generate a diff of this commit:
cvs rdiff -u -r1.1738 -r1.1739 src/doc/CHANGES
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/mkdep/t_mkdep.sh
cvs rdiff -u -r1.20 -r1.21 src/tools/host-mkdep/host-mkdep.in
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/mkdep/mkdep.1
cvs rdiff -u -r1.40 -r1.41 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/doc/CHANGES
diff -u src/doc/CHANGES:1.1738 src/doc/CHANGES:1.1739
--- src/doc/CHANGES:1.1738	Sun Aug 26 12:30:33 2012
+++ src/doc/CHANGES	Sun Aug 26 22:37:19 2012
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.1738 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.1739 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -106,3 +106,4 @@ Changes from NetBSD 6.0 to NetBSD 7.0:
 	mfi(8): Added tagged queuing support.  [bouyer 20120823]
 	mfi(8): Added support for LSI SAS2208-based controllers.
 		[bouyer 20120823]
+	mkdep(1): Add -P option.  [jmmv 20120826]

Index: src/tests/usr.bin/mkdep/t_mkdep.sh
diff -u src/tests/usr.bin/mkdep/t_mkdep.sh:1.3 src/tests/usr.bin/mkdep/t_mkdep.sh:1.4
--- src/tests/usr.bin/mkdep/t_mkdep.sh:1.3	Tue Jun 14 11:44:25 2011
+++ src/tests/usr.bin/mkdep/t_mkdep.sh	Sun Aug 26 22:37:19 2012
@@ -1,4 +1,4 @@
-# $NetBSD: t_mkdep.sh,v 1.3 2011/06/14 11:44:25 njoly Exp $
+# $NetBSD: t_mkdep.sh,v 1.4 2012/08/26 22:37:19 jmmv Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -28,12 +28,24 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+atf_test_case prefix
+prefix_head() {
+	atf_set "descr" "Test adding a prefix to a single target"
+	atf_set "require.progs" "mkdep cc"
+}
+prefix_body() {
+
+	atf_check touch sample.c
+
+	atf_check mkdep -f sample.d -P some/path/ sample.c
+	atf_check -o ignore grep '^some/path/sample.o:' sample.d
+}
+
 atf_test_case suffixes
 suffixes_head() {
 	atf_set "descr" "Test suffixes list"
 	atf_set "require.progs" "mkdep cc"
 }
-
 suffixes_body() {
 
 	atf_check touch sample.c
@@ -51,6 +63,21 @@ suffixes_body() {
 	atf_check -o ignore grep '^sample:' sample.d
 }
 
+atf_test_case prefix_and_suffixes
+prefix_and_suffixes_head() {
+	atf_set "descr" "Test the combination of a prefix and suffixes"
+	atf_set "require.progs" "mkdep cc"
+}
+prefix_and_suffixes_body() {
+
+	atf_check touch sample.c
+
+	atf_check mkdep -f sample.d -s '.a .b' -P c/d sample.c
+	atf_check -o ignore grep '^c/dsample.b c/dsample.a:' sample.d
+}
+
 atf_init_test_cases() {
+	atf_add_test_case prefix
 	atf_add_test_case suffixes
+	atf_add_test_case prefix_and_suffixes
 }

Index: src/tools/host-mkdep/host-mkdep.in
diff -u src/tools/host-mkdep/host-mkdep.in:1.20 src/tools/host-mkdep/host-mkdep.in:1.21
--- src/tools/host-mkdep/host-mkdep.in:1.20	Thu Jun 30 20:09:41 2011
+++ src/tools/host-mkdep/host-mkdep.in	Sun Aug 26 22:37:19 2012
@@ -1,6 +1,6 @@
 #!@BSHELL@ -
 #
-#	$NetBSD: host-mkdep.in,v 1.20 2011/06/30 20:09:41 wiz Exp $
+#	$NetBSD: host-mkdep.in,v 1.21 2012/08/26 22:37:19 jmmv Exp $
 #
 # Copyright (c) 1991, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -43,6 +43,7 @@ AWK_OPTIONAL=
 QUIET=false
 CPPFLAGS=
 NEWEXT=.o
+PREFIX=
 OUTFILE=.depend
 SRCS=
 
@@ -61,10 +62,10 @@ set_objlist()
 		IFS="$oifs"
 		objlist=
 		for suf in "$@"; do
-			objlist="$objlist${objlist:+ }$file$suf"
+			objlist="$objlist${objlist:+ }$PREFIX$file$suf"
 		done
 	else
-		objlist="$file"
+		objlist="$PREFIX$file"
 	fi
 }
 
@@ -84,7 +85,7 @@ while [ $# -gt 0 ]; do
 		-p)	NEWEXT=;;
 		-q)	QUIET=true;;
 
-		-[fs])	# Options with arguments
+		-[fPs])	# Options with arguments
 			[ -z "$optarg" ] && {
 				[ $# = 1 ] && usage
 				shift
@@ -92,6 +93,7 @@ while [ $# -gt 0 ]; do
 			}
 			case "-$option" in
 			-f)	OUTFILE="$optarg";;
+			-P)	PREFIX="$optarg";;
 			-s)	NEWEXT="$optarg";;
 			esac
 			optarg=

Index: src/usr.bin/mkdep/mkdep.1
diff -u src/usr.bin/mkdep/mkdep.1:1.16 src/usr.bin/mkdep/mkdep.1:1.17
--- src/usr.bin/mkdep/mkdep.1:1.16	Thu Jun 30 20:09:42 2011
+++ src/usr.bin/mkdep/mkdep.1	Sun Aug 26 22:37:19 2012
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mkdep.1,v 1.16 2011/06/30 20:09:42 wiz Exp $
+.\"	$NetBSD: mkdep.1,v 1.17 2012/08/26 22:37:19 jmmv 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 October 15, 2010
+.Dd August 26, 2012
 .Dt MKDEP 1
 .Os
 .Sh NAME
@@ -39,6 +39,7 @@
 .Nm
 .Op Fl aDdopq
 .Op Fl f Ar file
+.Op Fl P Ar prefix
 .Op Fl s Ar suffixes
 .Li --
 .Op Ar flags
@@ -81,6 +82,14 @@ Write the include file dependencies to
 instead of the default ``.depend''.
 .It Fl o
 Add an additional .OPTIONAL line for each dependent file.
+.It Fl P
+Prepend the string given in
+.Ar prefix
+to every target filename.
+This is useful for programs that have source files in multiple subdirectories
+and a single Makefile that references all of them explicitly (without using
+the VPATH functionality because there can be files with the same name in
+each subdirectory).
 .It Fl p
 Cause
 .Nm

Index: src/usr.bin/mkdep/mkdep.c
diff -u src/usr.bin/mkdep/mkdep.c:1.40 src/usr.bin/mkdep/mkdep.c:1.41
--- src/usr.bin/mkdep/mkdep.c:1.40	Sun Sep  4 20:30:06 2011
+++ src/usr.bin/mkdep/mkdep.c	Sun Aug 26 22:37:19 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdep.c,v 1.40 2011/09/04 20:30:06 joerg Exp $ */
+/* $NetBSD: mkdep.c,v 1.41 2012/08/26 22:37:19 jmmv 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.40 2011/09/04 20:30:06 joerg Exp $");
+__RCSID("$NetBSD: mkdep.c,v 1.41 2012/08/26 22:37:19 jmmv Exp $");
 #endif /* not lint */
 
 #include <sys/mman.h>
@@ -91,7 +91,8 @@ __dead static void
 usage(void)
 {
 	(void)fprintf(stderr,
-	    "usage: %s [-aDdopq] [-f file] [-s suffixes] -- [flags] file ...\n",
+	    "usage: %s [-aDdopq] [-f file] [-P prefix] [-s suffixes] "
+	    "-- [flags] file ...\n",
 	    getprogname());
 	exit(EXIT_FAILURE);
 }
@@ -216,6 +217,7 @@ main(int argc, char **argv)
 	int	fd;
 	size_t  slen;
 	const char *fname;
+	const char *prefix = NULL;
 	const char *suffixes = NULL, *s;
 	suff_list_t *suff_list = NULL, *sl;
 
@@ -235,7 +237,7 @@ main(int argc, char **argv)
 	opterr = 0;	/* stop getopt() bleating about errors. */
 	for (;;) {
 		ok_ind = optind;
-		ch = getopt_long(argc, argv, "aDdf:opqRs:", longopt, NULL);
+		ch = getopt_long(argc, argv, "aDdf:oP:pqRs:", longopt, NULL);
 		switch (ch) {
 		case -1:
 			ok_ind = optind;
@@ -257,6 +259,9 @@ main(int argc, char **argv)
 		case 'o':	/* Mark dependent files .OPTIONAL */
 			oflag = 1;
 			continue;
+		case 'P':	/* Prefix for each target filename */
+			prefix = optarg;
+			continue;
 		case 'p':	/* Program mode (x.o: -> x:) */
 			suffixes = "";
 			continue;
@@ -401,12 +406,18 @@ main(int argc, char **argv)
 				{
 					if (sl != suff_list)
 						write(dependfile, " ", 1);
+					if (prefix != NULL)
+						write(dependfile, prefix,
+						    strlen(prefix));
 					write(dependfile, line, suf - line);
 					write(dependfile, sl->suff, sl->len);
 				}
 				write(dependfile, colon, eol - colon);
-			} else
+			} else {
+				if (prefix != NULL)
+					write(dependfile, prefix, strlen(prefix));
 				write(dependfile, line, eol - line);
+			}
 
 			if (oflag)
 				save_for_optional(colon + 1, eol);

Reply via email to