1、条件关键字四个
ifdef <variable-name>
a、ifeq
ifeq (<arg1>,<arg2>)ifeq '<arg1>' '<arg2>'
ifeq "<arg1>" "<arg2>"
ifeq "arg1" 'arg2'
ifeq 'arg1' "arg2"
endif
关键字比较参数arg1和arg2的值是否相同,如果相同则表达式为真,否则为假。
例:
a=1
b=2
all:
ifeq ($a,$b)
echo "a=b"
else
echo "a!=b"
endif
ifeq '$a' '$b'
echo "a=b"
else
echo "a!=b"
endif
ifeq "$a" "$b"
echo "a=b"
else
echo "a!=b"
endif
ifeq '$a' "$b"
echo "a=b"
else
echo "a!=b"
endif
ifeq "$a" '$b'
echo "a=b"
else
echo "a!=b"
endif
make -s -all
a!=b
a!=b
a!=b
a!=b
a!=b
b、ifneq
ifneq (<arg1>,<arg2>)
ifneq '<arg1>' '<arg2>'
ifneq "<arg1>" "<arg2>"
ifneq "arg1" 'arg2'
ifneq 'arg1' "arg2"
endif
关键字比较参数arg1和arg2的值是否相同,如果不相同则表达式为真,否则为假。
例:
a=1
b=2
all:
ifneq ($a,$b)
echo "a=b"
else
echo "a!=b"
endif
ifneq '$a' '$b'
echo "a=b"
else
echo "a!=b"
endif
ifneq "$a" "$b"
echo "a=b"
else
echo "a!=b"
endif
ifneq '$a' "$b"
echo "a=b"
else
echo "a!=b"
endif
ifneq "$a" '$b'
echo "a=b"
else
echo "a!=b"
endif
make -s -all
a=b
a=b
a=b
a=b
a=b
c、ifdef
ifdef关键字表示如果值非空则执行,其格式如下ifdef <variable-name>
ifdef关键字判断变量<variable-name>的值,如果非空,则表达式为真否则为假。
例:
a=a
b=b
all:
ifdef a
echo $a
else
echo null
endif
ifdef b
echo $b
else
echo null
endif
ifdef c
echo $c
else
echo null
endif
make -s -all
a
b
null
ifndef <variable-name>
ifndef关键字判断变量<variable-name>的值。如果为空则表示为真,否则为假。例:
a=a
b=b
c=
all:
ifndef a
echo $a
else
echo null
endif
ifndef b
echo $b
else
echo null
endif
ifndef c
echo c
else
echo null
endif
make -s -all
null
null
c
循环编译每个子目录的Makefile
SUBDIRS=src\
sec
all:
@if test "$(SUBDIRS)" != ""; then \
it="$(SUBDIRS)" ; \
for i in $$it ; do \
echo "making all in `pwd`/$$i"; \
( cd $$i ; $(MAKE) ) ; \
if test $$? != 0 ; then \
exit 1 ; \
fi \
done \
fi