Greater than string comparison in a Makefile

前端 未结 3 1223
甜味超标
甜味超标 2021-01-02 02:00

How do I express the following logic in a Makefile?

if $(XORG_VERSION) > \"7.7\"
   
fi

Conditional Parts of Makefi

3条回答
  •  长情又很酷
    2021-01-02 02:40

    Using shell commands, as mentioned in the other answers, should suffice for most use cases:

    if [ 1 -gt 0 ]; then \
        #do something \
    fi
    

    However, if you, like me, want to use greater-than comparison in order to then set a make variable via make's $(eval) command, then you will find that attempting to do so using the other answer's model:

    if [ 1 -gt 0 ]; then \
        $(eval FOO := value) \
    fi
    

    raises an error:

    if [ 1 -gt 0 ]; then  fi;
    /bin/bash: -c: line 0: syntax error near unexpected token `fi'
    /bin/bash: -c: line 0: `if [ 1 -gt 0 ]; then  fi;'
    make: *** [clean] Error 2```
    

    I found a way how to sort out that problem and posted it as a solution to this other question. I hope someone finds it helpful!

提交回复
热议问题