反转make变量中字符串顺序的最简单方法 [英] Simplest way to reverse the order of strings in a make variable

查看:59
本文介绍了反转make变量中字符串顺序的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆