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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

706 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

12 Experts available now in Live!

Get 1:1 Help Now