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

 
 

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

Submitted by:  None
Submitted on:  Mon 10 Jul 2017 02:11:04 PM UTC  
 
Severity: 3 - NormalItem Group: Documentation
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: NoneOperating System: POSIX-Based
Fixed Release: NoneTriage Status: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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 File(s):
   
   
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
  • -unavailable- added by psmith (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 10 Jul 2017 03:54:26 PM UTCpsmithStatusNone=>Not A Bug
      Open/ClosedOpen=>Closed
    Mon 10 Jul 2017 02:15:17 PM UTCNoneAttached File-=>Added makefile, #41159

    Back to the top


    Powered by Savane 3.1-cleanup1