eclipse 使用make创建文件失败,但可以使用Eclispe

utugiqy6  于 2023-10-18  发布在  Eclipse
关注(0)|答案(1)|浏览(167)

我试图运行一个makefile使用bash,通常是运行在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工作?

oxosxuxt

oxosxuxt1#

看起来make中有一两个bug(至少在我的版本- 3.81中),处理#符号。
有趣的是:

$(info #this works)
VAR := $(info #this doesnt)
VAR := $(info \#this does)

$(shell echo #this works > tmp.txt)
VAR := $(shell echo #this doesnt >> tmp.txt)

最好的解决方案是将其编写为目标和配方:

../prebuild.h:
    @echo "/* Generated file. Do not edit. *//" > $@
    @echo "#define PROJECT_NAME \""$(PROJECT_NAME)"\"" >> $@
    @echo "#define VARIANT \""$(VARIANT)"\"" >> $@
    @echo "#define $(VARIANT) \""$(VARIANT)"\"" >> $@

否则,要么升级到更高版本的make,要么让make调用一个shell脚本来为您完成这项工作。

相关问题