# /usr/bin/perl 
# /usr/share/perl/5.6.0/ExtUtils/xsubpp 
# -C++ -typemap /usr/share/perl/5.6.0/ExtUtils/typemap 
# -typemap typemap AbiWord.xs > AbiWord.xsc && mv AbiWord.xsc AbiWord.cpp

# XSUBPPDIR = /usr/lib/perl5/5.6.0/ExtUtils

include $(top_srcdir)/includes.mk

noinst_LIBRARIES = libabiperl.a

libabiperl_a_SOURCES = AbiWord.cpp
BUILT_SOURCES = AbiWord.cpp

perldir = $(top_builddir)/src/bindings/perl
XSUBPP = $(XSUBPPDIR)/xsubpp
XSPROTOARG = 
XSUBPPDEPS = $(XSUBPPDIR)/typemap typemap $(XSUBPP)
XSUBPPARGS = -typemap $(XSUBPPDIR)/typemap -typemap typemap

###################
PERL_ARCHLIB = @PERL_ARCHLIB@
PERL_LIB = @PERL_LIB@
POD2MAN_EXE = @POD2MAN_EXE@
SITE_LIB = @SITE_LIB@
SITE_ARCHLIB = @SITE_ARCHLIB@
PERM_RW = 644
###################

INCLUDES=\
	-DABIWORD_APP_NAME="\"$(ABIWORD_APP_NAME)\"" -DPERL_GCC_BRACE_GROUPS_FORBIDDEN=1\
	$(AF_INCLUDES) $(WP_INCLUDES) $(OTHER_INCLUDES) \
	$(TEXT_INCLUDES) $(SCRIPT_CFLAGS) -I$(top_srcdir) \
	$(AF_INCLUDES) $(AP_INCLUDES) @GMODULE_CFLAGS@ @GTK_CFLAGS@ 

AbiWord.cpp: AbiWord.xs $(srcdir)/typemap
	@perl $(XSUBPP) -typemap $(XSUBPPDIR)/typemap -typemap typemap \
		$(srcdir)/AbiWord.xs > $(perldir)/AbiWord.xsc && mv $(perldir)/AbiWord.xsc  $(perldir)/AbiWord.cpp

install-exec-local:
	@perl -we '%m=@ARGV;for (keys %m){' \
		-e 'next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M "Makefile";' \
		-e 'print "Manifying $$m{$$_}\n";' \
		-e 'system(qq[$$^X ].q["-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" $(POD2MAN_EXE) ].qq[$$_>$$m{$$_}])==0 or warn "Couldn\047t install $$m{$$_}\n";' \
		-e 'chmod(oct($(PERM_RW))), $$m{$$_} or warn "chmod $(PERM_RW) $$m{$$_}: $$!\n";}' \
		$(perldir)/AbiWord.pm $(perldir)/blib/man3/AbiWord.3pm
	@perl -Iblib/lib -I$(PERL_LIB) -MExtUtils::Install -e "install({@ARGV},'1',0,'0');" \
		read $(SITE_ARCHLIB)/auto/AbiWord/.packlist \
		write $(SITE_ARCHLIB)/auto/AbiWord/.packlist \
		blib/lib $(SITE_LIB) \
		blib/arch $(SITE_ARCHLIB) \
		blib/bin /usr/bin \
		blib/script /usr/bin \
		blib/man1 /usr/share/man/man1 \
		blib/man3 /usr/share/man/man3
	@perl -we 'exit unless -f $$ARGV[0];' \
		-e 'print "WARNING: I have found an old package in\n";' \
		-e 'print "\t$$ARGV[0].\n";' \
		-e 'print "Please make sure the two installations are not conflicting\n";' \
		$(PERL_ARCHLIB)/auto/AbiWord
	@perl -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command \
		-e mkpath $(PERL_ARCHLIB)
	@perl -e '$$\="\n\n";' -e 'print "=head2 ", scalar(localtime), ": C<", shift, ">", " L<", shift, ">";' \
		-e 'print "=over 4";' \
		-e 'while (defined($$key = shift) and defined($$val = shift)){print "=item *";print "C<$$key: $$val>";}' \
		-e 'print "=back";' \
		"Module" "AbiWord" \
		"installed into" "/usr/lib/perl5/site_perl/5.6.0" \
		LINKTYPE "dynamic" \
		VERSION "0.01" \
		EXE_FILES "" \
		>> $(PERL_ARCHLIB)/perllocal.pod
	@echo Appending installation info to $(PERL_ARCHLIB)/perllocal.pod
