Can I verify in a makefile that a directory exists ?
For example if the dir already exists and I do mkdir <dir> it gives me an error. and the scripts execution ends. I don't want that. Can I do the verification in the makefile?
Printable View
Can I verify in a makefile that a directory exists ?
For example if the dir already exists and I do mkdir <dir> it gives me an error. and the scripts execution ends. I don't want that. Can I do the verification in the makefile?
Two ways...
Attempt to make the directory, but do not exit the makefile on error.Code:default:
- mkdir bin
- mkdir bin
- mkdir bin
Test for the directory before attempting to make it.Code:default:
if [ ! -d bin ]; then mkdir bin; fi;
if [ ! -d bin ]; then mkdir bin; fi;
if [ ! -d bin ]; then mkdir bin; fi;
Another way of doing it (which should be more portable than QuestionC's second method) is to set each directory as a target:
Code:default: dirA dirB
dirA:
mkdir dirA
dirB:
mkdir dirB