makefile - Make dummy target that checks the age of an existing file? -


i'm using make control data flow in statistical analysis. if have raw data in directory ./data/raw_data_files, , i've got data manipulation script creates cleaned data cache @ ./cache/clean_data. make rule like:

cache/clean_data:   scripts/clean_data  

i not want touch data in ./data/, either make, or of data munging scripts. there way in make create dependency cache/clean_data checks whether specific files in ./data/ newer last time make ran?

if clean_data single file, let depend on data files:

cache/clean_data: data/*     scripts/clean_data 

if directory containing multiple cleaned files, easiest way write stamp file , have depend on data files:

cache/clean_data-stamp: data/*     scripts/clean_data     touch cache/clean_data-stamp 

note regenerates clean_data files if 1 data file changes. more elaborate approach possible if have 1-to-1 mapping between data , cleaned files. gnu make manual has decent example of this. here adaptation:

 datafiles:= $(wildcard data/*)  cachefiles:= $(patsubst data/%,cache/clean_data/%,$(datafiles))   cache/clean_data/% : data/%          scripts/clean_data --input $< --output $@   all: $(cachefiles) 

here, use wildcard list of files under data. replace data path cache path using patsubst. tell make how generate cache files via static pattern rule, , finally, define target all generates required cache files.

of course can list cachefiles explicitly in makefile (cachefiles:= cache/clean_data/a cache/clean_data/b), typically more convenient let make handle automatically, if possible.

notice complex example works gnu make, not in windows' nmake. further info, consult gnu make manual, great resource makefile needs.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -