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

时间:2022-03-09 14:59:03

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

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

错误告警如下

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

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

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

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

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

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

原始代码如下:

 $(obj).depend:    $(src)Makefile $(TOPDIR)/config.mk $(SRCS) $(HOSTSRCS)
@rm -f $@
@for f in $(SRCS); do \
g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
$(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
done
@for f in $(HOSTSRCS); do \
g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
$(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
done
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.

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

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