作者sshc (My Chemical Romance)
看板Linux
标题[问题] makefile define macro问题
时间Mon Mar 9 14:48:00 2020
在makefile撰写上遇到了一个问题,以下是我makefile内的一段程式
define collect-names:
cd $1; \
shopt -s nullglob; \
for f1 in $(foreach sub_dir,$2,'(sub_dir)'); do \
echo "Collect Files from...$1$$f1"; \
for f2 in $(foreach file_ext,$3,'$(file_ext)'); do \
echo "**Collect File Type : *$$f2"; \
files=( `echo$$f1$/*$(if $$f2,$$f2)` ); \
if (( $${#files[@] >0} )); \
then \
printf '"%s"\n' $${fiels[@]}; \
fi; \
echo ""; \
done \
done
endef
all:
@$(call collect-names,/root_dir/,sub_dir1/ sub_dir2/,.v .sv)
但是我发现如果将第二层for loop内的 echo ""; \
往上移至第一层for loop内,如下所示
define collect-names:
cd $1; \
shopt -s nullglob; \
for f1 in $(foreach sub_dir,$2,'(sub_dir)'); do \
echo "Collect Files from...$1$$f1"; \
for f2 in $(foreach file_ext,$3,'$(file_ext)'); do \
echo "**Collect File Type : *$$f2"; \
files=( `echo$$f1$/*$(if $$f2,$$f2)` ); \
if (( $${#files[@] >0} )); \
then \
printf '"%s"\n' $${fiels[@]}; \
fi; \
done \
echo ""; \
done
endef
all:
@$(call collect-names,/root_dir/,sub_dir1/ sub_dir2/,.v .sv)
程式便会产生error,想请问这是什麽缘故呢?
谢谢各位
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 211.72.173.145 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Linux/M.1583736482.A.A18.html
1F:推 Gold740716: 为什麽你的第一个 for 双引号右边是单引号? 03/09 22:51
※ 编辑: sshc (211.72.173.145 台湾), 03/13/2020 11:38:39
2F:→ sshc: sorry,是笔误,已改正 03/13 11:39