2005-09-01  Stepan Kasal  <kasal@ucw.cz>

	This change fixes interaction with AM_GNU_GETTEXT and helps when
	intltool is used with multiple po directories.

	* intltool.m4 (IT_PO_SUBDIR): New macro, installs a hook which
	  fixes $1/Makefile and touches $1/stamp-it.
	(IT_PROG_INTLTOOL): Call IT_PO_SUBDIR([po]), instead of the
	  AC_CONFIG_COMMANDS_PRE hook.
	* Makefile.in.in (POTFILES, Makefile): These rules now use the
	  stamp file "stamp-it".
	(distclean): Remove the file "stamp-it".  Don't delete $(GMOFILES),
	  because AM_GNU_GETTEXT adds srcdir prefix to the files; use mere
	  "*.gmo" instead.

Index: Makefile.in.in
===================================================================
RCS file: /cvs/gnome/intltool/Makefile.in.in,v
retrieving revision 1.13
diff -u -r1.13 Makefile.in.in
--- Makefile.in.in	23 Aug 2005 15:00:11 -0000	1.13
+++ Makefile.in.in	1 Sep 2005 10:41:03 -0000
@@ -190,8 +190,8 @@
 clean: mostlyclean
 
 distclean: clean
-	rm -f Makefile Makefile.in POTFILES
-	rm -f *.mo *.msg *.cat *.cat.m $(GMOFILES)
+	rm -f Makefile Makefile.in POTFILES stamp-it
+	rm -f *.mo *.msg *.cat *.cat.m *.gmo
 
 maintainer-clean: distclean
 	@echo "This command is intended for maintainers to use;"
@@ -237,23 +237,15 @@
 	  fi; \
 	done
 
-# POTFILES is created from POTFILES.in by stripping comments, empty lines
-# and Intltool tags (enclosed in square brackets), and appending a full
-# relative path to them
-POTFILES: POTFILES.in
-	( posrcprefix='$(top_srcdir)/'; \
-	  rm -f $@-t $@ \
-	    && (sed -e '/^#/d' 					\
-		    -e 's/^[[].*] *//' 				\
-		    -e '/^[ 	]*$$/d' 			\
-		    -e "s@^@	$$posrcprefix@" $(srcdir)/$@.in	\
-		| sed -e '$$!s/$$/ \\/') > $@-t \
-	    && chmod a-w $@-t \
-	    && mv $@-t $@ )
+Makefile POTFILES: stamp-it
+	@if test ! -f $@; then \
+	  rm -f stamp-it; \
+	  $(MAKE) stamp-it; \
+	fi
 
-Makefile: Makefile.in.in ../config.status POTFILES
+stamp-it: Makefile.in.in ../config.status POTFILES.in
 	cd .. \
-	  && CONFIG_FILES=$(subdir)/$@.in CONFIG_HEADERS= \
+	  && CONFIG_FILES=$(subdir)/Makefile.in CONFIG_HEADERS= CONFIG_LINKS= \
 	       $(SHELL) ./config.status
 
 # Tell versions [3.59,3.63) of GNU make not to export all variables.
Index: intltool.m4
===================================================================
RCS file: /cvs/gnome/intltool/intltool.m4,v
retrieving revision 1.86
diff -u -r1.86 intltool.m4
--- intltool.m4	23 Aug 2005 15:01:28 -0000	1.86
+++ intltool.m4	1 Sep 2005 10:41:03 -0000
@@ -101,13 +101,7 @@
 AC_PATH_PROG(INTLTOOL_MSGMERGE, msgmerge, msgmerge)
 AC_PATH_PROG(INTLTOOL_XGETTEXT, xgettext, xgettext)
 
-# Remove file type tags (using []) from po/POTFILES.
-AC_CONFIG_COMMANDS_PRE([
-   [mv -f po/POTFILES po/POTFILES.tmp
-    sed -e '/[[]encoding.*]/d' -e 's/[[].*] *//' < po/POTFILES.tmp > po/POTFILES
-    rm -f po/POTFILES.tmp
-   ]dnl
-])
+IT_PO_SUBDIR([po])
 
 # Manually sed perl in so people don't have to put the intltool scripts in AC_OUTPUT.
 
@@ -156,6 +150,43 @@
 XGETTEXT='${INTLTOOL_XGETTEXT}')
 
 ])
+
+
+# IT_PO_SUBDIR(DIRNAME)
+# ---------------------
+# All po subdirs have to be declared with this macro; the subdir "po" is
+# declared by IT_PROG_INTLTOOL.
+#
+AC_DEFUN([IT_PO_SUBDIR],
+[AC_PREREQ([2.53])dnl We use ac_top_srcdir inside AC_CONFIG_COMMANDS.
+dnl
+dnl The following CONFIG_COMMANDS should be exetuted at the very end
+dnl of config.status.
+AC_CONFIG_COMMANDS_PRE([
+  AC_CONFIG_COMMANDS([$1/stamp-it], [
+    rm -f "$1/stamp-it" "$1/stamp-it.tmp" "$1/POTFILES" "$1/Makefile.tmp"
+    >"$1/stamp-it.tmp"
+    [sed '/^#/d
+	 s/^[[].*] *//
+	 /^[ 	]*$/d
+	'"s|^|	$ac_top_srcdir/|" \
+      "$srcdir/$1/POTFILES.in" | sed '$!s/$/ \\/' >"$1/POTFILES"
+    ]
+    if test ! -f "$1/Makefile"; then
+      AC_MSG_ERROR([$1/Makefile is not ready.])
+    fi
+    mv "$1/Makefile" "$1/Makefile.tmp"
+    [sed '/^POTFILES =/,/[^\\]$/ {
+		/^POTFILES =/!d
+		r $1/POTFILES
+	  }
+	 ' "$1/Makefile.tmp" >"$1/Makefile"]
+    rm -f "$1/Makefile.tmp"
+    mv "$1/stamp-it.tmp" "$1/stamp-it"
+  ])
+])dnl
+])
+
 
 # deprecated macros
 AU_ALIAS([AC_PROG_INTLTOOL], [IT_PROG_INTLTOOL])
