# Makefile for help2man
# $Id: Makefile.in,v 1.28 2005/10/29 06:50:33 bod Exp $

SHELL = @SHELL@
VPATH = @srcdir@

srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
libdir = @libdir@
mandir = @mandir@
datadir = @datadir@
infodir = @infodir@
localedir = $(datadir)/locale

DESTDIR =
LINGUAS = $(basename $(notdir $(wildcard $(srcdir)/po/*.po)))

CC = @CC@
PERL = @PERL@
LIBS = @LIBS@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_INFO = @INSTALL_INFO@
MAKEINFO = @MAKEINFO@
MSGFMT = @MSGFMT@
MKINSTALLDIRS = $(srcdir)/mkinstalldirs

target = help2man
preload = hacklocaledir

all: $(target) man info @extra_make_all@

install: all install_base @extra_make_install@
install_base:
	$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
	$(MKINSTALLDIRS) $(DESTDIR)$(libdir)
	$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
	$(MKINSTALLDIRS) $(DESTDIR)$(infodir)

	$(INSTALL_PROGRAM) $(target) $(DESTDIR)$(bindir)
	$(INSTALL_DATA) $(srcdir)/$(target).1 $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/$(target).info \
	    $(DESTDIR)$(infodir)/$(target).info

	if test -f $(DESTDIR)$(infodir)/dir; \
	then \
	    $(INSTALL_INFO) --info-dir=$(DESTDIR)$(infodir) \
		$(srcdir)/$(target).info; \
	fi

install_preload: preload
	$(INSTALL_PROGRAM) $(preload).so $(DESTDIR)$(libdir)

install_l10n: man_l10n
	for lang in $(LINGUAS); \
	do \
	    $(MKINSTALLDIRS) $(DESTDIR)$(mandir)/$$lang/man1; \
	    $(MKINSTALLDIRS) $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES; \
	    $(INSTALL_DATA) $(srcdir)/$(target).$$lang.1 \
		$(DESTDIR)$(mandir)/$$lang/man1/$(target).1; \
	    $(INSTALL_DATA) $(srcdir)/po/$$lang.gmo \
		$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(target).mo; \
	done

uninstall:
	rm -f $(DESTDIR)$(bindir)/$(target) \
	    $(DESTDIR)$(libdir)/$(preload).so \
	    $(DESTDIR)$(mandir)/man1/$(target).1 \
	    $(DESTDIR)$(mandir)/*/man1/$(target).1 \
	    $(DESTDIR)$(localedir)/*/LC_MESSAGES/$(target).mo \
	    $(DESTDIR)$(infodir)/$(target).info

	if test -f $(DESTDIR)$(infodir)/dir; \
	then \
	    $(INSTALL_INFO) --delete --info-dir=$(DESTDIR)$(infodir) \
		$(target).info; \
	fi

clean:
	-rm -f $(target) $(preload).so

mostlyclean: clean
	cd $(srcdir) && rm -f $(target).dvi $(target).aux $(target).cp \
	    $(target).cps $(target).fn $(target).ky $(target).log \
	    $(target).pg $(target).toc $(target).tp $(target).vr po/*.po~

distclean: mostlyclean
	-rm -rf config.cache config.log config.status Makefile autom4te.cache

realclean: distclean
	cd $(srcdir) && rm -f $(target).info $(target).1 $(target).*.1 po/*.gmo

maintainer-clean: realclean
	rm -f configure

$(target): $(srcdir)/$(target).PL
	$(PERL) $?

preload: $(preload).so
$(preload).so: $(srcdir)/$(preload).c
	$(CC) $(CFLAGS) -o $@ -fPIC -shared $? $(LIBS)

man: $(target).1
$(target).1: $(srcdir)/$(target).PL $(srcdir)/$(target).h2m
	$(MAKE) $(target)
	./$(target) --include=$(srcdir)/$(target).h2m \
	    --output=$@ ./$(target)

man_l10n: $(addprefix $(target).,$(addsuffix .1,$(LINGUAS)))
$(target).%.1: $(srcdir)/$(target).PL $(srcdir)/$(target).%.h2m $(srcdir)/po/%.po
	lang=$(patsubst $(target).%.1,%,$@); \
	$(MAKE) $(target) $(preload).so po/$$lang.gmo && \
	LD_PRELOAD="./$(preload).so preloadable_libintl.so" \
	TEXTDOMAIN=help2man \
	    ./$(target) --include=$(srcdir)/$(target).$$lang.h2m \
		--output=$@ --locale=$$lang ./$(target)

po/%.gmo: $(srcdir)/po/%.po
	test -d po || mkdir po
	$(MSGFMT) -o $@ $?

info: $(target).info
$(target).info: $(srcdir)/$(target).texi
	$(MAKEINFO) $? -o $@

dvi: $(target).dvi
$(target).dvi: $(srcdir)/$(target).texi
	$(TEXI2DVI) $?

Makefile: $(srcdir)/Makefile.in
	./config.status

update-po: $(srcdir)/po/$(target).pot
	for lang in $(LINGUAS); \
	do \
	    echo -n "Updating $$lang "; \
	    msgmerge -U $(srcdir)/po/$$lang.po $(srcdir)/po/$(target).pot; \
	done

$(srcdir)/po/$(target).pot: $(target)
	xgettext -L Perl -k_ -kN_ -o $@ $?

.PHONY: all clean distclean preload man man_l10n info dvi install \
    install_base install_preload install_l10n mostlyclean realclean \
    uninstall

.SUFFIXES:
