在 cygwin 上测试 if 条件 makefile
Test in if condition makefile on cygwin
我试图在 makefile 的 if 条件下进行最简单的比较。
我正在使用 cygwin。我一直收到错误 XX was unexpected at this time
。其中 XX
是比较运算符的 LHS。这个确切的 makefile 在 mks 上运行,但现在我必须使用 cygwin,因为我现在 运行 它在 64 位 windows 上。
这是我的代码:
DEBUG=0
all:
if test $(DEBUG) != 0 then\
echo "not equal to 0"\
fi
我也试过这个:
DEBUG=0
all:
if [ $(DEBUG) != 0 ] then\
echo "not equal to 0"\
fi
还有这个:
DEBUG=0
all:
if [ "$(DEBUG)" != "0" ] then\
echo "not equal to 0"\
fi
这是错误:
0 was unexpected at this time. *** [all] Error 255
============================================= =======
更新:
我尝试添加缺失的 ;
并将其作为 @Jonas 的单行。建议但仍然遇到同样的问题。
一个班轮:
if [ $(DEBUG) != 0 ] ; then echo "not equal to 0" ; fi
带分号:
if [ $(DEBUG) != 0 ] ; then \
echo "not equal to 0" ; \
fi
是的,我使用的是制表符而不是空格。而且我已将行结尾更改为 LF
而已。
你需要两个 ;
。如果没有最后一个分号,则 fi
是 echo
的参数。它适用于: Linux debian 3.16.0-4-amd64.
上的 GNU Make 4.0
注意:使用旧版本的 GNU Make 时可能会出现问题。
DEBUG=1
all:
if [ $(DEBUG) != 0 ]; then \
echo "not equal to 0" ; \
fi
我试图在 makefile 的 if 条件下进行最简单的比较。
我正在使用 cygwin。我一直收到错误 XX was unexpected at this time
。其中 XX
是比较运算符的 LHS。这个确切的 makefile 在 mks 上运行,但现在我必须使用 cygwin,因为我现在 运行 它在 64 位 windows 上。
这是我的代码:
DEBUG=0
all:
if test $(DEBUG) != 0 then\
echo "not equal to 0"\
fi
我也试过这个:
DEBUG=0
all:
if [ $(DEBUG) != 0 ] then\
echo "not equal to 0"\
fi
还有这个:
DEBUG=0
all:
if [ "$(DEBUG)" != "0" ] then\
echo "not equal to 0"\
fi
这是错误:
0 was unexpected at this time. *** [all] Error 255
============================================= ======= 更新:
我尝试添加缺失的 ;
并将其作为 @Jonas 的单行。建议但仍然遇到同样的问题。
一个班轮:
if [ $(DEBUG) != 0 ] ; then echo "not equal to 0" ; fi
带分号:
if [ $(DEBUG) != 0 ] ; then \
echo "not equal to 0" ; \
fi
是的,我使用的是制表符而不是空格。而且我已将行结尾更改为 LF
而已。
你需要两个 ;
。如果没有最后一个分号,则 fi
是 echo
的参数。它适用于: Linux debian 3.16.0-4-amd64.
注意:使用旧版本的 GNU Make 时可能会出现问题。
DEBUG=1
all:
if [ $(DEBUG) != 0 ]; then \
echo "not equal to 0" ; \
fi