您如何在makefiles中中止shell命令错误? [英] How do you abort on shell command errors in makefiles?

查看:91
本文介绍了您如何在makefiles中中止shell命令错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个makefile来打包一些PHP脚本.我还希望它在构建最终的zip文件之前检查语法错误(使用内置的php lint工具),以防止发生任何意外错误.

I'm trying to write a makefile to package up some PHP scripts. I would also like it to check for syntax errors (using the built in php lint tool) before building the final zip file, to prevent any accidental errors slipping in.

到目前为止,我已经拥有

So far I have

all: dist
clean:
    rm -f output.zip
dist: clean
    for i in `find . -name "*.php"`; do php -l $$i; done
    zip -r output.zip src -x "*/.*" "*/tests*"

这有效,但是如果出现PHP错误,我希望它能够中断并且不继续构建zip文件(出于明显的原因).目前,它们可能只是在成功运行lint和zip文件的输出页面中丢失了.

This works, but if there is a PHP error I would like it to break and not continue building the zip file (for obvious reasons). Currently they may just get lost in the pages of output from successful lint runs and the zip file.

我要这样做正确吗?我应该使用make循环而不是shell循环吗?如何使make在Shell命令错误时中止?

Am I going about this the right way? Should I be using a make loop rather than a shell loop? How to you get make to abort on shell command errors?

推荐答案

您可以执行以下操作:

for i in `find . -name "*.php"`; do \
  php -l $$i; \
  if [ $$? -ne 0 ] ; then exit 42 ; fi \
done

这篇关于您如何在makefiles中中止shell命令错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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