Makefiles: can canned recipes have options?

My question is about GNU make.

If you have a sequence of commands that are useful as a recipe for several purposes, you may need a canned recipe . I could look like this:

define run-foo # Here comes a # sequence of commands that are # executed line by line endef 

Now you can use the canned recipe as follows:

 file1: input1: $(run-foo) $(pattern) : sub/% : %.inp $(run-foo) 

etc. I wonder if it is possible to define canned recipes (or something similar) that take parameters so that I can execute them as follows:

 file2: input2 $(run-foo) specific-parameter2 "additional" file3: input3 $(run-foo) another-parameter3 "text" 

Is it possible? Any hints are welcome :)

+6
source share
1 answer

You do it:

  • Using parameters $1 , $2 ... etc. in the define macro
  • Macro call through $(call ...)

eg:

 define recipe echo $1 endef all: t1 t2 t1: $(call recipe,"One") t2: $(call recipe,"Two") 
+11
source

All Articles