Added a -V option to print make's idea of the value of a variable.

Submitted by:	mark@linus.demon.co.uk (Mark Valentine)

Fixed bugs and inconsistencies in synopsis and usage message.
This commit is contained in:
Bruce Evans 1996-07-17 11:02:43 +00:00
parent a21dc21cee
commit 375633ec49
2 changed files with 47 additions and 8 deletions

View File

@ -107,6 +107,8 @@ Boolean allPrecious; /* .PRECIOUS given on line by itself */
static Boolean noBuiltins; /* -r flag */ static Boolean noBuiltins; /* -r flag */
static Lst makefiles; /* ordered list of makefiles to read */ static Lst makefiles; /* ordered list of makefiles to read */
static Boolean printVars; /* print value of one or more vars */
static Lst variables; /* list of variables to print */
int maxJobs; /* -J argument */ int maxJobs; /* -J argument */
static int maxLocal; /* -L argument */ static int maxLocal; /* -L argument */
Boolean compatMake; /* -B argument */ Boolean compatMake; /* -B argument */
@ -153,9 +155,9 @@ MainParseArgs(argc, argv)
optind = 1; /* since we're called more than once */ optind = 1; /* since we're called more than once */
#ifdef notyet #ifdef notyet
# define OPTFLAGS "BD:I:L:PSd:ef:ij:knqrst" # define OPTFLAGS "BD:I:L:PSVd:ef:ij:knqrst"
#else #else
# define OPTFLAGS "D:I:d:ef:ij:knqrst" # define OPTFLAGS "D:I:V:d:ef:ij:knqrst"
#endif #endif
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) { rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
switch(c) { switch(c) {
@ -169,6 +171,12 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL); Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break; break;
case 'V':
printVars = TRUE;
(void)Lst_AtEnd(variables, (ClientData)optarg);
Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
break;
#ifdef notyet #ifdef notyet
case 'B': case 'B':
compatMake = TRUE; compatMake = TRUE;
@ -453,6 +461,8 @@ main(argc, argv)
create = Lst_Init(FALSE); create = Lst_Init(FALSE);
makefiles = Lst_Init(FALSE); makefiles = Lst_Init(FALSE);
printVars = FALSE;
variables = Lst_Init(FALSE);
beSilent = FALSE; /* Print commands as executed */ beSilent = FALSE; /* Print commands as executed */
ignoreErrors = FALSE; /* Pay attention to non-zero returns */ ignoreErrors = FALSE; /* Pay attention to non-zero returns */
noExecute = FALSE; /* Execute all commands */ noExecute = FALSE; /* Execute all commands */
@ -622,6 +632,21 @@ main(argc, argv)
if (DEBUG(GRAPH1)) if (DEBUG(GRAPH1))
Targ_PrintGraph(1); Targ_PrintGraph(1);
/* print the values of any variables requested by the user */
if (printVars) {
LstNode ln;
for (ln = Lst_First(variables); ln != NILLNODE;
ln = Lst_Succ(ln)) {
char *value = Var_Value((char *)Lst_Datum(ln),
VAR_GLOBAL, &p1);
printf("%s\n", value ? value : "");
if (p1)
free(p1);
}
}
/* /*
* Have now read the entire graph and need to make a list of targets * Have now read the entire graph and need to make a list of targets
* to create. If none was given on the command line, we consult the * to create. If none was given on the command line, we consult the
@ -636,7 +661,7 @@ main(argc, argv)
* this was original amMake -- want to allow parallelism, so put this * this was original amMake -- want to allow parallelism, so put this
* back in, eventually. * back in, eventually.
*/ */
if (!compatMake) { if (!compatMake && !printVars) {
/* /*
* Initialize job module before traversing the graph, now that * Initialize job module before traversing the graph, now that
* any .BEGIN and .END targets have been read. This is done * any .BEGIN and .END targets have been read. This is done
@ -652,14 +677,16 @@ main(argc, argv)
/* Traverse the graph, checking on all the targets */ /* Traverse the graph, checking on all the targets */
outOfDate = Make_Run(targs); outOfDate = Make_Run(targs);
} else } else if (!printVars) {
/* /*
* Compat_Init will take care of creating all the targets as * Compat_Init will take care of creating all the targets as
* well as initializing the module. * well as initializing the module.
*/ */
Compat_Run(targs); Compat_Run(targs);
}
Lst_Destroy(targs, NOFREE); Lst_Destroy(targs, NOFREE);
Lst_Destroy(variables, NOFREE);
Lst_Destroy(makefiles, NOFREE); Lst_Destroy(makefiles, NOFREE);
Lst_Destroy(create, (void (*) __P((ClientData))) free); Lst_Destroy(create, (void (*) __P((ClientData))) free);
@ -919,8 +946,8 @@ static void
usage() usage()
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: make [-eiknqrst] [-D variable] [-d flags] [-f makefile ]\n\ "usage: make [-eiknqrst] [-D variable] [-d flags] [-f makefile] [-I directory]\n\
[-I directory] [-j max_jobs] [variable=value]\n"); [-j max_jobs] [-V variable] [variable=value] [target ...]\n");
exit(2); exit(2);
} }

View File

@ -39,7 +39,7 @@
.Nd maintain program dependencies .Nd maintain program dependencies
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm make .Nm make
.Op Fl eiknqrstv .Op Fl eiknqrst
.Op Fl D Ar variable .Op Fl D Ar variable
.Op Fl d Ar flags .Op Fl d Ar flags
.Op Fl f Ar makefile .Op Fl f Ar makefile
@ -47,6 +47,7 @@
.Bk -words .Bk -words
.Op Fl j Ar max_jobs .Op Fl j Ar max_jobs
.Ek .Ek
.Op Fl V Ar variable
.Op Ar variable=value .Op Ar variable=value
.Op Ar target ... .Op Ar target ...
.Sh DESCRIPTION .Sh DESCRIPTION
@ -74,7 +75,8 @@ and makefiles, please refer to
The options are as follows: The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl D Ar variable .It Fl D Ar variable
Define Ar variable Define
.Ar variable
to be 1, in the global context. to be 1, in the global context.
.It Fl d Ar flags .It Fl d Ar flags
Turn on debugging, and specify which portions of Turn on debugging, and specify which portions of
@ -155,6 +157,16 @@ before each command line in the makefile.
.It Fl t .It Fl t
Rather than re-building a target as specified in the makefile, create it Rather than re-building a target as specified in the makefile, create it
or update its modification time to make it appear up-to-date. or update its modification time to make it appear up-to-date.
.It Fl V Ar variable
Print
.Nm make Ns 's
idea of the value of
.Ar variable ,
in the global context.
Do not build any targets.
Multiple instances of this option may be specified;
the variables will be printed one per line,
with a blank line for each null or undefined variable.
.It Ar variable=value .It Ar variable=value
Set the value of the variable Set the value of the variable
.Ar variable .Ar variable