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 |
7563
|
aaronmk
|
all: _always extract ;
|
13 |
|
|
$(MAKE) tables
|
14 |
7362
|
aaronmk
|
|
15 |
|
|
##### Downloads
|
16 |
|
|
|
17 |
|
|
urlPrefix := http://apps.fs.fed.us/fiadb-downloads/
|
18 |
|
|
|
19 |
|
|
states := AS GU PW AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME\
|
20 |
|
|
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\
|
21 |
|
|
VT VI VA WA WV WI WY
|
22 |
|
|
|
23 |
7364
|
aaronmk
|
allZips := $(states:%=%.zip)
|
24 |
7362
|
aaronmk
|
|
25 |
7364
|
aaronmk
|
download: _always $(allZips) ;
|
26 |
|
|
|
27 |
7362
|
aaronmk
|
%.zip:
|
28 |
|
|
-wget -O $@ $(urlPrefix)$@
|
29 |
|
|
# ignore errors if wget not installed
|
30 |
7364
|
aaronmk
|
|
31 |
|
|
##### Extraction
|
32 |
|
|
|
33 |
|
|
zips := $(wildcard $(allZips))
|
34 |
|
|
zips := $(if $(zips),$(zips),$(allZips))
|
35 |
7382
|
aaronmk
|
dirs := $(zips:%.zip=%)
|
36 |
7364
|
aaronmk
|
|
37 |
|
|
extract: _always $(dirs) ;
|
38 |
|
|
|
39 |
|
|
%: %.zip
|
40 |
|
|
$(if $(wildcard $@),,$(unzip))
|
41 |
|
|
|
42 |
|
|
##### Table bundling
|
43 |
7382
|
aaronmk
|
|
44 |
|
|
csvPattern = $(dir)/$(dir)_%.CSV
|
45 |
|
|
csvPattern* = $(subst %,*,$(csvPattern))
|
46 |
|
|
dirCsvs = $(wildcard $(csvPattern*))
|
47 |
|
|
dirTables = $(patsubst $(csvPattern),%,$(dirCsvs))
|
48 |
|
|
tableNames := $(sort $(foreach dir,$(dirs),$(dirTables)))
|
49 |
7383
|
aaronmk
|
tableDirs := $(tableNames:%=../%)
|
50 |
7382
|
aaronmk
|
|
51 |
|
|
tables: _always $(tableDirs) ;
|
52 |
|
|
|
53 |
7384
|
aaronmk
|
tableCsvs = $(wildcard $(foreach dir,$(dirs),$(subst %,$*,$(csvPattern))))
|
54 |
7382
|
aaronmk
|
|
55 |
7383
|
aaronmk
|
$(tableDirs): ../%: _always
|
56 |
7382
|
aaronmk
|
$(call mkdir,$@)
|
57 |
|
|
$(if $(tableCsvs),mv $(tableCsvs) $@)
|