Project

General

Profile

1
include ../lib/common.Makefile
2

    
3

    
4
##### Vars/functions
5

    
6
# Paths
7
bin := ../bin
8
inputCoreMaps := DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv\
9
VegX-VegBIEN.stems.csv
10

    
11
# Via formats
12
coreMaps := $(wildcard *-VegBIEN.*.csv)
13
filenameVia = $(shell echo '$(1)'|grep --only-matching --extended-regexp\
14
'^[a-zA-Z]+')
15
# can't use --ignore-case because in Mac grep, a bug causes it to break [] exprs
16
vias := $(strip $(sort $(foreach coreMap,$(coreMaps),$(call filenameVia,$(coreMap)))))
17

    
18
# Commands
19

    
20
review_ = $(bin)/review <$(1) >for_review/$(1)
21
review = $(call review_,$@)
22

    
23
join = env header_num=1 $(bin)/join_union_sort
24
selfMap_ = $(bin)/cols 0 0
25
mkSelfMap = $(selfMap_) <$<|$(bin)/sort_map >$@
26

    
27
define chRoot
28
$(bin)/ch_root <$< >$@
29
$(review)
30
endef
31

    
32
##### General targets
33

    
34
all: _always $(inputCoreMaps) dwc_maps vegx_maps self_maps ;
35

    
36
clean: _always
37
	$(RM) $(all)
38

    
39
all :=
40

    
41
##### Core maps cleanup
42

    
43
ifneq ($(filter .%.last_cleanup,$(MAKECMDGOALS)),)
44
.%.last_cleanup: %
45
	$(bin)/in_place $< $(bin)/simplify_xpath
46
	$(bin)/in_place $< $(bin)/sort_map
47
	touch $@
48
	$(call review_,$<)
49
else
50
$(inputCoreMaps): _always
51
	$(MAKE) $(@:%=.%.last_cleanup)
52
endif
53

    
54
##### Self maps
55

    
56
selfMaps :=
57

    
58
viaCoreMap = $(via)-VegBIEN.%.csv
59
viaSelfMap = $(via).self.%.csv
60
viaCoreMaps = $(wildcard $(subst %,*,$(viaCoreMap)))
61

    
62
define selfMapTargets
63
selfMaps += $(viaCoreMaps:$(viaCoreMap)=$(viaSelfMap))
64

    
65
$(viaSelfMap): $(viaCoreMap)
66
	$$(mkSelfMap)
67
endef
68
$(foreach via,$(vias),$(eval $(selfMapTargets)))
69

    
70
ifneq ($(filter self_maps,$(MAKECMDGOALS)),)
71
self_maps: _always $(selfMaps) ;
72
else
73
self_maps: _always
74
	$(MAKE) self_maps
75
# re-run make so that cache of existing files for $(viaCoreMaps) is reset
76
endif
77

    
78
all += $(selfMaps)
79

    
80
##### DwC
81

    
82
dwcMaps :=
83

    
84
DwC.cs-VegBIEN.specimens.csv: DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv
85
	$(join) <$+ >$@
86
dwcMaps += DwC.cs-VegBIEN.specimens.csv
87

    
88
DwC-VegBIEN.specimens.csv: DwC.cs-VegBIEN.specimens.csv
89
	$(bin)/ci_map $< >$@
90
dwcMaps += DwC-VegBIEN.specimens.csv
91

    
92
dwc_maps: _always $(dwcMaps) ;
93

    
94
all += $(dwcMaps)
95

    
96
##### VegX
97

    
98
vegxMaps :=
99

    
100
rootAttrs :=
101

    
102
VegX-VegBIEN.organisms.csv: VegX-VegBIEN.stems.csv
103
	env \
104
left_in_root= left_out_root= \
105
right_in_root='/stemobservation/*_id/plantobservation' \
106
right_out_root='/plantobservation' \
107
$(chRoot)
108
vegxMaps += VegX-VegBIEN.organisms.csv
109

    
110
VegX-VegBIEN.plots.csv: VegX-VegBIEN.organisms.csv
111
	env \
112
left_in_root= left_out_root= \
113
right_in_root='/plantobservation/*_id/aggregateoccurrence/*_id/taxonoccurrence/*_id/locationevent' \
114
right_out_root='/locationevent' \
115
$(chRoot)
116
vegxMaps += VegX-VegBIEN.plots.csv
117

    
118
vegx_maps: _always $(vegxMaps) ;
119

    
120
all += $(vegxMaps)
(9-9/18)