# Makefile for building a finite-state library for Alpino
# Copyright (c) Jan Daciuk <j.daciuk@let.rug.nl>, 2001.
#

ifeq "$(shell ls ../Makefile.defs)" "../Makefile.defs"
include ../Makefile.defs
S_FSA_PATH=$(S_FSA)
else
# S_FSA_PATH
# path to Daciuk's s_fsa utilities programme
S_FSA_PATH=/usr/local/src/s_fsa

# Installation program
INSTALL = cp

endif


PWD:=${shell pwd}


# Compile options (for fsa_build add FLEXIBLE and NUMBERS)
# LOOSING_RPM	- to work around a bug in rpm libstdc++ library
# MORPH_INFIX	- makes it possible to use -I and -P options in fsa_morph
#		  for recognition of coded prefixes and infixes
# NEXTBIT	- changes the format of the automaton, so that when there are
#		  chains of nodes, one following another, one bit is set
#		  in the goto field to indicate that fact, and only one byte
#		  from the goto field is used; it usually gives smaller
#		  automata
# POOR_MORPH	- enables -A option in fsa_morph for morphological analysis
#		  giving only categories, and no base forms.
# STOPBIT	- changes the format of the automaton, so that there are
#		  no counters, but for each arc there is a bit that says
#		  whether it is the last one in the node; this gives smaller
#		  automata
# TAILS		- changes the format of the automaton, allowing for more
#		  arc sharing, so more compression at the cost of construction
#		  time
# WEIGHTED	- introduces weights on arcs for guessing automata.
# OLD_COMPILER	- older versions of g++ create files for ifstream if not
#		  given ios::nocreate option. The new ones probably don't,
#		  and they also treat ios::nocreat as error. Happy compiling!
# SPARSE	- sparse matrix representation is used, which means
#		  larger dictionaries, but faster access (not much though).
#
#
# Some versions of g++ (or stdlibc++) are broken - if so, don't use -O2!
# !!! If you change these, please do make clean first before each make
CPPFLAGS=-O2 --pedantic -Wall -fPIC\
  -DFLEXIBLE \
  -DNUMBERS \
  -DSTOPBIT \
  -DNEXTBIT \
  -DMORPH_INFIX \
  -DPOOR_MORPH \
  -DLOOSING_RPM \
  -DMULTICOLUMN # -DSPARSE
  # -DOLD_COMPILER
  # -DINTERPOLATED \
  # -DDEBUG # -DDMALLOC


# Normally empty
#LDFLAGS=-L/usr/local/lib -ldmallocxx
LDFLAGS=

########################################################################

all: libfadd.so maketuple.pl print_tuple.pl pro_fadd.so pro_fadd.po test_fadd\
     pro_fadd.s.o

c_plus_plus: libfadd.so

%.po : %.pl
	echo "compile('$*'), save_files('$*','$*')." | hdrug -notk

maketuple.pl: maketuple.pl.in
	sed -e 's|@@S_FSA_PATH@@|$(S_FSA_PATH)|g' <maketuple.pl.in \
                                                 >maketuple.pl
	chmod +x maketuple.pl
print_tuple.pl: print_tuple.pl.in
	sed -e 's|@@S_FSA_PATH@@|$(S_FSA_PATH)|g' <print_tuple.pl.in \
                                                 >print_tuple.pl
	chmod +x print_tuple.pl

pro_fadd.so: libfadd.so fadd.h fsa.h pro_fadd.c pro_fadd.pl
	splfr pro_fadd.pl pro_fadd.c --cflag="${CPPFLAGS}"\
             -LD  -Wl,-rpath,$(PWD) -L. -lfadd

pro_fadd.s.o: libfadd.so fadd.h fsa.h pro_fadd.c pro_fadd.pl
	splfr pro_fadd.pl pro_fadd.c --cflag="${CPPFLAGS}"\
              --static\
             -LD -Wl,-rpath,$(PWD) -L. -lfadd

libfadd.so: fadd.cc fadd.h
	gcc $(CPPFLAGS) fadd.cc -lstdc++ -shared -o libfadd.so

test_fadd: libfadd.so test_fadd.o
	g++ test_fadd.o -Wl,-rpath,$(PWD) -L. -lfadd -o test_fadd

acctuple: acctuple.o
	g++ $(CPPFLAGS) acctuple.o -o acctuple -pg

acctuple.o: acctuple.cc
	g++ $(CPPFLAGS) -c acctuple.cc -pg

test_fadd.o: fadd.h test_fadd.c
	$(CC) $(CPPFLAGS) -c test_fadd.c

test_guess: test_guess.o libfadd.so
	g++ $(CPPFLAGS) $< -Wl,-rpath,$(PWD) -L. -lfadd -o $@

test_guess.o: test_guess.c
	$(CC) $(CPPFLAGS) -c $<

clean:
	rm -f *.o 

realclean: clean
	rm -f *.so *.po test_fadd maketuple.pl print_tuple.pl


## to test sicstus interface:
## sicstus -l fadd
## ?- pro_init_tuple(['test1.tab.tpl'],Number), 
##    pro_word_tuple_grams([jan],Number, Result).
## 
##
## cd ~vannoord/z/Alpino/Lexicon
## sicstus -l tst
## ?- fadd:init_morph('tst_dict.fsa',0,0,0,0,Dict),
##    fadd:pro_morph_word(kom,Dict,List).

install:
