【发布时间】:2013-06-15 15:38:09
【问题描述】:
我有一个复杂的逻辑来检测 Makefile 变量的路径。我放弃了用make语言做这件事,所以我用Python编写了代码,并希望将代码嵌入到Makefile中来设置变量。但是,这不起作用:
define DETECT_SDK
import os
locations = [
"../google_appengine",
"/usr/local/google_appengine",
"../.locally/google_appengine",
]
for path in locations:
if os.path.exists(path):
print(path)
break
else:
print(".")
endef
SDK_PATH ?= $(shell python -c $(DETECT_SDK))
default:
python -c 'import sys; print(sys.argv)' $(SDK_PATH)
更新:从Is it possible to create a multi-line string variable in a Makefile 更新了多行定义
以前它因Makefile:2: *** missing separator. Stop. 而失败。现在它失败并出现另一个错误:
/bin/sh: 1: Syntax error: "(" unexpected
python -c 'import sys; print(sys.argv)'
['-c']
【问题讨论】: