[Top][All Lists]

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

Re: Testing gnuMake flags

From: Philip Guenther
Subject: Re: Testing gnuMake flags
Date: Fri, 8 May 2009 13:47:54 -0700

On Thu, May 7, 2009 at 7:30 PM, pip9ball <address@hidden> wrote:
> I'm having some difficulty testing for flags used when executing gmake.  In
> particular, if the user calls gmake with the "-j" parallel flag, I want to
> set a variable differently.  The reason why I need this is we have a batch
> system in place where I need to disable interactive jobs when running in
> parallel so the stdout isn't inter-dispersed.  I've created a small
> testcase, however I don't understand why this doesn't work.
> ifeq (,$(filter j, $(MAKEFLAGS)))
>        NC_RUN_EXE = nc run -I blah ...
> else
> In both cases above, the ifeq ($findstring...) function is taking the 'true'
> branch.

Uh, I see a $(filter), not a $(findstring) in that Makefile snippet.

Even with that fixed, however, it won't work: it appears that make
doesn't add the -j option to MAKEFLAGS until it starts processing
rules.  I can't think of a good reason for that (it is _not_ related
to the .NOTPARALLEL target), so I think it's a bug.

The workaround is to delay the test to when the rule is processed and
use $(if).  Here's a makefile that demonstrates the bug and the
workaround.  Compare the output of "make", "make -j", and "make -t".

Side-note: I use $(value MAKEFLAGS) instead of just $(MAKEFLAGS)
because the latter will result in a false positive if there's a
command line variable assignment that contains a 'j'.

Philip Guenther

ifneq (,$(findstring j,$(value MAKEFLAGS)))
  $(info has -j!)
ifneq (,$(findstring t,$(value MAKEFLAGS)))
  $(info has -t!)

HAS_J = $(if $(findstring j,$(value MAKEFLAGS)),has -j,no -j)

        @echo $(MAKEFLAGS)
        @echo $(if $(findstring j,$(value MAKEFLAGS)),has -j,no -j)
        @echo $(HAS_J)

.PHONY: all

reply via email to

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