Suppress make rule error output

gnu-make, makefile

Solution

The traditional way to handle directory creation is to use a stamp file that is depended on and creates the dir as a side effect. Remove the stamp file when making `distclean` or whatever your "really clean" target is:

bin/.dirstamp:
    mkdir -p $(DIRS)
    touch $@

bin/foo: bin/.dirstamp
    $(MKFOO) -o $@

distclean:
    rm -rf bin

The reason for this is as follows: whenever a file in `bin` is created/removed, the mtime of the containing directory is updated. If a target depends on `bin`, then the next time `make` runs, it will then recreate files that it doesn't need to.

Problem

I have an rule that creates a directory ``` bin: -mkdir $@ ``` However after the first time the directory has been generated, I receive this output: ``` mkdir bin mkdir: cannot create directory `bin': File exists make: [bin] Error 1 (ignored) ``` Is there some way I can only run the rule if the directory doesn't exist, or suppress the output when the directory already exists?

Original source

Related problems