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 1272 aaronmk
VegX-VegBIEN.organisms.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 438 aaronmk
VegX-VegBIEN.plots.csv: VegX-VegBIEN.organisms.csv
107 188 aaronmk
	env \
108 1816 aaronmk
left_in_root='$(rootAttrs)/*s/individualOrganismObservation/*ID->/*s/plotObservation' \
109 439 aaronmk
left_out_root='/*s/plotObservation' \
110 525 aaronmk
right_in_root='/taxonoccurrence/*_id/locationevent' \
111
right_out_root='/locationevent' \
112 439 aaronmk
$(chRoot)
113 1812 aaronmk
vegxMaps += VegX-VegBIEN.plots.csv
114 439 aaronmk
115
VegX-VegBIEN.stems.csv: VegX-VegBIEN.organisms.csv
116
	env \
117 1816 aaronmk
left_in_root='$(rootAttrs)/*s/individualOrganismObservation->/*s/individualOrganismObservation[relatedItem[relationshipType=stemParent]/relatedItemID]' \
118 1823 aaronmk
left_out_root='/*s/individualOrganismObservation[relatedItem[relationshipType=stemParent]/relatedItemID]' \
119 681 aaronmk
right_in_root='/taxonoccurrence/aggregateoccurrence/*_id/plantobservation/stemobservation' \
120 673 aaronmk
right_out_root='/stemobservation' \
121 439 aaronmk
$(chRoot)
122 1816 aaronmk
vegxMaps += VegX-VegBIEN.stems.csv
123 924 aaronmk
124 1824 aaronmk
vegx_maps: _always $(vegxMaps) ;
125 924 aaronmk
126 1812 aaronmk
all += $(vegxMaps)