makefile define macro問題 - Linux
![Andrew avatar](/img/beret.jpg)
By Andrew
at 2020-03-09T14:48
at 2020-03-09T14:48
Table of Contents
在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,想請問這是什麼緣故呢?
謝謝各位
--
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,想請問這是什麼緣故呢?
謝謝各位
--
Tags:
Linux
All Comments
![Skylar Davis avatar](/img/boy1.jpg)
By Skylar Davis
at 2020-03-10T14:26
at 2020-03-10T14:26
![Kama avatar](/img/girl2.jpg)
By Kama
at 2020-03-11T10:25
at 2020-03-11T10:25
Related Posts
Centos7.5 識別主機板sata插槽
![Hardy avatar](/img/cat2.jpg)
By Hardy
at 2020-03-06T17:26
at 2020-03-06T17:26
Lubuntu 18.04 MAC位置亂跳
![Jake avatar](/img/boy2.jpg)
By Jake
at 2020-03-05T14:56
at 2020-03-05T14:56
教學影片分享-用圖片輕鬆學Docker
![Isabella avatar](/img/woman.jpg)
By Isabella
at 2020-03-04T23:07
at 2020-03-04T23:07
Re: 公用電腦系統逐年更換至 linux 連署
![Emma avatar](/img/cat1.jpg)
By Emma
at 2020-03-04T15:20
at 2020-03-04T15:20
Re: 公用電腦系統逐年更換至 linux 連署
![Frederica avatar](/img/girl2.jpg)
By Frederica
at 2020-03-03T14:18
at 2020-03-03T14:18