nowox
nowox

Reputation: 29116

Ensure that called scripts exist and are executable with make

I have a Makefile that call a bunch of makers such as compilers and small scripts. Sometime (often a ClearCase issue), the executable flag is missing or worse the script is missing.

What is the best way to check the executable flag and the existence of a list of programs in a Makefile.

My first implementation was to foreach on each executable and call them, then catch the exit flag. Because that check takes some time, I had to ifdef it in order to bypass the check for all makes rules that does not need to use these scripts. For example the case of make clean only call rm which has to be installed on all platforms. I don't need to check the other programs.

The second implementation was just to check the execution flag with a $(shell) and a [ -x foo ] combined in a ifdef directive. I feed this solution is a bit ugly.

The third solution is to call a shell script that do the job. However, this shell script must remain executable in any case. I can do FOO != chmod u+x checker but this is also quite ugly.

What would be the best solution?

Upvotes: 0

Views: 74

Answers (1)

Mario Zannone
Mario Zannone

Reputation: 2883

Will an approach like the following help?

target: source ./script_1
    test -x ./script_1 || chmod +x ./script_1
    ./script_1 < source > target

Upvotes: 1

Related Questions