FILES = Makefile README iso2022.h en2022cn.c de2022cn.c \
	b5cns.h b5map.c b5cns.awk RFC1922.txt b2g_tables.S.c\
	sample.gb sample.cns sample.big5 BeTTY.doc

PROGRAMS = en2022cn de2022cn

# This should be nawk or gawk (GNU version awk).
AWK = nawk

CMP = cmp

all: ${PROGRAMS}

en2022cn: iso2022.h en2022cn.c b5map.o
	$(CC) -o en2022cn $(CFLAGS) en2022cn.c b5map.o

de2022cn: iso2022.h de2022cn.c b5map.o
	$(CC) -o de2022cn $(CFLAGS) de2022cn.c b5map.o

b5map.o: iso2022.h b5cns.h b2g_tables.S.c b5map.c
	$(CC) -c $(CFLAGS) b5map.c 

b5cns.h: RFC1922.txt b5cns.awk
	$(AWK) -f b5cns.awk < RFC1922.txt > b5cns.h

verify: ${PROGRAMS}
	./en2022cn gb < sample.gb > temp
	./de2022cn gb < temp > temp2
	@if $(CMP) sample.gb temp2; then\
	  echo GB is correctly handled.;\
	else\
	  echo GB handling has some error.;\
	fi
	./en2022cn cns < sample.cns > temp
	./de2022cn cns < temp > temp2
	@if $(CMP) sample.cns temp2; then\
	  echo CNS is correctly handled.;\
	else\
	  echo CNS handling has some error.;\
	fi
	./en2022cn big5 < sample.big5 > temp
	./de2022cn big5 < temp > temp2
	@if $(CMP) sample.big5 temp2; then\
	  echo BIG5 is correctly handled.;\
	else\
	  echo BIG5 handling has some error.;\
	fi
	rm -f temp temp2

clean:
	rm -f ${PROGRAMS} b5map.o *~ core temp*

iso-cn.tgz: ${FILES}
	tar cfz iso-cn.tgz ${FILES}

iso-cn.uue: iso-cn.tgz
	uuencode iso-cn.tgz iso-cn.tgz > iso-cn.uue

pack: iso-cn.tgz

uuencode: iso-cn.uue

