1 eval 'exec perl -wS $0 ${1+\"$@\"}'
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
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.
42 use English
; # $OSNAME, ...
48 our $help; # Help option flag
49 our $version; # Version option flag
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.
65 our $version_info = 'compare.pl';
68 "ghostscript" => \
$ghostscript,
69 "imagemagick" => \
$imagemagick,
71 "printerdriver" => \
$printerdriver,
72 "verbose" => \
$verbose,
75 "version" => \
$version
83 # Check for version option
86 print STDERR
"$version_info\n";
90 # prepare the GlobalIniFile
94 my $sEnv = "$ENV{PRJ}";
97 print "Warning: Seems you are not in a makefile.mk environment.\n";
100 my $sPath = getcwd
();
101 $sPath .= "/" . $sEnv;
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);
114 $path =~ s/\\/\//g; # make out of '\' a '/'
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($$)
123 my $sPathList = shift;
126 if ($OSNAME eq "MSWin32")
130 my @path = split($sep, $sPathList);
135 my $olddir = getcwd();
137 my $sWindowsHomeDir = unixpath(lc($ENV{WINDIR}));
139 foreach $startdir (@path)
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);
156 if (opendir (DIR, $startdir)) # open directory
158 print "path: $startdir" if ($verbose);
162 while ($myfile = readdir(DIR)) # get filename
164 if (-f $myfile ) # is it a file?
167 if ($myfile eq $sFile) # is it the real file?
176 print " ($nCount)\n" if ($verbose);
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
204 $error = $error / 256;
208 $error = $error - 256;
213 # for every error we increment this variable by 1
214 our $nGlobalErrors = 0;
222 print "ERROR: search for $sText has failed with Errornumber: $error\n";
227 sub convertCygwinPath
($)
231 if ($OSNAME eq "cygwin")
233 # print "Cygwin Path Patch.\n" if ($verbose);
234 if ($sPath =~ /\/cygdrive\
/(.)/)
237 $sPath =~ s/\/cygdrive\/${Letter
}/${Letter}\:/;
238 # print "Cygwin Path Patch: '$sPath'\n" if ($verbose);
244 # append key=value to GlobalIniFile
250 $sValue = convertCygwinPath
($sValue);
251 my $sIniFile = convertCygwinPath
($sGlobalIniFile);
253 if (open(INIFILE
, ">>" . $sIniFile ))
255 print INIFILE
"$sKey=$sValue\n";
265 my $sIniFile = convertCygwinPath
($sGlobalIniFile);
266 if (open(INIFILE
, $sIniFile))
269 while ($line = <INIFILE
>)
272 if ( $line =~ /^$sKey=(.*)$/ )
275 # print INIFILE "$sKey=$sValue\n";
283 sub checkForGhostscript
()
285 print "Search for Ghostscript\n" if ($verbose);
286 if ($OSNAME eq "linux" ||
287 $OSNAME eq "solaris")
289 # search for ghostscript
291 if (open(GHOSTSCRIPT
, "which gs 2>&1 |"))
294 while ($line = <GHOSTSCRIPT
>)
297 print "- $line\n" if ($verbose);
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");
311 $sGSPath = searchForFileInPath
($sGSExe, $ENV{PATH
});
313 if ( ! -e
"$sGSPath/$sGSExe")
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";
321 insertPath
("gs.path", $sGSPath);
322 insertPath
("gs.exe", $sGSExe);
325 if ( -e
"$sGSPath/$sGSExe" )
327 print "Found Ghostscript: '$sGSPath'\n" if ($verbose);
332 print "ERROR: Check for Ghostscript failed, due to unsupported '$OSNAME' environment.\n";
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
};
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";
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
367 if (open(IMAGEMAGICK
, "which convert 2>&1 |"))
370 while ($line = <IMAGEMAGICK
>)
373 print "- $line\n" if ($verbose);
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")
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";
398 insertPath
("imagemagick.path", $sImageMagickPath);
399 # insertPath("gs.exe", $sImageMagickExe);
404 # next try, search image magick in $PROGRAMFILES
405 my $sPrograms = unixpath
($ENV{PROGRAMFILES
});
409 print "There exist no \$PROGRAMFILES path, wrong Windows version?\n";
415 if (opendir (DIR
, $sPrograms)) # open program directory
418 while ($myfile = readdir(DIR
)) # get a filename
420 if ($myfile =~ /ImageMagick/)
422 $sImageMagickPath = $sPrograms . "/" . $myfile;
428 if (! -e
$sImageMagickPath)
430 print "ImageMagick not found.\n";
435 insertPath
("imagemagick.path", $sImageMagickPath);
441 if ( -e
"$sImageMagickPath/$sImageMagickExe" )
443 print "Found ImageMagick: '$sImageMagickPath'\n" if ($verbose);
448 print "ERROR: not supported environment\n";
454 print "Search for Java6\n" if ($verbose);
455 my $javaexe = "java";
458 $javaexe = $ENV{JAVA6
};
461 if ($OSNAME eq "linux" || $OSNAME eq "cygwin")
463 # search for imagemagick
465 if (open(JAVA
, "$javaexe -version 2>&1 |"))
468 while ($line = <JAVA
>)
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";
481 print "It is possible to overwrite the java exe with environment variable JAVA6='path'.\n";
485 insertPath
("java.exe", $javaexe);
492 my $error = errorAdaption
($?
);
493 handleError
($error, "Java");
495 elsif ($OSNAME eq "MSWin32")
497 my $javaexe = "java";
500 $javaexe = $ENV{JAVA6
};
505 print "Java not found.\n";
510 print "Found Java: '$javaexe'\n" if ($verbose);
511 insertPath
("java.exe", $javaexe);
516 print "ERROR: Java not found.\n";
521 print "Environment '$OSNAME'\n" if ($verbose);
529 checkForGhostscript
();
533 checkForImageMagick
();
540 # return with found errors
541 exit($nGlobalErrors);
543 # ------------------------------------------------------------------------------
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
559 -h, --help Print this help, then exit
560 -v, --version Print version number, then exit