I think it's been reported here before, but I can't find the reference
now. Anyway, the ranlib example in the manual is wrong because it is
way too simplistic; try, e.g.,
make --no-print-directory FOO=bart
Below is a patch that might make the section less fitting for what it
was intended, but at least the code has less problems, or so I hope;
also, I think it is useful to have this code snippet in the manual
so people can copy it.
And yes, even the line wrapping cause headaches to get right.
Thanks,
Ralf
2011-01-26 Ralf Wildenhues
* doc/make.texi (Testing Flags): Fix MAKEFLAGS testing example
and adjusted text to cope with passed variable assignments and
long options.
Index: doc/make.texi
===
RCS file: /cvsroot/make/make/doc/make.texi,v
retrieving revision 1.69
diff -u -r1.69 make.texi
--- doc/make.texi 30 Nov 2010 14:48:53 - 1.69
+++ doc/make.texi 26 Jan 2011 20:08:49 -
@@ -6449,23 +6449,31 @@
@section Conditionals that Test Flags
You can write a conditional that tests @code{make} command flags such as
-@samp{-t} by using the variable @code{MAKEFLAGS} together with the
-@code{findstring} function
-(@pxref{Text Functions, , Functions for String Substitution and Analysis}).
+@samp{-t} by using the variable @code{MAKEFLAGS} together with the a
+couple of @code{make} functions
+(@pxref{Functions, , Functions for Transforming Text}).
This is useful when @code{touch} is not enough to make a file appear up
to date.
-The @code{findstring} function determines whether one string appears as a
-substring of another. If you want to test for the @samp{-t} flag,
-use @samp{t} as the first string and the value of @code{MAKEFLAGS} as
-the other.
+The @code{foreach} function expands text repeatedly for each element of
+a list. The @code{filter-out} function removes words from text matching
+a pattern. The @code{findstring} function determines whether one string
+appears as a substring of another. Finally, the @code{if} function
+expands code conditionally, based on whether the condition is nonempty
+or not.
+
+Now, if you want to test for the @samp{-t} flag, you can use @samp{t} as
+the string to find in @code{MAKEFLAGS}, after filtering out long options
+and variable assignments that might match wrongly
+(@pxref{Options/Recursion}).
For example, here is how to arrange to use @samp{ranlib -t} to finish
marking an archive file up to date:
@example
archive.a: @dots{}
-ifneq (,$(findstring t,$(MAKEFLAGS)))
+ifneq (,$(foreach flag,$(filter-out --%,$(MAKEFLAGS)),$(if \
+ $(findstring =,$(flag)),,$(findstring t,$(flag)
+touch archive.a
+ranlib -t archive.a
else
___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make