bugmake - Bugs: bug #19122, $* doesn't work as expected

 
 

bug #19122: $* doesn't work as expected

Submitted by:  None
Submitted on:  Thu 22 Feb 2007 08:25:56 AM UTC  
 
Severity: 3 - NormalItem Group: Bug
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: 3.81Operating 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.

 

Thu 22 Feb 2007 01:59:21 PM UTC, comment #2:

Philip is correct.

As for the difference in clearmake, presumably clearmake has some extra suffix rules including one for .bin, that GNU make doesn't have.

You can either avoid $* (using $(basename ...) or similar to get rid of the suffix) or define a suffix for .bin.

Paul D. Smith <psmith>
Project Administrator
Thu 22 Feb 2007 09:25:43 AM UTC, comment #1:

It's behaving exactly as described in the GNU make info pages. In particular, as described in section 10.5.3 "Automatic Variables":

`$*'
The stem with which an implicit rule matches (*note How
Patterns Match: Pattern Match.). If the target is
dir/a.foo.b' and the target pattern is `a.%.b' then the
stem is `dir/foo'. The stem is useful for constructing
names of related files.
<...>
In an explicit rule, there is no stem; so `$*' cannot be
determined in that way. Instead, if the target name ends
with a recognized suffix (*note Old-Fashioned Suffix
Rules: Suffix Rules.), `$*' is set to the target name
minus the suffix. For example, if the target name is
`foo.c', then `$*' is set to `foo', since `.c' is a
suffix. GNU `make' does this bizarre thing only for
compatibility with other implementations of `make'. You
should generally avoid using `$*' except in implicit rules
or static pattern rules.

If the target name in an explicit rule does not end with
a recognized suffix, `$*' is set to the empty string for
that rule.

The rule in your example is an explicit rule and the target is not in the default suffix list. Therefore $* will be empty in that rule. As mentioned in the text above, use of $* in explicit rules is discouraged. You should either
a) hardcode the stem for the rule (there's only one target
in your example, so there's only one stem),
b) extract the correct stem for the the target using $(patsubst)
against $@, or whatever is appropriate, OR
c) add ".bin" to the suffix list by naming .bin as a dependency
of the .SUFFIXES pseudo-target.

Philip Guenther

Anonymous
Thu 22 Feb 2007 08:25:56 AM UTC, original submission:

$* doesn't work for me - it returns empty string, while using in this way:
[code]
all: app.bin

app.bin:
touch $@
echo \$$* = $*
[/code]

When I run this Makefile, GNU Make 3.81 gives following output:
[output]
touch app.bin
echo \$* =
$* =
[output]

However, clearmake gives following (expected by me) result:
[output]
touch app.bin
echo \$* = app
$* = app
[/output]

$(D) and $(F) variables also return empty string in GNU Make.

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

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 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 22 Feb 2007 01:59:21 PM UTCpsmithStatusNone=>Not A Bug
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1