From a4063c43b43c6e712f7e75586440adbee08868a7 Mon Sep 17 00:00:00 2001 From: Max Okumoto Date: Thu, 16 Dec 2004 21:28:28 +0000 Subject: [PATCH] Change the algorithm that matches the builtin shells from the name keyword of the .SHELL target. Formerly it used to select the shell with the longest common trailing substring, so that bash would select sh, but pocsh would select csh. Now an exact match is required so that specifying bash without also giving a path and the other keywords will give an error. Taken-from: FreeBSD Author: harti --- usr.bin/make/job.c | 50 +++++++------------- usr.bin/make/make.1 | 112 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 127 insertions(+), 35 deletions(-) diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index b290a23e99..ca0d1e87ff 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -38,7 +38,7 @@ * * @(#)job.c 8.2 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/job.c,v 1.17.2.2 2001/02/13 03:13:57 will Exp $ - * $DragonFly: src/usr.bin/make/job.c,v 1.27 2004/12/16 00:17:05 okumoto Exp $ + * $DragonFly: src/usr.bin/make/job.c,v 1.28 2004/12/16 21:28:28 okumoto Exp $ */ #ifndef OLD_JOKE @@ -2388,7 +2388,7 @@ Job_Empty(void) * Find a matching shell in 'shells' given its final component. * * Results: - * A pointer to a freshly allocated Shell structure with is a copy + * A pointer to a freshly allocated Shell structure with a copy * of the static structure or NULL if no shell with the given name * is found. * @@ -2401,45 +2401,29 @@ static Shell * JobMatchShell(const char *name) { const struct CShell *sh; /* Pointer into shells table */ - const struct CShell *match; /* Longest-matching shell */ struct Shell *nsh; - const char *cp1; - const char *cp2; - const char *eoname; - eoname = name + strlen(name); - - match = NULL; + for (sh = shells; sh < shells + __arysize(shells); sh++) + if (strcmp(sh->name, name) == 0) + break; - for (sh = shells; sh < shells + __arysize(shells); sh++) { - for (cp1 = eoname - strlen(sh->name), cp2 = sh->name; - *cp1 != '\0' && *cp1 == *cp2; - cp1++, cp2++) { - continue; - } - if (*cp1 != *cp2) { - continue; - } else if (match == NULL || strlen(match->name) < strlen(sh->name)) { - match = sh; - } - } - if (match == NULL) + if (sh == shells + sizeof(shells) / sizeof(shells[0])) return (NULL); /* make a copy */ nsh = emalloc(sizeof(*nsh)); - nsh->name = estrdup(match->name); - nsh->echoOff = estrdup(match->echoOff); - nsh->echoOn = estrdup(match->echoOn); - nsh->hasEchoCtl = match->hasEchoCtl; - nsh->noPrint = estrdup(match->noPrint); - nsh->noPLen = match->noPLen; - nsh->hasErrCtl = match->hasErrCtl; - nsh->errCheck = estrdup(match->errCheck); - nsh->ignErr = estrdup(match->ignErr); - nsh->echo = estrdup(match->echo); - nsh->exit = estrdup(match->exit); + nsh->name = estrdup(sh->name); + nsh->echoOff = estrdup(sh->echoOff); + nsh->echoOn = estrdup(sh->echoOn); + nsh->hasEchoCtl = sh->hasEchoCtl; + nsh->noPrint = estrdup(sh->noPrint); + nsh->noPLen = sh->noPLen; + nsh->hasErrCtl = sh->hasErrCtl; + nsh->errCheck = estrdup(sh->errCheck); + nsh->ignErr = estrdup(sh->ignErr); + nsh->echo = estrdup(sh->echo); + nsh->exit = estrdup(sh->exit); return (nsh); } diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index 8b9dcf0b6e..20d65c9cd2 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -31,9 +31,9 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" $FreeBSD: src/usr.bin/make/make.1,v 1.29.2.15 2002/12/17 19:01:18 seanc Exp $ -.\" $DragonFly: src/usr.bin/make/make.1,v 1.17 2004/12/10 00:41:06 okumoto Exp $ +.\" $DragonFly: src/usr.bin/make/make.1,v 1.18 2004/12/16 21:28:28 okumoto Exp $ .\" -.Dd August 18, 2004 +.Dd December 2, 2004 .Dt MAKE 1 .Os .Sh NAME @@ -1228,6 +1228,114 @@ If no sources are specified, the .Ic .PRECIOUS attribute is applied to every target in the file. +.It Ic .SHELL +Select another shell. +The sources of this target have the format +.Ar key Ns = Ns Ar value . +The +.Ar key +is one of: +.Bl -tag -width ".Va hasErrCtl" +.It Va path +Specify the path to the new shell. +.It Va name +Specify the name of the new shell. +This may be either one of the three builtin shells (see below) or any +other name. +.It Va quiet +Specify the shell command to turn echoing off. +.It Va echo +Specify the shell command to turn echoing on. +.It Va filter +Usually shells print the echo off command before turning echoing off. +This is the exact string that will be printed by the shell and is used +to filter the shell output to remove the echo off command. +.It Va echoFlag +The shell option that turns echoing on. +.It Va errFlag +The shell option to turn on error checking. +If error checking is on, the shell should exit if a command returns +a non-zero status. +.It Va hasErrCtl +True if the shell has error control. +.It Va check +If +.Va hasErrCtl +is true then this is the shell command to turn error checking on. +If +.Va hasErrCtl +is false then this is a command template to echo commands for which error +checking is disabled. +The template must contain a +.Ql %s . +.It Va ignore +If +.Va hasErrCtl +is true, this is the shell command to turn error checking off. +If +.Va hasErrCtl +is false, this is a command template to execute a command so that errors +are ignored. +The template must contain a +.Ql %s . +.El +.Pp +Values that are strings must be surrounded by double quotes. +Boolean values are specified as +.Ql T +or +.Ql Y +(in either case) to mean true. +Any other value is taken to mean false. +.Pp +There are several uses of the +.Ic .SHELL +target: +.Bl -bullet +.It +Selecting one of the builtin shells. +This is done by just specifying the name of the shell with the +.Va name +keyword. +It is also possible to modify the parameters of the builtin shell by just +specifying other keywords (except for +.Va path ) . +.It +Using another executable for one of the builtin shells. +This is done by specifying the path to the executable with the +.Va path +keyword. +If the last component is the same as the name of the builtin shell, no +name needs to be specified; if it is different, the name must be given: +.Bd -literal -offset indent +\&.SHELL: path="/usr/local/bin/sh" +.Ed +.Pp +selects the builtin shell +.Dq Li sh +but will execute it from +.Pa /usr/local/bin/sh . +Like in the previous case, it is possible to modify parameters of the builtin +shell by just specifying them. +.It +Using an entirely different shell. +This is done by specifying all keywords. +.El +.Pp +The builtin shells are +.Dq Li sh , +.Dq Li csh +and +.Dq Li ksh . +Because +.Fx +has no +.Nm ksh +in +.Pa /bin , +it is unwise to specify +.Va name Ns = Ns Qq Li ksh +without also specifying a path. .It Ic .SILENT Apply the .Ic .SILENT -- 2.41.0