error-handling - Makefile中的自定义错误处理

标签 error-handling makefile

我需要构建一个需要特定Linux软件包的C程序。我将一个变量PACKAGENOTIFICATION设置到一个shell命令,该命令应该检查是否已为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

不幸的是,在进行依赖时,它会遇到需要该包的文件,并且在执行我的PACKAGENOTIFIFICATION之前会出错。另一种替代方法是制定一个单独的目标,该目标的唯一目的是运行通知:
maintarget: notify other_dependencies
            commands

notify: 
            $(PACKAGENOTIFICATION)

但是,由于始终需要执行此幻影依赖关系,因此,请不要让该用户报告该程序是最新的。

使始终保持最新状态并在通知消失之前执行我的通知的最佳方法是什么?

谢谢!

最佳答案

如果您的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)

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

关于error-handling - Makefile中的自定义错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853317/

相关文章:

c - SDL makefile 缺少分隔符

ubuntu - 在 Ubuntu 20.04 上编译和运行 Xrotor

spring - 使用DeadLetterPublishingRecoverer处理Spring-kafka错误

c# - 如何在多层应用程序中向用户显示异常详细信息以供解决

PHP 忽略错误并继续处理

swift - 尝试在不提示位置授权的情况下启动 MapKit 位置更新

c++ - 在 Makefile 中处理多个扩展的优雅方法

error-handling - Mule:未调用异常策略

c++ - makefile 中的条件变量

c++ - 添加 -lrt 无效时跟踪编译器错误 "undefined reference"