prefix=@prefix@
prgdir=@PRGDIR@
imdir=@IMDIR@
CFLAGS = @CFLAGS@

CFLAGS += -I. -I..

LIBDIR  = $(prefix)$(imdir)
LD      = gcc $(CFLAGS)
RM      = rm -f
INSTALL = install -c

GROUP = root

EXECPROGS = cin2tab txt2tab txt2tab1 tab2txt tab2txt1

PROGS = $(EXECPROGS) sysphrase.tab usrphrase.tab

all: $(PROGS)

pinyin.tab pinyin.tab.lx pinyin.tab.phr: cin2tab pinyin.cin
	./cin2tab pinyin

cin2tab: cin2tab.c
	$(LD) -o cin2tab cin2tab.c


tab2dat: tab2dat.c
	$(LD) -o tab2dat tab2dat.c

cin2dat: cin2dat.c
	$(LD) -o cin2dat cin2dat.c

txt2tab: txt2tab.c
	$(LD) -o txt2tab txt2tab.c

txt2tab1: txt2tab1.c
	$(LD) -o txt2tab1 txt2tab1.c

tab2txt: tab2txt.c
	$(LD) -o tab2txt tab2txt.c

tab2txt1: tab2txt1.c 
	$(LD) -o tab2txt1 tab2txt1.c

sysphrase.tab: sysphrase.txt pinyin.map txt2tab
	./txt2tab sysphrase.txt ../../turbo/sort.char.count sysphrase.tab 2>/dev/null

usrphrase.tab: usrphrase.txt pinyin.map txt2tab1
	./txt2tab1 usrphrase.txt usrphrase.tab
	
depend .depend:
	$(CC) $(CFLAGS) -M *.c > .depend

clean:
	rm -f $(EXECPROGS)
	rm -f *.o
	rm -f *.tab *.tab.lx *.tab.phr *.idx *.dat
distclean:clean
	rm -f Makefile
install: $(PROGS)
	mkdir -p $(LIBDIR)/bin
	mkdir -p $(LIBDIR)/cce
	$(INSTALL) -m 755 -d $(LIBDIR)
	$(INSTALL) -s -m 755 cin2tab $(LIBDIR)/bin
	$(INSTALL) -s -m 755 txt2tab $(LIBDIR)/bin
	$(INSTALL) -s -m 755 tab2txt $(LIBDIR)/bin
	$(INSTALL) -m 644 pinyin.map $(LIBDIR)/cce
	$(INSTALL) -m 644 sysphrase.tab $(LIBDIR)/cce
	$(INSTALL) -m 644 usrphrase.tab $(LIBDIR)/cce

ifeq (.depend, $(wildcard .depend))
include .depend
endif

