Variable expansion in makefiles question

Posted on 2006-06-22
Last Modified: 2010-04-17

For the following command in Makefile, I want to find out when the variables and the call function are expanded:

  ifdef someDEF
      $(call someFUNC, $(someVAR))
      $(call anotherFUNC)

I have read that " all instances of conditional syntax are parsed immediately at the point it was read (before execute specified targets) ".  So the call function expands immediately?
But I have also read that:
  define someDEF
someDEF will expand immediately, but someFUNC in this case will not expand until someDEF is referenced.  So when does the call function expand?

Thank you in advance,

Question by:sctccomm
1 Comment
LVL 18

Accepted Solution

JoseParrot earned 500 total points
ID: 17015089

Good question.
Actually both assertives are correct. They're not conflitant or exclusive.

In the first example, (pardon me for the obvious) if someDEF was already defined, someFUNC will be expanded immediately, otherwhise make will expand anotherFUNC immediately. That is, one of the them will expand.
Remember: by definition,    call     expands a user-defined function.

In the second example, you're right: make will define someDEF, which is immediately expanded, but will not expand someFUNC in the moment is parsing the command.

So, if these samples would be in a makefile, the    define someDEF  was before  ifdef someDEF. And, it could be:

  define someDEF

  ifdef someDEF
      $(call someDEF, $(someVAR))   <--- someDEF was defined before. It calls someFUNC
      $(call anotherFUNC)

Another example to be clear:


   define call-func1
      $(call someFUNC,$(somevar))

   define call-func2
      $(call anotherFUNC)


Hope it helps.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now