Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / scp2 / macros / macro.pl
blob7f54298f9a3e2decf5677285237c4f51e3ac72cd
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 my $outfile;
20 my $destfile;
21 my $config_stamp;
22 my $lastcompletelangiso_var;
23 my $completelangiso_var = $ENV{COMPLETELANGISO_VAR};
24 my $help_langs_var = $ENV{HELP_LANGS};
26 if ( !defined $completelangiso_var) {
27 print STDERR "ERROR: No language defined!\n";
28 exit 1;
31 if (!args_require_build()) {
32 print STDERR "No new languages, or config. Keeping old file\n";
33 exit 0;
36 my @completelangiso = split " +", $completelangiso_var;
37 my @helplangs = split " +", $help_langs_var;
39 open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
41 print OUTFILE "// generated file, do not edit\n\n";
42 print OUTFILE "// languages used for last time generation\n";
43 print OUTFILE "// completelangiso: $completelangiso_var\n\n";
44 print OUTFILE "// help_langs: $help_langs_var\n\n";
45 write_ITERATE_ALL_LANG();
46 write_ALL_LANG();
47 write_OTHER_LANGS();
48 write_DIR_ISOLANGUAGE_ALL_LANG_2();
49 write_DIR_ISOLANGUAGE_ALL_LANG();
50 write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ();
51 write_EXTRA_ALL_LANG();
52 write_EXTRA_ALL_LANG_BUT_EN_US();
53 write_MO_ALL_LANG_EXCEPT_EN_US_AND_QTZ();
54 write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG();
55 write_RESFILE_ALL_LANG();
56 write_README_ALL_LANG();
57 write_README_TXT_ALL_LANG();
58 write_FILE_ALL_LANG_LETTER();
60 close OUTFILE;
62 rename $outfile, $destfile;
64 sub write_ITERATE_ALL_LANG
66 print OUTFILE "#define ITERATE_ALL_LANG_FILE(gid,dir,macro,name,ext) ";
67 foreach $lang (@helplangs) {
68 my $shortlang = $lang;
69 $shortlang = "en" if $shortlang eq "en-US";
70 my $speciallang = $lang;
71 $speciallang =~ s/-/_/;
72 print OUTFILE "\\\nFile CONCAT3(gid_File_,gid,_$speciallang)";
73 print OUTFILE "\\\n\tDir = CONCAT3(gid_Dir_,dir,_$speciallang);";
74 print OUTFILE "\\\n\tmacro;";
75 print OUTFILE "\\\n\tName = STRING(CONCAT3(name,_$lang,ext)); ";
76 print OUTFILE "\\\nEnd ";
77 print OUTFILE "\\\n";
79 print OUTFILE "\n\n";
81 print OUTFILE "#define ITERATE_ALL_LANG_DIR_LPROJ(gid,parent) ";
82 foreach $lang (@helplangs) {
83 my $shortlang = $lang;
84 $shortlang = "en" if $shortlang eq "en-US";
85 my $speciallang = $lang;
86 $speciallang =~ s/-/_/;
87 print OUTFILE "\\\nDirectory CONCAT3(gid_Dir_,gid,_$speciallang)";
88 print OUTFILE "\\\n\tParentID = CONCAT2(gid_Dir_,parent);";
89 print OUTFILE "\\\n\tDosName = \"$shortlang.lproj\"; ";
90 print OUTFILE "\\\nEnd ";
91 print OUTFILE "\\\n";
93 print OUTFILE "\n\n";
96 sub write_ALL_LANG
98 print OUTFILE "#define ALL_LANG(ident, resid) ";
99 foreach $lang (@completelangiso) {
100 print OUTFILE "\\\n\tident ($lang) = resid";
101 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
103 print OUTFILE "\n\n";
106 sub write_OTHER_LANGS
108 print OUTFILE "#define OTHER_LANGS ";
109 foreach $lang (@completelangiso) {
110 next if ( $lang eq "en-US");
111 print OUTFILE "\\\n\tDosName ($lang) = \"$lang\"";
112 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
114 print OUTFILE "\n\n";
117 sub write_DIR_ISOLANGUAGE_ALL_LANG_2
119 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_2 ";
120 print OUTFILE "\\\n\tDosName (en-US) = \"en-US\"; \\\n\t";
121 print OUTFILE "OTHER_LANGS";
122 print OUTFILE "\n\n";
125 sub write_DIR_ISOLANGUAGE_ALL_LANG
127 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG ";
128 print OUTFILE "\\\n\tDosName (en-US) = \"en\"; \\\n\t";
129 print OUTFILE "OTHER_LANGS";
130 print OUTFILE "\n\n";
133 sub write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ
135 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_LPROJ ";
136 foreach $lang (@completelangiso) {
137 my $speciallang = $lang;
138 if ( $speciallang eq "en-US" ) { $speciallang = "en"; }
139 print OUTFILE "\\\n\tDosName ($lang) = \"$speciallang.lproj\"";
140 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
142 print OUTFILE "\n\n";
145 sub write_EXTRA_ALL_LANG
147 print OUTFILE "#define EXTRA_ALL_LANG(name,ext) ";
148 foreach $lang (@completelangiso) {
149 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
150 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
152 print OUTFILE "\n\n";
155 sub write_EXTRA_ALL_LANG_BUT_EN_US
157 print OUTFILE "#define EXTRA_ALL_LANG_BUT_EN_US(name,ext) ";
158 my $first = 1;
159 foreach $lang (@completelangiso) {
160 if ($lang ne "en-US") {
161 print OUTFILE "; " unless $first;
162 $first = 0;
163 print OUTFILE
164 "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
167 print OUTFILE "\n\n";
170 sub write_MO_ALL_LANG_EXCEPT_EN_US_AND_QTZ
172 print OUTFILE "#define MO_ALL_LANG_EXCEPT_EN_US_AND_QTZ(name) ";
173 my $first = 1;
174 foreach $lang (@completelangiso) {
175 if (($lang ne "en-US") and ($lang ne "qtz")) {
176 print OUTFILE "; " unless $first;
177 $first = 0;
178 my $SRC_ROOT = $ENV{"SRC_ROOT"};
179 my $langdir = `$SRC_ROOT/solenv/bin/localestr $lang`;
180 chomp $langdir;
181 print OUTFILE
182 "\\\n\tName ($lang) = STRING(CONCAT3($langdir/LC_MESSAGES/,name,.mo))";
185 print OUTFILE "\n\n";
188 sub write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG
190 my $first = 1;
191 my $source;
192 if ($ENV{'ENABLE_HTMLHELP'} eq 'TRUE') {
193 $source = 'html-help'; # found in instsetoo_native/util/openoffice.lst.in's {filelistpath}/CustomTarget/helpcontent2/help3xsl/filelists
194 } else {
195 $source = 'HelpTarget';
197 print OUTFILE "#define EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(name) ";
198 foreach $lang (@helplangs) {
199 print OUTFILE ";" unless $first;
200 $first = 0;
201 print OUTFILE "\\\n\tName ($lang) = EXTRAFILELISTNAME($source/,name,/$lang)";
203 print OUTFILE "\n\n";
206 sub write_RESFILE_ALL_LANG
208 print OUTFILE "#define RESFILE_ALL_LANG(name) ";
209 foreach $lang (@completelangiso) {
210 print OUTFILE "\\\n\tName ($lang) = RESFILENAME(name,$lang)";
211 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
213 print OUTFILE "\n\n";
216 sub write_README_ALL_LANG
218 print OUTFILE "#define README_ALL_LANG(key, name) ";
219 foreach $lang (@completelangiso) {
220 print OUTFILE "\\\n\tkey ($lang) = READMEFILENAME(name,_$lang)";
221 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
223 print OUTFILE "\n\n";
226 sub write_README_TXT_ALL_LANG
228 print OUTFILE "#define README_TXT_ALL_LANG(key, name, ext) ";
229 foreach $lang (@completelangiso) {
230 print OUTFILE "\\\n\tkey ($lang) = READMETXTFILENAME(name,_$lang,ext)";
231 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
233 print OUTFILE "\n\n";
236 sub write_FILE_ALL_LANG_LETTER
238 print OUTFILE "#define FILE_ALL_LANG_LETTER(name, ext) ";
239 foreach $lang (@completelangiso) {
240 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,$lang,ext)";
241 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
243 print OUTFILE "\n\n";
246 sub args_require_build
248 while (@ARGV) {
249 $opt = shift @ARGV;
250 $destfile = shift @ARGV if ($opt eq '-o');
251 $config_stamp = shift @ARGV if ($opt eq '-c');
253 usage() if (!defined ($destfile) || !defined ($config_stamp));
254 $outfile = "$destfile.tmp";
256 if ( -f "$destfile" ) {
257 # changed script - run always
258 return 1 if (stat($0))[9] > (stat("$destfile"))[9] ;
260 # changed config timestamp - run always
261 if (-f "$config_stamp") {
262 return 1 if (stat($config_stamp))[9] > (stat($destfile))[9];
265 open OLDFILE, "$destfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
266 while ( $line = <OLDFILE> ) {
267 if ( $line =~ /^\/\/.*completelangiso:/ ) {
268 $lastcompletelangiso_var = $line;
269 chomp $lastcompletelangiso_var;
270 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
271 last;
275 close OLDFILE;
277 return 0 if ( "$completelangiso_var" eq "$lastcompletelangiso_var" );
279 return 1;
282 sub usage
284 print STDERR "Generate language dependent macros use in *.scp files\n";
285 print STDERR "perl $0 -o <outputfile> -c <config_stamp_file>\n";
286 exit 1;