help-make
[Top][All Lists]
Advanced

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

Re: defined but unused variables


From: Paul Smith
Subject: Re: defined but unused variables
Date: Sat, 11 Jul 2015 12:39:12 -0400

On Tue, 2015-02-17 at 21:54 -0800, Dale Lukas Peterson wrote:
> I am working with a build system that has a lot of undefined make
> variables used in the makefiles.  The --warn-undefined-variables flag
> has been very helpful in cleaning things up.  Is there a way to warn
> when a make variable is defined but never used?  This would further
> help remove dead build system code.

The hard thing about this is that GNU make never evaluates the contents
of recipes that it doesn't invoke.  This means that variables used only
within recipes that are never evaluated, would not be noticed as being
"used":

  CLEAN = foo.o bar.o biz.o

  all: foo
    ...

  clean: ; rm -f $(CLEAN)

Here if you run "make" or "make all", the variable CLEAN is never
expanded and so would be considered "unused".

The only way to determine if a variable is really unused would be for
make to go through and expand all the recipes to see which variables
were evaluated.  And, just expanding recipes can have unpleasant
side-effects as sometimes they contain $(shell ...), $(eval ...),
$(info ...), etc. functions which actually perform some behavior.




reply via email to

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