http://www.perlmonks.org?node_id=1038692

bhasky76 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am using a makefile to do the following things 1. perl script to parse a C file. Then 2. using gcc to compile the same C file. Now in case there is a gcc compilation error it stops the make utility at that point. But I am unable to stop the make if there is any compilation/runtime error while executing the perl script. Please shed some light.

The makefile is like
@echo Parsing tmp.c; \ perl c_parser.pl arg1 arg2;\ echo Compiling tmp.c;\ gc tmp.c

Replies are listed 'Best First'.
Re: perl from makefile
by choroba (Cardinal) on Jun 13, 2013 at 07:31 UTC
    Makefile stops, if the command returns a non-zero exit status. In a command list (i.e. simple commands separarated by semicolons), the exit status is the status of the last command in the list. You have two options:
    1. Remove the semicolons and backslashes. Make will run each line separately and stop if there is a problem.
    2. Replace each semicolon with a &&. That way, the shell will stop on the first error (short circuiting the "and").
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: perl from makefile
by aitap (Curate) on Jun 13, 2013 at 07:27 UTC
    This is Makefile question, not a Perl question. Your Makefile says: "run a command consisting of four lines without printing it". Remove backslashes, and you'll have four different commands, and make will be able to stop the execution if Perl parser fails. You can also add set -e; \ before perl ..., this will make the subshell which is running your multi-line command fail if any of the following commands fail.