I want to write a Makefile that reads a file list.txt and produces result.tar containing the contents. If there is a change in either the list.txt file, or any of the files it points at, then result.tar should be rebuilt. How can I express this in a Makefile? The closest I have come is:
result.tar : list.txt
cat list.txt | xargs tar -cf result.tar
But this omits the dependency on the contents of list.txt.
asked Feb 10, 2012 at 17:37
Neil Mitchell
9,2801 gold badge30 silver badges87 bronze badges
1 Answer 1
I think there should be something like this:
result.tar : list.txt $(shell cat list.txt) cat list.txt | xargs tar -cf result.tar
Or, a bit better (extracting list.txt to a variable and using automatic variables):
LIST_FILE := list.txt result.tar : $(LIST_FILE) $(shell cat $(LIST_FILE)) cat $< | xargs tar -cf $@
answered Feb 10, 2012 at 18:22
Eldar Abusalimov
25.7k4 gold badges71 silver badges73 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Matthew Hannigan
This will break if xargs invokes tar more than once. Each invocation overwrites the tar file. Just remove the xargs to make it work correctly.