2 # -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*-
5 # The Intltool Message Updater
7 # Copyright (C) 2000-2003 Free Software Foundation.
9 # Intltool is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # version 2 published by the Free Software Foundation.
13 # Intltool is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 # As a special exception to the GNU General Public License, if you
23 # distribute this file as part of a program that contains a
24 # configuration script generated by Autoconf, you may include it under
25 # the same distribution terms that you use for the rest of that program.
27 # Authors: Kenneth Christiansen <kenneth@gnu.org>
29 # Darin Adler <darin@bentspoon.com>
31 ## Release information
32 my $PROGRAM = "intltool-update";
33 my $VERSION = "0.35.4";
34 my $PACKAGE = "intltool";
43 ## Scalars used by the option stuff
52 my $GETTEXT_PACKAGE = "";
57 my %po_files_by_lang = ();
59 # Regular expressions to categorize file types.
60 # FIXME: Please check if the following is correct
63 "xml(?:\\.in)*|". # http://www.w3.org/XML/ (Note: .in is not required)
64 "ui|". # Bonobo specific - User Interface desc. files
66 "glade2?(?:\\.in)*|". # Glade specific - User Interface desc. files (Note: .in is not required)
67 "scm(?:\\.in)*|". # ? (Note: .in is not required)
68 "oaf(?:\\.in)+|". # DEPRECATED: Replaces by Bonobo .server files
70 "server(?:\\.in)+|". # Bonobo specific
71 "sheet(?:\\.in)+|". # ?
72 "schemas(?:\\.in)+|". # GConf specific
73 "pong(?:\\.in)+|". # DEPRECATED: PONG is not used [by GNOME] any longer.
74 "kbd(?:\\.in)+"; # GOK specific.
77 "icon(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec
78 "desktop(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
79 "caves(?:\\.in)+|". # GNOME Games specific
80 "directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
81 "soundlist(?:\\.in)+|". # GNOME specific
82 "keys(?:\\.in)+|". # GNOME Mime database specific
83 "theme(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec
84 "service(?:\\.in)+"; # DBus specific
86 my $buildin_gettext_support =
87 "c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py";
89 ## Always flush buffer when printing
92 ## Sometimes the source tree will be rooted somewhere else.
93 my $SRCDIR = $ENV{"srcdir"} || ".";
96 $POTFILES_in = "<$SRCDIR/POTFILES.in";
98 my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
103 "help" => \$HELP_ARG,
104 "version" => \$VERSION_ARG,
105 "dist|d" => \$DIST_ARG,
106 "pot|p" => \$POT_ARG,
107 "headers|s" => \$HEADERS_ARG,
108 "maintain|m" => \$MAINTAIN_ARG,
109 "report|r" => \$REPORT_ARG,
110 "verbose|x" => \$VERBOSE,
111 "gettext-package|g=s" => \$GETTEXT_PACKAGE,
112 "output-file|o=s" => \$OUTPUT_FILE,
113 ) or &Console_WriteError_InvalidOption;
115 &Console_Write_IntltoolHelp if $HELP_ARG;
116 &Console_Write_IntltoolVersion if $VERSION_ARG;
118 my $arg_count = ($DIST_ARG > 0)
121 + ($MAINTAIN_ARG > 0)
124 &Console_Write_IntltoolHelp if $arg_count > 1;
126 my $PKGNAME = FindPackageName ();
128 # --version and --help don't require a module name
129 my $MODULE = $GETTEXT_PACKAGE || $PKGNAME || "unknown";
140 elsif ($MAINTAIN_ARG)
148 &Console_Write_CoverageReport;
150 elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
154 ## Report error if the language file supplied
155 ## to the command line is non-existent
156 &Console_WriteError_NotExisting("$SRCDIR/$lang.po")
157 if ! -s "$SRCDIR/$lang.po";
161 print "Working, please wait..." if $VERBOSE;
165 &POFile_Update ($lang, $OUTPUT_FILE);
166 &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
170 &Console_Write_IntltoolHelp;
177 sub Console_Write_IntltoolVersion
180 ${PROGRAM} (${PACKAGE}) $VERSION
181 Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
183 Copyright (C) 2000-2003 Free Software Foundation, Inc.
184 This is free software; see the source for copying conditions. There is NO
185 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
190 sub Console_Write_IntltoolHelp
193 Usage: ${PROGRAM} [OPTION]... LANGCODE
194 Updates PO template files and merge them with the translations.
196 Mode of operation (only one is allowed):
197 -p, --pot generate the PO template only
198 -s, --headers generate the header files in POTFILES.in
199 -m, --maintain search for left out files from POTFILES.in
200 -r, --report display a status report for the module
201 -d, --dist merge LANGCODE.po with existing PO template
204 -g, --gettext-package=NAME override PO template name, useful with --pot
205 -o, --output-file=FILE write merged translation to FILE
206 -x, --verbose display lots of feedback
207 --help display this help and exit
208 --version output version information and exit
211 ${PROGRAM} --pot just create a new PO template
212 ${PROGRAM} xy create new PO template and merge xy.po with it
214 Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
215 or send email to <xml-i18n-tools\@gnome.org>.
223 my $ret = `echo "$str"`;
225 $ret =~ s/\n$//; # do we need the "s" flag?
230 sub POFile_DetermineType ($)
235 my $xml_regex = "(?:" . $xml_support . ")";
236 my $ini_regex = "(?:" . $ini_support . ")";
237 my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
239 if ($type =~ /\[type: gettext\/([^\]].*)]/)
243 elsif ($type =~ /schemas(\.in)+$/)
245 $gettext_type="schemas";
247 elsif ($type =~ /glade2?(\.in)*$/)
249 $gettext_type="glade";
251 elsif ($type =~ /scm(\.in)*$/)
253 $gettext_type="scheme";
255 elsif ($type =~ /keys(\.in)+$/)
257 $gettext_type="keys";
262 elsif ($type =~ /$xml_regex$/)
266 elsif ($type =~ /$ini_regex$/)
270 elsif ($type =~ /$buildin_regex$/)
272 $gettext_type="buildin";
276 $gettext_type="unknown";
279 return "gettext\/$gettext_type";
282 sub TextFile_DetermineEncoding ($)
284 my $gettext_code="ASCII"; # All files are ASCII by default
285 my $filetype=`file $_ | cut -d ' ' -f 2`;
289 if ($filetype =~ /^(ISO|UTF)/)
291 chomp ($gettext_code = $filetype);
293 elsif ($filetype =~ /^XML/)
295 $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
299 return $gettext_code;
302 sub isNotValidMissing
306 return if $file =~ /^\{arch\}\/.*$/;
307 return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/;
314 @buf_i18n_xml_unmarked,
317 @buf_potfiles_ignore,
319 @buf_allfiles_sorted,
320 @buf_potfiles_sorted,
321 @buf_potfiles_ignore_sorted
324 ## Search and find all translatable files
326 push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/;
327 push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/;
328 push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/;
329 push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
333 open POTFILES, $POTFILES_in or die "$PROGRAM: there's no POTFILES.in!\n";
334 @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
337 foreach (@buf_potfiles) {
341 print "Searching for missing translatable files...\n" if $VERBOSE;
343 ## Check if we should ignore some found files, when
344 ## comparing with POTFILES.in
345 foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
347 (-s $ignore) or next;
349 if ("$ignore" eq "POTFILES.ignore")
351 print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
352 "content of this file to POTFILES.skip.\n";
355 print "Found $ignore: Ignoring files...\n" if $VERBOSE;
356 open FILE, "<$SRCDIR/$ignore" or die "ERROR: Failed to open $SRCDIR/$ignore!\n";
360 push @buf_potfiles_ignore, $_ unless /^(#|\s*$)/;
364 @buf_potfiles_ignore_sorted = sort (@buf_potfiles_ignore);
367 foreach my $file (@buf_i18n_plain)
375 # Handle continued multi-line comment.
378 next unless s-.*\*/--;
382 # Handle continued macro.
385 $in_macro = 0 unless /\\$/;
389 # Handle start of macro (or any preprocessor directive).
392 $in_macro = 1 if /^([^\\]|\\.)*\\$/;
396 # Handle comments and quoted text.
397 while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
408 elsif ($match eq "//")
414 if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-)
416 warn "mismatched quotes at line $. in $file\n";
422 if (/\w\.GetString *\(QUOTEDTEXT/)
424 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
425 ## Remove the first 3 chars and add newline
426 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
431 ## N_ Q_ and _ are the three macros defined in gi8n.h
432 if (/[NQ]?_ *\(QUOTEDTEXT/)
434 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
435 ## Remove the first 3 chars and add newline
436 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
444 foreach my $file (@buf_i18n_xml)
450 # FIXME: share the pattern matching code with intltool-extract
451 if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
453 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
454 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
462 foreach my $file (@buf_i18n_ini)
469 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
470 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
478 foreach my $file (@buf_i18n_xml_unmarked)
480 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
481 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
486 @buf_allfiles_sorted = sort (@buf_allfiles);
487 @buf_potfiles_sorted = sort (@buf_potfiles);
490 foreach (@buf_potfiles_sorted)
495 foreach (@buf_potfiles_ignore_sorted)
502 foreach (@buf_allfiles_sorted)
504 if (!exists($in2{$_}))
510 my @buf_potfiles_notexist;
512 foreach (@buf_potfiles_sorted)
514 chomp (my $dummy = $_);
515 if ("$dummy" ne "" and !(-f "$SRCDIR/../$dummy" or -f "../$dummy"))
517 push @buf_potfiles_notexist, $_;
521 ## Save file with information about the files missing
522 ## if any, and give information about this procedure.
523 if (@result + @buf_potfiles_notexist > 0)
527 print "\n" if $VERBOSE;
529 open OUT, ">missing";
532 warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n".
533 "\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n";
534 print STDERR @result, "\n";
535 warn "If some of these files are left out on purpose then please add them to\n".
536 "POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n".
537 "of left out files has been written in the current directory.\n";
539 if (@buf_potfiles_notexist)
542 open OUT, ">notexist";
543 print OUT @buf_potfiles_notexist;
545 warn "\n" if ($VERBOSE or @result);
546 warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
547 warn @buf_potfiles_notexist, "\n";
548 warn "Please remove them from POTFILES.in. A file \e[1m'notexist'\e[0m\n".
549 "containing this list of absent files has been written in the current directory.\n";
553 ## If there is nothing to complain about, notify the user
555 print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
559 sub Console_WriteError_InvalidOption
561 ## Handle invalid arguments
562 print STDERR "Try `${PROGRAM} --help' for more information.\n";
568 my $EXTRACT = "/home/milang/devel/mapper/intltool-extract";
571 $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} if $ENV{"INTLTOOL_EXTRACT"};
573 ## Generate the .h header files, so we can allow glade and
574 ## xml translation support
577 print STDERR "\n *** The intltool-extract script wasn't found!"
578 ."\n *** Without it, intltool-update can not generate files.\n";
583 open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
588 next if /^\[\s*encoding/;
590 ## Find xml files in POTFILES.in and generate the
591 ## files with help from the extract script
593 my $gettext_type= &POFile_DetermineType ($1);
595 if (/\.($xml_support|$ini_support)$/ || /^\[/)
599 my $filename = "../$_";
603 system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
604 "--type=$gettext_type", $filename);
608 system ($EXTRACT, "--update", "--type=$gettext_type",
609 "--srcdir=$SRCDIR", "--quiet", $filename);
618 # Generate .pot file from POTFILES.in
620 sub GeneratePOTemplate
622 my $XGETTEXT = $ENV{"XGETTEXT"} || "/usr/bin/xgettext";
623 my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
628 print STDERR " *** xgettext is not found on this system!\n".
629 " *** Without it, intltool-update can not extract strings.\n";
633 print "Building $MODULE.pot...\n" if $VERBOSE;
635 open INFILE, $POTFILES_in;
636 unlink "POTFILES.in.temp";
637 open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
639 my $gettext_support_nonascii = 0;
641 # checks for GNU gettext >= 0.12
642 my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
645 $gettext_support_nonascii = 1;
649 # urge everybody to upgrade gettext
650 print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n".
651 " strings. That means you should install a version of gettext\n".
652 " that supports non-ASCII strings (such as GNU gettext >= 0.12),\n".
653 " or have to let non-ASCII strings untranslated. (If there is any)\n";
656 my $encoding = "ASCII";
657 my $forced_gettext_code;
659 my $encoding_problem_is_reported = 0;
663 next if (/^#/ or /^\s*$/);
669 if (/^\[\s*encoding:\s*(.*)\s*\]/)
671 $forced_gettext_code=$1;
673 elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
676 print OUTFILE "../$_.h\n";
677 push @temp_headers, "../$_.h";
678 $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
682 print OUTFILE "$SRCDIR/../$_\n";
683 $gettext_code = &TextFile_DetermineEncoding ("$SRCDIR/../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
686 next if (! $gettext_support_nonascii);
688 if (defined $forced_gettext_code)
690 $encoding=$forced_gettext_code;
692 elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
694 if ($encoding eq "ASCII")
696 $encoding=$gettext_code;
698 elsif ($gettext_code ne "ASCII")
700 # Only report once because the message is quite long
701 if (! $encoding_problem_is_reported)
703 print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
704 " but $PROGRAM thinks that most of the source files are in\n".
705 " $encoding encoding, while \"$_\" is (likely) in\n".
706 " $gettext_code encoding. If you are sure that all translatable strings\n".
707 " are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
708 " line to POTFILES.in:\n\n".
709 " [encoding: UTF-8]\n\n".
710 " and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
711 "(such warning message will only be reported once.)\n";
712 $encoding_problem_is_reported = 1;
721 unlink "$MODULE.pot";
722 my @xgettext_argument=("$XGETTEXT",
725 "--output\=$MODULE\.pot",
726 "--files-from\=\.\/POTFILES\.in\.temp");
727 my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
728 push @xgettext_argument, $XGETTEXT_KEYWORDS;
729 my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
730 push @xgettext_argument, "--msgid-bugs-address\=$MSGID_BUGS_ADDRESS" if $MSGID_BUGS_ADDRESS;
731 push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
732 push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
733 my $xgettext_command = join ' ', @xgettext_argument;
735 # intercept xgettext error message
736 print "Running $xgettext_command\n" if $VERBOSE;
737 my $xgettext_error_msg = `$xgettext_command 2>\&1`;
738 my $command_failed = $?;
740 unlink "POTFILES.in.temp";
742 print "Removing generated header (.h) files..." if $VERBOSE;
743 unlink foreach (@temp_headers);
744 print "done.\n" if $VERBOSE;
746 if (! $command_failed)
748 if (! -e "$MODULE.pot")
750 print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
754 print "Wrote $MODULE.pot\n" if $VERBOSE;
759 if ($xgettext_error_msg =~ /--from-code/)
761 # replace non-ASCII error message with a more useful one.
762 print STDERR "ERROR: xgettext failed to generate PO template file because there is non-ASCII\n".
763 " string marked for translation. Please make sure that all strings marked\n".
764 " for translation are in uniform encoding (say UTF-8), then \e[1m*prepend*\e[0m the\n".
765 " following line to POTFILES.in and rerun $PROGRAM:\n\n".
766 " [encoding: UTF-8]\n\n";
770 print STDERR "$xgettext_error_msg";
771 if (-e "$MODULE.pot")
774 print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
775 " Please consult error message above if there is any.\n";
779 print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
780 " error message above if there is any.\n";
789 -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
791 my $MSGMERGE = $ENV{"MSGMERGE"} || "/usr/bin/msgmerge";
792 my ($lang, $outfile) = @_;
794 print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
796 my $infile = "$SRCDIR/$lang.po";
797 $outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
799 # I think msgmerge won't overwrite old file if merge is not successful
800 system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
803 sub Console_WriteError_NotExisting
807 ## Report error if supplied language file is non-existing
808 print STDERR "$PROGRAM: $file does not exist!\n";
809 print STDERR "Try '$PROGRAM --help' for more information.\n";
815 my @po_files = glob ("./*.po");
817 @languages = map (&POFile_GetLanguage, @po_files);
819 foreach my $lang (@languages)
821 $po_files_by_lang{$lang} = shift (@po_files);
825 sub POFile_GetLanguage ($)
827 s/^(.*\/)?(.+)\.po$/$2/;
831 sub Console_Write_TranslationStatus
833 my ($lang, $output_file) = @_;
834 my $MSGFMT = $ENV{"MSGFMT"} || "/usr/bin/msgfmt";
836 $output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
838 system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
841 sub Console_Write_CoverageReport
843 my $MSGFMT = $ENV{"MSGFMT"} || "/usr/bin/msgfmt";
847 foreach my $lang (@languages)
850 &POFile_Update ($lang, "");
853 print "\n\n * Current translation support in $MODULE \n\n";
855 foreach my $lang (@languages)
858 system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
862 sub SubstituteVariable
866 # always need to rewind file whenever it has been accessed
869 # cache each variable. varhash is global to we can add
870 # variables elsewhere.
875 ($varhash{$1} = $2) =~ s/^["'](.*)["']$/$1/;
879 if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/)
884 # Ignore recursive definitions of variables
885 $sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
887 return SubstituteVariable ("$untouched$sub$rest");
890 # We're using Perl backticks ` and "echo -n" here in order to
891 # expand any shell escapes (such as backticks themselves) in every variable
892 return echo_n ($str);
897 my $base_dirname = getcwd();
898 $base_dirname =~ s@.*/@@;
900 my ($conf_in, $src_dir);
902 if ($base_dirname =~ /^po(-.+)?$/)
909 open (IN, "<Makevars") || die "can't open Makevars: $!";
913 if (/^top_builddir[ \t]*=/)
916 $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
919 if (-f "$src_dir" . "/configure.ac") {
920 $conf_in = "$src_dir" . "/configure.ac" . "\n";
922 $conf_in = "$src_dir" . "/configure.in" . "\n";
929 $conf_in || die "Cannot find top_builddir in Makevars.";
931 elsif (-f "../configure.ac")
933 $conf_in = "../configure.ac";
935 elsif (-f "../configure.in")
937 $conf_in = "../configure.in";
944 open (IN, "<Makefile") || return;
948 if (/^top_srcdir[ \t]*=/)
951 $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
954 $conf_in = "$src_dir" . "/configure.in" . "\n";
961 $conf_in || die "Cannot find top_srcdir in Makefile.";
964 open (CONF, "<$conf_in");
968 print STDERR "$PROGRAM: Unable to proceed.\n" .
969 "Make sure to run this script inside the po directory.\n";
977 my $domain = &FindMakevarsDomain;
978 my $name = $domain || "untitled";
984 open (IN, "<&CONF") || return $name;
986 local $/; # slurp mode
991 # priority for getting package name:
993 # 2. first argument of AC_INIT (with >= 2 arguments)
994 # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
996 # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m
997 # the \s makes this not work, why?
998 if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
1000 ($name, $version) = ($1, $2);
1001 $name =~ s/[\[\]\s]//g;
1002 $version =~ s/[\[\]\s]//g;
1003 $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
1004 $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
1005 $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
1006 $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
1009 if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m)
1011 ($name, $version) = ($1, $2);
1012 $name =~ s/[\[\]\s]//g;
1013 $version =~ s/[\[\]\s]//g;
1014 $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
1015 $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
1016 $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
1017 $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
1020 # \s makes this not work, why?
1021 $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
1023 # m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
1024 # as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
1025 $name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
1027 $name = $domain if $domain;
1029 $name = SubstituteVariable ($name);
1030 $name =~ s/^["'](.*)["']$/$1/;
1032 return $name if $name;
1039 my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_ --keyword\=Q\_";
1040 my $varname = "XGETTEXT_OPTIONS";
1043 open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
1045 local $/; # slurp mode
1046 $make_source = <IN>;
1050 $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
1055 sub FindMakevarsDomain
1059 my $makevars_source; {
1061 open (IN, "<Makevars") || return $domain;
1063 local $/; # slurp mode
1064 $makevars_source = <IN>;
1068 $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
1069 $domain =~ s/^\s+//;
1070 $domain =~ s/\s+$//;
1075 sub FindMakevarsBugAddress
1079 my $makevars_source; {
1081 open (IN, "<Makevars") || return undef;
1083 local $/; # slurp mode
1084 $makevars_source = <IN>;
1088 $address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
1089 $address =~ s/^\s+//;
1090 $address =~ s/\s+$//;