diff options
author | hoek <hoek@FreeBSD.org> | 1999-07-31 20:53:02 +0000 |
---|---|---|
committer | hoek <hoek@FreeBSD.org> | 1999-07-31 20:53:02 +0000 |
commit | c33aa2784f44cc50d00d3e7b28135f09340397de (patch) | |
tree | a957a389488e4956197a01865dc2f7f45dbe9d92 /usr.bin/make | |
parent | 09a53fd5c6f60c39e4e980d9caf11e21482bb3c4 (diff) | |
download | FreeBSD-src-c33aa2784f44cc50d00d3e7b28135f09340397de.zip FreeBSD-src-c33aa2784f44cc50d00d3e7b28135f09340397de.tar.gz |
Add a -E flag, similar to -e (overide variables from environment) except
that -E only operates for a specified variable. Useful since the -e option
will often pull-in many unwanted variable overrides (esp. in a make world
situation). Uses include overriding BINOWN (which cannot be done by normal
methods or through abuses of MAKEFLAGS) or likely for ports to honour CFLAGS
(provided they're running on a system whose make(1) has this option).
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/main.c | 19 | ||||
-rw-r--r-- | usr.bin/make/make.1 | 10 | ||||
-rw-r--r-- | usr.bin/make/make.h | 7 | ||||
-rw-r--r-- | usr.bin/make/var.c | 25 |
4 files changed, 47 insertions, 14 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 6b06e68..ea47823 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -47,7 +47,7 @@ static const char copyright[] = static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #endif static const char rcsid[] = - "$Id: main.c,v 1.30 1999/03/01 06:01:05 imp Exp $"; + "$Id: main.c,v 1.31 1999/07/31 20:40:23 hoek Exp $"; #endif /* not lint */ /*- @@ -137,6 +137,7 @@ Boolean beSilent; /* -s flag */ Boolean beVerbose; /* -v flag */ Boolean oldVars; /* variable substitution style */ Boolean checkEnvFirst; /* -e flag */ +Lst envFirstVars; /* (-E) vars to override from env */ static Boolean jobsRunning; /* TRUE if the jobs might be running */ static void MainParseArgs __P((int, char **)); @@ -173,9 +174,9 @@ MainParseArgs(argc, argv) optind = 1; /* since we're called more than once */ #ifdef REMOTE -# define OPTFLAGS "BD:I:L:PSV:d:ef:ij:km:nqrstv" +# define OPTFLAGS "BD:E:I:L:PSV:d:ef:ij:km:nqrstv" #else -# define OPTFLAGS "BD:I:PSV:d:ef:ij:km:nqrstv" +# define OPTFLAGS "BD:E:I:PSV:d:ef:ij:km:nqrstv" #endif rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { switch(c) { @@ -279,6 +280,15 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); break; } + case 'E': + p = malloc(strlen(optarg) + 1); + if (!p) + Punt("make: cannot allocate memory."); + (void)strcpy(p, optarg); + (void)Lst_AtEnd(envFirstVars, (ClientData)p); + Var_Append(MAKEFLAGS, "-E", VAR_GLOBAL); + Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + break; case 'e': checkEnvFirst = TRUE; Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL); @@ -599,6 +609,7 @@ main(argc, argv) create = Lst_Init(FALSE); makefiles = Lst_Init(FALSE); + envFirstVars = Lst_Init(FALSE); printVars = FALSE; variables = Lst_Init(FALSE); beSilent = FALSE; /* Print commands as executed */ @@ -1295,7 +1306,7 @@ static void usage() { (void)fprintf(stderr, "%s\n%s\n%s\n", -"usage: make [-Beiknqrstv] [-D variable] [-d flags] [-f makefile]", +"usage: make [-Beiknqrstv] [-D variable] [-d flags] [-E variable] [-f makefile]", " [-I directory] [-j max_jobs] [-m directory] [-V variable]", " [variable=value] [target ...]"); exit(2); diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index e4d9833..1b228ce 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 -.\" $Id: make.1,v 1.16 1998/11/29 13:46:39 pds Exp $ +.\" $Id: make.1,v 1.17 1999/04/19 07:30:03 imp Exp $ .\" .Dd March 19, 1994 .Dt MAKE 1 @@ -43,6 +43,7 @@ .Op Fl Beiknqrstv .Op Fl D Ar variable .Op Fl d Ar flags +.Op Fl E Ar variable .Op Fl f Ar makefile .Op Fl I Ar directory .Bk -words @@ -118,9 +119,12 @@ Print debugging information about target list maintenance. .It Ar v Print debugging information about variable assignment. .El +.It Fl E Ar variable +Specify a variable whose environment value (if any) will override +macro assignments within makefiles. .It Fl e -Specify that environment variables override macro assignments within -makefiles. +Specify that environment values override macro assignments within +makefiles for all variables. .It Fl f Ar makefile Specify a makefile to read instead of the default .Ql Pa makefile diff --git a/usr.bin/make/make.h b/usr.bin/make/make.h index 52d01db..fad9a9d 100644 --- a/usr.bin/make/make.h +++ b/usr.bin/make/make.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * from: @(#)make.h 8.3 (Berkeley) 6/13/95 - * $Id: make.h,v 1.7 1997/02/22 19:27:16 peter Exp $ + * $Id: make.h,v 1.8 1998/11/14 16:15:04 dg Exp $ */ /*- @@ -311,7 +311,10 @@ extern Boolean queryFlag; /* TRUE if we aren't supposed to really make * of-date */ extern Boolean checkEnvFirst; /* TRUE if environment should be searched for - * variables before the global context */ + * all variables before the global context */ +extern Lst envFirstVars; /* List of specific variables for which the + * environment should be searched before the + * global context */ extern GNode *DEFAULT; /* .DEFAULT rule */ diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 5ae9a1a..92b35b8 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -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.11 1998/06/02 13:11:04 thepish Exp $ + * $Id: var.c,v 1.12 1999/04/19 07:30:04 imp Exp $ */ #ifndef lint @@ -218,6 +218,7 @@ VarFind (name, ctxt, flags) * FIND_ENV set means to look in the * environment */ { + Boolean localCheckEnvFirst; LstNode var; Var *v; @@ -256,6 +257,20 @@ VarFind (name, ctxt, flags) name = TARGET; break; } + + /* + * Note whether this is one of the specific variables we were told through + * the -E flag to use environment-variable-override for. + */ + if (Lst_Find (envFirstVars, (ClientData)name, + (int (*)(ClientData, ClientData)) strcmp) != NILLNODE) + { + localCheckEnvFirst = TRUE; + } + else { + localCheckEnvFirst = FALSE; + } + /* * First look for the variable in the given context. If it's not there, * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, @@ -266,8 +281,8 @@ VarFind (name, ctxt, flags) if ((var == NILLNODE) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) { var = Lst_Find (VAR_CMD->context, (ClientData)name, VarCmp); } - if (!checkEnvFirst && (var == NILLNODE) && (flags & FIND_GLOBAL) && - (ctxt != VAR_GLOBAL)) + if ((var == NILLNODE) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL) && + !checkEnvFirst && !localCheckEnvFirst) { var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp); } @@ -287,8 +302,8 @@ VarFind (name, ctxt, flags) v->flags = VAR_FROM_ENV; return (v); - } else if (checkEnvFirst && (flags & FIND_GLOBAL) && - (ctxt != VAR_GLOBAL)) + } else if ((checkEnvFirst || localCheckEnvFirst) && + (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL)) { var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp); if (var == NILLNODE) { |