bugmake - Bugs: bug #56206, ifndef false positive for exported...

 
 

bug #56206: ifndef false positive for exported variable

Submitter:  Valentin Rusu <valir>
Submitted:  Wed 24 Apr 2019 03:47:58 PM UTC
   
 
Severity:  3 - Normal Priority:  5 - Normal
Item Group:  Bug Status:  Not A Bug
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Component Version:  4.2.1
Operating System:  POSIX-Based Fixed Release:  None
Triage Status:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Sun 12 May 2019 10:43:43 PM UTC, comment #2: 

Somehow my previous comment was truncated (I do so HATE Savannah markup :( ):


There is another assignment operator for variables, ‘?=’. This is called a conditional variable
assignment operator, because it only has an effect if the variable is not yet defined.
This statement:

  FOO ?= bar

is exactly equivalent to this (see The origin Function):

  ifeq ($(origin FOO), undefined)
    FOO = bar
  endif

Note that a variable set to an empty value is still defined, so ‘?=’ will not set that variable.


Paul D. Smith <psmith>
Group administrator
Sun 12 May 2019 10:42:06 PM UTC, comment #1: 

This behavior is correct.  The confusion is because the ?= operator and the ifndef operator have different behaviors for variables which are defined to have an empty value.

ifdef/ifndef test whether the expansion of the variable is the empty string or not:


ifndef variable-name

    If the variable variable-name has an empty value, the text-if-true is effective;
    otherwise, the text-if-false, if any, is effective.


However, the ?= operator tests whether the variable is actually defined or not, not whether it has an empty value:


There is another assignment operator for variables, ‘?=’. This is called a conditional
variable assignment operator, because it only has an effect if the variable is not
yet defined. This statement:

  FOO ?= bar

is exactly equivalent to this (see The origin Function):

  ifeq ($(origin FOO), undefined)
    FOO = bar
  endif

  Note that a variable set to an empty value is still defined, so ‘?=’ will not set that variable.
-verbatim=

Paul D. Smith <psmith>
Group administrator
Wed 24 Apr 2019 03:47:58 PM UTC, original submission:  

Platforms: ArchLinux and Fedora 29

We struggled a bit with this one but here is the test case.
Please check the attached makefiles, after placing them together in the same directory.

Test case 1:

# With the files as given here:
$ make all
make -f child.mk all
make[1]: Entering directory ....
TEST_VAR=test
make[1]: Leaving directory ....

Now go and modify the files as described in the "child.mk" comments, then run again:

$ make all
make -f child.mk all
make[1]: Entering directory ...
TEST_VAR=
make[1]: ...

As you can see, the TEST_VAR was now empty.

We are not sure here what's the correct behavior. Does the export from the main Makefile defines the variable? Either ways, one of the test cases shows that we are having a bug here.

Thanks,


Valentin Rusu <valir>

 

Attached Files

Attached Files
file #46825:  Makefile added by valir (52B - application/octet-stream)
file #46826:  child.mk added by valir (260B - text/x-makefile)

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

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

    Votes

    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.

     

    History

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-05-12 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2019-04-24 valir Attached File- Added Makefile, #46825
        Attached File- Added child.mk, #46826
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.16.
    Corresponding source code