Allow .SHELL: to control the shell used by compat mode too.

Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
This commit is contained in:
sjg 2003-08-01 00:39:52 +00:00
parent 1a4743265a
commit 3716ad7f49
7 changed files with 111 additions and 41 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.45 2003/07/14 18:19:11 christos Exp $ */
/* $NetBSD: compat.c,v 1.46 2003/08/01 00:39:52 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: compat.c,v 1.45 2003/07/14 18:19:11 christos Exp $";
static char rcsid[] = "$NetBSD: compat.c,v 1.46 2003/08/01 00:39:52 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.45 2003/07/14 18:19:11 christos Exp $");
__RCSID("$NetBSD: compat.c,v 1.46 2003/08/01 00:39:52 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -259,8 +259,12 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
* -e flag as well as -c if it's supposed to exit when it hits an
* error.
*/
static const char *shargv[4] = { _PATH_BSHELL };
static const char *shargv[4];
shargv[0] = shellPath;
/*
* The following work for any of the builtin shell specs.
*/
if (DEBUG(SHELL))
shargv[1] = (errCheck ? "-exc" : "-xc");
else
@ -550,6 +554,8 @@ Compat_Run(Lst targs)
GNode *gn = NULL;/* Current root target */
int errors; /* Number of targets not remade due to errors */
Shell_Init(); /* setup default shell */
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
signal(SIGINT, CompatInterrupt);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: config.h,v 1.14 2002/01/16 03:40:29 tv Exp $ */
/* $NetBSD: config.h,v 1.15 2003/08/01 00:39:52 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -40,7 +40,9 @@
* from: @(#)config.h 8.1 (Berkeley) 6/6/93
*/
#ifndef DEFSHELL
#define DEFSHELL 1 /* Bourne shell */
#endif
/*
* DEFMAXJOBS

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.80 2003/07/16 07:16:24 itojun Exp $ */
/* $NetBSD: job.c,v 1.81 2003/08/01 00:39:52 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: job.c,v 1.80 2003/07/16 07:16:24 itojun Exp $";
static char rcsid[] = "$NetBSD: job.c,v 1.81 2003/08/01 00:39:52 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: job.c,v 1.80 2003/07/16 07:16:24 itojun Exp $");
__RCSID("$NetBSD: job.c,v 1.81 2003/08/01 00:39:52 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -207,6 +207,16 @@ static Shell shells[] = {
"v",
#endif
"e",
},
/*
* KSH description.
*/
{
"ksh",
TRUE, "set +v", "set -v", "set +v", 6,
TRUE, "set -e", "set +e",
"v",
"e",
},
/*
* UNKNOWN.
@ -223,10 +233,10 @@ static Shell *commandShell = &shells[DEFSHELL];/* this is the shell to
* commands in the Makefile.
* It is set by the
* Job_ParseShell function */
static const char *shellPath = NULL, /* full pathname of
const char *shellPath = NULL, /* full pathname of
* executable image */
*shellName = NULL, /* last component of shell */
*shellArgv = NULL; /* Custom shell args */
*shellName = NULL; /* last component of shell */
static const char *shellArgv = NULL; /* Custom shell args */
static int maxJobs; /* The most children we can run at once */
@ -2531,6 +2541,28 @@ Job_Make(GNode *gn)
(void) JobStart(gn, 0, NULL);
}
void
Shell_Init()
{
if (shellPath == NULL) {
/*
* The user didn't specify a shell to use, so we are using the
* default one... Both the absolute path and the last component
* must be set. The last component is taken from the 'name' field
* of the default shell description pointed-to by commandShell.
* All default shells are located in _PATH_DEFSHELLDIR.
*/
shellName = commandShell->name;
shellPath = str_concat(_PATH_DEFSHELLDIR, shellName, STR_ADDSLASH);
}
if (commandShell->exit == NULL) {
commandShell->exit = "";
}
if (commandShell->echo == NULL) {
commandShell->echo = "";
}
}
/*-
*-----------------------------------------------------------------------
* Job_Init --
@ -2581,24 +2613,7 @@ Job_Init(int maxproc, int maxlocal)
targFmt = TARG_FMT;
}
if (shellPath == NULL) {
/*
* The user didn't specify a shell to use, so we are using the
* default one... Both the absolute path and the last component
* must be set. The last component is taken from the 'name' field
* of the default shell description pointed-to by commandShell.
* All default shells are located in _PATH_DEFSHELLDIR.
*/
shellName = commandShell->name;
shellPath = str_concat(_PATH_DEFSHELLDIR, shellName, STR_ADDSLASH);
}
if (commandShell->exit == NULL) {
commandShell->exit = "";
}
if (commandShell->echo == NULL) {
commandShell->echo = "";
}
Shell_Init();
if (pipe(exit_pipe) < 0)
Fatal("error in pipe: %s", strerror(errno));

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.h,v 1.18 2003/07/14 18:19:12 christos Exp $ */
/* $NetBSD: job.h,v 1.19 2003/08/01 00:39:53 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -231,6 +231,9 @@ typedef struct Shell {
const char *exit; /* exit on error */
} Shell;
extern const char *shellPath;
extern const char *shellName;
extern int job_pipe[2]; /* token pipe for jobs. */
extern int jobTokensRunning; /* tokens currently "out" */
extern int jobTokensFree; /* tokens free but not yet released to pipe */
@ -251,6 +254,7 @@ extern Lst stoppedJobs; /* List of jobs that are stopped or didn't
* quite get started */
#endif
void Shell_Init(void);
void Job_Touch(GNode *, Boolean);
Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...));
void Job_CatchChildren(Boolean);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.89 2003/07/14 18:19:12 christos Exp $ */
/* $NetBSD: main.c,v 1.90 2003/08/01 00:39:53 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,7 +39,7 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: main.c,v 1.89 2003/07/14 18:19:12 christos Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.90 2003/08/01 00:39:53 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.89 2003/07/14 18:19:12 christos Exp $");
__RCSID("$NetBSD: main.c,v 1.90 2003/08/01 00:39:53 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -1224,10 +1224,12 @@ Cmd_Exec(const char *cmd, const char **err)
*err = NULL;
if (!shellName)
Shell_Init();
/*
* Set up arguments for shell
*/
args[0] = "sh";
args[0] = shellName;
args[1] = "-c";
args[2] = cmd;
args[3] = NULL;
@ -1258,7 +1260,7 @@ Cmd_Exec(const char *cmd, const char **err)
(void) dup2(fds[1], 1);
(void) close(fds[1]);
(void) execv(_PATH_BSHELL, UNCONST(args));
(void) execv(shellPath, UNCONST(args));
_exit(1);
/*NOTREACHED*/

View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.82 2003/07/16 11:34:16 wiz Exp $
.\" $NetBSD: make.1,v 1.83 2003/08/01 00:39:54 sjg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
.Dd July 14, 2003
.Dd July 31, 2003
.Dt MAKE 1
.Os
.Sh NAME
@ -1256,6 +1256,50 @@ If no sources are specified, the
.Ic .PRECIOUS
attribute is applied to every
target in the file.
.It Ic .SHELL
Sets the shell that
.Nm
will use to execute commands.
The sources are a set of
.Ar field=value
pairs.
.Bl -tag -width hasErrCtls
.It Ar name
This is the minimal specification, used to select one of the builtin
shell specs;
.Ar sh ,
.Ar ksh ,
and
.Ar csh .
.It Ar path
Specifies the path to the shell.
.It Ar hasErrCtl
Indicates whether the shell supports exit on error.
.It Ar check
The command to turn on error checking.
.It Ar ignore
The command to disable error checking.
.It Ar echo
The command to turn on echoing of commands executed.
.It Ar quiet
The command to turn off echoing of commands executed.
.It Ar filter
The output to filter after issuing the
.Ar quiet
command. It is typically identical to
.Ar quiet .
.It Ar errFlag
The flag to pass the shell to enable error checking.
.It Ar echoFlag
The flag to pass the shell to enable command echoing.
.El
Example:
.Bd -literal
\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \\
check="set -e" ignore="set +e" \\
echo="set -v" quiet="set +v" filter="set +v" \\
echoFlag=v errFlag=e
.Ed
.It Ic .SILENT
Apply the
.Ic .SILENT

View File

@ -1,4 +1,4 @@
/* $NetBSD: pathnames.h,v 1.10 2002/09/14 15:23:49 thorpej Exp $ */
/* $NetBSD: pathnames.h,v 1.11 2003/08/01 00:39:54 sjg Exp $ */
/*
* Copyright (c) 1990, 1993
@ -48,9 +48,6 @@
#ifndef _PATH_DEFSHELLDIR
#define _PATH_DEFSHELLDIR "/bin"
#endif
#ifndef _PATH_BSHELL
#define _PATH_BSHELL "/bin/sh"
#endif
#define _PATH_DEFSYSMK "sys.mk"
#ifndef _PATH_DEFSYSPATH
#define _PATH_DEFSYSPATH "/usr/share/mk"