2

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

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.