#
# makefile for text filter into PostScript
#
# Copyright (C) 2001-2003 Taiji Yamada <taiji@aihara.co.jp>
#
#PREFIX=/opt/local
PREFIX=/usr/local
INSTALL_BIN_DIR=$(PREFIX)/bin
INSTALL_LIB_DIR=$(PREFIX)/share/tops
INSTALL=cp
#MKDIRHIER=mkdirhier
MKDIRHIER=mkdir -p

#
# scripts for single-byte encodings
#
SCRIPTS= \
ishow-iso-8859-1.ps \
ishow-iso-8859-2.ps \
ishow-iso-8859-3.ps \
ishow-iso-8859-4.ps \
ishow-iso-8859-5.ps \
ishow-iso-8859-7.ps \
ishow-iso-8859-9.ps \
ishow-iso-8859-10.ps \
ishow-iso-8859-13.ps \
ishow-iso-8859-14.ps \
ishow-iso-8859-15.ps \
ishow-koi8-r.ps \
ishow-mac-ce.ps \
ishow-mac-croatian.ps \
ishow-mac-cyrillic.ps \
ishow-mac-greek.ps \
ishow-mac-icelandic.ps \
ishow-mac-roman.ps \
ishow-mac-turkish.ps \
\
ishow-ms-cp1250.ps \
ishow-ms-cp1251.ps \
ishow-ms-cp1252.ps \
ishow-ms-cp1253.ps \
ishow-ms-cp1254.ps \
ishow-ms-cp1257.ps \
ishow-ms-cp1258.ps

#ishow-iso-8859-6.ps \
#ishow-ms-cp1256.ps \
#\
#ishow-iso-8859-8.ps \
#ishow-mac-hebrew.ps \
#ishow-ibm-cp862.ps \
#ishow-ms-cp1255.ps \
#ishow-ibm-cp874.ps \
#ishow-ms-cp874.ps \
#\
#ishow-mac-arabic.ps \
#ishow-mac-devanagari.ps \
#ishow-mac-farsi.ps \
#ishow-mac-gujarati.ps \
#ishow-mac-gurmukhi.ps \
#ishow-mac-romanian.ps \
#ishow-mac-thai.ps \
#ishow-mac-ukrainian.ps \
#\
#ishow-ibm-cp037.ps \
#ishow-ibm-cp1026.ps \
#ishow-ibm-cp500.ps \
#ishow-ibm-cp875.ps \
#ishow-ibm-cp437.ps \
#ishow-ibm-cp737.ps \
#ishow-ibm-cp775.ps \
#ishow-ibm-cp850.ps \
#ishow-ibm-cp852.ps \
#ishow-ibm-cp855.ps \
#ishow-ibm-cp857.ps \
#ishow-ibm-cp860.ps \
#ishow-ibm-cp861.ps \
#ishow-ibm-cp863.ps \
#ishow-ibm-cp864.ps \
#ishow-ibm-cp865.ps \
#ishow-ibm-cp866.ps \
#ishow-ibm-cp869.ps \

#
# scripts for multi-byte encodings
#
SCRIPT= \
ishow-b5-eten.ps \
ishow-big5.ps \
ishow-euc-china.ps \
ishow-euc-cn.ps \
ishow-euc-korea.ps \
ishow-euc-kr.ps \
ishow-euc-tw.ps \
ishow-euccn.ps \
ishow-euckr.ps \
ishow-gbk2k.ps \
ishow-hkscs.ps \
ishow-iso-2022-cn.ps \
ishow-iso-2022-jp.ps \
ishow-iso-2022-jp2.ps \
ishow-iso-2022-kr.ps \
ishow-iso-2022-m17n.ps \
ishow-shift_jis.ps \
ishow-uhc.ps \
ishow-utf8-cn.ps \
ishow-utf8-jp.ps \
ishow-utf8-kr.ps \
ishow-utf8-tw.ps \
ishow-utf16-cn.ps \
ishow-utf16-jp.ps \
ishow-utf16-kr.ps

all: $(SCRIPTS) $(SCRIPT) tops

tops: tops.sh
	sed "s|tops_dir='.*'|tops_dir='$(INSTALL_LIB_DIR)'|" $< > $@
	chmod +x $@

#
# making scripts for single-byte encodings
#

# based on ishow-iso-6429.ps
ishow-%.ps: Resource/Encoding/%-encoding ishow-iso-6429.ps
	(case $* in\
	iso-8859-1)	font='Courier';;\
	iso-8859-2)	font='Courier';;\
	iso-8859-3)	font='CourierNewLatin3';;\
	iso-8859-4)	font='CourierNewLatin4';;\
	iso-8859-5)	font='CourierNewCyrillic';;\
	iso-8859-6)	font='CourierNewArabic';;\
	iso-8859-7)	font='CourierNewGreek';;\
	iso-8859-8)	font='CourierNewHebrew';;\
	iso-8859-9)	font='Courier';;\
	iso-8859-10)	font='CourierNewLatin6';;\
	iso-8859-13)	font='Courier';;\
	iso-8859-14)	font='CourierNewLatin8';;\
	iso-8859-15)	font='Courier';;\
	koi8-r)		font='CourierNewCyrillic';;\
	mac-arabic)	font='CourierNewArabic';;\
	mac-ce)		font='Courier';;\
	mac-croatian)	font='CourierNewCroatian';;\
	mac-cyrillic)	font='CourierNewCyrillic';;\
	mac-devanagari)	font='CourierNewDevanagari';;\
	mac-farsi)	font='CourierNewFarsi';;\
	mac-greek)	font='CourierNewGreek';;\
	mac-gujarati)	font='CourierNewGujarati';;\
	mac-gurmukhi)	font='CourierNewGurmukhi';;\
	mac-hebrew)	font='CourierNewHebrew';;\
	mac-icelandic)	font='CourierNewIcelandic';;\
	mac-roman)	font='CourierNewRoman';;\
	mac-romanian)	font='CourierNewRomanian';;\
	mac-thai)	font='CourierNewThai';;\
	mac-turkish)	font='CourierNewTurkish';;\
	mac-ukrainian)	font='CourierNewUkrainian';;\
	ms-cp874)	font='CourierNewThai';;\
	ms-cp1250)	font='Courier';;\
	ms-cp1251)	font='CourierNewCyrillic';;\
	ms-cp1252)	font='Courier';;\
	ms-cp1253)	font='CourierNewGreek';;\
	ms-cp1254)	font='Courier';;\
	ms-cp1255)	font='CourierNewHebrew';;\
	ms-cp1256)	font='CourierNewArabic';;\
	ms-cp1257)	font='Courier';;\
	ms-cp1258)	font='CourierNewVietnamese';;\
	esac;\
	echo '/^%%BeginProlog/{'>tmp.sed;\
	echo "a\\">>tmp.sed;\
	echo ''>>tmp.sed;\
	echo "r $<">>tmp.sed;\
	echo '}'>>tmp.sed;\
	echo '/^%%EndProlog/{'>>tmp.sed;\
	echo "a\\">>tmp.sed;\
	echo "/$$font-$* /$$font /$*-encoding reencode-font pop\\">>tmp.sed;\
	echo "/$$font-$*,Bold /$$font,Bold /$*-encoding reencode-font pop">>tmp.sed;\
	echo '}'>>tmp.sed;\
	echo "s/^\/Courier findfont/\/$$font-$* findfont/">>tmp.sed)
	sed -e "s/ishow-iso-6429/ishow-$*/" -f tmp.sed ishow-iso-6429.ps > $@
	rm tmp.sed

#
# making scripts for multi-byte encodings
#
Encoding_iso-2022-m17n= \
ISOLatin1 \
ISOLatin2 \
ISOLatin3 \
ISOLatin4 \
ISOCyrillic \
ISOGreek \
ISOLatin5 \
ISOLatin6 \
ISOLatin7 \
ISOLatin9
#ISOHebrew \

# based on ishow-euc-jp.ps
ishow-big5.ps: ishow-euc-jp.ps
	sed 's/euc-jp/big5/g;s/EUC-JP/Big5/g;s/EUC/ETen-B5/g;s/KozMin-Regular/LiSungLight/g;s/KozMin-Bold/LiGothicMed/g' $< > $@
ishow-euc-cn.ps: ishow-big5.ps
	sed 's/big5/euc-cn/g;s/Big5/EUC-CN/g;s/ETen-B5/GBK2K/g;s/LiSungLight/SIL-FangSong-/g;s/LiGothicMed/SIL-Hei-Med-Jian/g' $< > $@
ishow-euc-kr.ps: ishow-big5.ps
	sed 's/big5/euc-kr/g;s/Big5/EUC-KR/g;s/ETen-B5/KSCms-UHC/g;s/LiSungLight/SMMyungjo-Medium/g;s/LiGothicMed/SMGothic-Bold/g' $< > $@
ishow-euc-tw.ps: ishow-big5.ps
	sed 's/big5/euc-tw/g;s/Big5/EUC-TW/g;s/ETen-B5/CNS-EUC/g;s/LiSungLight/LiSungLight/g;s/LiGothicMed/LiGothicMed/g' $< > $@
ishow-shift_jis.ps: ishow-big5.ps
	sed 's/big5/shift_jis/g;s/Big5/SHIFT_JIS/g;s/ETen-B5/90ms-RKSJ/g;s/LiSungLight/KozMin-Regular/g;s/LiGothicMed/KozMin-Bold/g' $< > $@

ishow-utf8-cn.ps: ishow-euc-cn.ps
	sed 's/euc-cn/utf8-cn/g;s/EUC-CN/UTF8-CN/g;s/GBK2K/UniGB-UTF8/g' $< > $@
ishow-utf8-jp.ps: ishow-euc-jp.ps
	sed 's/euc-jp/utf8-jp/g;s/EUC-JP/UTF8-JP/g;s/EUC/UniJIS-UTF8/g' $< > $@
ishow-utf8-kr.ps: ishow-euc-kr.ps
	sed 's/euc-kr/utf8-kr/g;s/EUC-KR/UTF8-KR/g;s/KSCms-UHC/UniKS-UTF8/g' $< > $@
ishow-utf8-tw.ps: ishow-euc-tw.ps
	sed 's/euc-tw/utf8-tw/g;s/EUC-TW/UTF8-TW/g;s/CNS-EUC/UniCNS-UTF8/g' $< > $@

# based on ishow-eucjp.ps
ishow-euccn.ps: ishow-eucjp.ps
	sed 's/eucjp/euccn/g;s/EUC-/GB-EUC-/g;s/KozMin-Regular/SIL-FangSong-/g;s/KozMin-Bold/SIL-Hei-Med-Jian/g' $< > $@
ishow-euckr.ps: ishow-eucjp.ps
	sed 's/eucjp/euckr/g;s/EUC-/KSC-EUC-/g;s/KozMin-Regular/SMMyungjo-Medium/g;s/KozMin-Bold/SMGothic-Bold/g' $< > $@

# based on ishow-euc-japan.ps
ishow-euc-china.ps: ishow-euc-japan.ps
	sed 's/euc-japan/euc-china/g;s/EUC-/GB-EUC-/g;s/KozMin-Regular/SIL-FangSong-/g;s/KozMin-Bold/SIL-Hei-Med-Jian/g' $< > $@
ishow-euc-korea.ps: ishow-euc-japan.ps
	sed 's/euc-japan/euc-korea/g;s/EUC-/KSC-EUC-/g;s/KozMin-Regular/SMMyungjo-Medium/g;s/KozMin-Bold/SMGothic-Bold/g' $< > $@

# based on ishow-iso-2022-cjk.ps
ishow-iso-2022-cn.ps: ishow-iso-2022-cjk.ps
	sed 's/iso-2022-cjk/iso-2022-cn/;s/^[ %]\(.*% iso-2022:\)/%\1/g;s/^%\(.*% iso-2022:\(ascii\|gb-2312-1980\)\)/ \1/g' $< > $@
ishow-iso-2022-jp.ps: ishow-iso-2022-cjk.ps
	sed 's/iso-2022-cjk/iso-2022-jp/;s/^[ %]\(.*% iso-2022:\)/%\1/g;s/^%\(.*% iso-2022:\(ascii\|jis-x-0201-kana\|jis-x-0201-roman\|jis-x-0208-1983\)\)/ \1/g' $< > $@
ishow-iso-2022-jp2.ps: ishow-iso-2022-cjk.ps
	sed 's/iso-2022-cjk/iso-2022-jp2/;s/^[ %]\(.*% iso-2022:\)/%\1/g;s/^%\(.*% iso-2022:\(ascii\|jis-x-0201-kana\|jis-x-0201-roman\|jis-x-0208-1978\|jis-x-0208-1983\|jis-x-0212-1990\)\)/ \1/g' $< > $@
ishow-iso-2022-kr.ps: ishow-iso-2022-cjk.ps
	sed 's/iso-2022-cjk/iso-2022-kr/;s/^[ %]\(.*% iso-2022:\)/%\1/g;s/^%\(.*% iso-2022:\(ascii\|ks-x-1001-1992\)\)/ \1/g' $< > $@
ishow-iso-2022-m17n.ps: ishow-iso-2022-cjk.ps
	(echo '/^%%BeginProlog/{'>tmp.sed;\
	for e in $(Encoding_iso-2022-m17n); do\
	echo "a\\">>tmp.sed;\
	echo ''>>tmp.sed;\
	echo "a\\">>tmp.sed;\
	echo "/$${e}Encoding /Encoding resourcestatus { pop pop } {">>tmp.sed;\
	echo "r Resource/Encoding/$${e}Encoding">>tmp.sed;\
	echo "a\\">>tmp.sed;\
	echo '} ifelse'>>tmp.sed;\
	done;\
	echo '}'>>tmp.sed)
	sed -e 's/iso-2022-cjk/iso-2022-m17n/;s/^[ %]\(.*% iso-2022:\)/%\1/g;s/^%\(.*% iso-2022:\(ascii\|iso-8859-1,\|iso-8859-2,\|iso-8859-5,\|iso-8859-9,\|jis-x-0201-kana\|jis-x-0201-roman\|jis-x-0208-1978\|gb-2312-1980\|jis-x-0208-1983\|ks-x-1001-1992\|jis-x-0212-1990\|gbt-12345-1990\|cns-11643-1992-p1\|cns-11643-1992-p2\|big5\)\)/ \1/g' -f tmp.sed $< > $@
	rm tmp.sed

# based on ishow-sjis.ps
ishow-b5-eten.ps: ishow-sjis.ps
	sed 's/sjis/b5-eten/g;s/RKSJ/ETen-B5/g;s/KozMin-Regular/LiSungLight/g;s/KozMin-Bold/LiGothicMed/g' $< > $@
ishow-hkscs.ps: ishow-sjis.ps
	sed 's/sjis/hkscs/g;s/RKSJ/HKscs-B5/g;s/KozMin-Regular/LiSungLight/g;s/KozMin-Bold/LiGothicMed/g' $< > $@
ishow-gbk2k.ps: ishow-sjis.ps
	sed 's/sjis/gbk2k/g;s/RKSJ/GBK2K/g;s/KozMin-Regular/SIL-FangSong-/g;s/KozMin-Bold/SIL-Hei-Med-Jian/g' $< > $@
ishow-uhc.ps: ishow-sjis.ps
	sed 's/sjis/uhc/g;s/RKSJ/KSCms-UHC/g;s/KozMin-Regular/SMMyungjo-Medium/g;s/KozMin-Bold/SMGothic-Bold/g' $< > $@

# based on ishow-utf16-tw.ps
ishow-utf16-cn.ps: ishow-utf16-tw.ps
	sed 's/utf16-tw/utf16-cn/g;s/UTF16-TW/UTF16-CN/g;s/UniCNS-UTF16/UniGB-UTF16/g;s/LiSungLight/SIL-FangSong-/g;s/LiGothicMed/SIL-Hei-Med-Jian/g' $< > $@
ishow-utf16-jp.ps: ishow-utf16-tw.ps
	sed 's/utf16-tw/utf16-jp/g;s/UTF16-TW/UTF16-JP/g;s/UniCNS-UTF16/UniJIS-UTF16/g;s/LiSungLight/KozMin-Regular/g;s/LiGothicMed/KozMin-Bold/g' $< > $@
ishow-utf16-kr.ps: ishow-utf16-tw.ps
	sed 's/utf16-tw/utf16-kr/g;s/UTF16-TW/UTF16-KR/g;s/UniCNS-UTF16/UniKS-UTF16/g;s/LiSungLight/SMMyungjo-Medium/g;s/LiGothicMed/SMGothic-Bold/g' $< > $@

#
# edit origins of scripts
#
edit:
	emacs ishow-eucjp.ps ishow-euc-jp.ps ishow-euc-jp2.ps ishow-euc-japan.ps ishow-iso-6429.ps ishow-sjis.ps ishow-iso-2022-cjk.ps ishow-utf16-tw.ps &

#
# install tops and scripts
#
install:
	$(INSTALL) tops $(INSTALL_BIN_DIR)
	if [ ! -d $(INSTALL_LIB_DIR) ]; then (set -x; $(MKDIRHIER) $(INSTALL_LIB_DIR)); fi
	$(INSTALL) ishow*.ps $(INSTALL_LIB_DIR)

clean::
	rm -f tops
scriptsclean:
	rm -f $(SCRIPTS)
scriptclean:
	rm -f $(SCRIPT)

#
# testing
#

#
# testing single-byte encodings
#
TESTS= \
iso-8859-1.ps \
iso-8859-2.ps \
iso-8859-3.ps \
iso-8859-4.ps \
iso-8859-5.ps \
iso-8859-7.ps \
iso-8859-9.ps \
iso-8859-10.ps \
iso-8859-13.ps \
iso-8859-14.ps \
iso-8859-15.ps \
koi8-r.ps \
mac-ce.ps \
mac-croatian.ps \
mac-cyrillic.ps \
mac-greek.ps \
mac-icelandic.ps \
mac-roman.ps \
mac-turkish.ps \
ms-cp1250.ps \
ms-cp1251.ps \
ms-cp1252.ps \
ms-cp1253.ps \
ms-cp1254.ps \
ms-cp1257.ps \
ms-cp1258.ps

#iso-8859-6.ps \
#ms-cp1256.ps \
#\
#iso-8859-8.ps \
#mac-hebrew.ps \
#ibm-cp862.ps \
#ms-cp1255.ps \
#ibm-cp874.ps \
#ms-cp874.ps \
#\
#mac-arabic.ps \
#mac-devanagari.ps \
#mac-farsi.ps \
#mac-gujarati.ps \
#mac-gurmukhi.ps \
#mac-romanian.ps \
#mac-thai.ps \
#mac-ukrainian.ps \

#
# testing multi-byte encodings
#
TEST= \
b5-eten.ps \
big5.ps \
euc-cn.ps \
euc-jp.ps \
euc-jp2.ps \
euc-kr.ps \
euc-tw.ps \
euccn.ps \
eucjp.ps \
euckr.ps \
gbk2k.ps \
hkscs.ps \
iso-2022-cjk.ps \
iso-2022-cn.ps \
iso-2022-jp.ps \
iso-2022-jp2.ps \
iso-2022-kr.ps \
iso-2022-m17n.ps \
iso-6429.ps \
shift_jis.ps \
sjis.ps \
uhc.ps \
utf8-cn.ps \
utf8-jp.ps \
utf8-kr.ps \
utf8-tw.ps \
utf16-cn.ps \
utf16-jp.ps \
utf16-kr.ps \
utf16-tw.ps \
\
echo.ps \
echo-j.ps \
gawk.ps \
gawk-j.ps \
tops.sh.ps \
\
euc-china.ps \
euc-japan.ps \
euc-korea.ps \
\
m17n-j.ps

#
# testing arguments of tops
#

tops_flags=-p cat	-1
#tops_flags=-p cat	-2
#tops_flags=-p cat	-4
#tops_flags=-p cat	-8
#tops_flags=-p cat	-9
#tops_flags=-p cat	-1l
#tops_flags=-p cat	-2l
#tops_flags=-p cat	-4l
#tops_flags=-p cat	-8l
#tops_flags=-p cat	-9l
#tops_flags=-p cat	-T huge
#tops_flags=-p cat	-T large
#tops_flags=-p cat	-T normal
#tops_flags=-p cat	-T small
#tops_flags=-p cat	-T tiny
#tops_flags=-p cat	-T micro
#tops_flags=-p cat	-T huge   -l
#tops_flags=-p cat	-T large  -l
#tops_flags=-p cat	-T normal -l
#tops_flags=-p cat	-T small  -l
#tops_flags=-p cat	-T tiny   -l
#tops_flags=-p cat	-T micro  -l
#tops_flags=-p cat	-T 1L
#tops_flags=-p cat	-T 1
#tops_flags=-p cat	-T 1l
#tops_flags=-p cat	-T 2
#tops_flags=-p cat	-T 2p
#tops_flags=-p cat	-T 3
#tops_flags=-p cat	-T 4L
#tops_flags=-p cat	-T 4
#tops_flags=-p cat	-T 4l
#tops_flags=-p cat	-T 4p
#tops_flags=-p cat	-T 5
#tops_flags=-p cat	-T 6
#tops_flags=-p cat	-T 6l
#tops_flags=-p cat	-T 7
#tops_flags=-p cat	-T 8
#tops_flags=-p cat	-T 8l
#tops_flags=-p cat	-T 8p
#tops_flags=-p cat	-T 9
#tops_flags=-p cat	-T 9l
#tops_flags=-p cat	-T 10

#
# texts to test single-byte encodings
#
TEXTS= \
test/iso-8859-1.txt \
test/iso-8859-2.txt \
test/iso-8859-3.txt \
test/iso-8859-4.txt \
test/iso-8859-5.txt \
test/iso-8859-7.txt \
test/iso-8859-9.txt \
test/iso-8859-10.txt \
test/iso-8859-13.txt \
test/iso-8859-14.txt \
test/iso-8859-15.txt \
test/koi8-r.txt \
test/mac-ce.txt \
test/mac-croatian.txt \
test/mac-cyrillic.txt \
test/mac-greek.txt \
test/mac-icelandic.txt \
test/mac-roman.txt \
test/mac-turkish.txt \
test/ms-cp1250.txt \
test/ms-cp1251.txt \
test/ms-cp1252.txt \
test/ms-cp1253.txt \
test/ms-cp1254.txt \
test/ms-cp1257.txt \
test/ms-cp1258.txt

#test/iso-8859-6.txt \
#test/ms-cp1256.txt \
#\
#test/iso-8859-8.txt \
#test/mac-hebrew.txt \
#test/ibm-cp862.txt \
#test/ms-cp1255.txt \
#test/ibm-cp874.txt \
#test/ms-cp874.txt \
#\
#test/mac-arabic.txt \
#test/mac-devanagari.txt \
#test/mac-farsi.txt \
#test/mac-gujarati.txt \
#test/mac-gurmukhi.txt \
#test/mac-romanian.txt \
#test/mac-thai.txt \
#test/mac-ukrainian.txt \

#
# texts to test multi-byte encodings
#
TEXT= \
test/b5-eten.txt \
test/euc-china.txt \
test/euc-japan.txt \
test/euc-korea.txt \
test/euc-tw.txt \
test/euccn.txt \
test/eucjp.txt \
test/euckr.txt \
test/gbk2k.txt \
test/hkscs.txt \
test/iso-2022-cn.txt \
test/iso-2022-jp2.txt \
test/iso-2022-kr.txt \
test/shift_jis.txt \
test/sjis.txt \
test/uhc.txt \
test/utf8-cn.txt \
test/utf8-jp.txt \
test/utf8-kr.txt \
test/utf8-tw.txt \
test/utf16-cn.txt \
test/utf16-jp.txt \
test/utf16-kr.txt \
test/utf16-tw.txt \
\
test/echo.txt \
test/echo-j.txt \
test/gawk.txt \
test/gawk-j.txt

#test/iso-2022-cjk.7bit-lock-ss2.txt \
#test/iso-2022-m17n.7bit-lock.txt \
#test/iso-2022-m17n.7bit-ss2.txt \
#test/iso-2022-m17n.8bit-ss2.txt \
#test/iso-2022-m17n.emacs-mule.txt \
#test/iso-2022-m17n.x-ctext.txt \

test: $(TESTS) $(TEST)
Test: $(TESTS:.ps=.pdf) $(TEST:.ps=.pdf)
TEST: $(TESTS:.ps=.ps2pdf.ps) $(TEST:.ps=.ps2pdf.ps)

#
# archive test results
#
archive.test:
	zip tops_result_ps.zip $(TESTS) $(TEST)
archive.Test:
	zip tops_result_pdf.zip $(TESTS:.ps=.pdf) $(TEST:.ps=.pdf)
archive.TEST:
	zip tops_result_ps2pdf_ps.zip $(TESTS:.ps=.ps2pdf.ps) $(TEST:.ps=.ps2pdf.ps)

#
# generating scripts to be tested
#
%.ps: test/%.txt	ishow-%.ps
	./tops.sh -I $*		$(tops_flags) $< > $@
echo.ps: test/echo.txt	ishow-iso-6429.ps
	./tops.sh -I iso-6429	$(tops_flags) $< > $@
echo-j.ps: test/echo-j.txt	ishow-eucjp.ps
	./tops.sh -I eucjp	$(tops_flags) $< > $@
gawk.ps: test/gawk.txt	ishow-iso-6429.ps
	./tops.sh -I iso-6429	$(tops_flags) $< > $@
gawk-j.ps: test/gawk-j.txt	ishow-eucjp.ps
	./tops.sh -I eucjp	$(tops_flags) $< > $@
#	./tops.sh -I euc-jp	$(tops_flags) $< > $@
#	./tops.sh -I euc-japan	$(tops_flags) $< > $@
encoding=iso-2022-jp
tops.sh.ps: tops.sh ishow-$(encoding).ps README makefile
	./tops.sh -I $(encoding)	$(tops_flags) $^ > $@
m17n-j.ps: test/m17n-j.txt
	nkf -j $^ | ./tops.sh -I iso-2022-jp $(tops_flags) > $@

#
# testing scripts
#
%.pdf: %.ps
	-ps2pdf -sPAPERSIZE=a4 $< $@

%.ps2pdf.ps: %.pdf
#	cat $< | acroread -toPostScript -level2 -size a4 > $@
#	cat $< | acroread -toPostScript -level3 -size a4 > $@
#	pdf2ps -sPAPERSIZE=a4 -dLanguageLevel=2 $< $@
	pdf2ps -sPAPERSIZE=a4 -dLanguageLevel=3 $< $@

clean:: clean.test clean.tests

clean.tests::
	rm -f $(TESTS)
	rm -f $(TESTS:.ps=.pdf)
	rm -f $(TESTS:.ps=.ps2pdf.ps)

clean.test::
	rm -f $(TEST)
	rm -f $(TEST:.ps=.pdf)
	rm -f $(TEST:.ps=.ps2pdf.ps)

#
# making texts for testing
#
text: $(TEXTS) $(TEXT)

#
# texts of single-byte encodings
#
ifeq (uncomment,comment)
EVEC_DIR=Resource/Encoding
EVEC2TXT=evec2txt.pl
test/%.txt: $(EVEC_DIR)/%-encoding
	$(EVEC2TXT) $< > $@
endif

#
# texts of multi-byte encodings
#
test/euc-tw.txt: test/big5.txt
	iconv -f BIG5 -t EUC-TW $< > $@
test/euc-china.txt: test/euccn.txt
	cp $< $@
test/euc-japan.txt: test/eucjp.txt
	cp $< $@
test/euc-korea.txt: test/euckr.txt
	cp $< $@
test/iso-2022-cn.txt: test/euc-cn.txt
#	iconv -f EUC-CN -t ISO-2022-CN $< > $@
	lv -Iec -Oc $< > $@
test/iso-2022-kr.txt: test/euc-kr.txt
	iconv -f EUC-KR -t ISO-2022-KR $< > $@
test/utf8-tw.txt: test/big5.txt
	iconv -f BIG5 -t UTF-8 $< > $@
test/utf8-cn.txt: test/euc-cn.txt
	iconv -f EUC-CN -t UTF-8 $< > $@
test/utf8-jp.txt: test/euc-jp.txt
	iconv -f EUC-JP -t UTF-8 $< > $@
test/utf8-kr.txt: test/euc-kr.txt
	iconv -f EUC-KR -t UTF-8 $< > $@
test/utf16-tw.txt: test/big5.txt
	iconv -f BIG5 -t UTF-16 $< > $@
test/utf16-cn.txt: test/euc-cn.txt
	iconv -f EUC-CN -t UTF-16 $< > $@
test/utf16-jp.txt: test/euc-jp.txt
	iconv -f EUC-JP -t UTF-16 $< > $@
test/utf16-kr.txt: test/euc-kr.txt
	iconv -f EUC-KR -t UTF-16 $< > $@
test/echo.txt:
	man echo > $@
test/echo-j.txt:
	jman echo > $@
test/gawk.txt:
	man gawk > $@
test/gawk-j.txt:
	jman gawk > $@
ifeq (uncomment,comment)
CMAP_DIR=/opt/local/gs6.51/share/ghostscript/Resource/CMap
#CMAP2TXT=cmap2txt.pl
CMAP2TXT=cmapdump.pl
test/b5-eten.txt: $(CMAP_DIR)/ETen-B5-H $(CMAP_DIR)/ETen-B5-V
	$(CMAP2TXT) $^ > $@
test/euccn.txt: $(CMAP_DIR)/GB-EUC-H $(CMAP_DIR)/GB-EUC-V
	$(CMAP2TXT) $^ > $@
test/eucjp.txt: $(CMAP_DIR)/EUC-H $(CMAP_DIR)/EUC-V
	$(CMAP2TXT) $^ > $@
test/euckr.txt: $(CMAP_DIR)/KSC-EUC-H $(CMAP_DIR)/KSC-EUC-V
	$(CMAP2TXT) $^ > $@
test/gbk2k.txt: $(CMAP_DIR)/GBK2K-H $(CMAP_DIR)/GBK2K-V
	$(CMAP2TXT) $^ > $@
test/hkscs.txt: $(CMAP_DIR)/HKscs-B5-H $(CMAP_DIR)/HKscs-B5-V
	$(CMAP2TXT) $^ > $@
test/shift_jis.txt: $(CMAP_DIR)/90ms-RKSJ-H $(CMAP_DIR)/90ms-RKSJ-V
	$(CMAP2TXT) $^ > $@
test/sjis.txt: $(CMAP_DIR)/RKSJ-H $(CMAP_DIR)/RKSJ-V
	$(CMAP2TXT) $^ > $@
test/uhc.txt: $(CMAP_DIR)/KSCms-UHC-H $(CMAP_DIR)/KSCms-UHC-V
	$(CMAP2TXT) $^ > $@
test/utf8-tw.txt: $(CMAP_DIR)/UniCNS-UTF8-H $(CMAP_DIR)/UniCNS-UTF8-V
	$(CMAP2TXT) $^ > $@
test/utf8-cn.txt: $(CMAP_DIR)/UniGB-UTF8-H $(CMAP_DIR)/UniGB-UTF8-V
	$(CMAP2TXT) $^ > $@
test/utf8-jp.txt: $(CMAP_DIR)/UniJIS-UTF8-H $(CMAP_DIR)/UniJIS-UTF8-V
	$(CMAP2TXT) $^ > $@
test/utf8-kr.txt: $(CMAP_DIR)/UniKS-UTF8-H $(CMAP_DIR)/UniKS-UTF8-V
	$(CMAP2TXT) $^ > $@
endif
#
# texts of multilingual encodings such as Emacs/Mule
#
ifeq (uncomment,comment)
COCO=/opt/local/bin/coco
test/iso-2022-cjk.7bit-lock-ss2.txt: test/iso-2022-cjk.txt
#	$(COCO) 'undecided' 'iso-2022-7bit-lock-ss2' < $< > $@
	cp $< $@
test/iso-2022-m17n.7bit-lock.txt: test/iso-2022-m17n.txt
#	$(COCO) 'undecided' 'iso-2022-7bit-lock' < $< > $@
	cp $< $@
test/iso-2022-m17n.7bit-ss2.txt: test/iso-2022-m17n.txt
#	$(COCO) 'undecided' 'iso-2022-7bit-ss2' < $< > $@
	cp $< $@
test/iso-2022-m17n.8bit-ss2.txt: test/iso-2022-m17n.txt
#	$(COCO) 'undecided' 'iso-2022-8bit-ss2' < $< > $@
	cp $< $@
test/iso-2022-m17n.emacs-mule.txt: test/iso-2022-m17n.txt
#	$(COCO) 'undecided' 'emacs-mule' < $< > $@
	cp $< $@
test/iso-2022-m17n.x-ctext.txt: test/iso-2022-m17n.txt
#	$(COCO) 'undecided' 'x-ctext' < $< > $@
	cp $< $@
endif

textsclean:
	rm -f $(TEXTS)
textclean:
	rm -f $(TEXT)

distclean: clean
	rm -f *~
	rm -f test/*~
