Bump version to 4.1-6
[LibreOffice.git] / scp2 / macros / macro.pl
blobe86623c454d4bfb1cf45bda480118fc159af568b
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};
25 if ( !defined $completelangiso_var) {
26 print STDERR "ERROR: No language defined!\n";
27 exit 1;
30 if (!args_require_build()) {
31 print STDERR "No new languages, or config. Keeping old file\n";
32 exit 0;
35 my @completelangiso = split " +", $completelangiso_var;
36 my @helplangs = split " +", $ENV{HELP_LANGS};
38 open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
40 print OUTFILE "// generated file, do not edit\n\n";
41 print OUTFILE "// languages used for last time generation\n";
42 print OUTFILE "// completelangiso: $completelangiso_var\n\n";
43 write_ALL_LANG();
44 write_OTHER_LANGS();
45 write_DIR_ISOLANGUAGE_ALL_LANG_2();
46 write_DIR_ISOLANGUAGE_ALL_LANG();
47 write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ();
48 write_EXTRA_ALL_LANG();
49 write_EXTRA_ALL_LANG_BUT_EN_US();
50 write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG();
51 write_RESFILE_ALL_LANG();
52 write_README_ALL_LANG();
53 write_README_TXT_ALL_LANG();
54 write_FILE_ALL_LANG_LETTER();
56 close OUTFILE;
58 rename $outfile, $destfile;
60 sub write_ALL_LANG
62 print OUTFILE "#define ALL_LANG(ident, resid) ";
63 foreach $lang (@completelangiso) {
64 print OUTFILE "\\\n\tident ($lang) = resid";
65 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
67 print OUTFILE "\n\n";
70 sub write_OTHER_LANGS
72 print OUTFILE "#define OTHER_LANGS ";
73 foreach $lang (@completelangiso) {
74 next if ( $lang eq "en-US");
75 print OUTFILE "\\\n\tDosName ($lang) = \"$lang\"";
76 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
78 print OUTFILE "\n\n";
81 sub write_DIR_ISOLANGUAGE_ALL_LANG_2
83 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_2 ";
84 print OUTFILE "\\\n\tDosName (en-US) = \"en-US\"; \\\n\t";
85 print OUTFILE "OTHER_LANGS";
86 print OUTFILE "\n\n";
89 sub write_DIR_ISOLANGUAGE_ALL_LANG
91 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG ";
92 print OUTFILE "\\\n\tDosName (en-US) = \"en\"; \\\n\t";
93 print OUTFILE "OTHER_LANGS";
94 print OUTFILE "\n\n";
97 sub write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ
99 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_LPROJ ";
100 foreach $lang (@completelangiso) {
101 my $speciallang = $lang;
102 if ( $speciallang eq "en-US" ) { $speciallang = "en"; }
103 print OUTFILE "\\\n\tDosName ($lang) = \"$speciallang.lproj\"";
104 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
106 print OUTFILE "\n\n";
109 sub write_EXTRA_ALL_LANG
111 print OUTFILE "#define EXTRA_ALL_LANG(name,ext) ";
112 foreach $lang (@completelangiso) {
113 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
114 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
116 print OUTFILE "\n\n";
119 sub write_EXTRA_ALL_LANG_BUT_EN_US
121 print OUTFILE "#define EXTRA_ALL_LANG_BUT_EN_US(name,ext) ";
122 my $first = 1;
123 foreach $lang (@completelangiso) {
124 if ($lang ne "en-US") {
125 print OUTFILE "; " unless $first;
126 $first = 0;
127 print OUTFILE
128 "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
131 print OUTFILE "\n\n";
134 sub write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG
136 my $first = 1;
137 print OUTFILE "#define EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(name) ";
138 foreach $lang (@helplangs) {
139 print OUTFILE ";" unless $first;
140 $first = 0;
141 print OUTFILE "\\\n\tName ($lang) = EXTRAFILELISTNAME(HelpTarget/,name,/$lang)";
143 print OUTFILE "\n\n";
146 sub write_RESFILE_ALL_LANG
148 print OUTFILE "#define RESFILE_ALL_LANG(name) ";
149 foreach $lang (@completelangiso) {
150 print OUTFILE "\\\n\tName ($lang) = RESFILENAME(name,$lang)";
151 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
153 print OUTFILE "\n\n";
156 sub write_README_ALL_LANG
158 print OUTFILE "#define README_ALL_LANG(key, name) ";
159 foreach $lang (@completelangiso) {
160 print OUTFILE "\\\n\tkey ($lang) = READMEFILENAME(name,_$lang)";
161 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
163 print OUTFILE "\n\n";
166 sub write_README_TXT_ALL_LANG
168 print OUTFILE "#define README_TXT_ALL_LANG(key, name, ext) ";
169 foreach $lang (@completelangiso) {
170 print OUTFILE "\\\n\tkey ($lang) = READMETXTFILENAME(name,_$lang,ext)";
171 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
173 print OUTFILE "\n\n";
176 sub write_FILE_ALL_LANG_LETTER
178 print OUTFILE "#define FILE_ALL_LANG_LETTER(name, ext) ";
179 foreach $lang (@completelangiso) {
180 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,$lang,ext)";
181 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
183 print OUTFILE "\n\n";
186 sub args_require_build
188 while (@ARGV) {
189 $opt = shift @ARGV;
190 $destfile = shift @ARGV if ($opt eq '-o');
191 $config_stamp = shift @ARGV if ($opt eq '-c');
193 usage() if (!defined ($destfile) || !defined ($config_stamp));
194 $outfile = "$destfile.tmp";
196 if ( -f "$destfile" ) {
197 # changed script - run always
198 return 1 if (stat($0))[9] > (stat("$destfile"))[9] ;
200 # changed config timestamp - run always
201 if (-f "$config_stamp") {
202 return 1 if (stat($config_stamp))[9] > (stat($destfile))[9];
205 open OLDFILE, "$destfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
206 while ( $line = <OLDFILE> ) {
207 if ( $line =~ /^\/\/.*completelangiso:/ ) {
208 $lastcompletelangiso_var = $line;
209 chomp $lastcompletelangiso_var;
210 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
211 last;
215 close OLDFILE;
217 return 0 if ( "$completelangiso_var" eq "$lastcompletelangiso_var" );
219 return 1;
222 sub usage
224 print STDERR "Generate language dependend macros use in *.scp files\n";
225 print STDERR "perl $0 -o <outputfile> -c <config_stamp_file>\n";
226 exit 1;