File: Makefile.in

package info (click to toggle)
festival-ca 3.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 230,584 kB
  • sloc: xml: 1,949,003; lisp: 50,289; sh: 687; perl: 681; makefile: 513
file content (762 lines) | stat: -rw-r--r-- 38,201 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#!/usr/bin/make
# Copyright (C) 2012  Sergio Oller <sergioller@gmail.com>
#
#  This script is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation,
#  version 2.1 of the License.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


# Meta Information:
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_URL = @PACKAGE_URL@

# Programs:
FESTIVAL = @FESTIVALBIN@
WAGON = @WAGON@
PERL = @PERL@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
MKDIR_P = @MKDIR_P@
SED = @SED@
GREP = @GREP@
AWK = @AWK@
NGRAM_BUILD = @NGRAMBUILD@
ONLYINSTALL = @ONLYINSTALL@

# Installation Variables:
FESTDATADIR = @FESTDATADIR@
LANGUAGESSCMFILE = @LANGUAGESSCMFILE@
LANGUAGESSCMVERSION = @LANGUAGESSCMVERSION@

# Empty variables to be filled:
CLEAN = 
DISTCLEAN = 

# File lists:
LTS_RULES_CENTRAL = festival/lib/dicts/upc/upc_catalan_lts_rules-central.scm
REDUCED_LEXICON_CENTRAL = festival/lib/dicts/upc/upcdict_catalan-1.0-central.out

LTS_RULES_VALENCIA = festival/lib/dicts/upc/upc_catalan_lts_rules-valencia.scm
REDUCED_LEXICON_VALENCIA = festival/lib/dicts/upc/upcdict_catalan-1.0-valencia.out

POSLEX = festival/lib/dicts/upc/upc_freeling_catalan.poslex

LIB_UPCCATALAN_FILES = festival/lib/upc_catalan/cat_intro.text \
              festival/lib/upc_catalan/upc_ca_generic_duration.scm \
              festival/lib/upc_catalan/upc_ca_generic_durdata-central.scm \
              festival/lib/upc_catalan/upc_ca_generic_durdata-valencia.scm \
              festival/lib/upc_catalan/upc_ca_generic_f0model.scm \
              festival/lib/upc_catalan/upc_ca_generic_intonation.scm \
              festival/lib/upc_catalan/upc_ca_generic_lexicon.scm \
              festival/lib/upc_catalan/upc_ca_generic_phoneset.scm \
              festival/lib/upc_catalan/upc_ca_generic_phrasing.scm \
              festival/lib/upc_catalan/upc_ca_generic_tagger.scm \
              festival/lib/upc_catalan/upc_ca_generic_tokenizer.scm \
              festival/lib/upc_catalan/upc_catalan_date.scm \
              festival/lib/upc_catalan/upc_catalan_hour.scm \
              festival/lib/upc_catalan/upc_catalan_numbers.scm \
              festival/lib/upc_catalan/upc_catalan_phones-central.scm \
              festival/lib/upc_catalan/upc_catalan_phones-valencia.scm \
              festival/lib/upc_catalan/upc_catalan_phones.scm \
              festival/lib/upc_catalan/upc_catalan_pos_tagger.scm \
              festival/lib/upc_catalan/upc_catalan.scm \
              festival/lib/upc_catalan/upc_catalan_tokenizer.scm \
              festival/lib/upc_catalan/upc_catalan_tokenpos.scm

ALLOWABLES = 
LIB_DICTS_UPCLEX = festival/lib/dicts/upc/upclex_catalan.scm \
              festival/lib/dicts/upc/upclex_central.scm \
              festival/lib/dicts/upc/upclex_valencia.scm \
              festival/lib/dicts/upc/upclex_postlex.scm \
              festival/lib/dicts/upc/upclex_syl.scm

LIB_DICTS_FILES = $(LTS_RULES_CENTRAL) \
              $(REDUCED_LEXICON_CENTRAL) \
              $(LTS_RULES_VALENCIA) \
              $(REDUCED_LEXICON_VALENCIA) \
              $(POSLEX) \
              festival/lib/dicts/upc/upc_freeling_catalan.tri.ngrambin \
              $(LIB_DICTS_UPCLEX)
LANGUAGE_FILES =  festival/lib/languages/language_catalan.scm \
              festival/lib/languages.scm

BUILD_FILES = $(LIB_UPCCATALAN_FILES) $(LIB_DICTS_FILES) $(LANGUAGE_FILES)

# Test files:
TESTTOKENIZERTXT = test/characters.txt test/full_llista.txt test/CheckPunctuation.txt
TESTTOKENIZEROUT = $(addsuffix .out,$(TESTTOKENIZERTXT))
TESTTOKENIZEROUT2 = $(addsuffix .out2,$(TESTTOKENIZERTXT))
TESTTOKENIZERDIFF = $(addsuffix .diff,$(TESTTOKENIZERTXT))
TESTTOKENIZERDIFF2 = $(addsuffix .diff2,$(TESTTOKENIZERTXT))
TESTTOKENIZERREF = $(addsuffix .ref,$(TESTTOKENIZERTXT))
TESTTOKENIZERREF2 = $(addsuffix .ref2,$(TESTTOKENIZERTXT))
TESTSRCFILES = $(TESTTOKENIZERTXT) $(TESTTOKENIZERREF) $(TESTTOKENIZERREF2) test/print_utterance

# Distribution variables:
DOCUMENTATIONFILES = AUTHORS AUTHORS.ca COPYRIGHT LICENSE-gpl-2.0.txt \
                     LICENSE-lgpl-2.1.txt README.ca.md README.md \
                     THANKS.md THANKS.ca.md USAGE.ca.md USAGE.md \
                     INSTALL.md INSTALL.ca.md

DISTBINFILES = Makefile.in Makefilevars.inc configure.ac configure \
               install-sh $(DOCUMENTATIONFILES) $(BUILD_FILES)
DISTSRCFILES = Makefile.in Makefilevars.inc configure.ac configure \
               install-sh $(DOCUMENTATIONFILES) $(BUILD_FILES) $(TESTSRCFILES)

CLEAN += $(TESTTOKENIZEROUT) $(TESTTOKENIZEROUT2) $(TESTTOKENIZERDIFF) $(TESTTOKENIZERDIFF2)

DISTCLEAN += Makefile config.status config.log

# Source directories
BUILDDICT = src/00-Dictionary
BUILDLTS = src/02-LTSMake
BUILDPOSLEX = src/03-Poslex
BUILDNGRAM = src/04-ngram
BUILDDATA = src/data
BUILDFUNC = src/functions

DICTANDTRANSCRIPTIONS = src/data/withtranscriptions/ca.orto
DICTANDTRANSCRIPTIONS_CENTRAL  = src/data/withtranscriptions/ca-central.phon
DICTANDTRANSCRIPTIONS_VALENCIA = src/data/withtranscriptions/ca-valencia.phon

.PHONY: all build install dist-bin dist-src test test-lts test-tokenizer

ifeq ($(ONLYINSTALL),yes)
  DEFAULTACTION = install
else
  DEFAULTACTION = build
endif

all: $(DEFAULTACTION)

build: $(BUILD_FILES)

# Files to be copied from src/data/festival...:
$(LANGUAGE_FILES) $(LIB_UPCCATALAN_FILES) $(LIB_DICTS_UPCLEX):
	$(MKDIR_P) $(@D) && \
	cp "$(BUILDDATA)/$@" "$@" || exit 1

# This rules are to perform the phonetic transcriptions of the Freeling Dictionary
# using an in-house tool at UPC.
# Phonetic transcriptions are distributed under a free license and 
# editing and correcting them is quite easy if you find mistakes or you would
# like to adapt them to other Catalan dialects.
src/data/withtranscriptions/ca.orto src/data/withtranscriptions/ca-central.phon:
	if [ -f `which phonetic_trn` ]; then \
	cd $(BUILDDATA) && \
	( ./transcribe.sh "withtranscriptions/from_phonetic_trn" from_freeling/*  || exit 1) && \
	( ./concatenate.sh "withtranscriptions" "withtranscriptions/from_phonetic_trn" || exit 1 ) ; \
	fi

####################################################################################
####################################################################################
## The Catalan Letter to Sound Rules and the Catalan dictionary are built as follows:
## 1. Using the freeling dictionary and some other complementary dictionaries, a lexicon 
##    with words and their phonetic transcriptions is built.
## 2. Using the upc_catalan_lts_rules, Letter to Sound rules are trained from the lexicon 
##    built in step 1. 
## 3. The lexicon is reduced removing the words that can already be predicted with LTS rules.
##    This is done by comparing the phonetic transcription from the Lexicon and the phonetic
##    transcription predicted by the LTS rules. Iff there is a mismatch between the transcriptions
##    the word with the correct transcription is kept in the lexicon, otherwise it is removed. 

# Clean and distclean and src files for dialect-independent:
CLEAN+= $(BUILDDICT)/merged $(BUILDDICT)/final
DISTCLEAN+= $(BUILDDICT)/CompileDictionary.sh

DISTSRCFILES+= $(BUILDDICT)/CreateInternalFormat.pl \
               $(BUILDDICT)/CompileDictionary.sh.in \
               $(BUILDDICT)/list2festival.pl \
               $(BUILDDICT)/allo2pho.pl

###############################################################################
###############################################################################
###############################################################################
##########################   CENTRAL   ########################################
###############################################################################
###############################################################################
###############################################################################

## Catala central:

DISTSRCFILES+= $(BUILDDICT)/addfinalentries-central.sh
COMPLETE_LEXICON_CENTRAL=$(BUILDDICT)/final/central/upcdict_catalan.out
# Step 1:
$(COMPLETE_LEXICON_CENTRAL): $(DICTANDTRANSCRIPTIONS) $(DICTANDTRANSCRIPTIONS_CENTRAL) $(BUILDDICT)/CreateInternalFormat.pl $(BUILDDICT)/CompileDictionary.sh $(BUILDDICT)/addfinalentries-central.sh $(BUILDDICT)/allo2pho.pl $(BUILDDICT)/list2festival.pl
	echo "Creating dictionary in internal format" && \
	cd $(BUILDDICT) && \
	( $(PERL) ./CreateInternalFormat.pl "../data/withtranscriptions/ca.orto" "../data/withtranscriptions/ca-central.phon" "merged/central/freeling.dic" || exit 1 ) && \
	echo "Adding other dictionaries" && \
	[ -d "../data/otherdic/central" ] && [ -e ../data/otherdic/central/*.dic ] && cp ../data/otherdic/central/*.dic "merged/central/" ; \
	echo "Compiling dictionary" && \
	( ./CompileDictionary.sh "final/central/" "central" merged/central/*.dic || exit 1 ) && \
	echo "Adding final entries" && \
	( ./addfinalentries-central.sh "final/central/upcdict_catalan.out" || exit 1 ) && \
	echo "Removing duplicates" && \
	cat "final/central/upcdict_catalan.out" | LANG=C uniq > "final/central/upcdict_catalan.out2" && \
	rm -f "final/central/upcdict_catalan.out" && mv "final/central/upcdict_catalan.out2" "final/central/upcdict_catalan.out" || exit 1

###############################################################################
###############################################################################
###############################################################################
##########################   VALENCIA   #######################################
###############################################################################
###############################################################################
###############################################################################

DISTSRCFILES+= $(BUILDDICT)/addfinalentries-valencia.sh

COMPLETE_LEXICON_VALENCIA=$(BUILDDICT)/final/valencia/upcdict_catalan.out
# Step 1:
$(COMPLETE_LEXICON_VALENCIA): $(DICTANDTRANSCRIPTIONS) $(DICTANDTRANSCRIPTIONS_VALENCIA) $(BUILDDICT)/CreateInternalFormat.pl $(BUILDDICT)/CompileDictionary.sh $(BUILDDICT)/addfinalentries-valencia.sh $(BUILDDICT)/allo2pho.pl $(BUILDDICT)/list2festival.pl
	echo "Creating dictionary in internal format" && \
	cd $(BUILDDICT) && \
	( $(PERL) ./CreateInternalFormat.pl "../data/withtranscriptions/ca.orto" "../data/withtranscriptions/ca-valencia.phon" "merged/valencia/freeling.dic" || exit 1 ) && \
	echo "Adding other dictionaries" && \
	[ -d "../data/otherdic/valencia" ] && [ -e ../data/otherdic/valencia/*.dic ] && cp ../data/otherdic/valencia/*.dic "merged/valencia/" ; \
	echo "Compiling dictionary" && \
	( ./CompileDictionary.sh "final/valencia/" "valencia" merged/valencia/*.dic || exit 1 ) && \
	echo "Adding final entries" && \
	( ./addfinalentries-valencia.sh "final/valencia/upcdict_catalan.out" || exit 1 ) && \
	echo "Removing duplicates" && \
	cat "final/valencia/upcdict_catalan.out" | LANG=C uniq > "final/valencia/upcdict_catalan.out2" && \
	rm -f "final/valencia/upcdict_catalan.out" && mv "final/valencia/upcdict_catalan.out2" "final/valencia/upcdict_catalan.out" || exit 1


##############################################################################
##############################################################################
##############################################################################
######################  CENTRAL: LTS   #######################################
##############################################################################
##############################################################################
##############################################################################
# Step 2: 

# Just to make thinks harder, Festival creates invalid filenames that cannot be represented in a UTF-8 Makefile.
# Makefilevars.inc contains the required makefile variables that must be encoded in ISO-8859-15
include Makefilevars.inc

ltsdataTRAINfeats_central = $(addprefix $(BUILDLTS)/lts_scratch/central/,$(ltsdataTRAINfeatsfn))
ltsdataTESTfeats_central  = $(addprefix $(BUILDLTS)/lts_scratch/central/,$(subst ltsdataTRAIN,ltsdataTEST,$(ltsdataTRAINfeatsfn)))
ltsNYtree_central         = $(addprefix $(BUILDLTS)/lts_scratch/central/,$(ltsNYtreefn))
ltsNYtreesrc_central      = $(BUILDLTS)/lts.ny.tree
ltsNYTRAINfeats_central        = $(addprefix $(BUILDLTS)/lts_scratch/central/,$(subst lts,ltsdataTRAIN,$(ltsNYtreefn:.tree=.feats)))
ltsNYTESTfeats_central        = $(addprefix $(BUILDLTS)/lts_scratch/central/,$(subst lts,ltsdataTEST,$(ltsNYtreefn:.tree=.feats)))
ltsdataTRAINtree_central  = $(subst ltsdataTRAIN,lts,$(ltsdataTRAINfeats_central:.feats=.tree))  $(ltsNYtree_central)
laNY_central              = $(subst lts.,,$(ltsNYtreefn:.tree=))

# Building the LTS rules requires some intermediate files.
ALLOWABLES += $(BUILDLTS)/allowables-1.1-central.scm
$(BUILDLTS)/lts_scratch/central/lex_entries.out: $(COMPLETE_LEXICON_CENTRAL)
	$(MKDIR_P) $(BUILDLTS)/lts_scratch/central && \
	$(BUILDLTS)/purge_fest_dic < $(COMPLETE_LEXICON_CENTRAL) | $(BUILDLTS)/fest2wagon > $(BUILDLTS)/lts_scratch/central/lex_entries.out

$(BUILDLTS)/lts_scratch/central/lex-pl-tablesp.scm: $(BUILDLTS)/lts_scratch/central/lex_entries.out $(BUILDLTS)/allowables-1.1-central.scm
	cd $(BUILDLTS) && ./build_lts cummulate  "allowables-1.1-central.scm" "lts_scratch/central" || exit 1

$(BUILDLTS)/lts_scratch/central/lex.feats: $(BUILDLTS)/lts_scratch/central/lex-pl-tablesp.scm $(BUILDLTS)/lts_scratch/central/lex_entries.out $(BUILDLTS)/allowables-1.1-central.scm
	cd $(BUILDLTS) && ./build_lts align "allowables-1.1-central.scm" "lts_scratch/central" || exit 1

$(BUILDLTS)/lts_scratch/central/lex.feats.train $(BUILDLTS)/lts_scratch/central/lex.feats.test \
$(BUILDLTS)/lts_scratch/central/lex.align.train $(BUILDLTS)/lts_scratch/central/lex.align.test: $(BUILDLTS)/lts_scratch/central/lex.feats
	cd $(BUILDLTS) && ./build_lts traintest "allowables-1.1-central.scm" "lts_scratch/central" || exit 1


$(BUILDLTS)/lts_scratch/central/ltsLTS.desc: $(BUILDLTS)/lts_scratch/central/lex.feats $(BUILDLTS)/lts_scratch/central/lex.feats.train
	echo "Creating ltsLTS.desc"
	export LANG=C; \
	echo "((Relation.LTS.down.name" > $@ ; \
	$(AWK) '{print $$1}' $< | sort -u >> $@ ; \
	echo ') (p.p.p.p.name ' >> $@ ; \
	$(AWK) '{print $$2}' $< | sort -u >> $@ ; \
	echo ') (p.p.p.name ' >> $@ ; \
	$(AWK) '{print $$3}' $< | sort -u >> $@ ; \
	echo ') (p.p.name ' >> $@ ; \
	$(AWK) '{print $$4}' $< | sort -u >> $@ ; \
	echo ') (p.name ' >> $@ ; \
	$(AWK) '{print $$5}' $< | sort -u >> $@ ; \
	echo ') (name ' >> $@ ; \
	$(AWK) '{print $$6}' $< | sort -u >> $@ ; \
	echo ') (n.name ' >> $@ ; \
	$(AWK) '{print $$7}' $< | sort -u >> $@ ; \
	echo ') (n.n.name ' >> $@ ; \
	$(AWK) '{print $$8}' $< | sort -u >> $@ ; \
	echo ') (n.n.n.name ' >> $@ ; \
	$(AWK) '{print $$9}' $< | sort -u >> $@ ; \
	echo ') (n.n.n.n.name ' >> $@ ; \
	$(AWK) '{print $$10}' $< | sort -u >> $@ ; \
	echo ') (pos ignore' >> $@ ; \
	$(AWK) 'BEGIN {print "n"} {print $$11}' $< | sort -u >> $@ ; \
	echo '))' >> $@
	echo "ltsLTS.desc created"

$(ltsdataTESTfeats_central): $(BUILDLTS)/lts_scratch/central/lex.feats.test
	echo "Building $@"
	$(eval LETRA := $(subst .,,$(suffix $(basename $@))))
	echo "Letra: $(LETRA)"
	export LANG=C; \
	cat $< | \
	$(AWK) '{if ($$6 == "$(LETRA)") print $$0}' > $@; 

$(ltsdataTRAINfeats_central): $(BUILDLTS)/lts_scratch/central/lex.feats.train
	echo "Building $@"
	$(eval LETRA := $(subst .,,$(suffix $(basename $@))))
	echo "Letra: $(LETRA)"
	export LANG=C; \
	cat $< | \
	$(AWK) '{if ($$6 == "$(LETRA)") print $$0}' > $@; 

$(ltsNYTRAINfeats_central) $(ltsNYTESTfeats_central):
	echo "La ny castellana ja se sap quin so té i no cal entrenar-la"
	$(MKDIR_P) $(@D) && \
	touch $@

#$(ltstreeNY_central): $(ltsNYtreesrc_central)
#	echo "This is copied"
#	cp $< $@ || exit 1
	
$(BUILDLTS)/lts_scratch/central/lts.%.tree: $(BUILDLTS)/lts_scratch/central/ltsdataTRAIN.%.feats $(BUILDLTS)/lts_scratch/central/ltsdataTEST.%.feats
	echo "Wagon with $*"
	if [ $(laNY_central) = "$*" ]; then \
		cp $(ltsNYtreesrc_central) $@ || exit 1; \
	else \
	$(WAGON) -data $(BUILDLTS)/lts_scratch/central/ltsdataTRAIN.$*.feats -test $(BUILDLTS)/lts_scratch/central/ltsdataTEST.$*.feats \
          -desc $(BUILDLTS)/lts_scratch/central/ltsLTS.desc -stop 3 -output $(BUILDLTS)/lts_scratch/central/lts.$*.tree || exit 1; \
	fi \

$(BUILDLTS)/lts_scratch/central/lex_lts_rules.scm: $(BUILDLTS)/lts_scratch/central/ltsLTS.desc  $(ltsdataTRAINtree_central)
	cd $(BUILDLTS) && ./build_lts merge  "allowables-1.1-central.scm" "lts_scratch/central" || exit 1

$(BUILDLTS)/lts_scratch/central/lts_test.log: $(BUILDLTS)/lts_scratch/central/lex_lts_rules.scm $(BUILDLTS)/lts_scratch/central/lex.align $(BUILDLTS)/lts_scratch/central/lex.align.test $(BUILDLTS)/allowables-1.1-central.scm
	cd $(BUILDLTS) && ./build_lts test  "allowables-1.1-central.scm" "lts_scratch/central"


$(LTS_RULES_CENTRAL): $(BUILDLTS)/lts_scratch/central/lex_lts_rules.scm
	$(MKDIR_P) "$(BUILDLTS)/final" && \
	$(SED) -e 's/·/"·"/g' -e 's/lex_lts_rules/upc_catalan_lts_rules-central/g' "$(BUILDLTS)/lts_scratch/central/lex_lts_rules.scm" > "$(BUILDLTS)/final/upc_catalan_lts_rules-central.scm" && \
	echo "(provide 'upc_catalan_lts_rules-central)" >> "$(BUILDLTS)/final/upc_catalan_lts_rules-central.scm" && \
	$(MKDIR_P) $(@D) && \
	cp $(BUILDLTS)/final/upc_catalan_lts_rules-central.scm $@ || exit 1

TESTLTS += $(BUILDLTS)/lts_scratch/central/lts_test.log

CLEAN+= $(BUILDLTS)/lex_lts_rules-central.scm $(BUILDLTS)/lts_scratch/central/ $(BUILDLTS)/final
DISTCLEAN+= $(BUILDLTS)/build_lts

DISTSRCFILES+= $(ALLOWABLES) \
               $(BUILDLTS)/build_lts.in \
               $(BUILDLTS)/build_lts_rules \
               $(BUILDLTS)/createmultiphonemes \
               $(BUILDLTS)/fest2wagon \
               $(BUILDLTS)/lts.ny.tree \
               $(BUILDLTS)/purge_fest_dic \
               $(BUILDLTS)/readme \
               $(BUILDLTS)/reduce_dict \
               $(BUILDLTS)/traintest \
               $(BUILDLTS)/upc_catalan_lts_rules

##############################################################################
##############################################################################
##############################################################################
######################  VALENCIA: LTS   ######################################
##############################################################################
##############################################################################
##############################################################################

# Just to make thinks harder, Festival creates invalid filenames that cannot be represented in a UTF-8 Makefile.
# Makefilevars.inc contains the required makefile variables that must be encoded in ISO-8859-15
include Makefilevars.inc

ltsdataTRAINfeats_valencia = $(addprefix $(BUILDLTS)/lts_scratch/valencia/,$(ltsdataTRAINfeatsfn))
ltsdataTESTfeats_valencia  = $(addprefix $(BUILDLTS)/lts_scratch/valencia/,$(subst ltsdataTRAIN,ltsdataTEST,$(ltsdataTRAINfeatsfn)))
ltsNYtree_valencia         = $(addprefix $(BUILDLTS)/lts_scratch/valencia/,$(ltsNYtreefn))
ltsNYtreesrc_valencia      = $(BUILDLTS)/lts.ny.tree
ltsNYTRAINfeats_valencia        = $(addprefix $(BUILDLTS)/lts_scratch/valencia/,$(subst lts,ltsdataTRAIN,$(ltsNYtreefn:.tree=.feats)))
ltsNYTESTfeats_valencia        = $(addprefix $(BUILDLTS)/lts_scratch/valencia/,$(subst lts,ltsdataTEST,$(ltsNYtreefn:.tree=.feats)))
ltsdataTRAINtree_valencia  = $(subst ltsdataTRAIN,lts,$(ltsdataTRAINfeats_valencia:.feats=.tree))  $(ltsNYtree_valencia)
laNY_valencia              = $(subst lts.,,$(ltsNYtreefn:.tree=))

# Building the LTS rules requires some intermediate files.
ALLOWABLES += $(BUILDLTS)/allowables-1.1-valencia.scm
$(BUILDLTS)/lts_scratch/valencia/lex_entries.out: $(COMPLETE_LEXICON_VALENCIA)
	$(MKDIR_P) $(BUILDLTS)/lts_scratch/valencia && \
	$(BUILDLTS)/purge_fest_dic < $(COMPLETE_LEXICON_VALENCIA) | $(BUILDLTS)/fest2wagon > $(BUILDLTS)/lts_scratch/valencia/lex_entries.out

$(BUILDLTS)/lts_scratch/valencia/lex-pl-tablesp.scm: $(BUILDLTS)/lts_scratch/valencia/lex_entries.out $(BUILDLTS)/allowables-1.1-valencia.scm
	cd $(BUILDLTS) && ./build_lts cummulate  "allowables-1.1-valencia.scm" "lts_scratch/valencia" || exit 1

$(BUILDLTS)/lts_scratch/valencia/lex.feats: $(BUILDLTS)/lts_scratch/valencia/lex-pl-tablesp.scm $(BUILDLTS)/lts_scratch/valencia/lex_entries.out $(BUILDLTS)/allowables-1.1-valencia.scm
	cd $(BUILDLTS) && ./build_lts align "allowables-1.1-valencia.scm" "lts_scratch/valencia" || exit 1

$(BUILDLTS)/lts_scratch/valencia/lex.feats.train $(BUILDLTS)/lts_scratch/valencia/lex.feats.test \
$(BUILDLTS)/lts_scratch/valencia/lex.align.train $(BUILDLTS)/lts_scratch/valencia/lex.align.test: $(BUILDLTS)/lts_scratch/valencia/lex.feats
	cd $(BUILDLTS) && ./build_lts traintest "allowables-1.1-valencia.scm" "lts_scratch/valencia" || exit 1


$(BUILDLTS)/lts_scratch/valencia/ltsLTS.desc: $(BUILDLTS)/lts_scratch/valencia/lex.feats $(BUILDLTS)/lts_scratch/valencia/lex.feats.train
	echo "Creating ltsLTS.desc"
	export LANG=C; \
	echo "((Relation.LTS.down.name" > $@ ; \
	$(AWK) '{print $$1}' $< | sort -u >> $@ ; \
	echo ') (p.p.p.p.name ' >> $@ ; \
	$(AWK) '{print $$2}' $< | sort -u >> $@ ; \
	echo ') (p.p.p.name ' >> $@ ; \
	$(AWK) '{print $$3}' $< | sort -u >> $@ ; \
	echo ') (p.p.name ' >> $@ ; \
	$(AWK) '{print $$4}' $< | sort -u >> $@ ; \
	echo ') (p.name ' >> $@ ; \
	$(AWK) '{print $$5}' $< | sort -u >> $@ ; \
	echo ') (name ' >> $@ ; \
	$(AWK) '{print $$6}' $< | sort -u >> $@ ; \
	echo ') (n.name ' >> $@ ; \
	$(AWK) '{print $$7}' $< | sort -u >> $@ ; \
	echo ') (n.n.name ' >> $@ ; \
	$(AWK) '{print $$8}' $< | sort -u >> $@ ; \
	echo ') (n.n.n.name ' >> $@ ; \
	$(AWK) '{print $$9}' $< | sort -u >> $@ ; \
	echo ') (n.n.n.n.name ' >> $@ ; \
	$(AWK) '{print $$10}' $< | sort -u >> $@ ; \
	echo ') (pos ignore' >> $@ ; \
	$(AWK) 'BEGIN {print "n"} {print $$11}' $< | sort -u >> $@ ; \
	echo '))' >> $@
	echo "ltsLTS.desc created"

$(ltsdataTESTfeats_valencia): $(BUILDLTS)/lts_scratch/valencia/lex.feats.test
	echo "Building $@"
	$(eval LETRA := $(subst .,,$(suffix $(basename $@))))
	echo "Letra: $(LETRA)"
	export LANG=C; \
	cat $< | \
	$(AWK) '{if ($$6 == "$(LETRA)") print $$0}' > $@; 

$(ltsdataTRAINfeats_valencia): $(BUILDLTS)/lts_scratch/valencia/lex.feats.train
	echo "Building $@"
	$(eval LETRA := $(subst .,,$(suffix $(basename $@))))
	echo "Letra: $(LETRA)"
	export LANG=C; \
	cat $< | \
	$(AWK) '{if ($$6 == "$(LETRA)") print $$0}' > $@; 

$(ltsNYTRAINfeats_valencia) $(ltsNYTESTfeats_valencia):
	echo "La ny castellana ja se sap quin so té i no cal entrenar-la"
	$(MKDIR_P) $(@D) && \
	touch $@

#$(ltstreeNY_valencia): $(ltsNYtreesrc_valencia)
#	echo "This is copied"
#	cp $< $@ || exit 1
	
$(BUILDLTS)/lts_scratch/valencia/lts.%.tree: $(BUILDLTS)/lts_scratch/valencia/ltsdataTRAIN.%.feats $(BUILDLTS)/lts_scratch/valencia/ltsdataTEST.%.feats
	echo "Wagon with $*"
	if [ $(laNY_valencia) = "$*" ]; then \
		cp $(ltsNYtreesrc_valencia) $@ || exit 1; \
	else \
	$(WAGON) -data $(BUILDLTS)/lts_scratch/valencia/ltsdataTRAIN.$*.feats -test $(BUILDLTS)/lts_scratch/valencia/ltsdataTEST.$*.feats \
          -desc $(BUILDLTS)/lts_scratch/valencia/ltsLTS.desc -stop 3 -output $(BUILDLTS)/lts_scratch/valencia/lts.$*.tree || exit 1; \
	fi \

$(BUILDLTS)/lts_scratch/valencia/lex_lts_rules.scm: $(BUILDLTS)/lts_scratch/valencia/ltsLTS.desc  $(ltsdataTRAINtree_valencia)
	cd $(BUILDLTS) && ./build_lts merge  "allowables-1.1-valencia.scm" "lts_scratch/valencia" || exit 1

$(BUILDLTS)/lts_scratch/valencia/lts_test.log: $(BUILDLTS)/lts_scratch/valencia/lex_lts_rules.scm $(BUILDLTS)/lts_scratch/valencia/lex.align $(BUILDLTS)/lts_scratch/valencia/lex.align.test $(BUILDLTS)/allowables-1.1-valencia.scm
	cd $(BUILDLTS) && ./build_lts test  "allowables-1.1-valencia.scm" "lts_scratch/valencia"


$(LTS_RULES_VALENCIA): $(BUILDLTS)/lts_scratch/valencia/lex_lts_rules.scm
	$(MKDIR_P) "$(BUILDLTS)/final" && \
	$(SED) -e 's/·/"·"/g' -e 's/lex_lts_rules/upc_catalan_lts_rules-valencia/g' "$(BUILDLTS)/lts_scratch/valencia/lex_lts_rules.scm" > "$(BUILDLTS)/final/upc_catalan_lts_rules-valencia.scm" && \
	echo "(provide 'upc_catalan_lts_rules-valencia)" >> "$(BUILDLTS)/final/upc_catalan_lts_rules-valencia.scm" && \
	$(MKDIR_P) $(@D) && \
	cp $(BUILDLTS)/final/upc_catalan_lts_rules-valencia.scm $@ || exit 1



TESTLTS += $(BUILDLTS)/lts_scratch/valencia/lts_test.log

CLEAN+= $(BUILDLTS)/lex_lts_rules-valencia.scm $(BUILDLTS)/lts_scratch/valencia/ $(BUILDLTS)/final
DISTCLEAN+= $(BUILDLTS)/build_lts

DISTSRCFILES+= $(ALLOWABLES) \
               $(BUILDLTS)/build_lts.in \
               $(BUILDLTS)/build_lts_rules \
               $(BUILDLTS)/createmultiphonemes \
               $(BUILDLTS)/fest2wagon \
               $(BUILDLTS)/lts.ny.tree \
               $(BUILDLTS)/purge_fest_dic \
               $(BUILDLTS)/readme \
               $(BUILDLTS)/reduce_dict \
               $(BUILDLTS)/traintest \
               $(BUILDLTS)/upc_catalan_lts_rules

##############################################################################
##############################################################################
##############################################################################
######################  CENTRAL: LTS   #######################################
##############################################################################
##############################################################################
##############################################################################
# Step 3:
$(BUILDLTS)/upclex_%.scm:  $(BUILDDATA)/festival/lib/dicts/upc/upclex_%.scm
	cp $< $@ || exit 1

$(REDUCED_LEXICON_CENTRAL): $(LTS_RULES_CENTRAL) $(addprefix $(BUILDLTS)/,$(notdir $(LIB_DICTS_UPCLEX)))
	echo "Reducing dictionary" && \
	cd $(BUILDLTS) && \
	$(MKDIR_P) "final_dict_reduced_central/dicttmp" && \
	cp $(addprefix ../../$(BUILDDATA)/festival/lib/dicts/upc/,$(notdir $(LIB_DICTS_UPCLEX))) "final_dict_reduced_central/dicttmp" && \
	cp "final/upc_catalan_lts_rules-central.scm" "final_dict_reduced_central/dicttmp/upc_catalan_lts_rules-central.scm" && \
	cp ../../$(BUILDDICT)/final/central/upcdict_catalan.out "final_dict_reduced_central/dicttmp/upcdict_catalan-1.0-central.out" && \
	$(FESTIVAL) --script "./reduce_dict" "final_dict_reduced_central/dicttmp/" "central" || exit 1
	$(MKDIR_P) $(@D) || exit 1
	cp $(BUILDLTS)/final_dict_reduced_central/dicttmp/upcdict_catalan.out  $@ || exit 1

CLEAN+= $(BUILDLTS)/final_dict_reduced_central $(addprefix $(BUILDLTS)/,$(notdir $(LIB_DICTS_UPCLEX)))


##############################################################################
##############################################################################
##############################################################################
######################  VALENCIA: LTS   ######################################
##############################################################################
##############################################################################
##############################################################################
# Step 3:
$(REDUCED_LEXICON_VALENCIA): $(LTS_RULES_VALENCIA) $(addprefix $(BUILDLTS)/,$(notdir $(LIB_DICTS_UPCLEX)))
	echo "Reducing dictionary" && \
	cd $(BUILDLTS) && \
	$(MKDIR_P) "final_dict_reduced_valencia/dicttmp" && \
	cp $(addprefix ../../$(BUILDDATA)/festival/lib/dicts/upc/,$(notdir $(LIB_DICTS_UPCLEX))) "final_dict_reduced_valencia/dicttmp" && \
	cp "final/upc_catalan_lts_rules-valencia.scm" "final_dict_reduced_valencia/dicttmp/upc_catalan_lts_rules-valencia.scm" && \
	cp ../../$(BUILDDICT)/final/valencia/upcdict_catalan.out "final_dict_reduced_valencia/dicttmp/upcdict_catalan-1.0-valencia.out" && \
	$(FESTIVAL) --script "./reduce_dict" "final_dict_reduced_valencia/dicttmp/" "valencia" || exit 1
	$(MKDIR_P) $(@D) || exit 1
	cp $(BUILDLTS)/final_dict_reduced_valencia/dicttmp/upcdict_catalan.out  $@ || exit 1

CLEAN+= $(BUILDLTS)/final_dict_reduced_valencia

#### END OF LEXICON AND LTS RULES #####
#######################################

############################
#### CREATE POS DATA #######
BUILDDATAPOS=$(BUILDDATA)/pos
CORPUSCA=$(BUILDDATAPOS)/corpus-ca
DICTAG=$(BUILDDATAPOS)/dictag.txt
VOCABULARY=$(BUILDDATAPOS)/voca.txt
CORPUSCASOURCES3LB = $(wildcard $(BUILDDATAPOS)/ancora-ca/3LB-CAT/*.xml)
CORPUSCASOURCESCATA = $(wildcard $(BUILDDATAPOS)/ancora-ca/CESS-CAT-A/*.xml)
CORPUSCASOURCESCATAAP =  $(wildcard $(BUILDDATAPOS)/ancora-ca/CESS-CAT-AAP/*.xml)
CORPUSCASOURCES = $(CORPUSCASOURCES3LB) $(CORPUSCASOURCESCATA) $(CORPUSCASOURCESCATAAP)
CORPUSCATXT = $(subst .xml,.txt,$(subst ancora-ca,work,$(CORPUSCASOURCES)))
BUILDDATAPOSWORK = $(BUILDDATAPOS)/work


$(BUILDDATAPOSWORK)/3LB-CAT/%.tbf.txt: $(BUILDDATAPOS)/ancora-ca/3LB-CAT/%.tbf.xml $(BUILDDATAPOS)/crea_corpusca.pl
	$(MKDIR_P) $(@D) || exit 1
	cat $< | $(PERL) $(BUILDDATAPOS)/crea_corpusca.pl > $@ || exit 1

$(BUILDDATAPOSWORK)/CESS-CAT-A/%.tbf.txt: $(BUILDDATAPOS)/ancora-ca/CESS-CAT-A/%.tbf.xml $(BUILDDATAPOS)/crea_corpusca.pl
	$(MKDIR_P) $(@D) || exit 1
	cat $< | $(PERL) $(BUILDDATAPOS)/crea_corpusca.pl > $@ || exit 1

$(BUILDDATAPOSWORK)/CESS-CAT-AAP/%.tbf.txt: $(BUILDDATAPOS)/ancora-ca/CESS-CAT-AAP/%.tbf.xml $(BUILDDATAPOS)/crea_corpusca.pl
	$(MKDIR_P) $(@D) || exit 1
	cat $< | $(PERL) $(BUILDDATAPOS)/crea_corpusca.pl > $@ || exit 1



$(CORPUSCA):  $(CORPUSCATXT)
	cat $(CORPUSCATXT) > $@

$(DICTAG): $(CORPUSCA) $(BUILDDATAPOS)/crea_dictag.pl
	$(PERL) $(BUILDDATAPOS)/crea_dictag.pl < $< > $@ || exit 1

CLEAN+= $(BUILDDATAPOSWORK) $(CORPUSCA) $(DICTAG)

#### END CREATE POS DATA ###
############################



#### BEGIN POSLEX TRAINING #####
################################
$(POSLEX): $(BUILDPOSLEX)/final/dicTAGGERcomplet.poslexR 
	cp "$(BUILDPOSLEX)/final/dicTAGGERcomplet.poslexR" $@

$(BUILDPOSLEX)/final/dicTAGGERcomplet.poslexR: $(BUILDPOSLEX)/final/dicTAGGERcomplet.poslexR_desord
	echo "MNCL" > $@ || exit 1
	export LANG=C; cat $< | sort | uniq >> $@ || exit 1

$(BUILDPOSLEX)/final/dicTAGGERcomplet.poslexR_desord $(VOCABULARY): $(BUILDPOSLEX)/simplifiedpos.orto $(DICTAG) $(BUILDPOSLEX)/02-FormatTaggerAmbAmpliació
	$(MKDIR_P) "$(BUILDPOSLEX)/final" || exit 1
	$(BUILDPOSLEX)/02-FormatTaggerAmbAmpliació "$(BUILDPOSLEX)/final/dicTAGGERcomplet.poslexR_desord" "$(DICTAG)" "$(BUILDPOSLEX)/simplifiedpos.orto" "$(BUILDPOSLEX)/log.txt" "$(VOCABULARY)" || exit 1

$(BUILDPOSLEX)/01-FormatDiccComplet.pl: $(BUILDFUNC)/functions_perl.pl
	touch $@

$(BUILDPOSLEX)/simplifiedpos.orto: $(BUILDDATA)/withtranscriptions/ca.orto $(BUILDPOSLEX)/01-FormatDiccComplet.pl
	$(MKDIR_P) $(@D)
	cat $(BUILDDATA)/withtranscriptions/ca.orto | \
	$(BUILDPOSLEX)/01-FormatDiccComplet.pl | \
	LANG=C sort | uniq >  $@ || exit 1

CLEAN+= $(BUILDPOSLEX)/simplifiedpos.orto $(BUILDPOSLEX)/final/ $(BUILDPOSLEX)/log.txt

DISTSRCFILES+= $(BUILDPOSLEX)/01-FormatDiccComplet.pl \
               $(BUILDPOSLEX)/02-FormatTaggerAmbAmpliació

#### END POSLEX TRAINING ####
#############################

#### BEGIN NGRAM ####
#####################

$(BUILDNGRAM)/01-ReducTAGCorpus.pl: $(BUILDFUNC)/functions_perl.pl
	touch $@

$(BUILDNGRAM)/work/corpus-ca-reduitsTAGS.out: $(CORPUSCA) $(BUILDNGRAM)/01-ReducTAGCorpus.pl
	$(MKDIR_P) $(BUILDNGRAM)/work && \
	$(PERL) $(BUILDNGRAM)/01-ReducTAGCorpus.pl < $< > $@ || exit 1

$(BUILDNGRAM)/work/corpus-ca.out $(BUILDNGRAM)/work/corpus-ca-frase.out: $(BUILDNGRAM)/work/corpus-ca-reduitsTAGS.out $(VOCABULARY) $(BUILDNGRAM)/02-FormatCorpus
	cd $(BUILDNGRAM) && \
	./02-FormatCorpus || exit 1

$(BUILDNGRAM)/work/corpus.train  $(BUILDNGRAM)/work/corpus.test $(BUILDNGRAM)/work/corpus_frases.train $(BUILDNGRAM)/work/corpus_frases.test:  $(BUILDNGRAM)/work/corpus-ca-frase.out $(BUILDNGRAM)/work/corpus-ca.out $(VOCABULARY) $(BUILDNGRAM)/03-SplitterCorpus.pl
	cd $(BUILDNGRAM) && \
	$(PERL) ./03-SplitterCorpus.pl || exit 1

$(BUILDNGRAM)/final/upc_freeling_catalan.tri.ngrambin: $(BUILDNGRAM)/work/corpus.train $(VOCABULARY) $(BUILDNGRAM)/04-ngrambuild.sh
	$(MKDIR_P) $(@D)
	export NGRAM_BUILD="$(NGRAM_BUILD)" ; \
	$(BUILDNGRAM)/04-ngrambuild.sh $(BUILDNGRAM)/work/corpus.train $(VOCABULARY) $@ || exit 1	

festival/lib/dicts/upc/upc_freeling_catalan.tri.ngrambin: $(BUILDNGRAM)/final/upc_freeling_catalan.tri.ngrambin
	$(MKDIR_P) $(@D) && \
	cp $< $@ || exit 1

CLEAN+= $(BUILDNGRAM)/work $(BUILDNGRAM)/final $(VOCABULARY)

DISTSRCFILES+= $(BUILDNGRAM)/01-ReducTAGCorpus.pl \
               $(BUILDNGRAM)/02-FormatCorpus \
               $(BUILDNGRAM)/03-SplitterCorpus.pl \
               $(BUILDNGRAM)/04-ngrambuild.sh


#### END NGRAM ####
###################

# Data files for distribution:
DISTSRCFILES+= $(BUILDFUNC)/functions_perl.pl \
               $(BUILDDATA)/concatenate.sh \
               $(BUILDDATA)/transcribe.sh \
               $(BUILDDATA)/unicode2sampa.sh \
               $(BUILDDATA)/festival/lib/dicts/upc/upclex_catalan.scm \
               $(BUILDDATA)/festival/lib/dicts/upc/upclex_central.scm \
               $(BUILDDATA)/festival/lib/dicts/upc/upclex_valencia.scm \
               $(BUILDDATA)/festival/lib/dicts/upc/upclex_syl.scm \
               $(BUILDDATA)/festival/lib/dicts/upc/upclex_postlex.scm \
               $(BUILDDATA)/festival/lib/languages/language_catalan.scm \
               $(BUILDDATA)/festival/lib/languages.scm \
               $(BUILDDATA)/festival/lib/upc_catalan \
               $(BUILDDATA)/festvox.orig \
               $(BUILDDATA)/from_freeling \
               $(BUILDDATA)/otherdic \
               $(BUILDDATA)/pos/crea_dictag.pl \
               $(BUILDDATA)/pos/crea_corpusca.pl \
               $(BUILDDATA)/pos/ancora-ca \
               $(BUILDDATA)/withtranscriptions/ca.orto \
               $(BUILDDATA)/withtranscriptions/ca-central.phon \
               $(BUILDDATA)/withtranscriptions/ca-valencia.phon

# Create directories, copy files and then:
# If we have a libdir/languages directory, 
# copy the language_catalan.scm inside.
# If we have a standard 2.1 installation
# edit languages.scm using sed
install:
	$(MKDIR_P) "$(FESTDATADIR)/dicts/upc" && \
	$(MKDIR_P) "$(FESTDATADIR)/upc_catalan" && \
	$(INSTALL_DATA) festival/lib/dicts/upc/* "$(FESTDATADIR)/dicts/upc" && \
	$(INSTALL_DATA) festival/lib/upc_catalan/* "$(FESTDATADIR)/upc_catalan" && \
	if test "$(LANGUAGESSCMVERSION)" = "directory" ; then \
	    $(MKDIR_P) "$(FESTDATADIR)/languages" && \
	    $(INSTALL_DATA) festival/lib/languages/language_catalan.scm "$(FESTDATADIR)/languages" ; \
	fi ; \
	if [ "$(LANGUAGESSCMVERSION)" = "2.1" ] ; then \
	     $(GREP) "catalan" "$(LANGUAGESSCMFILE)" > /dev/null && DOINSTALL="no" ||  DOINSTALL="yes"; \
	     if [ "$$DOINSTALL" = "yes" ]; then \
	        mv $(LANGUAGESSCMFILE) $(LANGUAGESSCMFILE).orig || exit 1; \
	     else \
	         if [ -f "$(LANGUAGESSCMFILE).orig" ]; then \
	             rm -f "$(LANGUAGESSCMFILE)"; \
		     DOINSTALL="yes"; \
		 else \
		     DOINSTALL="no"; \
		 fi ; \
	     fi ; \
	     if [ "$$DOINSTALL" = "yes" ]; then \
	         $(SED) "s|(define (select_language language)|\n\n;; Modification: Added language_catalan\n(define (language_catalan)\n\"(language_catalan)\nSet up language parameters for Catalan.\"\n\n   (defvar catalan-path (path-append (if (boundp 'datadir) datadir libdir) \"upc_catalan/\"))\n   (if (not (member_string catalan-path load-path))\n                      (set! load-path (cons catalan-path load-path)))(set! female1 (lambda () (voice_upc_ca_ona_hts)))\n (set! male1 ( lambda () (voice_upc_ca_pau_hts)))\n (female1)\n (Param.set 'Language 'catalan)\n)\n\n(define (select_language language)|g" $(LANGUAGESSCMFILE).orig | \
	         $(SED) "s/   ((equal? language 'klingon)/   ((equal? language 'catalan)\n    (language_catalan))\n   ((equal? language 'klingon)/g"  > $(LANGUAGESSCMFILE) ; \
	     fi; \
	fi ;

dist-bin: clean
	rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
	mkdir -p "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
	for thing in $(DISTBINFILES);do \
	       thingdir=$$(dirname "$$thing") && \
	       thingname=$$(basename "$$thing") && \
	       $(MKDIR_P) "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/$$thingdir" && \
	       cp -r "$$thing" "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/$$thingdir" || exit 1; \
	done
	tar czf ../$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tgz $(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
	rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"

dist-src: clean
	rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src"
	mkdir -p "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src"
	for thing in $(DISTSRCFILES);do \
	       thingdir=$$(dirname "$$thing") && \
	       thingname=$$(basename "$$thing") && \
	       $(MKDIR_P) "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src/$$thingdir" && \
	       cp -r "$$thing" "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src/$$thingdir" || exit 1; \
	done
	tar czf ../$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src.tgz $(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src
	rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-src"

test/%.txt.out test/%.txt.out2  test/%.txt.diff  test/%.txt.diff2: test/%.txt test/%.txt.ref test/%.txt.ref2 
	$(FESTIVAL) --script test/print_utterance "test" "$<" > "$@" 2> "$<".out2 || exit 1
	diff "$<".ref "$@" > "$<".diff ; diff "$<".ref2 "$@2" > "$<".diff2; \
	test -s "$<".diff -a -s "$<".diff2 && (echo "TEST $< FAILED" ; exit 1) || echo "TEST $< OK"

TEST = $(TESTTOKENIZEROUT) $(TESTLTS)


test-lts: $(TESTLTS)

test-tokenizer: $(TESTTOKENIZEROUT)

test: test-tokenizer test-lts

clean:
	rm -rf $(CLEAN)

distclean: clean
	rm -rf $(DISTCLEAN)