Project

General

Profile

1 7362 aaronmk
selfDir_XlThrr := $(dir $(lastword $(MAKEFILE_LIST)))
2
root := $(selfDir_XlThrr)../../..
3
include $(root)/lib/common.Makefile
4
5
6
##### Vars/functions
7
8 7364 aaronmk
unzip = unzip -d $@ $<
9
10 7362 aaronmk
##### General targets
11
12 7382 aaronmk
all: _always tables ;
13 7362 aaronmk
14
##### Downloads
15
16
urlPrefix := http://apps.fs.fed.us/fiadb-downloads/
17
18
states := AS GU PW AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME\
19
MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA PR RI SC SD TN TX UT\
20
VT VI VA WA WV WI WY
21
22 7364 aaronmk
allZips := $(states:%=%.zip)
23 7362 aaronmk
24 7364 aaronmk
download: _always $(allZips) ;
25
26 7362 aaronmk
%.zip:
27
	-wget -O $@ $(urlPrefix)$@
28
# ignore errors if wget not installed
29 7364 aaronmk
30
##### Extraction
31
32
zips := $(wildcard $(allZips))
33
zips := $(if $(zips),$(zips),$(allZips))
34 7382 aaronmk
dirs := $(zips:%.zip=%)
35 7364 aaronmk
36
extract: _always $(dirs) ;
37
38
%: %.zip
39
	$(if $(wildcard $@),,$(unzip))
40
41
##### Table bundling
42 7382 aaronmk
43
csvPattern = $(dir)/$(dir)_%.CSV
44
csvPattern* = $(subst %,*,$(csvPattern))
45
dirCsvs = $(wildcard $(csvPattern*))
46
dirTables = $(patsubst $(csvPattern),%,$(dirCsvs))
47
tableNames := $(sort $(foreach dir,$(dirs),$(dirTables)))
48 7383 aaronmk
tableDirs := $(tableNames:%=../%)
49 7382 aaronmk
50
tables: _always $(tableDirs) ;
51
52 7384 aaronmk
tableCsvs = $(wildcard $(foreach dir,$(dirs),$(subst %,$*,$(csvPattern))))
53 7382 aaronmk
54 7383 aaronmk
$(tableDirs): ../%: _always
55 7382 aaronmk
	$(call mkdir,$@)
56
	$(if $(tableCsvs),mv $(tableCsvs) $@)