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.vocab.csv
13
thesaurus := VegCore.thesaurus.csv
14

    
15
##### General targets
16

    
17
all: _always $(vocab) $(thesaurus) VegCore.tables.redmine $(inputCoreMaps) ;
18

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

    
22
all :=
23

    
24
##### Core maps
25

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

    
29
$(vocab): VegCore.htm
30
	(echo VegCore; $(sed) -n 's/^<h[2-4][^>]*>(<img [^>]*>)? *<a href="#[^>]*>(\??([a-z]|[A-Z]{2})[^<]*)<\/a>.*<a href="#[^"-]+".*$$/\2/p') \
31
<$< >$@
32
	$(bin)/in_place $@ $(bin)/sort_ci
33

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

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

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

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

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

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

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

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