php - 如何中止 makefile 中的 shell 命令错误?

标签 php makefile

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

到目前为止我已经

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 文件的输出页面中。

我的处理方式正确吗?我应该使用 make 循环而不是 shell 循环吗?如何让 make 在 shell 命令错误时中止?

最佳答案

你可以这样做:

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

关于php - 如何中止 makefile 中的 shell 命令错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6805253/

相关文章:

php - 无法在 Linux 上安装 OAuth

c++ - 如何从 C++ 流中排除某些#include 指令?

linux - 单个文件具有多个依赖项的 makefile

php - codeigniter echo 查询结果数组

Php 在 IIS7 上不报告任何错误

linux - mktemp : invalid option -- - on RHEL5 U3

c - 在头文件更改期间重建 Makefile

c++ - cc1plus错误: output filename specified twice

php - 不同时间的双 AJAX 请求

php - 将 Javascript 正则表达式转换为 PHP