help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing Function in Makefile


From: Paul Smith
Subject: Re: Writing Function in Makefile
Date: Tue, 27 Dec 2011 21:11:14 -0500

On Tue, 2011-12-27 at 13:03 +0530, Ajay Jain wrote:
> Hello,
> 
> I need to do an operation repeatedly in various Makefiles and therefore
> want to make a function that I can call:
> 
> Contents of the function:
> -----------------------------------
> 
> ifeq ($(LOG_LEVEL),LOG_LEVEL_PANIC)
>   CFLAGS += -DLOG_LEVEL=1
> else ifeq ($(LOG_LEVEL),LOG_LEVEL_ERR)
>  CFLAGS += -DLOG_LEVEL=2
> else ifeq ($(LOG_LEVEL),LOG_LEVEL_WARN)
>  CFLAGS += -DLOG_LEVEL=3
> else ifeq ($(LOG_LEVEL),LOG_LEVEL_INFO)
>  CFLAGS += -DLOG_LEVEL=4
> else ifeq ($(LOG_LEVEL),LOG_LEVEL_DBG)
>  CFLAGS += -DLOG_LEVEL=5
> else ifeq ($(LOG_LEVEL),LOG_LEVEL_NONE)
>  CFLAGS += -DLOG_LEVEL=6
> else
>  $(error INCORRECT LOG_LEVEL = $(LOG_LEVEL))
> endif
> 
> 
> Invoke the function:
> ----------------------------
> $(call convert_logstring_to_num,$(LOG_LEVEL))
> 
> where LOG_LEVEL = LOG_LEVEL_INFO (for example).
> 
> Can I do this in my Makefile inside a function so that I can call it at
> multiple places? If yes, any suggestion? The usage of eval and call seems
> to be too tricky ..

You can't use call without eval for this situation.  Any expansion which
requires multiple newlines and must be interpreted as make statements
MUST use eval.

However, I wouldn't do it like this at all.  You don't give enough
information about how and where you would want to use this function in
your makefiles, but it seems to me that you can do whatever you want a
LOT more straightforwardly by using constructed variable names.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]