# Special Makefile for `recode' tables.			-*- Makefile -*-
# Copyright © 1997, 1998, 1999, 2000 Progiciels Bourbeau-Pinard inc.
# François Pinard <pinard@iro.umontreal.ca>, 1997.

# 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, or (at your option)
# any later version.

# 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.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

include Makefile

## Some files in the `recode' distribution are mechanically derived
## from data files while is available from the net using FTP or HTTP.
## These original files are not distributed.  From the *distribution*
## standpoint, one might consider those derived files just as sources,
## forgetting there is some hidden magic behind them.  But the magic
## is revealed here! :-).  The distribution already contains all
## non-trivial derivation tools I made.  For completeness, this
## special Makefile holds the accompanying derivation recipes.

## For activating the included recipes, it suffices to link this
## `Makemore' file as `GNUmakefile' in the `doc/' directory of your
## *build* hierarchy.  You need GNU make, GNU wget, Python and Internet
## connectivity for all this to work.  However, be warned that if
## external files changed, you may be hit.  I am interested in hearing
## about such problems (maybe at `recode-bugs@iro.umontreal.ca'), but
## I do not want to commit myself at maintaining the derivation stuff
## at the same level as for the the remainder of `recode'.

CHSET = chset32a
LIBICONV =
MAPURL = ftp://ftp.unicode.org/MAPPINGS

MNEMONICS_DS = mnemonic,ds
ISO10646_DEF = $(CHSET)/iso10646.def
CHARSETS_DEF = $(CHSET)/charsets.def
ENCODINGS_DEF = ../libiconv/encodings.def ../libiconv/encodings_local.def
MNEMONICS_DS = keld-email/iso10646.def
ISO10646_DEF = keld-email/iso10646.def
CHARSETS_DEF = keld-email/charsets.def
MNEMONICS_DS = keld-email/iso10646.def keld-email/other.def keld-email/control.def
NOMS_CARACS = noms_juc_19981216.txt
NOMS_CARACS = NomsSeulsfinal.lst

PYTHON = python
SURF = netscape
WGET = wget

# Merely add our things to standard `all' goal.
all: $(srcdir)/libiconv.texi $(srcdir)/rfc1345.texi \
$(srcdir)/fr-libiconv.texi $(srcdir)/fr-rfc1345.texi \
$(top_srcdir)/src/libiconv.h $(top_srcdir)/src/rfc1345.h \
$(top_srcdir)/src/charname.h $(top_srcdir)/src/fr-charname.h

doc-check: all
	-cd $(top_srcdir)/src && diff -u charname.h{-,}
	-cd $(top_srcdir)/src && diff -u fr-charname.h{-,}
	-cd $(top_srcdir)/src && diff -u rfc1345.h{-,}
	-cd $(top_srcdir)/src && diff -u strip-data.c{-,}
	-cd $(top_srcdir)/src && diff -u strip-pool.c{-,}
	-cd $(srcdir) && diff -u libiconv.texi{-,}
	-cd $(srcdir) && diff -u fr-libiconv.texi{-,}
	-cd $(srcdir) && diff -u rfc1345.texi{-,}
	-cd $(srcdir) && diff -u fr-rfc1345.texi{-,}

# The next rules, when written, for example:
#rfc1345.texi pool.c tables.c: ...
# may launch many parallel occurrences of the action.  This is bad.
# Any idea, someone?  For now, just list one of them.

$(top_srcdir)/src/charname.h: tables.py $(MNEMONICS_DS) rfc1345.txt
	cd $(srcdir) && $(PYTHON) tables.py -n $(MNEMONICS_DS) rfc1345.txt
	mv $(srcdir)/charname.h $@

$(top_srcdir)/src/fr-charname.h: tables.py $(NOMS_CARACS)
	cd $(srcdir) && $(PYTHON) tables.py -Fn $(NOMS_CARACS)
	mv $(srcdir)/fr-charname.h $@

$(top_srcdir)/src/libiconv.h: tables.py $(ENCODINGS_DEF)
	cd $(srcdir) && $(PYTHON) tables.py -l $(ENCODINGS_DEF)
	mv $(srcdir)/libiconv.h $@

$(top_srcdir)/src/rfc1345.h: tables.py $(MNEMONICS_DS)
	cd $(srcdir) && $(PYTHON) tables.py -m $(MNEMONICS_DS)
	mv $(srcdir)/rfc1345.h $@

$(srcdir)/libiconv.texi: tables.py $(ENCODINGS_DEF)
	cd $(srcdir) && $(PYTHON) tables.py -s $(ENCODINGS_DEF)

$(srcdir)/fr-libiconv.texi: tables.py $(ENCODINGS_DEF)
	cd $(srcdir) && $(PYTHON) tables.py -Fs $(ENCODINGS_DEF)

$(srcdir)/rfc1345.texi: tables.py $(MNEMONICS_DS) $(CHARSETS_DEF)
	cd $(srcdir) && $(PYTHON) tables.py -pt $(MNEMONICS_DS) $(CHARSETS_DEF)
	mv $(srcdir)/strip-pool.c $(top_srcdir)/src/strip-pool.c
	mv $(srcdir)/strip-data.c $(top_srcdir)/src/strip-data.c

$(srcdir)/fr-rfc1345.texi: tables.py $(MNEMONICS_DS) $(CHARSETS_DEF)
	cd $(srcdir) && $(PYTHON) tables.py -Ft $(MNEMONICS_DS) $(CHARSETS_DEF)

# -----------------------------------#
# External files built into recode.  #
# -----------------------------------#

$(srcdir)/$(CHARSET_DEFS): $(srcdir)/$(CHSET)

$(srcdir)/$(CHSET):
	mkdir $@-tmp
	$(WGET) ftp://dkuug.dk/pub/$(CHSET).tar
	tar xfC $(CHSET).tar $@-tmp
	rm $(CHSET).tar
	mv $@-tmp $@

# Also look in `ftp://dkuug.dk/i18n/WG15-collection/charmaps/iso10646'.
$(srcdir)/mnemonic,ds:
	$(WGET) ftp://dkuug.dk/i18n/WG15-collection/repertoiremaps/mnemonic,ds
	test $(srcdir) = . || mv mnemonic,ds $@

$(srcdir)/rfc1345.txt:
	$(WGET) ftp://nic.ddn.mil/rfc/rfc1345.txt
	test $(srcdir) = . || mv rfc1345.txt $@

# -------------------------------------------------#
# Useful external files, but unbuilt into recode.  #
# -------------------------------------------------#

$(srcdir)/cp1250.txt:
	$(WGET) $(MAPURL)/VENDORS/MICSFT/WINDOWS/CP1250.TXT
	mv CP1250.TXT $@

$(srcdir)/cp1251.txt:
	$(WGET) $(MAPURL)/VENDORS/MICSFT/WINDOWS/CP1251.TXT
	mv CP1251.TXT $@

$(srcdir)/cp1252.txt:
	$(WGET) $(MAPURL)/VENDORS/MICSFT/WINDOWS/CP1252.TXT
	mv CP1252.TXT $@

# Index at `http://www.dkuug.dk/jtc1/sc22/wg20/docs/projects.html.en'.
i18n.txt:
	$(WGET) http://www.dkuug.dk/jtc1/sc22/wg20/docs/i18n.txt
i18nrep.txt:
	$(WGET) http://www.dkuug.dk/jtc1/sc22/wg20/docs/i18nrep.txt

# Various files.
iso2375reg.txt:
	$(WGET) ftp://dkuug.dk/i18n/iso2375reg.txt

# Online documentation.
# Index at `http://osiris.dkuug.dk/jtc1/sc2/wg3'.
character-sets:
	$(SURF) http://www.ewos.be/tg-cs/gtop.htm
