Date: Fri, 12 Jul 1996 22:42:25 +0000 From: mark@linus.demon.co.uk (Mark Valentine) To: Bruce Evans <bde@zeta.org.au>, pst@freefall.freebsd.org Cc: hackers@freebad.org Subject: Re: cvs commit: src/share/mk bsd.obj.mk Message-ID: <199607131423.OAA10588@linus.demon.co.uk> Resent-Message-ID: <199607131423.OAA10588@linus.demon.co.uk> In-Reply-To: Bruce Evans's message of Jul 12, 4:46pm
next in thread | raw e-mail | index | archive | help
> From: Bruce Evans <bde@zeta.org.au>
> Date: Fri 12 Jul, 1996
> Subject: Re: cvs commit: src/share/mk bsd.obj.mk
[redirected from the CVS commit lists]
> > Modified: share/mk bsd.obj.mk
> > Log:
> > Add whereobj target to find that pesky obj dir
>
> I still think that this is important enough to justify builtin support.
> E.g., `make -P variable' could print make's idea of the value of `variable'.
> Then `make -P .OBJDIR' would show where the obj dir is.
Yes! I'd been puzzling over a way to do this which wasn't a special purpose
hack. So, here's an implementation (the man page patch also includes a small
bug fix for the description of the -D option). -P was (sort of) taken, so I
used -V.
(This patch is against -current's make; I actually compiled and lightly tested
a variant of this - against a slightly older make [prior to jkh's changes].)
Jordan's recent modifications to quite a few makefiles changed them from one
bad assumption to another. This change allows a simpler fix than the one I
saw in a random OpenBSD makefile, which generated a small makefile on the
fly to echo ${.OBJDIR}. Such a fix would allow all those makefiles to work
with both the old and new build systems.
For example, for /usr/src/games/boggle/Makefile:
MKDICTOBJ != cd ${.CURDIR}/mkdict; make -V .OBJDIR
MKINDXOBJ != cd ${.CURDIR}/mkindex; make -V .OBJDIR
MKDICT = ${MKDICTOBJ}/mkdict
MKINDX = ${MKINDXOBJ}/mkindex
The old version of the Makefile failed for most obj directory configurations;
the -current version of the Makefile (and the new build system in general) only
allows one (broken) way to do obj directories.
Mark.
--- make.1.ctm Thu Apr 11 22:02:30 1996
+++ make.1 Fri Jul 12 21:44:37 1996
@@ -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 @@
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 @@
.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
--- main.c.ctm Wed Jul 10 01:12:08 1996
+++ main.c.new Fri Jul 12 21:22:53 1996
@@ -107,6 +107,8 @@
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 @@
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 "DV:I:d:ef:ij:knqrst"
#endif
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
switch(c) {
@@ -169,6 +171,12 @@
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 @@
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,20 @@
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 +660,7 @@
* 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 +676,16 @@
/* 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);
--
Mark Valentine at Home <mailto:mv@pobox.com> <http://www.pobox.com/~mv/>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607131423.OAA10588>
