# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

srcdir=		@srcdir@
VPATH=		@srcdir@
prefix=		@prefix@
exec_prefix=	@exec_prefix@
datarootdir=	@datarootdir@
localedir=	@localedir@

CC=		@CC@
CFLAGS=		@CFLAGS@
CPPFLAGS=	@CPPFLAGS@ -I. -DSHAREDIR=\"@datarootdir@\" -DLOCALEDIR=\"$(localedir)\"
LDFLAGS=	@LDFLAGS@
LIBM=		-lm
LIBS=		@LIBS@

CATALOGS=	de.mo en_GB.mo nl.mo

all:		diction style all-po-@USE_NLS@
all-po-no:
all-po-yes:	$(CATALOGS)

diction:	diction.o sentence.o misc.o getopt.o getopt1.o
		$(CC) -o $@ $(LDFLAGS) diction.o sentence.o misc.o \
		getopt.o getopt1.o $(LIBS)

style:		style.o sentence.o misc.o getopt.o getopt1.o
		$(CC) -o $@ $(LDFLAGS) style.o sentence.o misc.o \
		getopt.o getopt1.o $(LIBM) $(LIBS)

check:		diction
		for i in $(srcdir)/test/test*; do $$i || break; done

install:	all
		[ -d $(DESTDIR)@bindir@ ] || @INSTALL@ -m 755 -d $(DESTDIR)@bindir@
		@INSTALL@ diction $(DESTDIR)@bindir@/diction
		@INSTALL@ style $(DESTDIR)@bindir@/style
		@INSTALL@ -m 755 -d $(DESTDIR)@datarootdir@/diction
		@INSTALL@ -m 644 $(srcdir)/de $(DESTDIR)@datarootdir@/diction/de
		@INSTALL@ -m 644 $(srcdir)/en $(DESTDIR)@datarootdir@/diction/en
		(cd $(DESTDIR)@datarootdir@/diction; rm -f C; ln en C)
		@INSTALL@ -m 644 $(srcdir)/en_GB $(DESTDIR)@datarootdir@/diction/en_GB
		@INSTALL@ -m 644 $(srcdir)/nl $(DESTDIR)@datarootdir@/diction/nl
		[ -d $(DESTDIR)@mandir@/man1 ] || @INSTALL@ -m 755 -d $(DESTDIR)@mandir@/man1
		@INSTALL@ -m 644 diction.1 $(DESTDIR)@mandir@/man1/diction.1
		@INSTALL@ -m 644 style.1 $(DESTDIR)@mandir@/man1/style.1
		make install-po-@USE_NLS@

install-po-no:
install-po-yes:	$(CATALOGS)
		for cat in $(CATALOGS); do \
		  dir=$(localedir)/`basename $$cat .mo`/LC_MESSAGES; \
		  [ -d $(DESTDIR)$$dir ] || @INSTALL@ -m 755 -d $(DESTDIR)$$dir; \
		  @INSTALL@ -m 644 $$cat $(DESTDIR)$$dir/diction.mo; \
		done

.c.o:
		$(CC) -c $(CPPFLAGS) $(CFLAGS) $<

.SUFFIXES:	.po .mo

.po.mo:
		msgfmt -o $@ $<

$(CATALOGS:.mo=.po):	diction.pot
		for cat in $@; do \
		  [ -f $$cat ] || cp $(srcdir)/$$cat .; \
		  if msgmerge $$cat diction.pot -o $$cat.tmp; then \
		    mv -f $$cat.tmp $$cat; \
		    cmp -s $$cat $(srcdir)/$$cat || \
		      cp $$cat $(srcdir)/$$cat; \
		  else \
		    echo "msgmerge for $$cat failed!"; \
		    rm -f $$cat.tmp; \
		    exit 1; \
		  fi; \
		done

diction.pot:	$(srcdir)/*.c
		(objdir=`pwd`; cd $(srcdir); \
		  xgettext --add-comments --keyword=_ \
		           --output=$$objdir/messages.po *.c )
		test -f messages.po && mv messages.po $@
# The sources have changed -- update diction.pot in srcdir as well.
		cmp $@ $(srcdir)/$@ || cp $@ $(srcdir)/$@

diction.html:	diction.texi
		makeinfo --html diction.texi

diction.info:	diction.texi
		makeinfo diction.texi

#{{{script}}}#{{{ clean
clean:
		rm -f *.out core *.o *.mo diction.html diction.info
#}}}
#{{{ distclean
distclean:	clean
		rm -f diction style config.cache config.h config.log config.status configure.lineno Makefile diction.1 diction.texi style.1 test/rundiction
		rm -rf autom4te.cache
#}}}
#{{{ tar
tar:		distclean
		(b=`pwd`; b=`basename $$b`; cd ..; tar zcvf $$b.tar.gz $$b/COPYING $$b/INSTALL $$b/Makefile.in $$b/README $$b/NEWS $$b/configure $$b/install-sh $$b/de $$b/en $$b/en_GB $$b/nl $$b/test $$b/[a-z]*.*)
#}}}
#{{{ dependencies
diction.o:	diction.c config.h getopt.h misc.h sentence.h
getopt.o:	getopt.c getopt.h getopt_int.h
getopt1.o:	getopt1.c getopt.h getopt_int.h
misc.o:	misc.c config.h misc.h
sentence.o:	sentence.c config.h misc.h sentence.h
style.o:	style.c config.h getopt.h misc.h sentence.h
#}}}
