Solved

Variable expansion in makefiles question

Posted on 2006-06-22
1
297 Views
Last Modified: 2010-04-17
Hi,

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))
  else
      $(call anotherFUNC)
  endif

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
      someFUNC
  endef
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,
Jessica

0
Comment
Question by:sctccomm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
Jose Parrot earned 500 total points
ID: 17015089
Hi,

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
      someFUNC
  endef

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


Another example to be clear:

   define
      FISRTOPTION
   endef

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

   define call-func2
      $(call anotherFUNC)
   endef

   ifdef FIRSTOPTION
      call-func1
   else
      call-func2
   endif


Hope it helps.

Jose
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…

710 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