从MSVC输出生成Makefile依赖项 [英] Generate Makefile dependency from MSVC output

查看:436
本文介绍了从MSVC输出生成Makefile依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GCC编译C/C ++源代码时,可以使用标记-MMD -MT $@ -MF $(basename $@).d以Makefile规则格式创建其他依赖项信息.我使Makefile脚本与GCC和MSVC工具链兼容,但是我仍然在MSVC上依赖文件的生成方面苦苦挣扎.
有一个标志/showIncludes 输出源文件的信息以以下格式Note: including file: filename包含在stdout中.试图解析它(到目前为止成功),我得到了以下makefile函数:

While compiling a C/C++ source using GCC additional dependency info can be created in a Makefile rule form using the flags -MMD -MT $@ -MF $(basename $@).d. I made my Makefile script compatible with GCC and MSVC toolchains, but i still strugle with the dependency file generation on MSVC.
There is a flag /showIncludes that outputs source file include information in stdout in the following form Note: including file: filename. Trying to parse it (so far successfully) i got as far as the following makefile function:

msvc-dep-gen =  echo $@: $< |\
    sed -e "s/^.*$$/&\\/" >$(basename $@).d && \
    $(1) /showIncludes |\
    sed -e "/^Note: including file:/!d"\
        -e "s/^Note: including file:\s*\(.*\)$$/\1/"\
        -e "s/\\/\//g"\
        -e "s/ /\\ /g"\
        -e "s/^\(.*\)$$/\t\1 \\/" >> $(basename $@).d

其中参数$(1)是包装的命令,用于使用MSVC编译给定的源文件.这样可以很好地生成依赖文件,但是输出被过滤掉了,所以我丢失了所有警告,并且编译器产生了错误退出.关于如何防止这种情况有任何聪明的主意吗?

Where the parameter $(1) is the wrapped command to compile the given source file with MSVC. This generates the dependency file fine, but the output is filtered out so i lose all the warnings and the error exits produced by the compiler. Any clever ideas on how to prevent this?

推荐答案

如果将其放在顶部set -e的shell脚本中,则失败将导致退出并显示非零代码,Make会看到它.

If you put this in a shell script with set -e at the top, then failures will result in exiting with a non-zero code, and Make will see it.

这篇关于从MSVC输出生成Makefile依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆