#
# Copyright (C) 2007-2009  Kazuhiro Ito
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

PACKAGE = oald7-fpw-20090320
DIR = OALD_7
SUBDIRS = OALD7 OALD7CG OALD7WF
PACKAGEEXTRA = README.PKG gaiji-tables
PACKAGEDEPS = gaiji-table
ARCHIVEEXTRA = ChangeLog README README.PKG gaiji/*.xbm gaiji/halfchar.txt \
		gaiji-table.pl gaiji-tables.in/*.in tables \
		oald7cgraph oald7sound
CLEANEXTRA = gaiji-tables/OALD7.map gaiji-tables/OALD7CG.map \
		gaiji-tables/OALD7WF.map gaiji-tables/oald7-pkg.el

.SUFFIXES:

include fpwutils.mk

gaiji-table: userchar-recursive
	@rm -rf gaiji-tables
	@mkdir gaiji-tables
	${PERL} gaiji-table.pl OALD7/${WORKDIR}/halfchar \
	  gaiji-tables.in gaiji-tables
	@cp -p gaiji-tables/OALD7.map gaiji-tables/OALD7CG.map
	@cp -p gaiji-tables/OALD7.map gaiji-tables/OALD7WF.map

catalogs.txt: $(addsuffix /catalogs.txt,${SUBDIRS})
	rm -f $@
	echo "[Catalog]" > $@
	echo "FileName	= catalogs" >> $@
	echo "Type		= EPWING5" >> $@
	${PERL} -e 'printf "Books\t\t= %d\n", scalar(@ARGV)' ${SUBDIRS} >> $@
	for subdir in ${SUBDIRS} ; do \
	   echo "[Book]" >> $@ ; \
	   sed -n -e '/^Title[ 	]*=/p' $$subdir/$@ >> $@ ; \
	   sed -n -e '/^BookType[ 	]*=/p' $$subdir/$@ >> $@ ; \
	   sed -n -e '/^HanGaiji[ 	]*=/p' $$subdir/$@ >> $@ ; \
	   sed -n -e '/^ZenGaiji[ 	]*=/p' $$subdir/$@ >> $@ ; \
	   echo "Directory	= \"$$subdir\"" >> $@ ; \
	done
