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 := VegCore-VegBIEN.csv VegX-VegCore.csv
12
vocab := VegCore.csv
13
dict := Veg+-VegCore.csv
14

    
15
##### General targets
16

    
17
all: _always VegCore.csv Veg+-VegCore.csv VegCore.tables.redmine\
18
$(inputCoreMaps) ;
19

    
20
clean: _always
21
	$(RM) $(all)
22

    
23
all :=
24

    
25
##### Core maps
26

    
27
VegCore.htm:
28
	php -r 'fpassthru(fopen("https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore", "r"));' >$@
29

    
30
VegCore.csv: VegCore.htm
31
	(echo VegCore; $(sed) -n 's/^.*<h[24][^>]*><a href="#[^>]*>(([a-z]|[A-Z]{2})[^<]*)<\/a><a href="#[^"-]+".*$$/\1/p'\
32
|sort -u) <$< >$@
33

    
34
Veg+-VegCore.csv: VegCore.htm
35
	(echo "Veg+,VegCore"; $(bin)/redmine_synonyms|grep -vE '^\??[A-Z][a-z]')\
36
<$< >$@
37
	# Canonicalize alternatives of ambiguous terms using unambiguous mappings
38
	$(bin)/in_place $@ $(bin)/translate 1 <(grep -vE '^\?' $(dict))
39
	$(bin)/in_place $@ $(bin)/collapse_multimap
40
	# Replace ambiguous terms with alternatives lists
41
	$(bin)/in_place $@ $(bin)/translate 1 $(dict)
42
	$(bin)/in_place $@ $(bin)/sort 0 1
43

    
44
VegCore.tables.csv: VegCore.htm
45
	<$< $(sed) -n 's/^.*<h1 *><a href="#[^>]+>([^?<][^<]*).*$$/\1/p' >$@
46

    
47
VegCore.tables.redmine: VegCore.tables.csv
48
	$(sed) -n 's/^.*$$/[[VegCore#&|&]]/p' <$< >$@
49

    
50
# This tracks VegCore terms that are mapped to VegBIEN but not documented in
51
# VegCore.csv. This file is *not* svn:ignored, so it will show up with a ? when
52
# the user runs `svn st` if there are any unsourced terms.
53
VegCore-VegBIEN.unsourced_terms.csv: VegCore-VegBIEN.csv VegCore.csv
54
	$(bin)/filter_out_ci 0 <$+ >$@
55
	$(bin)/autoremove $@
56

    
57
ifneq ($(filter .%.last_cleanup,$(MAKECMDGOALS)),)
58

    
59
.VegX-VegCore.csv.last_cleanup: .%.last_cleanup: % $(dict)
60
	$(bin)/in_place $< $(bin)/translate_ci 1 $(dict)
61
	$(bin)/in_place $< $(bin)/sort 0 1
62
	touch $@
63
.PRECIOUS: .VegX-VegCore.csv.last_cleanup
64

    
65
.VegCore-VegBIEN.csv.last_cleanup: .%.last_cleanup: % $(dict) $(vocab)
66
	$(bin)/in_place $< $(bin)/translate_ci 0 $(dict)
67
	$(bin)/in_place $< $(bin)/canon 0 $(vocab)
68
	$(bin)/in_place $< $(bin)/sort_map
69
	touch $@
70
	$(bin)/review 1 <$< >for_review/$<
71
	$(MAKE) VegCore-VegBIEN.unsourced_terms.csv
72
.PRECIOUS: .VegCore-VegBIEN.csv.last_cleanup
73

    
74
else
75
$(inputCoreMaps): _always
76
	$(MAKE) $(@:%=.%.last_cleanup)
77
.PRECIOUS: $(inputCoreMaps)
78
endif
(5-5/16)