diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile index da2c13dbe108..7ef58f8ef71b 100644 --- a/usr.bin/make/Makefile +++ b/usr.bin/make/Makefile @@ -12,4 +12,20 @@ SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \ lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c .PATH: ${.CURDIR}/lst.lib +# Set the shell which make(1) uses. Bourne is the default, but a decent +# Korn shell works fine, and much faster. Using the C shell for this +# will almost certainly break everything, but it's Unix tradition to +# allow you to shoot yourself in the foot if you want to :-) + +MAKE_SHELL?= sh +.if ${MAKE_SHELL} == "csh" +CFLAGS+= -DDEFSHELL=0 +.elif ${MAKE_SHELL} == "sh" +CFLAGS+= -DDEFSHELL=1 +.elif ${MAKE_SHELL} == "ksh" +CFLAGS+= -DDEFSHELL=2 +.else +.error "MAKE_SHELL must be set to one of \"csh\", \"sh\" or \"ksh\"." +.endif + .include diff --git a/usr.bin/make/config.h b/usr.bin/make/config.h index 9d97eb5e4b60..1bf6e9f883e3 100644 --- a/usr.bin/make/config.h +++ b/usr.bin/make/config.h @@ -39,8 +39,6 @@ * $FreeBSD$ */ -#define DEFSHELL 1 /* Bourne shell */ - /* * DEFMAXJOBS * DEFMAXLOCAL diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index f553768322b8..213bed0b0651 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -187,6 +187,16 @@ static Shell shells[] = { FALSE, "echo \"%s\"\n", "sh -c '%s || exit 0'\n", #endif "v", "e", +}, + /* + * KSH description. The Korn shell has a superset of + * the Bourne shell's functionality. + */ +{ + "ksh", + TRUE, "set -", "set -v", "set -", 5, + TRUE, "set -e", "set +e", + "v", "e", }, /* * UNKNOWN. diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 9530a0e594f9..2694eededd0d 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -478,6 +478,13 @@ main(argc, argv) /* avoid faults on read-only strings */ static char syspath[] = _PATH_DEFSYSPATH; +#if DEFSHELL == 2 + /* + * Turn off ENV to make ksh happier. + */ + unsetenv("ENV"); +#endif + #ifdef RLIMIT_NOFILE /* * get rid of resource limit on file descriptors @@ -1000,7 +1007,13 @@ Cmd_Exec(cmd, err) (void) dup2(fds[1], 1); (void) close(fds[1]); +#if DEFSHELL == 1 (void) execv("/bin/sh", args); +#elif DEFSHELL == 2 + (void) execv("/bin/ksh", args); +#else +#error "DEFSHELL must be 1 or 2." +#endif _exit(1); /*NOTREACHED*/