我正在尝试使用 bash 运行 makefile,该文件通常在 Mac 上使用 Eclispe 运行。该文件是:
#Project variables for prebuild.h
PROJECT_NAME := myproject
VARIANT := RELEASE
#Create prebuild.h file
CREATE_FILE := $(shell echo "/* Generated file. Do not edit. *//" > ../prebuild.h)
CREATE_FILE := $(shell echo "#define PROJECT_NAME \""$(PROJECT_NAME)"\"" >> ../prebuild.h)
CREATE_FILE := $(shell echo "#define VARIANT \""$(VARIANT)"\"" >> ../prebuild.h)
CREATE_FILE := $(shell echo "#define $(VARIANT) \""$(VARIANT)"\"" >> ../prebuild.h)
我收到的错误如下:
bash-3.2$ make
../makefile.defs:7: *** unterminated call to function `shell': missing `)'. Stop.
它可以在 Mac 上的 Eclispe 上运行,为什么不能在 bash 上运行?
你必须转义 shell 宏内的哈希值:
#Create prebuild.h file
$(shell echo "/* Generated file. Do not edit. *//" > ../prebuild.h)
$(shell echo "\#define PROJECT_NAME \""$(PROJECT_NAME)"\"" >> ../prebuild.h)
$(shell echo "\#define VARIANT \""$(VARIANT)"\"" >> ../prebuild.h)
$(shell echo "\#define $(VARIANT) \""$(VARIANT)"\"" >> ../prebuild.h)
(注意:不需要
CREATE_FILE
变量)
当然,这最好作为规则来写(做这种事情就是 make 的目的......):
prebuild.h:
@echo "/* Generated file. Do not edit. *//" > $@
@echo "#define PROJECT_NAME \""$(PROJECT_NAME)"\"" >> $@
@echo "#define VARIANT \""$(VARIANT)"\"" >> $@
@echo "#define $(VARIANT) \""$(VARIANT)"\"" >> $@