Source-Changes-HG archive

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

[src/trunk]: src Add a new "-P prefix" option to mkdep(1).



details:   https://anonhg.NetBSD.org/src/rev/91ec868446f7
branches:  trunk
changeset: 781209:91ec868446f7
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Sun Aug 26 22:37:19 2012 +0000

description:
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).

diffstat:

 doc/CHANGES                    |   3 ++-
 tests/usr.bin/mkdep/t_mkdep.sh |  31 +++++++++++++++++++++++++++++--
 tools/host-mkdep/host-mkdep.in |  10 ++++++----
 usr.bin/mkdep/mkdep.1          |  13 +++++++++++--
 usr.bin/mkdep/mkdep.c          |  21 ++++++++++++++++-----
 5 files changed, 64 insertions(+), 14 deletions(-)

diffs (236 lines):

diff -r c273652132bc -r 91ec868446f7 doc/CHANGES
--- a/doc/CHANGES       Sun Aug 26 16:22:32 2012 +0000
+++ b/doc/CHANGES       Sun Aug 26 22:37:19 2012 +0000
@@ -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 @@
        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]
diff -r c273652132bc -r 91ec868446f7 tests/usr.bin/mkdep/t_mkdep.sh
--- a/tests/usr.bin/mkdep/t_mkdep.sh    Sun Aug 26 16:22:32 2012 +0000
+++ b/tests/usr.bin/mkdep/t_mkdep.sh    Sun Aug 26 22:37:19 2012 +0000
@@ -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 @@
        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
 }
diff -r c273652132bc -r 91ec868446f7 tools/host-mkdep/host-mkdep.in
--- a/tools/host-mkdep/host-mkdep.in    Sun Aug 26 16:22:32 2012 +0000
+++ b/tools/host-mkdep/host-mkdep.in    Sun Aug 26 22:37:19 2012 +0000
@@ -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 @@
 QUIET=false
 CPPFLAGS=
 NEWEXT=.o
+PREFIX=
 OUTFILE=.depend
 SRCS=
 
@@ -61,10 +62,10 @@
                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 @@
                -p)     NEWEXT=;;
                -q)     QUIET=true;;
 
-               -[fs])  # Options with arguments
+               -[fPs]) # Options with arguments
                        [ -z "$optarg" ] && {
                                [ $# = 1 ] && usage
                                shift
@@ -92,6 +93,7 @@
                        }
                        case "-$option" in
                        -f)     OUTFILE="$optarg";;
+                       -P)     PREFIX="$optarg";;
                        -s)     NEWEXT="$optarg";;
                        esac
                        optarg=
diff -r c273652132bc -r 91ec868446f7 usr.bin/mkdep/mkdep.1
--- a/usr.bin/mkdep/mkdep.1     Sun Aug 26 16:22:32 2012 +0000
+++ b/usr.bin/mkdep/mkdep.1     Sun Aug 26 22:37:19 2012 +0000
@@ -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 @@
 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
diff -r c273652132bc -r 91ec868446f7 usr.bin/mkdep/mkdep.c
--- a/usr.bin/mkdep/mkdep.c     Sun Aug 26 16:22:32 2012 +0000
+++ b/usr.bin/mkdep/mkdep.c     Sun Aug 26 22:37:19 2012 +0000
@@ -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 @@
 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 @@
        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 @@
        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 @@
                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 @@
                                {
                                        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);



Home | Main Index | Thread Index | Old Index