1
votes

I'm having some problem in makefile multiple files dependency. Understand makefile's rule with target and dependency.

target: dependencies

But how to code the makefile if I have multiple dependencies, and either one gets updated will trigger the target, at the same time the not all dependency file exist, it's optional.

Example:

target.txt: file1.txt file2.txt file3.txt file4.txt
    @echo "Compiling target.txt file"
    target_gen.sh -output target.txt

Is above case, file1.txt file2.txt file3.txt file4.txt are optional files, where they can all exist or either one exist. Either one of the listed dependency files get the update will trigger the re-compile of target.txt file. target_gen.sh is a script will search for file1 - file4 and compile it into a single target file.

Appreciate your advice, -Kian Boon-

1

1 Answers

0
votes

You could use a function to grab them all

OPTIONAL_FILE_DEPS=$(wildcard file*.txt)

target.txt : $(OPTIONAL_FILE_DEPS)
    ./generate-target $^ > target.txt

This will rebuild when any file*.txt is newer than target.txt, but won't notice if you delete one.