Project

General

Profile

1 785 aaronmk
##### Vars/functions
2
3 1272 aaronmk
# Paths
4 895 aaronmk
bin := ../bin
5 1824 aaronmk
inputCoreMaps := DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv\
6 1843 aaronmk
VegX-VegBIEN.stems.csv
7 895 aaronmk
8 1824 aaronmk
# 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 1272 aaronmk
# Commands
16
17 1115 aaronmk
review_ = $(bin)/review <$(1) >for_review/$(1)
18
review = $(call review_,$@)
19 924 aaronmk
20 1272 aaronmk
join = env header_num=1 $(bin)/join_union_sort
21 1824 aaronmk
selfMap_ = $(bin)/cols 0 0
22
mkSelfMap = $(selfMap_) <$<|$(bin)/sort_map >$@
23 744 aaronmk
24 1272 aaronmk
define chRoot
25
$(bin)/ch_root <$< >$@
26
$(review)
27
endef
28
29 785 aaronmk
##### General targets
30
31 1824 aaronmk
all: _always $(inputCoreMaps) dwc_maps vegx_maps self_maps ;
32 150 aaronmk
33 1260 aaronmk
.SUFFIXES: # turn off built-in suffix rules
34
.SECONDARY: # don't automatically delete intermediate files
35 1354 aaronmk
.DELETE_ON_ERROR: # delete target if recipe fails
36 223 aaronmk
37 383 aaronmk
_always:
38
.PHONY: _always
39 188 aaronmk
40 383 aaronmk
clean: _always
41 196 aaronmk
	$(RM) $(all)
42 188 aaronmk
43 924 aaronmk
all :=
44
45 785 aaronmk
##### Core maps cleanup
46 198 aaronmk
47 895 aaronmk
ifneq ($(filter .%.last_cleanup,$(MAKECMDGOALS)),)
48
.%.last_cleanup: %
49
	$(bin)/in_place $< $(bin)/simplify_xpath
50 1132 aaronmk
	$(bin)/in_place $< $(bin)/sort_map
51 895 aaronmk
	touch $@
52 1115 aaronmk
	$(call review_,$<)
53 895 aaronmk
else
54 1824 aaronmk
$(inputCoreMaps): _always
55 895 aaronmk
	$(MAKE) $(@:%=.%.last_cleanup)
56
endif
57 350 aaronmk
58 1824 aaronmk
##### 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 1272 aaronmk
##### DwC
85 1115 aaronmk
86 1812 aaronmk
dwcMaps :=
87 1115 aaronmk
88 1452 aaronmk
DwC.cs-VegBIEN.specimens.csv: DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv
89
	$(join) <$+ >$@
90 1812 aaronmk
dwcMaps += DwC.cs-VegBIEN.specimens.csv
91 1452 aaronmk
92 1802 aaronmk
DwC-VegBIEN.specimens.csv: DwC.cs-VegBIEN.specimens.csv
93 1457 aaronmk
	$(bin)/ci_map $< >$@
94 1812 aaronmk
dwcMaps += DwC-VegBIEN.specimens.csv
95 1118 aaronmk
96 1824 aaronmk
dwc_maps: _always $(dwcMaps) ;
97 1140 aaronmk
98 1812 aaronmk
all += $(dwcMaps)
99 1115 aaronmk
100 1272 aaronmk
##### VegX
101 212 aaronmk
102 1812 aaronmk
vegxMaps :=
103 924 aaronmk
104 1818 aaronmk
rootAttrs := :[@xmlns:tcs="http://www.tdwg.org/schemas/tcs/1.01"]
105 1816 aaronmk
106 1843 aaronmk
VegX-VegBIEN.organisms.csv: VegX-VegBIEN.stems.csv
107
	env \
108
left_in_root='$(rootAttrs)/*s/individualOrganismObservation[relatedIndividual/relatedItem[itemRelationship=stemParent]/relatedItemID]/relatedIndividual/relatedItem[itemRelationship=stemParent]/relatedItemID->/*s/individualOrganismObservation' \
109
left_out_root='$(rootAttrs)/*s/individualOrganismObservation' \
110
right_in_root='/stemobservation/*_id/plantobservation' \
111
right_out_root='/plantobservation' \
112
$(chRoot)
113
vegxMaps += VegX-VegBIEN.organisms.csv
114
115 438 aaronmk
VegX-VegBIEN.plots.csv: VegX-VegBIEN.organisms.csv
116 188 aaronmk
	env \
117 1816 aaronmk
left_in_root='$(rootAttrs)/*s/individualOrganismObservation/*ID->/*s/plotObservation' \
118 439 aaronmk
left_out_root='/*s/plotObservation' \
119 1843 aaronmk
right_in_root='/plantobservation/aggregateoccurrence/*_id/taxonoccurrence/*_id/locationevent' \
120 525 aaronmk
right_out_root='/locationevent' \
121 439 aaronmk
$(chRoot)
122 1812 aaronmk
vegxMaps += VegX-VegBIEN.plots.csv
123 439 aaronmk
124 1824 aaronmk
vegx_maps: _always $(vegxMaps) ;
125 924 aaronmk
126 1812 aaronmk
all += $(vegxMaps)