I have created the following bash build script file :
BLD_INCLUDE="-I..source/module1 -I..source/module2"
SRC_MOD1="$(find ../source/module1 -name '*.c')"
SRC_MOD2="$(find ../source/module2 -name '*.c')"
BLD_SOURCES="../source/program.c $SRC_MOD1 $SRC_MOD2"
BLD_LINKER="" #if there is any need of linker - irrelevant here
gcc $BLD_FLAGS $BLD_INCLUDE -o outputobject $BLD_SOURCES $BLD_LINKER
I am building like this because there are lot of files I need to compile.
The problem is, when executing multiple files using gcc, like above, if the compilation of one of the files fails, it prompts for the error along with "compilation terminated" and then continues executing other files.
The behaviour I want is, that even if one of the file fails to compile, whole compilation stops.
That is, in my case : suppose there is a header file missing. Now gcc tries to compile the very first .c
, finds that the header file is missing, prompts
fatal error : file missing error compilation terminated.
and then continues with execution of other .c
files. Since the header file is missing in all, it keeps on giving me this error and continues execution.
I want this build script to terminate as soon as compilation fails even of one of the files.
Edit : Not a duplicate of Stop GCC on error with multiple files compilation, it originated from this very question itself (read comments). The question even refers back to this.