Project

General

Profile

1
include ../lib/common.Makefile
2

    
3

    
4
##### Vars/functions
5

    
6
# Make
7
SHELL := /bin/bash
8

    
9
# Paths
10
bin := ../bin
11
inputCoreMaps := DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv\
12
VegX-VegBIEN.stems.csv VegX-VegCSV.stems.csv
13

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

    
21
# Commands
22

    
23
review_ = $(bin)/review 1 <$(1) >for_review/$(1)
24
review = $(call review_,$@)
25

    
26
join = env header_num=1 $(bin)/join_union_sort
27
selfMap_ = $(bin)/cols 0 0
28
mkSelfMap = $(selfMap_) <$<|$(bin)/sort_map >$@
29

    
30
##### General targets
31

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

    
34
clean: _always
35
	$(RM) $(all)
36

    
37
all :=
38

    
39
##### Core maps cleanup
40

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

    
51
##### Self maps
52

    
53
selfMaps :=
54

    
55
viaCoreMap = $(via)-VegBIEN.%.csv
56
viaSelfMap = $(via).self.%.csv
57
viaCoreMaps = $(wildcard $(subst %,*,$(viaCoreMap)))
58

    
59
define selfMapTargets
60
selfMaps += $(viaCoreMaps:$(viaCoreMap)=$(viaSelfMap))
61

    
62
$(viaSelfMap): $(viaCoreMap)
63
	$$(mkSelfMap)
64
endef
65
$(foreach via,$(vias),$(eval $(selfMapTargets)))
66

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

    
75
all += $(selfMaps)
76

    
77
##### DwC
78

    
79
dwcMaps :=
80

    
81
DwC.cs-VegBIEN.specimens.csv: DwC1-DwC2.specimens.csv DwC2-VegBIEN.specimens.csv
82
	$(join) <$+ >$@
83
dwcMaps += DwC.cs-VegBIEN.specimens.csv
84

    
85
DwC-VegBIEN.specimens.csv: DwC.cs-VegBIEN.specimens.csv
86
	$(bin)/ci_map $< >$@
87
dwcMaps += DwC-VegBIEN.specimens.csv
88

    
89
for_review/VegBIEN-DwC2.specimens.csv: for_review/DwC2-VegBIEN.specimens.csv
90
	$(bin)/invert <$< >$@
91
dwcMaps += for_review/VegBIEN-DwC2.specimens.csv
92
# keep comments column(s)
93

    
94
dwc_maps: _always $(dwcMaps) ;
95

    
96
all += $(dwcMaps)
97

    
98
##### VegCSV
99

    
100
vegcsvMaps :=
101

    
102
VegCSV-VegBIEN.specimens.csv: VegX-VegCSV.stems.csv VegX-VegBIEN.stems.csv\
103
DwC2-VegBIEN.specimens.csv
104
	<$< $(bin)/invert\
105
|$(bin)/join $(word 2,$+)\
106
|$(bin)/union $(word 3,$+)\
107
|$(bin)/sort_map >$@
108
vegcsvMaps += VegCSV-VegBIEN.specimens.csv
109

    
110
vegcsv_maps: _always $(vegcsvMaps) ;
111

    
112
all += $(vegcsvMaps)
(10-10/22)