Makefile:使用多行字符串作为命令的输入

Makefile:使用多行字符串作为命令的输入,makefile,typescript,Makefile,Typescript,我想使用多行json编码字符串作为 生成文件中的命令。现在,似乎没有什么能传递给你 命令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"

我想使用多行json编码字符串作为 生成文件中的命令。现在,似乎没有什么能传递给你 命令
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)

在makefiles中,您可以使用
\
在多行上拆分某些内容:

define WATCHMAN_TYPESCRIPT_TRIGGER = \
["trigger", "./ts", { \
  "name": "tsTrigger", \
  "expression": ["suffix", "ts"], \
  "command": ["make" "typescript"] \
}] \
endef

在makefiles中,您可以使用
\
在多行上拆分某些内容:

define WATCHMAN_TYPESCRIPT_TRIGGER = \
["trigger", "./ts", { \
  "name": "tsTrigger", \
  "expression": ["suffix", "ts"], \
  "command": ["make" "typescript"] \
}] \
endef

虽然make本身似乎不可能做到这一点——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"

虽然make本身似乎不可能做到这一点——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"

JSON是否必须以多行的形式传递给
看守人
,或者您只是希望能够以这种方式在makefile中写入以提高可读性?我是为了提高可读性并尽量避免反斜杠。JSON是否必须以多行的形式传递给
看守人
,或者你只是想在makefile中以这种方式编写它以提高可读性吗?我是为了提高可读性并尽量避免反斜杠。