Daniel YC Lin
Daniel YC Lin

Reputation: 16012

copy multiple files to null directory

I want to check if source file exist, so I assign TO_DIR=/dev/null in my gnu makefile.

APPS=a b c d
install:
  cp $(APPS) $(TO_DIR)

But it will failed, because /dev/null is not a pseudo directory. Is there better solution?

Upvotes: 3

Views: 1139

Answers (2)

chepner
chepner

Reputation: 531490

Here's a modification of spacediver's answer that just branches based on the value of TO_DIR

install:
    [ -z "$(TO_DIR)" ] && make install_for_real || make check

install_for_real:
    cp $(APPS) $(TO_DIR)

check:
    file $(APPS) > /dev/null

This should do the check for either of

make install
make install TO_DIR=

but the real installation for

make install TO_DIR=/path/to/installation/dir

Upvotes: 2

spacediver
spacediver

Reputation: 1493

You could do another make target, like this:

check:
  file $(APPS) > /dev/null

file utility will check the existence of all the files and fail when any of these does not exist. Its output is excessive for this task, so we pipe it to /dev/null

You will run check like this:

make check

Upvotes: 2

Related Questions