我希望使用多行json编码的字符串作为makefile中命令的输入。现在,似乎没有任何东西传递给命令watchman-typescript或watchman-debug。
Makefile
.PHONY: typescript
typescript:
tsc --target ES5 ts/main.ts
.PHONY: watch
watch:
watchman watch .
define WATCHMAN_TYPESCRIPT_TRIGGER =
["trigger", "./ts", {
"name": "tsTrigger",
"expression": ["suffix", "ts"],
"command": ["make", "typescript"]
}]
endef
.PHONY: watchman-typescript
watchman-typescript:
watchman -j '$(WATCHMAN_TYPESCRIPT_TRIGGER)'
.PHONY: watchman-debug
watchman-debug:
echo $(WATCHMAN_TYPESCRIPT_TRIGGER)发布于 2014-12-31 02:06:47
虽然这在make本身看来是不可能的--最终将变量的每一行解释为食谱中的命令--但有一个解决办法:您可以将变量导出为shell变量,并在命令中引用该变量。这就是:
define WATCHMAN_TYPESCRIPT_TRIGGER =
["trigger", "./ts", {
"name": "tsTrigger",
"expression": ["suffix", "ts"],
"command": ["make" "typescript"]
}]
endef
# export as shell variable
export WATCHMAN_TYPESCRIPT_TRIGGER
# ...
# use shell variable in the command. $$ in make means $ in the shell command.
watchman-typescript:
watchman -j "$$WATCHMAN_TYPESCRIPT_TRIGGER"发布于 2014-12-31 01:17:34
在makefile中,可以使用行延拓字符 \将某些内容拆分为多行:
define WATCHMAN_TYPESCRIPT_TRIGGER = \
["trigger", "./ts", { \
"name": "tsTrigger", \
"expression": ["suffix", "ts"], \
"command": ["make" "typescript"] \
}] \
endefhttps://stackoverflow.com/questions/27714675
复制相似问题