include ../../config.status
include ../../install.status

EXTRA_DEFINES = @EXTRA_DEFINES@
EXTRA_LIBS    = @EXTRA_LIBS@
TABS = @MAKEALL@

PROGS   = cin2tab cj2cin ph2xcin ar2cin

CIN2TAB    = ../../xcin/cin2tab
CONV.O     = ../../xcin/conv.o
XI.H       = ../../xcin/xi.h
CONSTANT.H = ../../xcin/constant.h


all: $(TABS)

.c.o:
	$(CC) -c -o $*.o $(CFLAGS) $(INC_PATH) $(DEFS) $(EXTRA_DEFINES) $<


cin2tab:
	rm -f cin2tab
	test -x $(CIN2TAB) && ln -s $(CIN2TAB) cin2tab

#
#  ETen input-method tables.
#
conv.o:  
	rm -f conv.o
	test -f $(CONV.O) && ln -s $(CONV.O) conv.o

constant.h:
	rm -f constant.h
	test -f $(CONSTANT.H) && ln -s $(CONSTANT.H) constant.h

xi.h:
	rm -f xi.h
	test -f $(XI.H) && ln -s $(XI.H) xi.h

tran.o: tran.c
 

cj.tab:	cj2cin changjei.tab changjei.uil cin2tab
	if [ ! -f ../cj.tab ]; then\
	    ./cj2cin > ../cj.cin;\
	    ./cin2tab ../cj;\
	fi
cj2cin:	cj2cin.c conv.o tran.o xi.h constant.h
	$(CC) $(CFLAGS) cj2cin.c conv.o tran.o -o $@
changjei.tab:
	rm -f changjei.tab
	ln -s $(PATH_XCIN_ETEN)/changjei.tab .
changjei.uil:
	rm -f changjei.uil
	ln -s $(PATH_XCIN_ETEN)/changjei.uil .
	
pho.tab: ph2xcin phonetic.tab
	if [ ! -f ../pho.tab ]; then ./ph2xcin; fi
ph2xcin: ph2xcin.c tran.o
	$(CC) $(CFLAGS) ph2xcin.c tran.o  -o $@
phonetic.tab:
	rm -f phonetic.tab
	ln -s $(PATH_XCIN_ETEN)/phonetic.tab .

ar30.tab: ar2cin et_array30.tab xusrar30.tbl cin2tab
	if [ ! -f ../ar30.tab ]; then\
	    ./ar2cin > ../ar30.cin;\
	    cat ar30.symbol >> ../ar30.cin;\
	    ./cin2tab ../ar30;\
	fi
ar2cin:	ar2cin.c conv.o tran.o xi.h constant.h
	$(CC) $(CFLAGS) ar2cin.c conv.o tran.o -o $@
et_array30.tab:
	rm -f array30.tab
	ln -s $(PATH_XCIN_ETEN)/array30.tab .
xusrar30.tbl:
	rm -f xusrar30.tbl
	ln -s $(PATH_XCIN_ETEN)/xusrar30.tbl .

#
# Free Input-Method Tables.
#
3-dayi.tab: cin2tab ../3-dayi.cin
	if [ ! -f ../3-dayi.tab ]; then ./cin2tab ../3-dayi; fi

pinyin.tab: cin2tab ../pinyin.cin
	if [ ! -f ../pinyin.tab ]; then ./cin2tab ../pinyin; fi

zmdbosh.tab: cin2tab ../zmdbosh.cin
	if [ ! -f ../zmdbosh.tab ]; then ./cin2tab ../zmdbosh; fi

phone.tab: cin2tab ../phone.cin
	if [ ! -f ../phone.tab ]; then ./cin2tab ../phone; fi

array30.tab: cin2tab ../array30.cin
	if [ ! -f ../array30.tab ]; then ./cin2tab ../array30; fi


install: all
	if [ ! -d $(PATH_XCIN_DIR) ]; then $(INSTALL_DIR) $(PATH_XCIN_DIR); fi
	for f in `/bin/ls ../*.cin`; do\
	    ff=`basename $$f .cin`;\
	    if [ ! -f ../$$ff.tab ]; then ./cin2tab ../$$ff; fi;\
	done
	for f in `ls ../*.cin ../*.tab*`; do\
	    ff=`basename $$f`;\
	    $(INSTALL_DATA) ../$$ff $(PATH_XCIN_DIR); echo $(PATH_XCIN_DIR)/$$ff >> ../filelist;\
	done

clean:
	rm -f *.o $(PROGS) xi.h constant.h ../filelist core *.tab* *.tbl ../*.tab* 

veryclean: clean
	rm -f Makefile ../cj.cin ../ar30.cin
