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

 
 

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

Submitter:  None
Submitted:  Thu 22 Feb 2007 08:25:56 AM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  3.81 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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 Files:
   
   
Comment:
   

No files currently attached

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2007-02-22 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code