bugmake - Bugs: bug #51434, Document that variables are...

 
 

bug #51434: Document that variables are treated differently in prerequisite lists and recipes

Submitter:  None
Submitted:  Mon 10 Jul 2017 02:11:04 PM UTC
   
 
Severity:  3 - Normal Item Group:  Documentation
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  None Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 10 Jul 2017 03:54:26 PM UTC, comment #1: 

There is a section of the GNU make manual dedicated to discussing the ways in which variable expansion differs around make constructs; see:

https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html

Paul D. Smith <psmith>
Group administrator
Mon 10 Jul 2017 02:11:04 PM UTC, original submission:  

The same variable is expanded at different times depending on whether it is used in a pre-requisites list or a recipe but this counter-intuitive difference is not documented anywhere.  It is the same for both "flavors" of variables.

Consider the following example

VARS=a.c b.c

p: $(VARS)
echo i am using  $(VARS) to build
echo $(VARS) > p

VARS=x.c y.c

Here $(VARS) in the prerequisite list is expanded when make reads that line of the file (to "a.c b.c") but the $(VARS) in the recipe on the next line is expanded to its value at the end of the makefile (here "x.c y.c")

A demonstration of the effect using the above example follows. In summary it builds p using x.c and y.c but build is triggered when a.c and b.c are touched

[x@m1 temp/make.vars]$ make
echo i am using  x.c y.c to build
i am using x.c y.c to build
echo x.c y.c > p
[x@m1 temp/make.vars]$ touch x.c
[x@m1 temp/make.vars]$ make
make: `p' is up to date.
[x@m1 temp/make.vars]$ touch b.c
[x@m1 temp/make.vars]$ make
echo i am using  x.c y.c to build
i am using x.c y.c to build
echo x.c y.c > p
[x@m1 temp/make.vars]$ vi
[x@m1 temp/make.vars]$ make --version
GNU Make 3.82
Built for i386-redhat-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[x@m1 temp/make.vars]$


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #41159:  makefile added by None (97B - application/octet-stream - attaching makefile since pasting onto web page lost the important tab character...)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-07-10 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2017-07-10 None Attached File- Added makefile, #41159

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code