[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

docs: fix MAKEFLAGS testing example

From: Ralf Wildenhues
Subject: docs: fix MAKEFLAGS testing example
Date: Wed, 26 Jan 2011 21:34:25 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

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.


2011-01-26  Ralf Wildenhues  <address@hidden>

        * 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 -0000      1.69
+++ doc/make.texi       26 Jan 2011 20:08:49 -0000
@@ -6449,23 +6449,31 @@
 @section Conditionals that Test Flags
 You can write a conditional that tests @code{make} command flags such as
address@hidden by using the variable @code{MAKEFLAGS} together with the
address@hidden function
-(@pxref{Text Functions, , Functions for String Substitution and Analysis}).
address@hidden 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
 For example, here is how to arrange to use @samp{ranlib -t} to finish
 marking an archive file up to date:
 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]