当前位置: 技术问答>linux和unix
Makefile 循环中赋值问题
来源: 互联网 发布时间:2016-06-13
本文导语: 有下面的makefile,循环中赋值有问题 LOCAL_INC:include SUBDIRS := cmm api cli ctr lic CURRDIR := CURRFB := PRJINC := $(CURRDIR)/$(LOCAL_INC) LINKPATH:= $(CURRFB) $(PRJINC) LOOPCNT := 1 ALLCNT := $(words $(SUBDIRS)) linkmd:linkpre whi...
有下面的makefile,循环中赋值有问题
LOCAL_INC:include
SUBDIRS := cmm api cli ctr lic
CURRDIR :=
CURRFB :=
PRJINC := $(CURRDIR)/$(LOCAL_INC)
LINKPATH:= $(CURRFB) $(PRJINC)
LOOPCNT := 1
ALLCNT := $(words $(SUBDIRS))
linkmd:linkpre
while [ $(LOOPCNT) -le $(ALLCNT) ]; do
CURRFB = $(word $(LOOPCNT), $(SUBDIRS)) ;
CURRFB += $(CURRDIR)/$(CURRFB)/$(LOCAL_INC)/*.H
@echo linking files...
-ln $(LINKPATH)
LOOPCNT=`expr $(LOOPCNT) + $n`
done
linkpre:
CURRDIR=$(shell pwd)
.PHONY: linkmd linkpre
循环中CURRFB LOOPCNT无法取得变量的数值,求教应如何修改
LOCAL_INC:include
SUBDIRS := cmm api cli ctr lic
CURRDIR :=
CURRFB :=
PRJINC := $(CURRDIR)/$(LOCAL_INC)
LINKPATH:= $(CURRFB) $(PRJINC)
LOOPCNT := 1
ALLCNT := $(words $(SUBDIRS))
linkmd:linkpre
while [ $(LOOPCNT) -le $(ALLCNT) ]; do
CURRFB = $(word $(LOOPCNT), $(SUBDIRS)) ;
CURRFB += $(CURRDIR)/$(CURRFB)/$(LOCAL_INC)/*.H
@echo linking files...
-ln $(LINKPATH)
LOOPCNT=`expr $(LOOPCNT) + $n`
done
linkpre:
CURRDIR=$(shell pwd)
.PHONY: linkmd linkpre
循环中CURRFB LOOPCNT无法取得变量的数值,求教应如何修改
|
[code=BatchFile]
SUBDIRS := cmm api cli ctr lic
LOOPCNT := 1
ALLCNT := $(words $(SUBDIRS))
all:
@loopcnt=$(LOOPCNT);
while [ $${loopcnt} -le $(ALLCNT) ]; do
echo "loopcnt: $${loopcnt}";
loopcnt=`expr $${loopcnt} + 1`;
done;
LOOPCNT=$${loopcnt};
echo '$$$${LOOPCNT}: ' "$${LOOPCNT}";
echo '$${LOOPCNT}: ' "${LOOPCNT}";
echo '$$(LOOPCNT): ' "$(LOOPCNT)"
# 输出为:
# loopcnt: 1
# loopcnt: 2
# loopcnt: 3
# loopcnt: 4
# loopcnt: 5
# $${LOOPCNT}: 6
# ${LOOPCNT}: 1
# $(LOOPCNT): 1
[/code]
从结果分析:
Makefile里的变量比如LOOPCNT在开始处理target之后,是不会被赋值的。
因为LOOPCNT=$${loopcnt}这类语句是给shell变量赋值。
看了下面的例子一定,大家都会觉得很糊涂。
[code=BatchFile]
SUBDIRS := cmm api cli ctr lic
LOOPCNT := 1
ALLCNT := $(words $(SUBDIRS))
all:
@LOOPCNT=$(LOOPCNT);
while [ $${LOOPCNT} -le $(ALLCNT) ]; do
echo "LOOPCNT: $${LOOPCNT}";
LOOPCNT=`expr $${LOOPCNT} + 1`;
done;
LOOPCNT=$${LOOPCNT};
echo '$$$${LOOPCNT}: ' "$${LOOPCNT}";
echo '$${LOOPCNT}: ' "${LOOPCNT}";
echo '$$(LOOPCNT): ' "$(LOOPCNT)"
[/code]
再看看下面的例子,大家应该什么都明白了
[code=BatchFile]
FOO = FOO_000
all:
FOO=FOO_001
echo $(FOO)
FOO=FOO_002;
echo $(FOO)
FOO=FOO_003;
echo $${FOO}
FOO=FOO_004
echo $(FOO)
echo $${FOO}
[/code]
SUBDIRS := cmm api cli ctr lic
LOOPCNT := 1
ALLCNT := $(words $(SUBDIRS))
all:
@loopcnt=$(LOOPCNT);
while [ $${loopcnt} -le $(ALLCNT) ]; do
echo "loopcnt: $${loopcnt}";
loopcnt=`expr $${loopcnt} + 1`;
done;
LOOPCNT=$${loopcnt};
echo '$$$${LOOPCNT}: ' "$${LOOPCNT}";
echo '$${LOOPCNT}: ' "${LOOPCNT}";
echo '$$(LOOPCNT): ' "$(LOOPCNT)"
# 输出为:
# loopcnt: 1
# loopcnt: 2
# loopcnt: 3
# loopcnt: 4
# loopcnt: 5
# $${LOOPCNT}: 6
# ${LOOPCNT}: 1
# $(LOOPCNT): 1
[/code]
从结果分析:
Makefile里的变量比如LOOPCNT在开始处理target之后,是不会被赋值的。
因为LOOPCNT=$${loopcnt}这类语句是给shell变量赋值。
看了下面的例子一定,大家都会觉得很糊涂。
[code=BatchFile]
SUBDIRS := cmm api cli ctr lic
LOOPCNT := 1
ALLCNT := $(words $(SUBDIRS))
all:
@LOOPCNT=$(LOOPCNT);
while [ $${LOOPCNT} -le $(ALLCNT) ]; do
echo "LOOPCNT: $${LOOPCNT}";
LOOPCNT=`expr $${LOOPCNT} + 1`;
done;
LOOPCNT=$${LOOPCNT};
echo '$$$${LOOPCNT}: ' "$${LOOPCNT}";
echo '$${LOOPCNT}: ' "${LOOPCNT}";
echo '$$(LOOPCNT): ' "$(LOOPCNT)"
[/code]
再看看下面的例子,大家应该什么都明白了
[code=BatchFile]
FOO = FOO_000
all:
FOO=FOO_001
echo $(FOO)
FOO=FOO_002;
echo $(FOO)
FOO=FOO_003;
echo $${FOO}
FOO=FOO_004
echo $(FOO)
echo $${FOO}
[/code]
|
你试试
LOOPCNT=$(($(LOOPCNT)) + ($n))
我现在没有 linux 环境,试不了。
LOOPCNT=$(($(LOOPCNT)) + ($n))
我现在没有 linux 环境,试不了。