简体   繁体   中英

If statement Makefile tcsh

I want something like :

my_rule:
       if($(VAR) == $@) then
             echo 'ok'
       else
             echo 'ko'
       endif

I have to use tsch but I know that Makefile use sh , so I really wonder if I have to use sh or tcsh if statement syntax here... ? The correct syntax for if statement in a tsch script is (I checked) :

#!/bin/csh

if(3 == 3) then
    echo 'yes'
else
    echo 'no'
endif

I tried to put ; and \\ everywhere in my Makefile but nothing work.

The shell is taken from the variable SHELL , and if not specified, defaults to /bin/sh . Assuming you're not overriding the shell, then your syntax would be:

my_rule:
       if [ "$(VAR)" == "$@" ]; then \
         echo 'ok'; \
       else \
         echo 'ko'; \
       fi

You need to use the \\ 's to concatenate the lines into a single recipe line. Notice this does not introduce actual newlines, so you also have to manually terminate each command with a ; . Finally, put quotes around the variables, so that if one happens to be blank, you don't get a syntax error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM