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

后端 未结 5 1893
鱼传尺愫
鱼传尺愫 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:26

    Playing off of both Ben Collins' and elmarco's answers, here's a punt to bash which handles whitespace "properly"1

    reverse = $(shell printf "%s\n" $(strip $1) | tac)
    

    which does the right thing, thanks to $(shell) automatically cleaning whitespace and printf automatically formatting each word in its arg list:

    $(info [ $(call reverse,  one two   three four  ) ] )
    

    yields:

    [ four three two one ]
    

    1...according to my limited test case (i.e., the $(info ...) line, above).

提交回复
热议问题