makefile - 如何通过 Makefile 中的分隔符拆分字符串?
问题描述
这是我的 Makefile 中的代码片段:
%/foo: %/bar.yaml
$(BINARY) generate -g go \
--package-name {COOL_VALUE}
# COOL_VALUE should be the parent folder of a `foo`, e.g., `foo1/foo2/foo -> foo2`
问题是如何拆分$@
字符串/
以获得倒数第二个元素:
例如,
make foo1/foo2/foo
> ./binary generate -g go \
--package-name foo2
make foo3/foo
> ./binary generate -g go \
--package-name foo3
我的尝试:我想出了
$(eval package_name := $(word 1,$(subst /, ,$@)))
% pick second last element somehow
解决方案
$(eval package_folders := $(filter-out foo,$(subst /, ,$@)))
$(eval package_name := $(word $(words $(package_folders)), $(package_folders)))
@echo "$(package_name)"
推荐阅读
- java - Android 应用程序在某些设备中无故崩溃
- javascript - Firebase 数据库 - 登录
- java - 我无法连接到 Maria db 它说套接字失败我尝试的所有解决方案都不起作用
- python - 使用 Discord.py 获取用户信息
- c# - System.Data.SqlClient 和多个活动结果集 (MARS)
- python - 在 matplotlib 中排除特定艺术家时自动缩放
- python - 试图关闭popover - python - selenium - Glassdoor
- android - Android:闪烁的片段标题
- swift - 模态选择器没有向右滚动SwiftUI
- python - 删除 pip 然后在 python3.x 中安装 pip3