IFDEF和MAKE:条件中的语法无效
我是新手。我只是想检查给出的成品的输入是否正确,如果用户不给出任何值,我将其设置为“ 0”。遇到的错误如下:
Makefile:11 *** invalid syntax in conditional. stop.
以下是我编写的一些代码:
ifndef farm_batch
farm_batch = 0
endif
ifdef farm_batch \ #<--------- line 11 ---------
ifneq ($(farm_batch),0) \
echo "please input the correct value" \
endif \
endif \
target:
#do something here using $(farm_batch)
注意:
删除反弹时,我遇到了其他错误,这些错误是:
makefile:13:***缺少SEPERATOR。停止。 makefile:255:***缺少'endif'。停止。
示例:
使目标farm_batch = 9
谢谢您的宝贵时间。
I am new in make. I was just trying to check whether the input given to the make is correct or not and if the user does not give any value, I'll just set it to '0'. The error encountered are as follows:
Makefile:11 *** invalid syntax in conditional. stop.
Below are some of the code that I've written:
ifndef farm_batch
farm_batch = 0
endif
ifdef farm_batch \ #<--------- line 11 ---------
ifneq ($(farm_batch),0) \
echo "please input the correct value" \
endif \
endif \
target:
#do something here using $(farm_batch)
Note:
When I remove the backlashes, I encountered additional errors which are:
Makefile:13: *** missing seperator. stop. Makefile:255: *** missing 'endif'. stop.
Example:
make target farm_batch=9
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您要使变量
farm_batch
具有默认值(0
),并且还检查它确实具有此值,否则打印一条消息。首先,命令行变量分配覆盖了makefile分配。因此,对于默认值,只需将以下行添加到您的makefile:
如果仅键入
make
,则farm_batch
的值将为0
。如果您键入make farm_batch = 1
它将是1
。接下来,请勿混合制作语法和shell语法(
echo
是shell命令)。 Shell语法仅用于规则的配方(几乎),即以标签开始的规则中的所有行。在其他任何地方,都使用制作语法。使用GNU MAKE,如果您想打印消息并退出
farm_batch
不等于0
:(替换
&lt; tab&lt; tab&gt;
选项卡,<代码>info
或警告
如果您需要使用错误>错误
在此处停止和退出)。使用另一个
make
不提供info
,警告
和错误>错误
函数,您将不得不打印食谱中的消息:(再次,用选项卡替换
&lt; tab&gt;
)。请注意,您还可以用外壳在食谱内进行测试,而不是使用有条件的条件:So, you want make variable
farm_batch
to have a default value (0
) and also to check that it indeed has this value, else print a message.First of all, command-line variable assignments override Makefile assignements. So, for the default value simply add the following line to your Makefile:
If you type just
make
, the value offarm_batch
will be0
. If you typemake farm_batch=1
it will be1
.Next, don't mix make syntax and shell syntax (
echo
is a shell command). Shell syntax is for rules' recipes only (almost), that is, all lines in a rule that start with a tab. Everywhere else, use make syntax.With GNU make, if you want to print a message and exit when
farm_batch
is not equal to0
:(replace
<TAB>
with a tab, and replaceerror
byinfo
orwarning
if you want a different severity level; witherror
make stops here and exits).With another
make
that does not provide theinfo
,warning
anderror
functions you will have to put the printing of the message inside a recipe:(again, replace
<TAB>
by tabs). Note that you can also do the test with the shell, inside the recipe, instead of using make conditionals: