1
|
##### Vars/functions
|
2
|
|
3
|
# Paths
|
4
|
bin := ../bin
|
5
|
inputCoreMaps := DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv\
|
6
|
VegX-VegBIEN.organisms.csv
|
7
|
|
8
|
# Via formats
|
9
|
coreMaps := $(wildcard *-VegBIEN.*.csv)
|
10
|
filenameVia = $(shell echo '$(1)'|grep --only-matching --extended-regexp\
|
11
|
'^[a-zA-Z]+')
|
12
|
# can't use --ignore-case because in Mac grep, a bug causes it to break [] exprs
|
13
|
vias := $(strip $(sort $(foreach coreMap,$(coreMaps),$(call filenameVia,$(coreMap)))))
|
14
|
|
15
|
# Commands
|
16
|
|
17
|
review_ = $(bin)/review <$(1) >for_review/$(1)
|
18
|
review = $(call review_,$@)
|
19
|
|
20
|
join = env header_num=1 $(bin)/join_union_sort
|
21
|
selfMap_ = $(bin)/cols 0 0
|
22
|
mkSelfMap = $(selfMap_) <$<|$(bin)/sort_map >$@
|
23
|
|
24
|
define chRoot
|
25
|
$(bin)/ch_root <$< >$@
|
26
|
$(review)
|
27
|
endef
|
28
|
|
29
|
##### General targets
|
30
|
|
31
|
all: _always $(inputCoreMaps) dwc_maps vegx_maps self_maps ;
|
32
|
|
33
|
.SUFFIXES: # turn off built-in suffix rules
|
34
|
.SECONDARY: # don't automatically delete intermediate files
|
35
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
36
|
|
37
|
_always:
|
38
|
.PHONY: _always
|
39
|
|
40
|
clean: _always
|
41
|
$(RM) $(all)
|
42
|
|
43
|
all :=
|
44
|
|
45
|
##### Core maps cleanup
|
46
|
|
47
|
ifneq ($(filter .%.last_cleanup,$(MAKECMDGOALS)),)
|
48
|
.%.last_cleanup: %
|
49
|
$(bin)/in_place $< $(bin)/simplify_xpath
|
50
|
$(bin)/in_place $< $(bin)/sort_map
|
51
|
touch $@
|
52
|
$(call review_,$<)
|
53
|
else
|
54
|
$(inputCoreMaps): _always
|
55
|
$(MAKE) $(@:%=.%.last_cleanup)
|
56
|
endif
|
57
|
|
58
|
##### Self maps
|
59
|
|
60
|
selfMaps :=
|
61
|
|
62
|
viaCoreMap = $(via)-VegBIEN.%.csv
|
63
|
viaSelfMap = $(via).self.%.csv
|
64
|
viaCoreMaps = $(wildcard $(subst %,*,$(viaCoreMap)))
|
65
|
|
66
|
define selfMapTargets
|
67
|
selfMaps += $(viaCoreMaps:$(viaCoreMap)=$(viaSelfMap))
|
68
|
|
69
|
$(viaSelfMap): $(viaCoreMap)
|
70
|
$$(mkSelfMap)
|
71
|
endef
|
72
|
$(foreach via,$(vias),$(eval $(selfMapTargets)))
|
73
|
|
74
|
ifneq ($(filter self_maps,$(MAKECMDGOALS)),)
|
75
|
self_maps: _always $(selfMaps) ;
|
76
|
else
|
77
|
self_maps: _always
|
78
|
$(MAKE) self_maps
|
79
|
# re-run make so that cache of existing files for $(viaCoreMaps) is reset
|
80
|
endif
|
81
|
|
82
|
all += $(selfMaps)
|
83
|
|
84
|
##### DwC
|
85
|
|
86
|
dwcMaps :=
|
87
|
|
88
|
DwC.cs-VegBIEN.specimens.csv: DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv
|
89
|
$(join) <$+ >$@
|
90
|
dwcMaps += DwC.cs-VegBIEN.specimens.csv
|
91
|
|
92
|
DwC-VegBIEN.specimens.csv: DwC.cs-VegBIEN.specimens.csv
|
93
|
$(bin)/ci_map $< >$@
|
94
|
dwcMaps += DwC-VegBIEN.specimens.csv
|
95
|
|
96
|
dwc_maps: _always $(dwcMaps) ;
|
97
|
|
98
|
all += $(dwcMaps)
|
99
|
|
100
|
##### VegX
|
101
|
|
102
|
vegxMaps :=
|
103
|
|
104
|
rootAttrs := :[@xmlns:tcs="http://www.tdwg.org/schemas/tcs/1.01"]
|
105
|
|
106
|
VegX-VegBIEN.plots.csv: VegX-VegBIEN.organisms.csv
|
107
|
env \
|
108
|
left_in_root='$(rootAttrs)/*s/individualOrganismObservation/*ID->/*s/plotObservation' \
|
109
|
left_out_root='/*s/plotObservation' \
|
110
|
right_in_root='/taxonoccurrence/*_id/locationevent' \
|
111
|
right_out_root='/locationevent' \
|
112
|
$(chRoot)
|
113
|
vegxMaps += VegX-VegBIEN.plots.csv
|
114
|
|
115
|
VegX-VegBIEN.stems.csv: VegX-VegBIEN.organisms.csv
|
116
|
env \
|
117
|
left_in_root='$(rootAttrs)/*s/individualOrganismObservation->/*s/individualOrganismObservation[relatedItem[relationshipType=stemParent]/relatedItemID]' \
|
118
|
left_out_root='/*s/individualOrganismObservation[relatedItem[relationshipType=stemParent]/relatedItemID]' \
|
119
|
right_in_root='/taxonoccurrence/aggregateoccurrence/*_id/plantobservation/stemobservation' \
|
120
|
right_out_root='/stemobservation' \
|
121
|
$(chRoot)
|
122
|
vegxMaps += VegX-VegBIEN.stems.csv
|
123
|
|
124
|
vegx_maps: _always $(vegxMaps) ;
|
125
|
|
126
|
all += $(vegxMaps)
|