pipeline - Makefile with variable number of targets -


i attempting data pipeline makefile. have big file want split in smaller pieces process in parallel. number of subsets , size of each subset not known beforehand. example, file

$ in {1..100}; echo $i >> a.txt; done 

the first step in makefile should compute ranges,... lets make them fixed

ranges.txt: a.txt    or in 0 25 50 75; echo  $$(($$i+1))'\t'$$(($$i+25)) >> $@; done 

next step should read ranges.txt, , create target file each range in ranges.txt, a_1.txt, a_2.txt, a_3.txt, a_4.txt. a_1.txt contains lines 1 through 25, a_2.txt lines 26-50, , on... can done?

you don't version of make you're using, i'll assume gnu make. there few ways of doing things this; wrote set of blog posts metaprogramming in gnu make (by mean having make generate own rules automatically).

if me i'd use constructed include files method this. so, have rule above ranges.txt instead create makefile, perhaps ranges.mk. makefile contain set of targets such a_1.txt, a_2.txt, etc. , define target-specific variables defining start , stop values. can -include generated ranges.mk , make rebuild it. 1 thing haven't described when want recompute ranges: depend on contents of a.txt?

anyway, like:

.phony: all:  ranges.mk: a.txt   # really? why?         in 0 25 50 75; \             echo 'a_$$i.txt : range_start := $$(($$i+1))'; \             echo 'a_$$i.txt : range_end   := $$(($$i+25))'; \             echo 'targets += a_$$i.txt'; \         done > $@  -include ranges.mk  all: $(targets) $(targets) : a.txt   # seems more         process --out $@ --in $< --start $(range_start) --end $(range_end) 

(or whatever command; don't give example).


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -