作者:
sshc (My Chemical Romance)
2020-03-09 14:48:00在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,想請問這是什麼緣故呢?
謝謝各位