Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Add :tA to attempt to resolve to absoute path u...



details:   https://anonhg.NetBSD.org/src/rev/1aa31d1d7242
branches:  trunk
changeset: 753984:1aa31d1d7242
user:      sjg <sjg%NetBSD.org@localhost>
date:      Thu Apr 15 03:48:39 2010 +0000

description:
Add :tA to attempt to resolve to absoute path using realpath().

diffstat:

 usr.bin/make/make.1 |   9 +++++++--
 usr.bin/make/var.c  |  39 +++++++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 6 deletions(-)

diffs (110 lines):

diff -r 8db375cbe6b4 -r 1aa31d1d7242 usr.bin/make/make.1
--- a/usr.bin/make/make.1       Thu Apr 15 03:36:18 2010 +0000
+++ b/usr.bin/make/make.1       Thu Apr 15 03:48:39 2010 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: make.1,v 1.169 2010/04/07 06:45:21 wiz Exp $
+.\"    $NetBSD: make.1,v 1.170 2010/04/15 03:48:39 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    from: @(#)make.1        8.4 (Berkeley) 3/19/94
 .\"
-.Dd April 6, 2010
+.Dd April 14, 2010
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -945,6 +945,10 @@
 .Nm .
 .It Cm \&:R
 Replaces each word in the variable with everything but its suffix.
+.It Cm \&:tA
+Attempt to convert variable to an absolute path using
+.Xr realpath 3 ,
+if that fails, the value is unchanged.
 .It Cm \&:tl
 Converts variable to lower-case letters.
 .It Cm \&:ts Ns Ar c
@@ -954,6 +958,7 @@
 If
 .Ar c
 is omitted, then no separator is used.
+The common escapes (including octal numeric codes), work as expected.
 .It Cm \&:tu
 Converts variable to upper-case letters.
 .It Cm \&:tW
diff -r 8db375cbe6b4 -r 1aa31d1d7242 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Thu Apr 15 03:36:18 2010 +0000
+++ b/usr.bin/make/var.c        Thu Apr 15 03:48:39 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.155 2009/11/19 00:30:25 sjg Exp $    */
+/*     $NetBSD: var.c,v 1.156 2010/04/15 03:48:39 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.155 2009/11/19 00:30:25 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.156 2010/04/15 03:48:39 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.155 2009/11/19 00:30:25 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.156 2010/04/15 03:48:39 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1859,6 +1859,32 @@
     return Buf_Destroy(&buf, FALSE);
 }
 
+
+/*-
+ * VarRealpath --
+ *     Replace each word with the result of realpath()
+ *     if successful.
+ */
+static Boolean
+VarRealpath(GNode *ctx __unused, Var_Parse_State *vpstate,
+           char *word, Boolean addSpace, Buffer *buf,
+           void *patternp __unused)
+{
+       char rbuf[MAXPATHLEN];
+       char *rp;
+                           
+       if (addSpace && vpstate->varSpace) {
+           Buf_AddByte(buf, vpstate->varSpace);
+       }
+       addSpace = TRUE;
+       rp = realpath(word, rbuf);
+       if (rp && *rp == '/')
+               word = rp;
+       
+       Buf_AddBytes(buf, strlen(word), word);
+       return(addSpace);
+}
+
 /*-
  *-----------------------------------------------------------------------
  * VarModify --
@@ -2849,7 +2875,12 @@
                         * Check for two-character options:
                         * ":tu", ":tl"
                         */
-                       if (tstr[1] == 'u' || tstr[1] == 'l') {
+                       if (tstr[1] == 'A') { /* absolute path */
+                           newStr = VarModify(ctxt, &parsestate, nstr,
+                                              VarRealpath, NULL);
+                           cp = tstr + 2;
+                           termc = *cp;
+                       } else if (tstr[1] == 'u' || tstr[1] == 'l') {
                            newStr = VarChangeCase(nstr, (tstr[1] == 'u'));
                            cp = tstr + 2;
                            termc = *cp;



Home | Main Index | Thread Index | Old Index