语句¶
条件语句¶
条件语句的语法:
1. # if ...:
<conditional-directive>
<text-if-true>
endif
2. # if ... else ...:
<conditional-directive>
<text-if-true>
else
<text-if-false>
endif
ifeq:条件判断,判断是否相等:
示例: 判断当前编译器是否 gcc ,然后指定不同的库文件: ifeq ($(CC),gcc) libs=$(libs_for_gcc) else libs=$(normal_libs) endif 例: 判断变量 ROOT_PACKAGE 是否为空: ifeq ($(ROOT_PACKAGE),)
ifneq:条件判断,判断是否不相等:
格式: ifneq (<arg1>, <arg2>) ifneq '<arg1>' '<arg2>' ifneq "<arg1>" "<arg2>"
ifdef:条件判断,判断变量是否已定义:
格式: ifdef <variable-name>
ifndef:条件判断,判断变量是否未定义:
格式: ifndef <variable-name>
循环语句¶
LIST = one two three
all:
for i in $(LIST); do \
echo $$i; \
done
# 等同于
all:
for i in one two three; do \
echo $i; \
done