summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1996-07-17 11:02:43 +0000
committerbde <bde@FreeBSD.org>1996-07-17 11:02:43 +0000
commiteee2e98b23b69ac1def76c0bf8462e89216b70d8 (patch)
tree027375d24b4e673f75a7d2c5d87c41758fc89a94 /usr.bin/make
parent230a782128a6a814787800c4556d1fcdafd4d771 (diff)
downloadFreeBSD-src-eee2e98b23b69ac1def76c0bf8462e89216b70d8.zip
FreeBSD-src-eee2e98b23b69ac1def76c0bf8462e89216b70d8.tar.gz
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.
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/main.c39
-rw-r--r--usr.bin/make/make.116
2 files changed, 47 insertions, 8 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 4094276..03a62da 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -107,6 +107,8 @@ Boolean allPrecious; /* .PRECIOUS given on line by itself */
static Boolean noBuiltins; /* -r flag */
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 */
static int maxLocal; /* -L argument */
Boolean compatMake; /* -B argument */
@@ -153,9 +155,9 @@ MainParseArgs(argc, argv)
optind = 1; /* since we're called more than once */
#ifdef notyet
-# define OPTFLAGS "BD:I:L:PSd:ef:ij:knqrst"
+# define OPTFLAGS "BD:I:L:PSVd:ef:ij:knqrst"
#else
-# define OPTFLAGS "D:I:d:ef:ij:knqrst"
+# define OPTFLAGS "D:I:V:d:ef:ij:knqrst"
#endif
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
switch(c) {
@@ -169,6 +171,12 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
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
case 'B':
compatMake = TRUE;
@@ -453,6 +461,8 @@ main(argc, argv)
create = Lst_Init(FALSE);
makefiles = Lst_Init(FALSE);
+ printVars = FALSE;
+ variables = Lst_Init(FALSE);
beSilent = FALSE; /* Print commands as executed */
ignoreErrors = FALSE; /* Pay attention to non-zero returns */
noExecute = FALSE; /* Execute all commands */
@@ -622,6 +632,21 @@ main(argc, argv)
if (DEBUG(GRAPH1))
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
* 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
* back in, eventually.
*/
- if (!compatMake) {
+ if (!compatMake && !printVars) {
/*
* Initialize job module before traversing the graph, now that
* 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 */
outOfDate = Make_Run(targs);
- } else
+ } else if (!printVars) {
/*
* Compat_Init will take care of creating all the targets as
* well as initializing the module.
*/
Compat_Run(targs);
+ }
Lst_Destroy(targs, NOFREE);
+ Lst_Destroy(variables, NOFREE);
Lst_Destroy(makefiles, NOFREE);
Lst_Destroy(create, (void (*) __P((ClientData))) free);
@@ -919,8 +946,8 @@ static void
usage()
{
(void)fprintf(stderr,
-"usage: make [-eiknqrst] [-D variable] [-d flags] [-f makefile ]\n\
- [-I directory] [-j max_jobs] [variable=value]\n");
+"usage: make [-eiknqrst] [-D variable] [-d flags] [-f makefile] [-I directory]\n\
+ [-j max_jobs] [-V variable] [variable=value] [target ...]\n");
exit(2);
}
diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1
index c007114..69b3598 100644
--- a/usr.bin/make/make.1
+++ b/usr.bin/make/make.1
@@ -39,7 +39,7 @@
.Nd maintain program dependencies
.Sh SYNOPSIS
.Nm make
-.Op Fl eiknqrstv
+.Op Fl eiknqrst
.Op Fl D Ar variable
.Op Fl d Ar flags
.Op Fl f Ar makefile
@@ -47,6 +47,7 @@
.Bk -words
.Op Fl j Ar max_jobs
.Ek
+.Op Fl V Ar variable
.Op Ar variable=value
.Op Ar target ...
.Sh DESCRIPTION
@@ -74,7 +75,8 @@ and makefiles, please refer to
The options are as follows:
.Bl -tag -width Ds
.It Fl D Ar variable
-Define Ar variable
+Define
+.Ar variable
to be 1, in the global context.
.It Fl d Ar flags
Turn on debugging, and specify which portions of
@@ -155,6 +157,16 @@ before each command line in the makefile.
.It Fl t
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.
+.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
Set the value of the variable
.Ar variable
OpenPOWER on IntegriCloud