Project

General

Profile

1
##### Vars/functions
2

    
3
# Paths
4
bin := ../bin
5
inputCoreMaps := DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv\
6
VegX-VegBIEN.stems.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
# uniq: remove duplicates resulting from multiple outputs for the same input
23
mkSelfMap = $(selfMap_) <$<|$(bin)/sort_map|uniq >$@
24

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

    
30
##### General targets
31

    
32
all: _always $(inputCoreMaps) dwc_maps vegx_maps self_maps ;
33

    
34
.SUFFIXES: # turn off built-in suffix rules
35
.SECONDARY: # don't automatically delete intermediate files
36
.DELETE_ON_ERROR: # delete target if recipe fails
37

    
38
_always:
39
.PHONY: _always
40

    
41
clean: _always
42
	$(RM) $(all)
43

    
44
all :=
45

    
46
##### Core maps cleanup
47

    
48
ifneq ($(filter .%.last_cleanup,$(MAKECMDGOALS)),)
49
.%.last_cleanup: %
50
	$(bin)/in_place $< $(bin)/simplify_xpath
51
	$(bin)/in_place $< $(bin)/sort_map
52
	touch $@
53
	$(call review_,$<)
54
else
55
$(inputCoreMaps): _always
56
	$(MAKE) $(@:%=.%.last_cleanup)
57
endif
58

    
59
##### Self maps
60

    
61
selfMaps :=
62

    
63
viaCoreMap = $(via)-VegBIEN.%.csv
64
viaSelfMap = $(via).self.%.csv
65
viaCoreMaps = $(wildcard $(subst %,*,$(viaCoreMap)))
66

    
67
define selfMapTargets
68
selfMaps += $(viaCoreMaps:$(viaCoreMap)=$(viaSelfMap))
69

    
70
$(viaSelfMap): $(viaCoreMap)
71
	$$(mkSelfMap)
72
endef
73
$(foreach via,$(vias),$(eval $(selfMapTargets)))
74

    
75
ifneq ($(filter self_maps,$(MAKECMDGOALS)),)
76
self_maps: _always $(selfMaps) ;
77
else
78
self_maps: _always
79
	$(MAKE) self_maps
80
# re-run make so that cache of existing files for $(viaCoreMaps) is reset
81
endif
82

    
83
all += $(selfMaps)
84

    
85
##### DwC
86

    
87
dwcMaps :=
88

    
89
DwC.cs-VegBIEN.specimens.csv: DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv
90
	$(join) <$+ >$@
91
dwcMaps += DwC.cs-VegBIEN.specimens.csv
92

    
93
DwC-VegBIEN.specimens.csv: DwC.cs-VegBIEN.specimens.csv
94
	$(bin)/ci_map $< >$@
95
dwcMaps += DwC-VegBIEN.specimens.csv
96

    
97
dwc_maps: _always $(dwcMaps) ;
98

    
99
all += $(dwcMaps)
100

    
101
##### VegX
102

    
103
vegxMaps :=
104

    
105
rootAttrs := :[@xmlns:tcs="http://www.tdwg.org/schemas/tcs/1.01"]
106

    
107
VegX-VegBIEN.organisms.csv: VegX-VegBIEN.stems.csv
108
	env \
109
left_in_root='$(rootAttrs)/*s/individualOrganismObservation[relatedIndividual/relatedItem[itemRelationship=stemParent]/relatedItemID]/relatedIndividual/relatedItem[itemRelationship=stemParent]/relatedItemID->/*s/individualOrganismObservation' \
110
left_out_root='$(rootAttrs)/*s/individualOrganismObservation' \
111
right_in_root='/stemobservation/*_id/plantobservation' \
112
right_out_root='/plantobservation' \
113
$(chRoot)
114
vegxMaps += VegX-VegBIEN.organisms.csv
115

    
116
VegX-VegBIEN.plots.csv: VegX-VegBIEN.organisms.csv
117
	env \
118
left_in_root='$(rootAttrs)/*s/individualOrganismObservation/*ID->/*s/plotObservation' \
119
left_out_root='/*s/plotObservation' \
120
right_in_root='/plantobservation/*_id/aggregateoccurrence/*_id/taxonoccurrence/*_id/locationevent' \
121
right_out_root='/locationevent' \
122
$(chRoot)
123
vegxMaps += VegX-VegBIEN.plots.csv
124

    
125
vegx_maps: _always $(vegxMaps) ;
126

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