We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Looking at some targets of my Makefile I saw that there were some duplication.
I didn't know that I could create functions... Until now :-)
Here is a simple Makefile with a custom function:
define generate_file
sed 's/{NAME}/$(1)/' greetings.tmpl >$(2).txt
endef
all:
$(call generate_file,John Doe,101)
$(call generate_file,Peter Pan,102)
Contents of greetings.tmpl:
Hello {NAME}
This is how you execute your custom function:
$(call <name_of_function>[, <param>][,<param>][,...])
In your function the first parameter becomes $(1)
, the second $(2)
, etc.
Source: https://coderwall.com/p/cezf6g/define-your-own-function-in-a-makefile
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.