shell - How can I pass and return a value from user defined function in MAKEFILE? -


i create function takes list argument, performs operation , returns list(or scalar value). define function using 'define'. function:

1) performs operation on input list
2) checks if resultant list empty, if list empty raise error. 3) otherwise return resultant list

this possible in languages c/c++. facing issues when try in makefile.

a) can point me examples or post example here?.
b) how makefile function returns value?

i checked makefile documentation , few other places on web not find useful. give me idea on starting functions. thank help!

define myfuntest fnames := $(filter %pattern, $(1)) ifneq ($(fnames),) $(error error) endif endef 

caller function like:

abc := documents downloads return_value := $(call mytestfun,$(abc)) 

i want 'fnames' returned in 'return_value'

user-defined macros must single "expression". returned value result of expanding expression. cannot use ifneq or variable assignments or other similar things in user-defined macro.

you can create makefile piece used alongside call, but can used eval, , means it's separate section of makefile, not "function" defined.

so, if can construct user-defined macro make functions such result of expansion result want can macro; example:

myfuntest = $(or $(filter %pattern,$(1)),$(error error))  results := $(call myfuntest,foo barpattern biz baz) 

if result of filter either list of matching words , assigned results, or else run error function.

however, if function more complex , cannot expressed in expression format, have use eval, , pass in name of variable assigned, this:

define myfuntest   ... compute fnames $(2) ... $(1) := $$(fnames) endef 

you must careful $ vs. $$, when using eval , call together. invoke like:

$(eval $(call myfuntest,return_value,$(abc))) 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -