From 86ebf3f5e5d38233e017c5d31a5b0a66ceefed23 Mon Sep 17 00:00:00 2001
From: Satoru SATOH <satoru.satoh@gmail.com>
Date: Tue, 19 Aug 2008 19:07:35 +0900
Subject: [PATCH] man-i18n: add m4 macros in m4/ and make aclocal look for this dir

---
 Makefile.am    |    1 +
 m4/doc_i18n.m4 |   29 +++++++++++++++
 m4/docbook.m4  |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 m4/xml2po.m4   |   15 ++++++++
 m4/xmllint.m4  |   64 ++++++++++++++++++++++++++++++++
 m4/xsltproc.m4 |  102 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 321 insertions(+), 0 deletions(-)
 create mode 100644 m4/doc_i18n.m4
 create mode 100644 m4/docbook.m4
 create mode 100644 m4/xml2po.m4
 create mode 100644 m4/xmllint.m4
 create mode 100644 m4/xsltproc.m4

diff --git a/Makefile.am b/Makefile.am
index e1b62c7..2f5c9a0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
 sbin_PROGRAMS =
 pkglib_LTLIBRARIES = 
 
+ACLOCAL_AMFLAGS	= -I m4
 
 if ENABLE_INET
 pkglib_LTLIBRARIES += lmtcpsrv.la lmtcpclt.la
diff --git a/m4/doc_i18n.m4 b/m4/doc_i18n.m4
new file mode 100644
index 0000000..ca1e59b
--- /dev/null
+++ b/m4/doc_i18n.m4
@@ -0,0 +1,29 @@
+#
+# doc-i18n.m4 - m4 macros for document i18n/l10n.
+#
+
+# 
+# AC_CHECK_MAN_I18N_TOOLS([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+#
+# Check the followings:
+#
+# 1. Are required tools and files for DocBook XML file to man page
+#    transformation available? Looks for xsltproc, DocBook DTD and DocBook XSL
+#    stylesheet for manpage target.
+#
+# 2. Is it possible to convert PO file to DocBook XML? Look for xml2po.
+#
+AC_DEFUN([AC_CHECK_MAN_I18N_TOOLS],[
+        AC_PROG_XMLLINT
+        AC_PROG_XSLTPROC
+        AC_PROG_XML2PO
+        AC_CHECK_DOCBOOK_DTD([4.5],[have_docbook_dtd="yes"])
+        AC_CHECK_DOCBOOK_XSL([current],[manpages],[have_docbook_xsl="yes"
+                AC_SUBST([DOCBOOK_MANPAGES_XSL_URI],[$DOCBOOK_XSL_URI])
+                ])
+        AS_IF([test "x$have_docbook_dtd" = "xyes" && test "x$have_docbook_xsl" = "xyes"],[
+                ifelse([$1],[],[ :],[$1])
+                ],[
+                ifelse([$2],[],[ :],[$2])])
+])
+
diff --git a/m4/docbook.m4 b/m4/docbook.m4
new file mode 100644
index 0000000..b254708
--- /dev/null
+++ b/m4/docbook.m4
@@ -0,0 +1,110 @@
+#
+# AC_CHECK_DOCBOOK_DTD and AC_CHECK_DOCBOOK_XSL
+#
+# Basic idea is borrowed from ac_check_docbook_dtd.m4 and
+# ac_check_docbook_xsl.m4 which are developed by Dustin J. Mitchell
+# (Zmanda Inc. <http://www.zmanda.com/>) and distributed under GPL v2+ with
+# special autoconf exception at Autoconf Macro Archive
+# (http://autoconf-archive.cryp.to/).
+# 
+# My version is sort of a simplified version of these macros. So if you want
+# complete one, try these macros.
+# 
+# This macro is distributed under the same license as these macros.
+#
+# NOTE: You need xmllint.m4 and xsltproc.m4 to use this macro.
+#
+# 
+# Copyright (c) 2008 Satoru SATOH <satoru.satoh@gmail.com>
+# 
+# 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 of the License, 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, see <http://www.gnu.org/licenses/>.
+# 
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+# 
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Macro Archive. When you make and
+# distribute a modified version of the Autoconf Macro, you may extend this
+# special exception to the GPL to apply to your modified version as well.
+#
+
+#
+# AC_CHECK_DOCBOOK_DTD([dtd-version],
+#       [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+#
+# Check access to DocBook DTD.
+#
+AC_DEFUN([AC_CHECK_DOCBOOK_DTD],[
+        AC_REQUIRE([AC_TRY_RUN_XMLLINT])
+
+        define([_DTDVER],[$1])
+        ifelse([_DTDVER],[],[define([_DTDVER],[4.5])]) dnl current?
+
+        cat << EOF > conftest.xml
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V[]_DTDVER//EN"
+        "http://www.oasis-open.org/docbook/xml/_DTDVER/docbookx.dtd">
+<book/>
+EOF
+        AC_MSG_CHECKING(for DocBook DTD v[]_DTDVER)
+        AC_TRY_RUN_XMLLINT([conftest.xml],[AC_MSG_RESULT(yes)
+                ifelse([$2],[],[:],[$2])
+                ],[AC_MSG_RESULT(no)
+                ifelse([$3],[],[:],[$3])])
+
+        rm -f conftest.xml
+        undefine([_DTDVER])
+])
+
+# 
+# AC_CHECK_DOCBOOK_XSL([xsl-stylesheet-version],[target-format],
+#       [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+#
+# Check access to DocBook XSL stylesheet, then define DOCBOOK_XSL_URI and set
+# the uri of that docbook xsl stylesheet if found.
+#
+# $2 (target-format) is one of target format names: fo, html, htmlhelp,
+# javahelp, manpages and xhtml.
+#
+AC_DEFUN([AC_CHECK_DOCBOOK_XSL],[
+        AC_REQUIRE([AC_TRY_RUN_XSLTPROC])
+
+        define([_XSLVER],[$1])
+        define([_FORMAT],[$2])
+        ifelse([_XSLVER],[],[define([_XSLVER],[current])])
+        ifelse([_FORMAT],[],[define([_FORMAT],[xhtml])])
+        db_xsl_uri="http://docbook.sourceforge.net/release/xsl/_XSLVER/_FORMAT/docbook.xsl"
+
+        cat << EOF > conftest.xsl
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
+<xsl:import href="$db_xsl_uri"/>
+</xsl:stylesheet>
+EOF
+        AC_MSG_CHECKING(for DocBook XSL stylesheet _XSLVER of target _FORMAT)
+        AC_TRY_RUN_XSLTPROC([none],[conftest.xsl],[AC_MSG_RESULT(yes)
+                AC_SUBST([DOCBOOK_XSL_URI],[$db_xsl_uri])
+                ifelse([$3],[],[:],[$3])
+                ],[AC_MSG_RESULT(no)
+                ifelse([$4],[],[:],[$4])])
+
+        dnl rm -f conftest.xsl
+        undefine([_XSLVER])
+        undefine([_FORMAT])
+])
diff --git a/m4/xml2po.m4 b/m4/xml2po.m4
new file mode 100644
index 0000000..3d14f7a
--- /dev/null
+++ b/m4/xml2po.m4
@@ -0,0 +1,15 @@
+#
+# AC_PROG_XML2PO 
+# 
+# Check xml2po is installed. Optionally, set options for xml2po.
+# (xml2po is contained in gnome-doc-utils.)
+#
+AC_DEFUN([AC_PROG_XML2PO],[
+        AC_PATH_PROG([XML2PO],[xml2po])
+
+        AC_SUBST([XML2PO_FLAGS],["-e"]) dnl default: --expand-all-entities
+        AC_ARG_WITH([xml2po-flags],
+                [AS_HELP_STRING([--with-xml2po-flags],
+                        [Options for xml2po. @<:@default="$XML2PO_FLAGS"@:>@])],
+                [XML2PO_FLAGS="$withval"],[])
+])
diff --git a/m4/xmllint.m4 b/m4/xmllint.m4
new file mode 100644
index 0000000..c6d48e7
--- /dev/null
+++ b/m4/xmllint.m4
@@ -0,0 +1,64 @@
+#
+# AC_PROG_XMLLINT and AC_TRY_RUN_XMLLINT
+#
+# Copyright (c) 2008 Satoru SATOH <satoru.satoh@gmail.com>
+#
+# 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 of the License, 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, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Macro Archive. When you make and
+# distribute a modified version of the Autoconf Macro, you may extend this
+# special exception to the GPL to apply to your modified version as well.
+#
+
+#
+# AC_PROG_XMLLINT
+#
+# Check xmllint is installed. Optionally, set options for xmllint.
+#
+AC_DEFUN([AC_PROG_XMLLINT],[
+        AC_PATH_PROG([XMLLINT],[xmllint])
+
+        AC_SUBST([XMLLINT_FLAGS],["--catalogs"])
+        AC_ARG_WITH([xmllint-flags],
+                [AS_HELP_STRING([--with-xmllint-flags],
+                        [Options for xmllint. @<:@default="$XMLLINT_FLAGS"@:>@])],
+                [XMLLINT_FLAGS="$withval"],[])
+])
+
+#
+# AC_TRY_RUN_XMLLINT(xml-file,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+#
+# Try to validate input xml file (xml-file) with xmllint.
+#
+# It requires that AC_PROG_XMLLINT is run previously and then $XMLLINT and
+# $XMLLINT_FLAGS are set successfully.
+#
+AC_DEFUN([AC_TRY_RUN_XMLLINT],[
+        AC_REQUIRE([AC_PROG_XMLLINT])
+
+        $XMLLINT $XMLLINT_FLAGS $1 > xmllint.conftest.out 2>&1
+        AS_IF([test "$?" = 0],[ifelse([$2],[],[:],[$2])],[ifelse([$3],[],[:],[$3])])
+
+        cat xmllint.conftest.out >& AS_MESSAGE_LOG_FD
+        rm -f xmllint.conftest.out
+])
diff --git a/m4/xsltproc.m4 b/m4/xsltproc.m4
new file mode 100644
index 0000000..998b610
--- /dev/null
+++ b/m4/xsltproc.m4
@@ -0,0 +1,102 @@
+#
+# AC_PROG_XSLTPROC and AC_TRY_RUN_XSLTPROC
+#
+# Basic idea is borrowed from ac_prog_xsltproc.m4 and ac_check_docbook_dtd.m4
+# which are developed by Dustin J. Mitchell (Zmanda Inc.
+# <http://www.zmanda.com/>) and distributed under GPL v2+ with special autoconf
+# exception at Autoconf Macro Archive (http://autoconf-archive.cryp.to/).
+#
+# My version is sort of a simplified version of these macros. So if you want
+# complete one, try these macros.
+#
+# This macro is distributed under the same license as these macros.
+#
+#
+# Copyright (c) 2008 Satoru SATOH <satoru.satoh@gmail.com>
+#
+# 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 of the License, 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, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Macro Archive. When you make and
+# distribute a modified version of the Autoconf Macro, you may extend this
+# special exception to the GPL to apply to your modified version as well.
+#
+
+#
+# AC_PROG_XSLTPROC
+#
+# Check xsltproc is installed. Optionally, set options for xsltproc.
+#
+AC_DEFUN([AC_PROG_XSLTPROC],[
+        AC_PATH_PROG([XSLTPROC],[xsltproc])
+
+        AC_SUBST([XSLTPROC_FLAGS],["--catalogs"])
+        AC_ARG_WITH([xsltproc-flags],
+                [AS_HELP_STRING([--with-xsltproc-flags],
+                        [Options for xsltproc. @<:@default="$XSLTPROC_FLAGS"@:>@])],
+                [XSLTPROC_FLAGS="$withval"],[])
+])
+
+#
+# AC_TRY_RUN_XSLTPROC([xml-file],[xsl-stylesheet],
+#       [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+#
+# Try to transform input xml file (xml-file) with xsltproc and specified
+# stylesheet (xsl-stylesheet).
+#
+# If $1 (xml-file) is "none", then just check the stylesheet (xsl-stylesheet).
+#
+# It requires that AC_PROG_XSLTPROC is run previously and then $XSLTPROC and
+# $XSLTPROC_FLAGS are set successfully.
+#
+AC_DEFUN([AC_TRY_RUN_XSLTPROC],[
+        AC_REQUIRE([AC_PROG_XSLTPROC])
+
+        input_xml=$1
+        stylesheet=$2
+        conftestout=try-run-xsltproc.conftest.out
+
+        AS_IF([test -z "$input_xml"],
+                [input_xml=conftest.xml; echo "<?xml version='1.0' encoding='ISO-8859-1'?><test/>" > $input_xml],
+                [AS_IF([test "x$input_xml" = "xnone"],[input_xml=""])])
+        AS_IF([test -z "$stylesheet"],[stylesheet=conftest.xsl;
+                cat << EOF > $stylesheet
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
+<xsl:output method="text"/>
+<xsl:template match="*|/"><xsl:apply-templates/></xsl:template>
+<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>
+</xsl:stylesheet>
+EOF
+                ])
+
+        $XSLTPROC $XSLTPROC_FLAGS $stylesheet $input_xml > $conftestout 2>&1
+        AS_IF([test "$?" = 0],
+                [AS_IF([grep 'warning: failed to load external entity' $conftestout > /dev/null 2>&1],
+                        [ifelse([$4],[],[:],[$4])
+                        ],[ifelse([$3],[],[:],[$3])
+                        ])],[
+                ifelse([$4],[],[:],[$4])])
+
+        cat $conftestout >& AS_MESSAGE_LOG_FD
+        rm -f $conftestout conftest.xsl conftest.xml
+])
-- 
1.5.6.4

