Variable expansion in makefiles question

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

sctccommAsked:
Who is Participating?
 
Jose ParrotConnect With a Mentor Graphics ExpertCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.