Add :Q to quote variable expansion to all proper expansion of

variables for recursive makes.  This makes it less painful to cross
build recent NetBSD kernels on FreeBSD.

Obtained from: NetBSD
This commit is contained in:
Warner Losh 1999-04-19 07:30:04 +00:00
parent 59d615f8c7
commit ab898e2ec9
2 changed files with 49 additions and 2 deletions

View file

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\" $Id: make.1,v 1.15 1998/11/15 05:51:55 bde Exp $
.\" $Id: make.1,v 1.16 1998/11/29 13:46:39 pds Exp $
.\"
.Dd March 19, 1994
.Dt MAKE 1
@ -488,6 +488,10 @@ This is identical to
.Ql Cm M ,
but selects all words which do not match
the rest of the modifier.
.It Cm Q
Quotes every shell meta-character in the variable, so that it can be passed
safely through recursive invocations of
.Nm make .
.It Cm R
Replaces each word in the variable with everything but its suffix.
.Sm off

View file

@ -35,7 +35,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: var.c,v 1.10 1997/09/29 03:53:53 imp Exp $
* $Id: var.c,v 1.11 1998/06/02 13:11:04 thepish Exp $
*/
#ifndef lint
@ -166,6 +166,7 @@ static Boolean VarSYSVMatch __P((char *, Boolean, Buffer, ClientData));
#endif
static Boolean VarNoMatch __P((char *, Boolean, Buffer, ClientData));
static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData));
static char *VarQuote __P((char *));
static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer,
ClientData),
ClientData));
@ -1070,6 +1071,40 @@ VarModify (str, modProc, datum)
return (str);
}
/*-
*-----------------------------------------------------------------------
* VarQuote --
* Quote shell meta-characters in the string
*
* Results:
* The quoted string
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
static char *
VarQuote(str)
char *str;
{
Buffer buf;
/* This should cover most shells :-( */
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
buf = Buf_Init (MAKE_BSIZE);
for (; *str; str++) {
if (strchr(meta, *str) != NULL)
Buf_AddByte(buf, (Byte)'\\');
Buf_AddByte(buf, (Byte)*str);
}
Buf_AddByte(buf, (Byte) '\0');
str = (char *)Buf_GetAll (buf, (int *)NULL);
Buf_Destroy (buf, FALSE);
return str;
}
/*-
*-----------------------------------------------------------------------
* Var_Parse --
@ -1613,6 +1648,14 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
free(pattern.rhs);
break;
}
case 'Q':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarQuote (str);
cp = tstr + 1;
termc = *cp;
break;
}
/*FALLTHRU*/
case 'T':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarModify (str, VarTail, (ClientData)0);