[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to conditionally pass a function to a function
From: |
Michael Ploujnikov |
Subject: |
Re: how to conditionally pass a function to a function |
Date: |
Wed, 29 Oct 2008 11:51:55 -0400 (EDT) |
----- "Paul Smith" <address@hidden> wrote:
> On Wed, 2008-10-29 at 11:26 -0400, Michael Ploujnikov wrote:
> > define rule-generator
> > $(1):
> > @echo "$(1) generating $(2)" && \
>
> > $(call $(3)) && \
>
> > $(call $(4))
> > endef
> >
> > $(eval $(call
> rule-generator,my-rule1,package-name,default-start-fun,default-end-fun))
>
> You really don't want to use ifdef for this. Ifdef is a preprocessor
> statement and it can't be used inside of backslash-extended lines
> like
> this. It gets appended to the previous line and bad things happen.
>
> Why don't you just use $(if ..)... or actually even $(or ...) would
> be
> more efficient (one less variable expansion)? Something like:
>
> define rule-generator
> $(1):
> @echo "$(1) generating $(2)" && \
>
> $(call $(or $(3),$(default-start-fun))) && \
>
> $(call $(or $(4),$(default-end-fun)))
> endef
>
> (totally untested).
Nice. This works wonderfully if I don't treat default-start-fun as a variable:
define rule-generator
$(1):
@echo "$(1) generating $(2)" && \
$(call $(or $(3),default-start-fun)) && \
$(call $(or $(4),default-end-fun))
endef
$(eval $(call rule-generator,my-rule1,package-name,custom-start-fun))
$ make -f /tmp/simple.mk
my-rule1 generating package-name
uh, oh, we are doing something different!
starting ... started
ending
ended
Thanks a lot. I never noticed the Make "or" function.