基于cygwin构建u-boot(三)make错误忽视

时间:2022-08-03 17:11:27

接上文,修改gcc 的-std标准后,.depend文件处理仍然出现了错误:

 

五、错误:make中命令报错(sed找不到需要的文件)

 错误告警如下

1 make -C examples/api all
2 make[1]: 进入目录“/u-boot-2010.09/u-boot-2010.09/examples/api”
3 sed -i 's/d:\//\/cygdrive\/d\//g' .depend
4 sed:无法读取 .depend:No such file or directory
5 make[1]: *** 没有规则可以创建“all”需要的目标“.depend”。 停止。
6 make[1]: 离开目录“/u-boot-2010.09/u-boot-2010.09/examples/api”
7 Makefile:378: recipe for target `examples/api' failed
8 make: *** [examples/api] Error 2

1、分析
错误提示比较明显,是 examples/api中,没有.depend规则的产生。

而之前 sed命令,是需要.depend文件存在的。

 

2、解决思路1:首先会想到if...else来实现

又有两种思路,一种是make自身带的,一种是shell工具。该部分单独讨论,不再本文描述。(大家可以自己尝试)

 

3、解决思路2:先建立一个空.depend文件

原始代码如下:

 1 $(obj).depend:    $(src)Makefile $(TOPDIR)/config.mk $(SRCS) $(HOSTSRCS)
 2         @rm -f $@
 3         @for f in $(SRCS); do \
 4             g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
 5             $(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
 6         done
 7         @for f in $(HOSTSRCS); do \
 8             g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
 9             $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
10         done
11         sed -i 's/d:\//\/cygdrive\/d\//g' $@

只需要在第2行后,增加 touch $@ 即可

 

4、解决思路3:利用make的忽视错误规则

make 对其规则中调用的外部程序返回的错误可选的应对。

To ignore errors in a recipe line, write a ‘-’ at the beginning of the line’s text

(after theinitial tab). The ‘-’ is discarded before the line is passed to the shell for execution. 

可知,如果将“-”放置到调用命令之前,就可以忽视外部命令的错误。

可以利用: - sed -i 's/d:\//\/cygdrive\/d\//g' $@

来忽视相关错误。

扩展:对于include这个内部命令也可以这样用,但还有一种别名:sinclude (相当于 -include)。

前文 autoconf.mk.dep 格式错误时,涉及到sinclude。其主要是解决引用找不到文件等错误,如果文件内部错误,sinclude也无法避免。

详细信息参见:https://www.gnu.org/software/make/manual/make.html#Errors

 

5、后记

make错误信息含义:

https://www.gnu.org/software/make/manual/make.html#Error-Messages

 之前,make的错误为:multiple target patterns. Stop.

 1 ‘missing target pattern. Stop.’
 2 ‘multiple target patterns. Stop.’  3 ‘target pattern contains no ‘%’. Stop.’
 4 ‘mixed implicit and static pattern rules. Stop.’
 5     These are generated for malformed static pattern rules. 
 6     The first means there’s no pattern in the target section of the rule; 
 7     the second means there are multiple patterns in the target section;  8     the third means the target doesn’t contain a pattern character (%); 
 9     and the fourth means that all three parts of the static pattern rule 
10       contain pattern characters (%)–only the first two parts should. 
11     If you see these errors and you aren’t trying to create a static pattern rule, 
12       check the value of any variables in your target and prerequisite lists 
13       to be sure they do not contain colons. 

 

===【未完待续】===