# Makefile tracking YYYY-MM directories

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)/ - 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 Points 1 & 2, how have I made myself not clear? :) – Kai Hendry Jan 2 '12 at 9:19 ## 2 Answers 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 >>$@

-

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.

-