Error handling makefile中的自定义错误处理

Error handling makefile中的自定义错误处理,error-handling,makefile,Error Handling,Makefile,我需要建立一个C程序,它需要一个特定的Linux包。我在shell命令中设置了一个变量PACKAGENOTIFICATION,该命令用于检查包是否是为Ubuntu安装的,如果不是,则打印一个通知: PACKAGENOTIFICATION := if cat /etc/issue | grep Ubuntu -c >>/dev/null; then if ! dpkg -l | grep libx11-dev -c >>/dev/null; then echo "<i

我需要建立一个C程序,它需要一个特定的Linux包。我在shell命令中设置了一个变量PACKAGENOTIFICATION,该命令用于检查包是否是为Ubuntu安装的,如果不是,则打印一个通知:

PACKAGENOTIFICATION := if cat /etc/issue | grep Ubuntu -c >>/dev/null; then if ! dpkg -l | grep libx11-dev -c >>/dev/null; then echo "<insert notification here>"; fi; fi

[...]

maintarget: dependencies
            $(PACKAGENOTIFICATION)
            other_commands
但是,由于始终需要执行此虚拟依赖项,因此make never报告程序是最新的

让“始终报告”保持最新,同时在通知失效前执行通知的最佳方式是什么


谢谢

如果您的Make版本支持“仅限订单”先决条件,则可以:

# Note the pipe
maintarget: other_dependencies | notify
            commands

# This should be an order-only preq of any target that needs the package
notify: 
            $(PACKAGENOTIFICATION)

如果没有,还有其他方法。

@Beta无论最新版本的Ubuntu附带什么,恐怕我不知道如何检查。但是,理想情况下,任何解决方案都应该与仍然广泛使用的所有版本一起工作,而且还应该是独立的(尽管上面的代码在这方面已经非常缺乏)。您可以尝试
make-v
来确定版本。它可能是GNUMake的一个相当现代的版本,这意味着它将只允许订单先决条件。编写与非GNU版本的Make一起工作的Make文件是一件非常痛苦的事情,它是GNU Make 3.81。而且它有效!我只需要颠倒顺序:
main目标:|通知其他依赖项命令
# Note the pipe
maintarget: other_dependencies | notify
            commands

# This should be an order-only preq of any target that needs the package
notify: 
            $(PACKAGENOTIFICATION)