Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

functions in makefiles?

Tags:

makefile

I have a slew of makefile targets that do the same thing:

${SOME_FILE}:
    ${FILES} | ${DIST_DIR}

    @@cat ${FILES} |                     \
        sed 's/@DATE/'"${DATE}"'/' |     \
        sed 's/@VERSION/'"${CR_VER}"'/'  \
        > ${OUT_FILE};

where ${FILES} and ${OUT_FILE} are the only things changing. I'm trying to figure out if it's possible to simplify these targets to something like:

${SOME_FILE}:
    compile(${FILES},${OUT_FILE})

Thanks for any insight.

like image 939
Nobody Avatar asked Jul 21 '11 21:07

Nobody


People also ask

What is the function of a makefile?

Makefile sets a set of rules to determine which parts of a program need to be recompile, and issues command to recompile them. Makefile is a way of automating software building procedure and other complex tasks with dependencies. Makefile contains: dependency rules, macros and suffix(or implicit) rules.

How do you call a function in makefile?

The call function is unique in that it can be used to create new parameterized functions. You can write a complex expression as the value of a variable, then use call to expand it with different values. The syntax of the call function is: $(call variable , param , param ,…)

What are rules in makefiles?

A rule appears in the makefile and says when and how to remake certain files, called the rule's targets (most often only one per rule). It lists the other files that are the dependencies of the target, and commands to use to create or update the target.


1 Answers

GNU make has this:

  • http://www.gnu.org/software/make/manual/make.html#Call-Function

To define a multi-line function, you would use this syntax:

  • http://www.gnu.org/software/make/manual/make.html#Canned-Recipes
like image 62
asdf Avatar answered Sep 20 '22 11:09

asdf