disable sd filters test for now
[LibreOffice.git] / oowintool
blobd8d340c7adbd8c23a7fc3a848ed73ebca0c0e795
1 #!/usr/bin/perl -w
3 use File::Copy;
5 my $output_format = 'u';
7 sub reg_get_value($)
9 # it is believed that the registry moves keys around
10 # depending on OS version, this will de-mangle that
11 my $key = shift;
12 my $fhandle;
13 my $value;
15 open ($fhandle, "/proc/registry/$key") || return;
16 # reg keys have 0x00 0x5c at the end
17 $value = (split /\0/, <$fhandle>)[0];
18 close ($fhandle);
20 if ( defined $value ) {
21 chomp ($value);
22 $value =~ s|\r\n||;
23 # print "Value '$value' at '$key'\n";
26 return $value;
29 sub reg_find_key($)
31 # it is believed that the registry moves keys around
32 # depending on OS version, this will de-mangle that
33 my $key = shift;
34 $key =~ s| |\\ |;
35 $key = `cd /proc/registry/ ; ls $key`;
37 return $key;
40 sub print_syntax()
42 print "oowintool [option] ...\n";
43 print " encoding options\n";
44 print " -w - windows form\n";
45 print " -u - unix form (default)\n";
46 print " commands:\n";
47 print " --msvc-ver - print version of MSVC eg. 6.0\n";
48 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
49 print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
50 print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
51 print " --msvc-productdir - print productdir\n";
52 print " --msvs-productdir - print productdir\n";
53 print " --dotnetsdk-dir - print .NET SDK path\n";
54 print " --csc-compilerdir - print .NET SDK compiler path\n";
55 print " --windows-sdk-home - print Windows SDK install dir\n";
56 print " --jdk-home - print the jdk install dir\n";
57 print " --nsis-dir - print NSIS path\n";
58 print " --help - print this message\n";
61 sub cygpath($$$)
63 my ($path, $input_format, $format) = @_;
65 return $path if ( ! defined $path );
66 # Strip trailing path separators
67 if ($input_format eq 'u') {
68 $path =~ s|/*\s*$||;
69 } else {
70 $path =~ s|\\*\s*$||;
73 # 'Unterminated quoted string errors' from 'ash' when
74 # forking cygpath so - reimplement cygpath in perl [ gack ]
75 if ($format eq 'u' && $input_format eq 'w') {
76 $path =~ s|\\|/|g;
77 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
79 elsif ($format eq 'w' && $input_format eq 'u') {
80 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
81 $path =~ s|/|\\|g;
84 return $path;
87 sub print_path($$)
89 my ($path, $unix) = @_;
91 $path = cygpath ($path, $unix, $output_format);
93 print $path;
96 sub print_windows_sdk_home()
98 my ($value, $key);
99 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.1/InstallationFolder');
100 if (!defined $value)
102 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
104 if (!defined $value)
106 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
108 if (!defined $value)
110 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
111 $value = reg_get_value ($key);
113 if (!defined $value)
115 my $dir = cygpath (find_msvc()->{'product_dir'}, 'w', $output_format);
116 $value = `/bin/find "$dir" -iname platformsdk | head -n 1`;
119 defined $value || die "Windows Sdk not found";
121 print cygpath ($value, 'w', $output_format);
124 my %msvs_2008 = (
125 'ver' => '9.0',
126 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
127 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
128 'dll_suffix' => '90'
130 my %msvc_2008 = (
131 'ver' => '9.0',
132 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
133 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
134 'dll_suffix' => '90'
136 my %msvs_express_2008 = (
137 'ver' => '9.0',
138 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
139 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
140 'dll_suffix' => '90'
142 my %msvc_express_2008 = (
143 'ver' => '9.0',
144 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
145 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
146 'dll_suffix' => '90'
148 my %msvs_2010 = (
149 'ver' => '10.0',
150 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
151 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
152 'dll_suffix' => '100'
154 my %msvc_2010 = (
155 'ver' => '10.0',
156 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
157 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
158 'dll_suffix' => '100'
161 sub find_msvs()
163 my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2010 );
165 for $ver (@ms_versions)
167 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
168 if (defined $install && $install ne '') {
169 $ver->{'product_dir'} = $install;
170 return $ver;
173 die "Can't find MS Visual Studio / VC++";
176 sub find_msvc()
178 my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2010 );
180 for $ver (@ms_versions)
182 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
183 if (defined $install && $install ne '') {
184 $ver->{'product_dir'} = $install;
185 return $ver;
188 die "Can't find MS Visual Studio / VC++";
191 sub print_msvc_ver()
193 my $ver = find_msvc();
194 print $ver->{'ver'};
197 sub print_msvc_product_dir()
199 my $ver = find_msvc();
200 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
203 sub print_msvs_productdir()
205 my $ver = find_msvs();
206 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
209 sub print_csc_compiler_dir()
211 my $dir = cygpath (reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
212 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
213 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
214 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
215 print `dirname $csc_exe`;
218 sub print_dotnetsdk_dir()
220 my $dir =
221 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
222 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
223 if ($dir) {
224 print cygpath ($dir, 'w', $output_format);
228 sub print_jdk_dir()
230 my $dir =
231 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
232 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
233 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
234 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
235 print cygpath($dir, 'w', $output_format);
238 sub print_nsis_dir()
240 my $dir = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/NSIS/@");
241 print cygpath ($dir, 'w', $output_format) if defined $dir;
244 sub copy_dll($$$)
246 my ($src, $fname, $dest) = @_;
248 -f "$src/$fname" || die "can't find $src";
249 -d $dest || die "no directory $dest";
251 print STDERR "Copying $src/$fname to $dest\n";
252 copy ("$src/$fname", $dest) || die "copy failed: $!";
253 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
256 sub msvc_find_version($)
258 my $checkpath = shift;
259 my $ver = find_msvc();
260 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
261 $ver->{$checkpath});
262 -d $srcdir && return $ver;
263 $ver = find_msvs();
264 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
265 $ver->{$checkpath});
266 -d $srcdir && return $ver;
267 return undef;
270 sub msvc_copy_dlls($)
272 my $dest = shift;
273 my $ver = msvc_find_version('dll_path');
274 defined $ver || return;
275 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
276 $ver->{'dll_path'});
278 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
279 $dest . $ver->{'dll_suffix'});
280 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
281 $dest . $ver->{'dll_suffix'});
282 if ($ver->{'dll_suffix'} == 90) {
283 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
284 $dest . $ver->{'dll_suffix'});
285 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
289 sub msvc_copy_msms($$)
291 # $postfix is empty for x86, and '_x64' for x64
292 my ($dest, $postfix) = @_;
293 my $common_files_path = $ENV{"CommonProgramFiles(x86)"};
294 if (!defined $common_files_path) {
295 $common_files_path = $ENV{CommonProgramFiles};
296 if (!defined $common_files_path) {
297 $common_files_path = "C:\\Program Files\\Common Files";
301 defined $common_files_path || die "Windows CommonProgramFiles not found";
303 my $msm_path = (cygpath $common_files_path . "\\Merge Modules", 'w', $output_format);
304 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
305 print STDERR "Copying $msm_path/$fname to $dest\n";
306 copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
310 if (!@ARGV) {
311 print_syntax();
312 exit 1;
315 my @commands = ();
316 my $opt;
317 while (@ARGV) {
318 $opt = shift @ARGV;
320 if ($opt eq '-w' || $opt eq '-u') {
321 $output_format = substr($opt, 1, 1);
322 } else {
323 push @commands, $opt;
327 while (@commands) {
328 $opt = shift @commands;
330 if (0) {
331 } elsif ($opt eq '--msvc-ver') {
332 print_msvc_ver();
333 } elsif ($opt eq '--msvc-copy-dlls') {
334 my $dest = shift @commands;
335 defined $dest || die "copy-dlls requires a destination directory";
336 msvc_copy_dlls( $dest );
337 } elsif ($opt eq '--msvc-copy-msms') {
338 my $dest = shift @commands;
339 defined $dest || die "copy-msms requires a destination directory";
340 msvc_copy_msms( $dest, '' );
341 } elsif ($opt eq '--msvc-copy-msms-64') {
342 my $dest = shift @commands;
343 defined $dest || die "copy-msms-64 requires a destination directory";
344 msvc_copy_msms( $dest, '_x64' );
345 } elsif ($opt eq '--msvs-productdir') {
346 print_msvs_productdir();
347 } elsif ($opt eq '--msvc-productdir') {
348 print_msvc_product_dir();
349 } elsif ($opt eq '--dotnetsdk-dir') {
350 print_dotnetsdk_dir();
351 } elsif ($opt eq '--csc-compilerdir') {
352 print_csc_compiler_dir();
353 } elsif ($opt eq '--windows-sdk-home') {
354 print_windows_sdk_home();
355 } elsif ($opt eq '--jdk-home') {
356 print_jdk_dir();
357 } elsif ($opt eq '--nsis-dir') {
358 print_nsis_dir();
359 } elsif ($opt eq '--help' || $opt eq '/?') {
360 print_syntax();
361 } else {
362 print "Unknown option '$opt'\n";
363 print_syntax();
364 exit 1;