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 [^>]*title="[^"S][^"]*:"[^>]*> *)?<a href="#[^>]*>(([a-z]|[A-Z]{2})[^<]*)<\/a>.*<a href="#[^"-]+".*$$/\2/p'\
31
|sort -u) <$< >$@
32

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

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

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

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

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

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

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

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