如何在Makefile中使用多个嵌套的if-then块?
例如
$(NAMING_SCHEME).$(COMPRESS_TYPE):
ifeq ($(COMPRESS_TYPE),lz4)
if [ ${LOG_LEVEL} -gt 0 ] ; then \
@echo hi \
if [ ${LOG_LEVEL} -gt 1 ] ; then \
@echo hi again \
if [ ${LOG_LEVEL} -gt 2 ] ; then \
@echo hi for the last time!!! \
fi; \
fi; \
fi;
endif
此结果导致
bin/sh: -c: line 2: syntax error near unexpected token 'then'
/bin/sh: -c: line 0: 'ifeq (1, 1)'
make: *** [Makefile:22: program_name.1.2.3.lz4] Error 1
我做错了什么?
make
单独将每一行发送到外壳,因此会破坏您的命令。要继续一行,请以反斜杠(\
)结束。
根据beta和vonbrand的建议,我能够使它成功,谢谢一百万!
ifeq ($(COMPRESS_TYPE),lz4)
if [ ${LOG_LEVEL} -gt 0 ] ; then \
echo 111 ${LOG_LEVEL} ;\
if [ ${LOG_LEVEL} -gt 1 ] ; then \
echo 222 ${LOG_LEVEL} ;\
if [ ${LOG_LEVEL} -gt 2 ] ; then \
echo 333 ${LOG_LEVEL} ;\
fi \
fi \
fi
endif
此输出(在Windows cmd中为::
if [ 2 -gt 0 ] ; then \
echo 111 2 ;\
if [ 2 -gt 1 ] ; then \
echo 222 2 ;\
if [ 2 -gt 2 ] ; then \
echo 333 2 ;\
fi \
fi \
fi
111 2
222 2