Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling makefiles from Shell Script

I am new to shell script. I want to call a list of make files from Shell script in a particular order. For each makefile I want to get the result (make is success or failure). If any error I want to stop the script execution. If it is success I have to run the next makefile.

like image 201
Srini2k6 Avatar asked Jun 14 '13 06:06

Srini2k6


1 Answers

A common idiom is to create a shell script with set -e; this will cause the script to exit on the first error.

#!/bin/sh
set -e
make -f Makefile1
make -f Makefile2
:

If you need more control over the script overall, maybe remove set -e and instead explicitly exit on make failure:

make -f Makefile1 || exit
make -f Makefile2 || exit

To reduce code duplication, create a loop:

for f in Makefile1 Makefile2; do
    make -f "$f" || exit
done

Just to be explicit, the || "or" and && "and" connectives are shorthand for

if make -f Makefile1; then
     : "and" part
else
    : "or" part
fi

Finally, the behavior you describe sounds exactly like how Make itself behaves. Perhaps a top-level Makefile would actually be a suitable solution for your scenario?

.PHONY: all
all:
    $(MAKE) -f Makefile1
    $(MAKE) -f Makefile2
like image 199
tripleee Avatar answered Sep 23 '22 23:09

tripleee