反转make变量中字符串顺序的最简单方法 [英] Simplest way to reverse the order of strings in a make variable
问题描述
假设您在makefile片段中有一个变量,如下所示:
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:
$(warning MY_LIST=${MY_LIST})
显示
MY_LIST=d c b a
真正的问题是
ld -r some_object.o ${MY_LIST}
会生成带有未定义符号的a.out
,因为MY_LIST
中的项目实际上是归档文件,但顺序错误.如果MY_LIST
的顺序颠倒,它将正确链接(我认为).如果您知道正确执行链接顺序的更聪明的方法,请提示我.
produces an a.out
with undefined symbols because the items in MY_LIST
are actually archives, but in the wrong order. If the order of MY_LIST
is reversed, it will link correctly (I think). If you know a smarter way to get the link order right, clue me in.
推荐答案
纯GNU make中的解决方案:
A solution in pure GNU make:
默认:全部
default: all
foo =请扭转我
reverse = $(如果$(1),$(调用 反向,$(单词列表2,$(单词 $(1)),$(1))))$(第一个单词$(1))
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
all:@echo $(回叫,$(foo))
all : @echo $(call reverse,$(foo))
赠予:
$ make
$ make
请我反向
这篇关于反转make变量中字符串顺序的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!