是否可以在Makefile中使用位置参数而不是命名参数

  • 本文关键字:参数 位置 Makefile 是否 makefile
  • 更新时间 :
  • 英文 :


我在Makefile中创建了一个工作目标,称为test-path-testname:

## Runs tests that match a file pattern and test name to speed up test time
test-path-testname: ensure-env
docker-compose run -p 9229:9229 
-e TYPEORM_URL=postgres://postgres@postgres/someapp_test 
-e DATABASE_URL_READONLY=postgres://postgres@postgres/someapp_test 
server npm run test-all -t $(path) -- 
--detectOpenHandles --watchAll --verbose=false -t "$(testname)" 
.PHONY: test-path-testname

使用pathtestname参数,它的功能非常完美:

make path=usersArea testname="should create a new user" test-path-testname

然而,这个命令很长-有没有办法在Makefile中使用位置参数而不是命名参数

例如,我希望能够运行上面的:

make usersArea "should create a new user" test-path-testname
不可能,因为所有不包含=的非选项都被视为目标。

在你的评论后编辑,并解释动机:

您正在解决XY问题。不要选择更多的变量,而是用替换来拆分目标名称$@

test-path-testname:
@echo path=$(word 2,$(subst -, ,$@)) testname=$(word 3,$(subst -, ,$@))
docker-compose ... -t $(word 3,$(subst -, ,$@)) ...

这假设目标名称中正好有两个连字符。

最新更新