Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have a directory full of YYYY-MM directories with statistics. I want to use a Makefile to only build summaries YYYY-MM.txt of the statistics if the contents of directory is newer than the summary.

So far my Makefile looks like:

2011-12.txt: 2011-12/
     @for i in $^/*; do tail -1 $$i; done | sort | uniq -c > $@

1) I am not sure how to build a list of targets from 20*/

2) Also I would like to optimize the dependency to be a basename of the target, i.e. $(basename 2011-12.txt .txt)/

share|improve this question
    
I am not sure I get what you are trying to ask. Maybe an example will help. But note this site is for the review of working code. If you need help getting it working then stackoverflow.com would be a better choice. –  Loki Astari Jan 2 '12 at 6:48
    
This is working code, I just want to make it even better :) –  Kai Hendry Jan 2 '12 at 7:12
    
Cool we can help with that. But I am still not quite clear what you want to make better. –  Loki Astari Jan 2 '12 at 7:55
1  
Points 1 & 2, how have I made myself not clear? :) –  Kai Hendry Jan 2 '12 at 9:19
add comment

2 Answers

up vote 0 down vote accepted

Is this what you are looking for?

ALL_DIRS        = $(filter-out %.txt,$(wildcard 20*))
ALL_OBJS        = $(patsubst %,%.txt,$(ALL_DIRS))

all:    $(ALL_OBJS)

%.txt: %/
    @for i in $^/*; do tail -1 $$i; done | sort | uniq -c >> $@
share|improve this answer
add comment

If I'm right, you don't want to repeat

  • the @for i in ... expression for every YYYY-MM folder,
  • 2011-12.txt: 2011-12/ rules for every YYYY-MM folder.

I'm not too familiar with Makefiles, but I'd check the Makefile Macros and Inference Rules.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.