在GNU makefile中的最后一个单词之前获取单词 [英] Get word before the last word inside GNU makefile

查看:66
本文介绍了在GNU makefile中的最后一个单词之前获取单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 $(MAKEFILE_LIST)中提取出最后一个单词之前的单词.

I need to extract the word before the last from $(MAKEFILE_LIST).

到目前为止,我无法提出比这种怪诞更好的东西:

So far I could not come up with anything better than this kind of monstrosity:

LIST := a b c

LAST_WORD_INDEX = $(words $(LIST))
BEFORE_LAST := $(word $(shell echo $(LAST_WORD_INDEX) - 1 | bc),$(LIST))
$(info word before last is $(BEFORE_LAST))

运行时:

word before last is b
make: *** No targets.  Stop.

结果是正确的,但是有没有更优雅,更理智的方法来实现相同的目标?

The result is correct, but is there more elegant and sane way to achieve the same?

推荐答案

$(words $ {LIST})将为您提供最后一个按钮的索引>单词,如果您将元素放在 LIST 之前.

$(words ${LIST}) will give you the index of the last-but-one word if you prepend an element to LIST.

BEFORE_LAST := $(word $(words ${LIST}),1st ${LIST})

注意那里的 1st .

这篇关于在GNU makefile中的最后一个单词之前获取单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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