Simplest way to reverse the order of strings in a make variable

后端 未结 5 1881
鱼传尺愫
鱼传尺愫 2021-02-19 11:19

Let\'s say you have a variable in a makefile fragment like the following:

MY_LIST=a b c d

How do I then reverse the order of that list? I need

5条回答
  •  粉色の甜心
    2021-02-19 11:37

    An improvement to the GNU make solution:

    reverse = $(if $(wordlist 2,2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1))) $(firstword $(1)),$(1))

    • better stopping condition, original uses the empty string wasting a function call
    • doesn't add a leading space to the reversed list, unlike the original

提交回复
热议问题