我在 GNU makefile 方面遇到了一个愚蠢的问题。 我想定义两个目标来构建一个c程序;一个有调试,另一个没有。
runNoDebug: setNoDeb objs runMe
runDebug: setDeb objs runMe
setNoDeb:
{EXPORT} MyDEBUG= -O3
setDeb:
{EXPORT} MyDEBUG="-DDEBUG=1 -g"
objs: cFiles
$(CC) -o $@ $^ $(cFiles) $(CFLAGS) $(LIBS) $(MYDEBUG)
runme: objs
./oo
运行此 makefile 时出现错误,设置调试的命令在子 shell 上执行,导致错误。如果添加“Export”,则变量将在该子 shell 中定义。
我想在 makefile 中定义这个变量,以便在构建对象时使用。
这可能吗?或者我应该复制“objs:cFiles”目标?
最佳答案
您需要target-specific variable values :
This feature allows you to define different values for the same variable, based on the target that make is currently building.
runNoDebug: setNoDeb runMe
runDebug: setDeb runMe
setNoDeb: CFLAGS += -O3
setNoDeb: objs
setDeb: CPPFLAGS += -DDEBUG=1
setDeb: CFLAGS += -g
setDeb: objs
objs: $(cFiles)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
关于linux - 在 Makefile 命令中设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11629233/