我正在尝试在Makefile中执行此操作:
value = 2.0
if ${greaterthan ${value}, 1.50}
-> execute a rule
elseif ${lessthan ${value}, 0.50}
-> execute a rule
endif
Run Code Online (Sandbox Code Playgroud)
这似乎是一件很常见的事情.这样做的最佳方法是什么?
man*_*tha 17
试试这个
在此示例中,检查VER大于4
ifeq ($(shell test $(VER) -gt 4; echo $$?),0)
IFLAGS += -I$(TOPDIR)/include
LIBS += -L$(TOPDIR)/libs -lpcap
endif
Run Code Online (Sandbox Code Playgroud)
eld*_*his 10
与此问题类似,但基本上您可以在Makefile中使用shell命令.所以以下是完全合法的:
foo:
if [ ${value} -gt 2 ] ; then \
#Do stuff;\
fi
Run Code Online (Sandbox Code Playgroud)
编辑小免责声明:IIRC,bash
不了解浮点运算.它可以将它们解释为字符串,但它可能会让事情变得有些奇怪.请务必考虑到这一点.
小智 5
我的首选方法是:
value = 2.0
ifeq ($(shell expr $(value) \>= 1.5), 1)
# execute a rule
else ifeq ($(shell expr $(value) \<= 0.5), 1)
# execute a rule
endif
Run Code Online (Sandbox Code Playgroud)