Bash 生成文件期间检查错误时出现错误
我想用makefile自动生成项目文档。 我还创建了一个目标文档(和一个变量Bash 生成文件期间检查错误时出现错误,bash,makefile,doxygen,Bash,Makefile,Doxygen,我想用makefile自动生成项目文档。 我还创建了一个目标文档(和一个变量doc\u DIRECTORY=../doc)来指定文档的目录。在我的doxygen文件中,我在../doc/目录中添加了一个日志文件名“doxyLog.log” 以下是我的目标定义: #Creation of the Doxygen documentation doc: $(DOC_DIRECTORY)/path_finder_doc doxygen $(DOC_DIRECTORY)/path_finder_d
doc\u DIRECTORY=../doc
)来指定文档的目录。在我的doxygen文件中,我在../doc/目录中添加了一个日志文件名“doxyLog.log”
以下是我的目标定义:
#Creation of the Doxygen documentation
doc: $(DOC_DIRECTORY)/path_finder_doc
doxygen $(DOC_DIRECTORY)/path_finder_doc
@echo $(shell test -s ../doc/doxyLog.log; echo $$?)
ifeq ($(shell test -s ../doc/doxyLog.log; echo $$?),1)
@echo "Generation of the doxygen documentation done"
else
@echo "Error during the creation of the documentation, please check $(DOC_DIRECTORY)/doxyLog.log"
endif
为了测试我的检查是否有效,我在文档中手动引入了一个错误(像\retufjdkshrn而不是\return这样的错误命令)。但是,当我启动make doc
时,此错误在第二次之后出现:
首先生成文档(文档中有一个错误)-->完成doxygen文档的生成
Second make doc(始终是文档中的错误)-->创建文档时出错,请检查../doc/doxyLog.log
我不明白为什么,有人能帮我吗?这里似乎有两件事不对,所以这个答案的一部分肯定是猜测 第一名:
ifeq ($(shell test -s ../doc/doxyLog.log; echo $$?),1)
@echo "Generation of the doxygen documentation done"
据我所知,如果文件存在,它将返回0
,如果文件不存在,它将返回1
。我怀疑您在将其放入makefile之前没有测试它
其次,您混淆了shell命令和Make命令。这:
ifeq ($(shell test -s ../doc/doxyLog.log; echo $$?),1)
@echo "Generation of the doxygen documentation done"
else
@echo "Error..."
endif
是有条件的。Make将在运行任何规则之前对其进行评估。由于日志文件尚不存在,shell
命令将返回1
(请参见首先),条件将计算为true,整个if-then-else
语句将变为true
@echo "Generation of the doxygen documentation done"
在执行规则之前,这将成为规则的一部分。在下一个过程中,文件已经存在,shell
命令返回0
,语句变为
@echo "Error..."
这就解释了为什么你会得到奇怪的结果
如果要报告刚进行的尝试的结果,必须在规则中的命令中放入shell条件:
doc: $(DOC_DIRECTORY)/path_finder_doc
doxygen $(DOC_DIRECTORY)/path_finder_doc
@if [ -s ../doc/doxyLog.log ]; then echo Log done; else echo error...; fi
好的,我不知道我们可以使用Make条件。我想-s检查文件是否为空?由于Make文档()的示例,我在条件中使用了此语法。哼,为了与我的案例相匹配,如果必须检查
@if[!-s../doc/doxyLog.log]代码>,因为如果出现任何错误,则文件为空。但这是一个细节