如何在目标文件和源文件具有相同扩展名的地方编写Makefile? [英] How to write Makefile where target and source files have the same extension?
问题描述
我有一些每小时获取的数据文件.它们的文件名看起来像:
I have some hourly acquired data files. They filenames look like:
20120101-00.raw
20120101-01.raw
...
YYYYMMDD-HH.raw
我必须将每小时文件汇总到每天,每天到每月等.汇总脚本的语法如下:
I have to aggregate hourly files to daily, daily to monthly etc. Syntax of the aggregate script is following:
aggregate output-file input-file1 input-file2 ...
汇总模式为:
20120101-[0-2][0-9].raw -> 20120101.raw
201201[0-3][0-9].raw -> 201201.raw
etc.
我正在尝试编写Makefile来自动执行过程,但是我完全陷入了困境-我不知道如何处理扩展名问题-源文件和目标文件具有相同的扩展名.我使用:
I am trying to write Makefile to automate process, but I am completely stuck - I don't know how to deal with problem of extensions - source and target files has the same extension. I use:
$(shell find . -type f | grep -e "\.raw1$$" | cut -c 8 | sort -u )
查找我必须生成的文件.
to find files I have to generate.
推荐答案
我同意奥利·查尔斯沃思(Oli Charlesworth)的观点,Make并不是完成这项工作的最佳工具-我会使用Perl脚本.但是,如果您想使用Make,可以做到这一点.这是一个使用sed
调用的不太可怕的技巧.可以将其收紧一点,但是我会为了便于阅读.
I agree with Oli Charlesworth that Make isn't the best tool for this job-- I'd use a Perl script. But if you want to use Make, it can be done. Here's a not-too-horrible hack using calls to sed
. It can be tightened up a little, but I'm going for readability.
FILES := $(shell ls *-??.raw)
DAYS := $(sort $(shell ls *-??.raw | sed 's/\(........\).*/\1.raw/'))
MONTHS := $(sort $(shell ls *-??.raw | sed 's/\(......\).*/\1.raw/'))
YEARS := $(sort $(shell ls *-??.raw | sed 's/\(....\).*/\1.raw/'))
all.raw: $(YEARS)
aggregate $@ $^
$(YEARS): %.raw : $(MONTHS)
aggregate $@ $(filter $*%, $^)
$(MONTHS): %.raw : $(DAYS)
aggregate $@ $(filter $*%, $^)
$(DAYS): %.raw :
aggregate $@ $(filter $*%, $(FILES))
这篇关于如何在目标文件和源文件具有相同扩展名的地方编写Makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!