Search code examples
unixif-statementmakefiletcsh

Makefile Rules and If Statements -- How?


I'm new to Makefiles so please bear with me.

I need to modify a Makefile so some rules call different utilities depending on a variable.

Right now, a rule looks like:

ci:
    [shell syntax for tool (A)]

But now I need ci to have a different syntax depending on the variable. So I define a global variable at the top of the file:

TOOL = toolA

or

TOOL = toolB

Ideally what I'd like is something like this, but obviously it doesn't work:

ifeq ($TOOL, toolA)
    ci:
        [syntax for tool (A)]
else
    ci:
        [syntax for tool (B)
endif

Does anyone know the best way to implement something like this properly?

Thanks!!

EDIT: The tool syntax is more complicated than one line. Sometimes its multiple lines and not just "toolA args etc etc". Sorry for the confusion!


Solution

  • You're just missing some parentheses:

    ifeq ($(TOOL), toolA)
    ...
    

    P.S. You can make the conditional a little tighter (and remove a little redundancy):

    ci:
    ifeq ($(TOOL), toolA)
        [syntax for tool (A)]
    else
        [syntax for tool (B)
    endif