Greater than string comparison in a Makefile

前端 未结 3 1219
甜味超标
甜味超标 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:30

    I use the sort function to compare values lexicographically. The idea is, sort the list of two values, $(XORG_VERSION) and 7.7, then take the first value - if it's 7.7 then the version is the same or greater.

    ifeq "7.7" "$(word 1, $(sort 7.7 $(XORG_VERSION)))"
       
    endif
    

    Adjust 7.7 to 7.8 if you need the strict greater-than condition.

    This approach improves portability by avoiding shell scripts and concomitant assumptions about the capabilities of the available OS shell. However, it fails if the lexicographic ordering is not equivalent to the numerical ordering, for example when comparing 7.7 and 7.11.

提交回复
热议问题