# This is the developer's makefile, not the user's makefile.
# Don't use it unless you know exactly what you do!

# This Makefile needs GNU make.

SHELL = /bin/sh
RM = rm -f

# My reason for writing "gmsgfmt" (although GNU gettext installs it as
# "msgfmt") is to force an error if Solaris msgfmt would be used. Either
# this, or one should put a comment in the Makefile.devel saying
# "This Makefile needs GNU make and GNU msgfmt (from the GNU gettext package)."
GMSGFMT = gmsgfmt --statistics

all : tmp pot gmo

# This is hardwired. (See clisp-xgettext.)
PREDEF_LINGUAS = en
# Other languages must be translated by hand. They must also be added
# to the variable ALL_LINGUAS in ../configure.in.
OTHER_LINGUAS = de fr es nl

LINGUAS = $(PREDEF_LINGUAS) $(OTHER_LINGUAS)

DSOURCES = \
 lispbibl fsubr subr pseudofun constsym constobj constpack avl sort subrkw bytecode unix amiga amiga2 acorn msdos win32 xthread \
 spvw spvw_module spvw_debug spvw_alloca spvw_mmap spvw_multimap spvw_singlemap spvw_page spvw_heap spvw_global spvw_gcstat spvw_space spvw_mark spvw_objsize spvw_update spvw_fault spvw_sigsegv spvw_sigcld spvw_sigpipe spvw_sigint spvw_sigwinch spvw_garcol spvw_genera1 spvw_genera2 spvw_genera3 spvw_allocate spvw_typealloc spvw_circ spvw_walk spvw_ctype spvw_language spvw_memfile \
 spvwtabf spvwtabs spvwtabo \
 eval control \
 encoding pathname stream socket io \
 array hashtabl list package record sequence \
 charstrg debug \
 error erramiga errdjgpp errunix errwin32 \
 misc time predtype symbol \
 lisparit aridecl arilev0 arilev1 arilev1c arilev1e arilev1i intelem intlog intplus intcomp intbyte intmal intdiv intgcd int2adic intsqrt intprint intread rational sfloat ffloat dfloat lfloat flo_konv flo_rest realelem realrand realtran compelem comptran \
 posixmath \
 rexx affi \
 foreign \
 unixaux win32aux acornaux acornsig amigaaux

LSPSOURCES = init defseq backquot defmacro macros1 macros2 defs1 timezone places floatpri type defstruc format savemem trace compiler disassem defs2 loop clos conditio gstream xcharin keyboard screen amigasock runprog query reploop dribble complete describe room edit macros3 foreign1 affi1 rexx1 defs3

SOURCES := $(patsubst %,%.d,$(DSOURCES)) $(patsubst %,%.lsp,$(LSPSOURCES))

# Lots of small catalog pieces. This will help reduce the building time
# for the catalogs, since most often only a few source files change.
SOURCES_POT := $(patsubst %,tmp/%.pot,$(SOURCES))
SOURCES_EN := $(patsubst %,tmp/%.en,$(SOURCES))

tmp :
	test -d tmp || mkdir tmp

$(SOURCES_POT) : tmp/%.pot : ../../% clisp-xgettext
	(cd ../.. ; $${CLISP} gettext/po/clisp-xgettext $* gettext/po/tmp)

# When a .pot file is built, it automatically builds also the .en file.
$(SOURCES_EN) : tmp/%.en : tmp/%.pot

pot : clisp.pot $(patsubst %,%.po,$(LINGUAS))

# We build the .pot file by simple concatenation. No sorting!!
clisp.pot : $(SOURCES_POT) ../../VERSION po_header clisp-msguniq
	(./po_header t ; cat $(SOURCES_POT)) > clisp.pox
	$${CLISP} ./clisp-msguniq clisp.pox $@
	$(RM) clisp.pox

en.po : $(SOURCES_EN) ../../VERSION po_header clisp-msguniq
	(./po_header en ; cat $(SOURCES_EN)) > en.pox
	$${CLISP} ./clisp-msguniq en.pox $@
	$(RM) en.pox


PACKAGE = clisp
MSGMERGE = msgmerge -v -w 1000
update-po : force
	for lang in $(OTHER_LINGUAS); do \
	  echo "$$lang:"; \
	  if $(MSGMERGE) $$lang.po $(PACKAGE).pot -o $$lang.pox; then \
	    cp -p $$lang.pox $$lang.po; \
	  else \
	    echo "msgmerge for $$lang.po failed!"; \
	  fi; \
	  rm -f $$lang.pox; \
	done

$(patsubst %,%.po,$(OTHER_LINGUAS)) : %.po : $(PACKAGE).pot
	$(MSGMERGE) $*.po $(PACKAGE).pot -o $*.pox
	cp -p $*.pox $*.po
	rm -f $*.pox

# A single "$(MSGMERGE) $*.po.new $(PACKAGE).pot" throws away old
# translations. Two separate $(MSGMERGE) runs don't do this.
$(patsubst %,%.po.merged,$(OTHER_LINGUAS)) : %.po.merged : %.po.new %.po $(PACKAGE).pot
	$(MSGMERGE) $*.po.new $*.po -o $*.po.tmp
	$(MSGMERGE) $*.po.tmp $(PACKAGE).pot -o $*.po.merged
	$(RM) $*.po.tmp


# We must generate and distribute the .gmo files, because on the machine
# where clisp is built, GNU's [g]msgfmt might not be available.

GMOFILES = $(patsubst %,%.gmo, $(LINGUAS))

gmo : $(GMOFILES)

$(GMOFILES) : %.gmo : %.po
	$(GMSGFMT) -o $@ $<


clean :
	$(RM) *.pox

force :
