summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2006-04-13 16:35:57 +0000
committerjlam <jlam@pkgsrc.org>2006-04-13 16:35:57 +0000
commit0f4967eb59854511c3cbd3d80e3a886dd7fb7fc7 (patch)
tree05edb3a0d35814dcd46fc6d587c479a7a041b561 /mk
parent56e51ad6bcbe62feec59ad6d8300df92c2e40784 (diff)
downloadpkgsrc-0f4967eb59854511c3cbd3d80e3a886dd7fb7fc7.tar.gz
Overhaul the way packages can ask for "msgfmt". If a package needs
msgfmt, then it should set the following in the package Makefile: USE_TOOLS+= msgfmt To deal with message files that use the "msgid_plural" statement, which isn't supported in NetBSD<=3.x and also in gettext<=0.10.35, we determine if the built-in "msgfmt" is sufficiently new enough to understand "msgid_plural". If it isn't, then we use the msgfmt.sh script to transform the msgid_plural statements to an equivalent construct that's understood by older msgfmt tools. The msgfmt.sh script is a straightforward translation of the original perl script msgfmt.pl script by Julio M. Merino Vidal into shell and awk, which are more lightweight dependencies than perl. We remove the USE_MSGFMT_PLURALS bits in gettext-lib/builtin.mk as they are made obsolete by the new code in mk/tools/msgfmt.mk. BUILD_USE_MSGFMT is still supported but will be removed in a separate commit.
Diffstat (limited to 'mk')
-rw-r--r--mk/bsd.pkg.use.mk7
-rw-r--r--mk/tools/bsd.tools.mk3
-rw-r--r--mk/tools/msgfmt.mk86
-rwxr-xr-xmk/tools/msgfmt.sh189
-rw-r--r--mk/tools/replace.mk18
-rw-r--r--mk/tools/tools.Linux.mk5
-rw-r--r--mk/tools/tools.NetBSD.mk5
7 files changed, 294 insertions, 19 deletions
diff --git a/mk/bsd.pkg.use.mk b/mk/bsd.pkg.use.mk
index 3dcc7d234ee..e7d531eec40 100644
--- a/mk/bsd.pkg.use.mk
+++ b/mk/bsd.pkg.use.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkg.use.mk,v 1.30 2006/03/11 04:01:27 reed Exp $
+# $NetBSD: bsd.pkg.use.mk,v 1.31 2006/04/13 16:35:58 jlam Exp $
#
# Turn USE_* macros into proper depedency logic. Included near the top of
# bsd.pkg.mk, after bsd.prefs.mk.
@@ -61,9 +61,8 @@ PKG_SKIP_REASON= "INSTALLATION_PREFIX can't be used in a pkgviews package"
### BUILD_USES_MSGFMT
-.if defined(BUILD_USES_MSGFMT) && \
- (!exists(/usr/bin/msgfmt) || ${_USE_GNU_GETTEXT} == "yes")
-BUILD_DEPENDS+= gettext-tools>=0.14.5:../../devel/gettext-tools
+.if defined(BUILD_USES_MSGFMT)
+USE_TOOLS+= msgfmt
.endif
### PKG_USE_KERBEROS
diff --git a/mk/tools/bsd.tools.mk b/mk/tools/bsd.tools.mk
index f12695bcb9a..ef4c5b2dbda 100644
--- a/mk/tools/bsd.tools.mk
+++ b/mk/tools/bsd.tools.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.tools.mk,v 1.32 2005/08/10 20:56:20 jlam Exp $
+# $NetBSD: bsd.tools.mk,v 1.33 2006/04/13 16:35:58 jlam Exp $
#
# Copyright (c) 2005 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -111,6 +111,7 @@ USE_TOOLS?= # empty
.include "../../mk/tools/automake.mk"
.include "../../mk/tools/autoconf.mk"
.include "../../mk/tools/texinfo.mk"
+.include "../../mk/tools/msgfmt.mk"
.include "../../mk/tools/ldconfig.mk"
.include "../../mk/tools/rpcgen.mk"
.include "../../mk/tools/strip.mk"
diff --git a/mk/tools/msgfmt.mk b/mk/tools/msgfmt.mk
new file mode 100644
index 00000000000..36a973aec6f
--- /dev/null
+++ b/mk/tools/msgfmt.mk
@@ -0,0 +1,86 @@
+# $NetBSD: msgfmt.mk,v 1.1 2006/04/13 16:35:58 jlam Exp $
+#
+# Copyright (c) 2006 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+.if !defined(TOOLS_IGNORE.msgfmt) && !empty(USE_TOOLS:C/:.*//:Mmsgfmt)
+. if !empty(PKGPATH:Mdevel/gettext-tools)
+MAKEFLAGS+= TOOLS_IGNORE.msgfmt=
+. else
+. if defined(TOOLS_PLATFORM.msgfmt) && !empty(TOOLS_PLATFORM.msgfmt)
+. if !defined(_TOOLS_USE_PKGSRC.msgfmt)
+#
+# Discover if the version on the builtin msgfmt is new enough to handle
+# msgid_plural (at least 0.10.35).
+#
+_TOOLS_VERSION.msgfmt!= ${TOOLS_PLATFORM.msgfmt} --version | \
+ ${AWK} '{ print $$4; exit }'
+_TOOLS_USE_PKGSRC.msgfmt!= \
+ if ${PKG_ADMIN} pmatch "gettext>=0.10.35" \
+ gettext-${_TOOLS_VERSION.msgfmt:Q}; then \
+ ${ECHO} no; \
+ else \
+ ${ECHO} yes; \
+ fi
+. endif
+MAKEVARS+= _TOOLS_USE_PKGSRC.msgfmt
+. else
+_TOOLS_USE_PKGSRC.msgfmt= yes
+. endif
+
+# If we're not using the builtin gettext implementation, then we should
+# definitely be using the pkgsrc version of msgfmt (gettext-tools).
+#
+CHECK_BUILTIN.gettext:= yes
+. include "../../devel/gettext-lib/builtin.mk"
+CHECK_BUILTIN.gettext:= no
+. if !empty(USE_BUILTIN.gettext:M[nN][oO])
+_TOOLS_USE_PKGSRC.msgfmt= yes
+. endif
+
+. if !empty(_TOOLS_USE_PKGSRC.msgfmt:M[yY][eE][sS])
+TOOLS_CREATE+= msgfmt
+TOOLS_DEPENDS.msgfmt?= {gettext>=0.10.36,gettext-tools>=0.14.5}:../../devel/gettext-tools
+TOOLS_FIND_PREFIX+= TOOLS_PREFIX.msgfmt=${TOOLS_DEPENDS.msgfmt:C/:.*//}
+TOOLS_PATH.msgfmt= ${TOOLS_PREFIX.msgfmt}/bin/msgfmt
+. else
+USE_TOOLS+= awk sh
+TOOLS_PATH.msgfmt= ${PKGSRCDIR}/mk/tools/msgfmt.sh
+TOOLS_SCRIPT.msgfmt= AWK=${TOOLS_AWK:Q} \
+ MSGFMT=${TOOLS_PLATFORM.msgfmt:Q} \
+ ${TOOLS_SH} ${TOOLS_PATH.msgfmt} "$$@"
+. endif
+. endif
+.endif
diff --git a/mk/tools/msgfmt.sh b/mk/tools/msgfmt.sh
new file mode 100755
index 00000000000..cb09303168c
--- /dev/null
+++ b/mk/tools/msgfmt.sh
@@ -0,0 +1,189 @@
+#!/bin/sh
+#
+# $NetBSD: msgfmt.sh,v 1.1 2006/04/13 16:35:58 jlam Exp $
+#
+# Copyright (c) 2004, 2005, 2006 Julio M. Merino Vidal <jmmv@NetBSD.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name of author nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+: ${AWK=awk}
+: ${MSGFMT=/usr/bin/msgfmt}
+
+case "${MSGFMT}" in
+/*) ;;
+*) echo 1>&2 "$0: \`\`${MSGFMT}'' must be an absolute pathname."
+ exit 1
+ ;;
+esac
+if test ! -x "${MSGFMT}"; then
+ echo 1>&2 "$0: \`\`${MSGFMT}'' does not exist."
+ exit 1
+fi
+
+# Parse the command line options.
+version=
+cmd="${MSGFMT}"
+while test $# -gt 0; do
+ case "$1" in
+ --version)
+ version="$1"
+ cmd="$cmd $1"; shift
+ ;;
+ -[aDo]|--alignment|--directory|--output-file)
+ cmd="$cmd $1 $2"; shift; shift;
+ ;;
+ [!-]*)
+ pofile="$1"
+ cmd="$cmd -"; shift
+ ;;
+ *)
+ cmd="$cmd $1"; shift
+ ;;
+ esac
+done
+
+# If we are asked for just the version, then avoid spawning awk.
+test -z "$version" || exec $cmd
+
+cat $pofile | ${AWK} '
+{
+ s = 0
+ p = 0
+
+ sub("^#~", "")
+
+ # Buffer any "msgid" statements into the singular array.
+ if ($0 ~ /^msgid[ ]+/) {
+ sub("^msgid[ ]+", "");
+ singular[s++] = $0
+ while (getline) {
+ if ($0 ~ /^$/) continue
+ if ($0 ~ /^[ ]*"/)
+ singular[s++] = $0
+ else
+ break
+ }
+ }
+
+ # Buffer any "msgid_plural" statements into the plural array.
+ if ($0 ~ /^msgid_plural[ ]+/) {
+ sub("^msgid_plural[ ]+", "");
+ plural[p++] = $0
+ while (getline) {
+ if ($0 ~ /^[ ]*"/)
+ plural[p++] = $0
+ else
+ break
+ }
+ }
+
+ # If we see "msgstr", then we are outputting the translation
+ # of a singular form of a message, so dump the contents of the
+ # singular array and output the "msgstr" translation.
+ #
+ if ($0 ~ /^msgstr[ ]+/) {
+ sub("^msgstr[ ]+", "");
+ if (s > 0) {
+ print "msgid " singular[0]
+ for (i = 1; i < s; i++) print singular[i]
+ }
+ print "msgstr " $0
+ while (getline) {
+ if ($0 ~ /^[ ]*"/)
+ print $0
+ else
+ break
+ }
+ }
+
+ # If we see "msgstr[0]", then we are outputting the translation
+ # of a singular form of a message, so dump the contents of the
+ # singular array and output the "msgstr[0]" translation.
+ #
+ if ($0 ~ /^msgstr\[0\][ ]+/) {
+ sub("^msgstr...[ ]+", "");
+ if (s > 0) {
+ print "msgid " singular[0]
+ for (i = 1; i < s; i++) print singular[i]
+ }
+ print "msgstr " $0
+ while (getline) {
+ if ($0 ~ /^[ ]*"/)
+ print $0
+ else
+ break
+ }
+ }
+
+ # If we see "msgstr[1]", then we are outputting the translation
+ # of a plural form of a message, so dump the contents of the
+ # plural array and output the "msgstr[1]" translation.
+ #
+ if ($0 ~ /^msgstr\[1\][ ]+/) {
+ #
+ # Check if the singular and plural arrays are equal.
+ # If they are, then we do not need to output an
+ # additional plural translation at all since the
+ # "singular" form is already correct.
+ #
+ equal = 0
+ if (s == p) {
+ equal = 1;
+ for (i = 0; i < s; i++) {
+ if (singular[i] != plural[i]) {
+ equal = 0; break
+ }
+ }
+ }
+ if (equal == 1) {
+ while (getline) {
+ if ($0 !~ /^[ ]*"/) break
+ }
+ s = 0; p = 0
+ next
+ }
+
+ sub("^msgstr...[ ]+", "");
+ if (p > 0) {
+ print "msgid " plural[0]
+ for (i = 1; i < p; i++) print plural[i]
+ }
+ print "msgstr " $0
+ while (getline) {
+ if ($0 ~ /^[ ]*"/)
+ print $0
+ else
+ break
+ }
+ }
+
+ # Skip comments and blank lines.
+ if ($0 ~ /^#/ || $0 ~ /^[ ]*$/) {
+ print $0
+ next
+ }
+}
+' | $cmd
diff --git a/mk/tools/replace.mk b/mk/tools/replace.mk
index 5a8d897923a..b0191e26b84 100644
--- a/mk/tools/replace.mk
+++ b/mk/tools/replace.mk
@@ -1,4 +1,4 @@
-# $NetBSD: replace.mk,v 1.164 2006/04/06 06:23:06 reed Exp $
+# $NetBSD: replace.mk,v 1.165 2006/04/13 16:35:58 jlam Exp $
#
# Copyright (c) 2005 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -79,13 +79,6 @@
# USE_TOOLS+= perl:run
#
-# XXX Keep this hack here until the day that msgfmt and msgfmt-plurals
-# XXX is handled directly by the tools framework.
-# XXX
-.if defined(USE_MSGFMT_PLURALS) && !empty(USE_MSGFMT_PLURALS:M[yY][eE][sS])
-USE_TOOLS+= perl
-.endif
-
# bison implies "bison-yacc"
.if !empty(USE_TOOLS:Mbison) || !empty(USE_TOOLS:Mbison\:*)
USE_TOOLS+= bison-yacc
@@ -885,17 +878,18 @@ TOOLS_PATH.${_t_}= ${TOOLS_PREFIX.${_t_}}/bin/${GNU_PROGRAM_PREFIX}${_t_}
######################################################################
# These tools are all supplied by the devel/gettext-tools package if there
-# is no native tool available.
+# is no native tool available. Don't add "msgfmt" to this list since it
+# needs special handling -- see mk/tools/msgfmt.mk.
#
-_TOOLS.gettext-tools= gettext msgfmt xgettext
-_TOOLS_DEP.gettext-tools= gettext<0.14.5,gettext-tools>=0.14.5
+_TOOLS.gettext-tools= gettext xgettext
+_TOOLS_DEP.gettext-tools= {gettext>0.10.35,gettext-tools>=0.14.5}
.for _t_ in ${_TOOLS.gettext-tools}
. if !defined(TOOLS_IGNORE.${_t_}) && !empty(_USE_TOOLS:M${_t_})
. if !empty(PKGPATH:Mdevel/gettext-tools)
MAKEFLAGS+= TOOLS_IGNORE.${_t_}=
. elif !empty(_TOOLS_USE_PKGSRC.${_t_}:M[yY][eE][sS])
-TOOLS_DEPENDS.${_t_}?= {${_TOOLS_DEP.gettext-tools}}:../../devel/gettext-tools
+TOOLS_DEPENDS.${_t_}?= ${_TOOLS_DEP.gettext-tools}:../../devel/gettext-tools
TOOLS_CREATE+= ${_t_}
TOOLS_FIND_PREFIX+= TOOLS_PREFIX.${_t_}=${TOOLS_DEPENDS.${_t_}:C/:.*//}
TOOLS_PATH.${_t_}= ${TOOLS_PREFIX.${_t_}}/bin/${_t_}
diff --git a/mk/tools/tools.Linux.mk b/mk/tools/tools.Linux.mk
index cc1c8ce8d9c..791c336fa96 100644
--- a/mk/tools/tools.Linux.mk
+++ b/mk/tools/tools.Linux.mk
@@ -1,4 +1,4 @@
-# $NetBSD: tools.Linux.mk,v 1.30 2006/03/06 05:25:45 jlam Exp $
+# $NetBSD: tools.Linux.mk,v 1.31 2006/04/13 16:35:59 jlam Exp $
#
# System-supplied tools for the Linux operating system.
@@ -123,6 +123,9 @@ TOOLS_PLATFORM.mkdir?= /bin/mkdir -p
.if exists(/usr/bin/mktemp)
TOOLS_PLATFORM.mktemp?= /usr/bin/mktemp
.endif
+.if exists(/usr/bin/msgfmt)
+TOOLS_PLATFORM.msgfmt?= /usr/bin/msgfmt
+.endif
TOOLS_PLATFORM.mv?= /bin/mv
.if exists(/bin/nice)
TOOLS_PLATFORM.nice?= /bin/nice
diff --git a/mk/tools/tools.NetBSD.mk b/mk/tools/tools.NetBSD.mk
index aab10c426af..ecfaf01d89e 100644
--- a/mk/tools/tools.NetBSD.mk
+++ b/mk/tools/tools.NetBSD.mk
@@ -1,4 +1,4 @@
-# $NetBSD: tools.NetBSD.mk,v 1.26 2006/03/06 05:25:45 jlam Exp $
+# $NetBSD: tools.NetBSD.mk,v 1.27 2006/04/13 16:35:59 jlam Exp $
#
# System-supplied tools for the NetBSD operating system.
@@ -59,6 +59,9 @@ TOOLS_PLATFORM.makeinfo?= /usr/bin/makeinfo
.endif
TOOLS_PLATFORM.mkdir?= /bin/mkdir -p
TOOLS_PLATFORM.mktemp?= /usr/bin/mktemp
+.if exists(/usr/bin/msgfmt)
+TOOLS_PLATFORM.msgfmt?= /usr/bin/msgfmt
+.endif
TOOLS_PLATFORM.mtree?= /usr/sbin/mtree
TOOLS_PLATFORM.mv?= /bin/mv
TOOLS_PLATFORM.nice?= /usr/bin/nice