Project

General

Profile

1
selfDir_XlThrr := $(dir $(lastword $(MAKEFILE_LIST)))
2
root := $(selfDir_XlThrr)../../..
3
include $(root)/lib/common.Makefile
4

    
5

    
6
##### Vars/functions
7

    
8
unzip = unzip -d $@ $<
9

    
10
##### General targets
11

    
12
all: _always tables ;
13

    
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
allZips := $(states:%=%.zip)
23

    
24
download: _always $(allZips) ;
25

    
26
%.zip:
27
	-wget -O $@ $(urlPrefix)$@
28
# ignore errors if wget not installed
29

    
30
##### Extraction
31

    
32
zips := $(wildcard $(allZips))
33
zips := $(if $(zips),$(zips),$(allZips))
34
dirs := $(zips:%.zip=%)
35

    
36
extract: _always $(dirs) ;
37

    
38
%: %.zip
39
	$(if $(wildcard $@),,$(unzip))
40

    
41
##### Table bundling
42

    
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
tableDirs := $(tableNames:%=../%)
49

    
50
tables: _always $(tableDirs) ;
51

    
52
tableCsvs = $(wildcard $(dirs:%=$(csvPattern)))
53

    
54
$(tableDirs): ../%: _always
55
	$(call mkdir,$@)
56
	$(if $(tableCsvs),mv $(tableCsvs) $@)
(3-3/5)