### Authors: 
### 2005-2006 Berthold Crysmann

### Copyright: DFKI GmbH

GGDIR=$(PWD)

DISTFILES = extra.tdl sorts.tdl some-tdl-built-ins.tdl intro-types.tdl morph.tdl ont.tdl mrsbasic.tdl sem-types.tdl synsem-types.tdl linking-types.tdl lexsem-types.tdl types.tdl incoh-types.tdl principles.tdl rule-types.tdl letter-rule-types.tdl lkb-list-types.tdl cross-list-types.tdl lex-rule-types.tdl sp-types.tdl mw-types.tdl lkb/lkbpatches.tdl le-types.tdl pn.tdl lex-rules.tdl opt-coh-lex-rules.tdl general-inflr.tdl noun-inflr.tdl verb-inflr.tdl irr-spelling-verb-inflr.tdl participle-inflr-pet.tdl participle-inflr-lkb.tdl adj-inflr.tdl part-inflr.tdl misc-inflr.tdl card-inflr.tdl mw-rules.tdl schemata.tdl aux-flip-schemata.tdl topic-drop-comp-schemata.tdl interj-q-tag-schemata.tdl left-dislocation-schema.tdl pvp-schemata.tdl appo.tdl relx-schemata.tdl sgf-schemata.tdl letter-rules.tdl  parse-nodes.tdl roots.tdl   lkb/*.lsp lkb/*.lisp  common.tdl german.tdl german.grm     MAL-*.tdl MAL-irregs.tab punctswitch.tdl punct-inflr.tdl $(LEXICON)  $(IRREGS) $(MTR) $(SEMI) $(RPP) $(TMR) $(PET)$(LISP) $(MEM) $(META) 

MTR = mtr.tdl trigger.mtr paraphrase.mtr

LISP = mrsglobals.lsp Version.lisp lkb/script

META = LICENSE README TODO TAGS Makefile

MEM = tgrp.mem tgrp.g.mem MRS-de.mem

SEMI = gg.smi core.smi semi.vpm 

PET = pet/flop.set pet/general.set pet/german.set pet/qc.tdl

TMR = tmt.tdl lfr.tdl tmr/*.tdl

RPP = rpp/*.rpp rpp/setup.lsp

LEXICON = lexicon.tdl gen-lex.tdl gen-lex-gen.tdl GG.main.skip.tdl $(LEXDB)

LEXDB = GG.rev GG.meta GG.fld GG.dfn

TDL = *.tdl pet/qc.tdl pet/flop.set

IRREGS = ax-pos-e-irregs.tab nx-irregs.tab nx-old.tab

.PHONY: all pack unfill clean realclean dist  

all: TAGS pet ace

lexdb: 
	cd $(LOGONROOT)/lingo/lkb/lexdb &&  $(LOGONROOT)/lingo/lkb/lexdb/install-lexdb.sh gg $(GGDIR) GG
	cd $(GGDIR)

stems: 
	grep 'MORPH.LIST.FIRST.STEM'  lexicon.tdl tiger-*.tdl|sed 's/^[^<]*<\([^>]*\)>.*$/\1/'|sed -e 's/\", \"/ /g' -e 's/^ *\"//' -e 's/\" *$//'|sort -u >gg.stems

# stag.tdl:
# 	cat tiger-ne.tdl tiger-adj.tdl tiger-nouns.tdl tiger-verbs.tdl gen-lex.tdl GG.main.skip.tdl lexicon.tdl|\
# 	grep :=| sed -e 's/[^ ]* *:= *\([^ ]*\) *& */\1/'| sort -u|\
# 	awk  -f scripts/stag.awk | sed \
# 		-e 's/\"aux-.*-le|"/\"aux-le\"/' \
# 		-e 's/\"[+]pvp-aux-.*-le\"/\"+pvp-aux-le\"/' \
# 		-e 's/\"pas-.*-le\"/\"pas-le\"/' \
# 		-e 's/\"[+]pvp-pas-.*-le\"/\"+pvp-pas-le\"/'\
# 		-e 's/\"cop-.*-le\"/\"cop-le\"/' \
# 		-e 's/\"[+]pvp-cop-.*-le\"/\"+pvp-cop-le\"/' > stag.tdl


unfill: german-unfill.grm 

pet/irregs.tab: $(IRREGS) 
	echo '"' > pet/irregs.tab	
	cat $(IRREGS) |grep -v '"' >> pet/irregs.tab
	echo '"' >> pet/irregs.tab	

pet: german.grm

german.grm: $(TDL) pet/irregs.tab mrsglobals.lsp Version.lisp
	flop -t german.tdl ||(/bin/rm german.grm && exit 1)

ace: ace/german.dat ace/german.g.dat


ace/german.dat: ace/config.parse.tdl ace/config.tdl semi.vpm $(TDL) *.tab Version.lisp 
	ace -G ace/german.dat -g ace/config.parse.tdl

ace/german.g.dat: ace/config.generate.tdl ace/config.tdl semi.vpm $(TDL) *.tab Version.lisp trigger.mtr generation.mtr
	ace -G ace/german.g.dat -g ace/config.generate.tdl  




TAGS: *.tdl	
	(etags -l none -r '/^[ \t]*\([_a-zA-Z+\*\-][_a-zA-Z0-9+\*\-]*\)[ \t]*\((.*\)?:[=<]/\1/' `/bin/ls  *.tdl lkb/*.tdl|grep -v lexicon.tdl|grep -v schemata.tdl|grep -v lex-rules.tdl|grep -v mw-rules`|grep -v stag) || exit 0 

realclean: clean
	find . -name \*\.grm -exec \rm -f {} \;
	\rm -f pet/irregs.tab
	\rm -f gg.tar.gz
	\rm -f gg.tar.bz2

clean:
	find . -name \*\.bak -exec \rm -f {} \;
	find . -name \*~ -exec \rm -f {} \;
	find . -name \*.fasl -exec \rm -f {} \;
	find . -name 'svn-commit.*.tmp' -exec \rm -f {} \;

dist: realclean all $(DISTFILES)  gg.tar.gz 

gg.tar.gz: 
	tar -czf gg.tar.gz $(DISTFILES)

gg.tar.bz2:
	mv lkb/user-prefs.lsp lkb/user-prefs.lsp.orig
	mv lkb/user-prefs.lsp.dist lkb/user-prefs.lsp
	tar -cjf gg.tar.bz2 $(DISTFILES)
	mv lkb/user-prefs.lsp lkb/user-prefs.lsp.dist
	mv lkb/user-prefs.lsp.orig lkb/user-prefs.lsp