jl165 merging heads
[LibreOffice.git] / testgraphical / prechecks / softwaretests.pl
blobf591fa13987980d7c31fc098e8980ecdbfce7f01
1 eval 'exec perl -wS $0 ${1+\"$@\"}'
2 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
31 # This is a pre check, which checks if some extra software exists
33 BEGIN
35 # Adding the path of this script file to the include path in the hope
36 # that all used modules can be found in it.
37 $0 =~ /^(.*)[\/\\]/;
38 push @INC, $1;
41 use strict;
42 use English; # $OSNAME, ...
43 use Getopt::Long;
44 use Cwd;
45 use Cwd 'chdir';
46 my $cwd = getcwd();
48 our $help; # Help option flag
49 our $version; # Version option flag
51 # flush STDOUT
52 # my $old_handle = select (STDOUT); # "select" STDOUT and save # previously selected handle
53 # $| = 1; # perform flush after each write to STDOUT
54 # select ($old_handle); # restore previously selected handle
56 $OUTPUT_AUTOFLUSH=1; # works only if use English is used.
58 our $sGlobalIniFile;
59 our $verbose = 0;
60 our $ghostscript;
61 our $imagemagick;
62 our $java6;
63 our $printerdriver;
65 our $version_info = 'compare.pl';
67 GetOptions(
68 "ghostscript" => \$ghostscript,
69 "imagemagick" => \$imagemagick,
70 "java6" => \$java6,
71 "printerdriver" => \$printerdriver,
72 "verbose" => \$verbose,
74 "help" => \$help,
75 "version" => \$version
78 if ($help)
80 print_usage(*STDOUT);
81 exit(0);
83 # Check for version option
84 if ($version)
86 print STDERR "$version_info\n";
87 exit(0);
90 # prepare the GlobalIniFile
92 sub prepare()
94 my $sEnv = "$ENV{PRJ}";
95 if (! $sEnv)
97 print "Warning: Seems you are not in a makefile.mk environment.\n";
98 $sEnv = "..";
100 my $sPath = getcwd();
101 $sPath .= "/" . $sEnv;
102 chdir ($sPath);
103 cwd();
104 $sPath = getcwd();
105 my $sInpath = $ENV{INPATH};
106 $sPath .= "/" . $sInpath . "/misc";
107 $sGlobalIniFile = "$sPath/pathes.ini";
108 print "Global Path ini file is: $sGlobalIniFile\n" if ($verbose);
111 sub unixpath($)
113 my $path = shift;
114 $path =~ s/\\/\//g; # make out of '\' a '/'
115 return $path;
118 # search for file in a given path list.
119 # the path list should be separated as the path variable in the corresponding OS
120 sub searchForFileInPath($$)
122 my $sFile = shift;
123 my $sPathList = shift;
125 my $sep = ':';
126 if ($OSNAME eq "MSWin32")
128 $sep = ';';
130 my @path = split($sep, $sPathList);
132 my $sPath;
133 my $startdir;
134 my $bFound = 0;
135 my $olddir = getcwd();
137 my $sWindowsHomeDir = unixpath(lc($ENV{WINDIR}));
139 foreach $startdir (@path)
141 my $nCount = 0;
143 # IMPORTANT: leave out windir path.
145 if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
147 my $sPath = unixpath(lc(convertCygwinPath($startdir)));
148 if ($sPath =~ /^$sWindowsHomeDir/ )
150 print "path: $startdir is windows path leave out.\n" if ($verbose);
151 next;
155 local *DIR;
156 if (opendir (DIR, $startdir)) # open directory
158 print "path: $startdir" if ($verbose);
159 chdir ($startdir);
160 cwd();
161 my $myfile;
162 while ($myfile = readdir(DIR)) # get filename
164 if (-f $myfile ) # is it a file?
166 $nCount ++;
167 if ($myfile eq $sFile) # is it the real file?
169 $sPath = $startdir;
170 $bFound = 1;
171 last;
175 closedir(DIR);
176 print " ($nCount)\n" if ($verbose);
178 if ($bFound == 1)
180 last;
183 chdir ($olddir);
184 cwd();
186 return $sPath;
190 prepare();
191 # don't remove the inifile, only build clean should do this.
192 # if ( -e "$sGlobalIniFile")
194 # unlink($sGlobalIniFile);
198 # small helper, which replaces the return code
199 sub errorAdaption($)
201 my $error = shift;
202 if ($error != 0)
204 $error = $error / 256;
206 if ($error > 127)
208 $error = $error - 256;
210 return $error;
213 # for every error we increment this variable by 1
214 our $nGlobalErrors = 0;
216 sub handleError($$)
218 my $error = shift;
219 my $sText = shift;
220 if ($error != 0)
222 print "ERROR: search for $sText has failed with Errornumber: $error\n";
223 $nGlobalErrors ++;
227 sub convertCygwinPath($)
229 my $sPath = shift;
231 if ($OSNAME eq "cygwin")
233 # print "Cygwin Path Patch.\n" if ($verbose);
234 if ($sPath =~ /\/cygdrive\/(.)/)
236 my $Letter = $1;
237 $sPath =~ s/\/cygdrive\/${Letter}/${Letter}\:/;
238 # print "Cygwin Path Patch: '$sPath'\n" if ($verbose);
241 return $sPath;
244 # append key=value to GlobalIniFile
245 sub insertPath($$)
247 my $sKey = shift;
248 my $sValue = shift;
250 $sValue = convertCygwinPath($sValue);
251 my $sIniFile = convertCygwinPath($sGlobalIniFile);
252 local *INIFILE;
253 if (open(INIFILE, ">>" . $sIniFile ))
255 print INIFILE "$sKey=$sValue\n";
257 close(INIFILE);
260 sub getFastPath($)
262 my $sKey = shift;
263 my $sValue;
264 local *INIFILE;
265 my $sIniFile = convertCygwinPath($sGlobalIniFile);
266 if (open(INIFILE, $sIniFile))
268 my $line;
269 while ($line = <INIFILE>)
271 chomp($line);
272 if ( $line =~ /^$sKey=(.*)$/ )
274 $sValue = $1;
275 # print INIFILE "$sKey=$sValue\n";
278 close(INIFILE);
280 return $sValue;
283 sub checkForGhostscript()
285 print "Search for Ghostscript\n" if ($verbose);
286 if ($OSNAME eq "linux" ||
287 $OSNAME eq "solaris")
289 # search for ghostscript
290 local *GHOSTSCRIPT;
291 if (open(GHOSTSCRIPT, "which gs 2>&1 |"))
293 my $line;
294 while ($line = <GHOSTSCRIPT>)
296 chomp($line);
297 print "- $line\n" if ($verbose);
299 close(GHOSTSCRIPT);
301 my $error = errorAdaption($?);
302 handleError($error, "Ghostscript");
304 elsif ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
306 my $sGSExe = "gswin32c.exe";
307 # my $sGSPath = "C:/gs/gs8.64/bin";
308 my $sGSPath = getFastPath("gs.path");
309 if (! $sGSPath)
311 $sGSPath = searchForFileInPath($sGSExe, $ENV{PATH});
313 if ( ! -e "$sGSPath/$sGSExe")
315 $nGlobalErrors ++;
316 print "ERROR: search for $sGSPath/$sGSExe failed.\n";
317 print "Please install ghostscript from www.adobe.com to and make it available in \$PATH variable \n";
319 else
321 insertPath("gs.path", $sGSPath);
322 insertPath("gs.exe", $sGSExe);
325 if ( -e "$sGSPath/$sGSExe" )
327 print "Found Ghostscript: '$sGSPath'\n" if ($verbose);
330 else
332 print "ERROR: Check for Ghostscript failed, due to unsupported '$OSNAME' environment.\n";
333 $nGlobalErrors ++;
338 sub checkForPSDriver()
340 # we don't need to check for unix here, due to the fact, unix is per default be able to print in postscript
341 if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
343 print "Check for postscript driver.\n" if ($verbose);
344 my $sWindowsRoot = $ENV{windir};
345 if (! $sWindowsRoot)
347 $sWindowsRoot = $ENV{WINDIR};
349 my $sCrossOfficeDriver = "${sWindowsRoot}/system32/crossoffice.ppd";
350 if ( ! -e "$sCrossOfficeDriver")
352 print "ERROR: Don't found Postscript driver $sCrossOfficeDriver file\n";
353 $nGlobalErrors ++;
354 print "Take a look on: http://so-gfxcmp.germany.sun.com/docs/further/convwatch/convwatch.html.\n";
359 sub checkForImageMagick()
361 print "Search for Imagemagick\n" if ($verbose);
362 if ($OSNAME eq "linux" ||
363 $OSNAME eq "solaris")
365 # search for imagemagick
366 local *IMAGEMAGICK;
367 if (open(IMAGEMAGICK, "which convert 2>&1 |"))
369 my $line;
370 while ($line = <IMAGEMAGICK>)
372 chomp($line);
373 print "- $line\n" if ($verbose);
375 close(IMAGEMAGICK);
377 my $error = errorAdaption($?);
378 handleError($error, "Imagemagick");
380 elsif ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
382 my $sImageMagickExe = "convert.exe";
383 # my $sImageMagickPath = "C:/gs/gs8.64/bin";
384 my $sImageMagickPath = getFastPath("imagemagick.path");
385 if (! $sImageMagickPath)
387 $sImageMagickPath = searchForFileInPath($sImageMagickExe, $ENV{PATH});
388 if ($sImageMagickPath)
390 if ( ! -e "$sImageMagickPath/$sImageMagickExe")
392 $nGlobalErrors ++;
393 print "ERROR: search for $sImageMagickPath/$sImageMagickExe failed.\n";
394 print "Please install ImageMagick from www.imagemagick.org to and make it available in \$PATH variable \n";
396 else
398 insertPath("imagemagick.path", $sImageMagickPath);
399 # insertPath("gs.exe", $sImageMagickExe);
402 else
404 # next try, search image magick in $PROGRAMFILES
405 my $sPrograms = unixpath($ENV{PROGRAMFILES});
407 if (! $sPrograms)
409 print "There exist no \$PROGRAMFILES path, wrong Windows version?\n";
410 $nGlobalErrors++;
412 else
414 local *DIR;
415 if (opendir (DIR, $sPrograms)) # open program directory
417 my $myfile;
418 while ($myfile = readdir(DIR)) # get a filename
420 if ($myfile =~ /ImageMagick/)
422 $sImageMagickPath = $sPrograms . "/" . $myfile;
423 last;
426 closedir(DIR);
428 if (! -e $sImageMagickPath)
430 print "ImageMagick not found.\n";
431 $nGlobalErrors ++;
433 else
435 insertPath("imagemagick.path", $sImageMagickPath);
441 if ( -e "$sImageMagickPath/$sImageMagickExe" )
443 print "Found ImageMagick: '$sImageMagickPath'\n" if ($verbose);
446 else
448 print "ERROR: not supported environment\n";
452 sub checkForJava6()
454 print "Search for Java6\n" if ($verbose);
455 my $javaexe = "java";
456 if ( $ENV{JAVA6} )
458 $javaexe = $ENV{JAVA6};
461 if ($OSNAME eq "linux" || $OSNAME eq "cygwin")
463 # search for imagemagick
464 local *JAVA;
465 if (open(JAVA, "$javaexe -version 2>&1 |"))
467 my $line;
468 while ($line = <JAVA>)
470 chomp($line);
471 print "- $line\n" if ($verbose);
472 if ( $line =~ /java version "(.*)"/ )
474 my $javaversion = $1;
475 my @version = split('\.', $javaversion);
476 print "Found Java version: $version[1] the complete version: $javaversion\n" if ($verbose);
477 if ( $version[1] < 6)
479 print "Wrong Java version, at least Java version 6 is need but found $javaversion.\n";
480 $nGlobalErrors++;
481 print "It is possible to overwrite the java exe with environment variable JAVA6='path'.\n";
483 else
485 insertPath("java.exe", $javaexe);
487 last;
490 close(JAVA);
492 my $error = errorAdaption($?);
493 handleError($error, "Java");
495 elsif ($OSNAME eq "MSWin32")
497 my $javaexe = "java";
498 if ( $ENV{JAVA6} )
500 $javaexe = $ENV{JAVA6};
503 if (! -e $javaexe)
505 print "Java not found.\n";
506 $nGlobalErrors ++;
508 else
510 print "Found Java: '$javaexe'\n" if ($verbose);
511 insertPath("java.exe", $javaexe);
514 else
516 print "ERROR: Java not found.\n";
520 # different checks
521 print "Environment '$OSNAME'\n" if ($verbose);
523 if ($printerdriver)
525 checkForPSDriver();
527 if ($ghostscript)
529 checkForGhostscript();
531 if ($imagemagick)
533 checkForImageMagick();
535 if ($java6)
537 checkForJava6();
540 # return with found errors
541 exit($nGlobalErrors);
543 # ------------------------------------------------------------------------------
544 sub print_usage(*)
546 local *HANDLE = $_[0];
547 my $tool_name = basename($0);
549 print(HANDLE <<END_OF_USAGE);
551 Usage: $tool_name [OPTIONS]
553 -ghostscript Try to find ghostscript in your environment
554 -imagemagick Try to find imagemagick
555 -java6 Checks for java 1.6.x
556 -printerdriver Try to find printer driver, windows only
557 -verbose be verbose
559 -h, --help Print this help, then exit
560 -v, --version Print version number, then exit
562 END_OF_USAGE