Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7575629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:43:40+00:00 2026-05-30T16:43:40+00:00

Given this bit of Makefile: # for pattern matching $(OBJDIR) := build # just

  • 0

Given this bit of Makefile:

# for pattern matching
$(OBJDIR) := build

# just to see if a level of indirection will work
my_dir = $(dir $(1))

$(OBJECTS) : $(OBJDIR)/% : $(HEADERS) $(SRCDIR)/% | % $(dir %) $(call my_dir,%)
  @echo output-only = $|

This is a static pattern rule with order-only prerequisites.

Consider the target “build/utility/debug.js”. The output of the above rule will be this:

output-only = utility/debug.js ./
  • The first component, “utility/debug.js”, is properly copied from the stem (%).
  • The second component, “./”, is the output of calling the dir function in the prerequisites list.
  • The third component, an empty string, is the output of calling my my_dir function in the prerequisites list.

If I change my_dir to this:

my_dir = $(1)

The output remains the same. If I change it to this:

my_dir = "foo"

Then make complains there is no rule to make “foo” (which is expected). It appears, then, that $(1) is not getting bound in the call to my_dir.

What’s going on? Why can’t I pass the stem to a function? I have a workaround that uses secondary expansion, but I want to know why I can’t write my rule this way.

EDIT: I’m new to stackoverflow, forgive me if this is not the way things are done here.

I want $(1) because I am passing the stem as an argument to my_dir, as Alex pointed out.

I don’t know why it was suggested I want “$”. I don’t believe $ by itself expands to anything in any context.

I know that automatic variables are only available in the recipe. I am not using an automatic variable in the prerequisites – I am using the stem:

Each target is matched against the target-pattern to extract a part of the target name, called the stem. This stem is substituted into each of the prereq-patterns to make the prerequisite names (one from each prereq-pattern). – the manual

The fact that the stem is available is demonstrated by the example: the stem expands to the correct value when used alone, but not when passed to a function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:43:42+00:00Added an answer on May 30, 2026 at 4:43 pm

    As can be seen in this section of the GNU make manual, variable and function references in the list of prerequisites are immediately expanded, during the read in phase. This means, before any pattern matching is done, so the % has no special meaning yet; it is interpreted as a literal character in the two function references, $(dir %) and $(call my_dir,%), both having ./ as a result, which get merged in the reference to $| in the recipe.

    I don’t know of any other workaround than the one you already found, i.e. secondary expansion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a bit bleeding edge, but here's the question anyway: Given
I was given this little bit of code by my teacher for this weeks
Struggling with this a bit in SQL Server, any ideas? Given this data (ID
Just to get it straight in my head. Consider this example bit of Erlang
I'm a bit confused about the following. Given this class: public class SomeClassToBeCasted {
I was given this bit of Scheme code, and have been tasked with translating
Sorry if this is a bit random, but is it good practice to give
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
Given this XML, what XPath returns all elements whose prop attribute contains Foo (the
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.