Solved

Variable expansion in makefiles question

Posted on 2006-06-22
1
294 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
1 Comment
 
LVL 18

Accepted Solution

by:
JoseParrot 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

776 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