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 extract ;
13
	$(MAKE) tables
14

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

    
25
download: _always $(allZips) ;
26

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

    
31
##### Extraction
32

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

    
37
extract: _always $(dirs) ;
38

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

    
42
##### Table bundling
43

    
44
refCsvPattern := FIADB_REFERENCE/%.CSV
45
refCsvPattern* := $(subst %,*,$(refCsvPattern))
46
refDirCsvs := $(wildcard $(refCsvPattern*))
47
refTables := $(patsubst $(refCsvPattern),%,$(refDirCsvs))
48
refDirs := $(refTables:%=../%)
49

    
50
csvPattern = $(dir)/$(dir)_%.CSV
51
csvPattern* = $(subst %,*,$(csvPattern))
52
dirCsvs = $(wildcard $(csvPattern*))
53
dirTables = $(patsubst $(csvPattern),%,$(dirCsvs))
54
tableNames := $(sort $(foreach dir,$(dirs),$(dirTables)))
55
tableDirs := $(tableNames:%=../%)
56

    
57
tables: _always $(refDirs) $(tableDirs) ;
58

    
59
tableCsvs = $(wildcard $(foreach dir,$(dirs),$(subst %,$*,$(csvPattern))))
60

    
61
$(tableDirs): ../%: _always
62
	$(call mkdir,$@)
63
	$(if $(tableCsvs),mv $(tableCsvs) $@)
64

    
65
../%: $(refCsvPattern) _always
66
	$(call mkdir,$@)
67
	mv $< $@
(32-32/60)